use of com.google.wireless.android.sdk.stats.AndroidStudioEvent in project android by JetBrains.
the class NlUsageTrackerManagerTest method testBasicLogging.
public void testBasicLogging() {
UsageTracker usageTracker = mock(UsageTracker.class);
LinkedList<AndroidStudioEvent> logCalls = new LinkedList<>();
doAnswer(invocation -> {
logCalls.add(((AndroidStudioEvent.Builder) invocation.getArguments()[0]).build());
return null;
}).when(usageTracker).log(any());
DesignSurface surface = mock(DesignSurface.class);
when(surface.getLayoutType()).thenReturn(NlLayoutType.LAYOUT);
when(surface.getScreenMode()).thenReturn(DesignSurface.ScreenMode.BOTH);
when(surface.getScale()).thenReturn(0.50);
Configuration configuration = getConfigurationMock();
when(surface.getConfiguration()).thenReturn(configuration);
NlUsageTracker tracker = new NlUsageTrackerManager(SYNC_EXECUTOR, surface, usageTracker);
tracker.logAction(LayoutEditorEvent.LayoutEditorEventType.API_LEVEL_CHANGE);
assertEquals(1, logCalls.size());
AndroidStudioEvent studioEvent = logCalls.getFirst();
assertEquals(AndroidStudioEvent.EventCategory.LAYOUT_EDITOR, studioEvent.getCategory());
assertEquals(AndroidStudioEvent.EventKind.LAYOUT_EDITOR_EVENT, studioEvent.getKind());
assertEquals(LayoutEditorEvent.LayoutEditorEventType.API_LEVEL_CHANGE, studioEvent.getLayoutEditorEvent().getType());
// Verify state
LayoutEditorState state = studioEvent.getLayoutEditorEvent().getState();
assertEquals(LayoutEditorState.Type.LAYOUT, state.getType());
assertEquals(LayoutEditorState.Surfaces.BOTH, state.getSurfaces());
assertEquals(50, state.getConfigZoomLevel());
assertEquals("mock", state.getConfigApiLevel());
assertEquals(LayoutEditorState.Orientation.PORTRAIT, state.getConfigOrientation());
logCalls.clear();
tracker.logAction(LayoutEditorEvent.LayoutEditorEventType.RESTORE_ERROR_PANEL);
assertEquals(1, logCalls.size());
studioEvent = logCalls.getFirst();
assertEquals(LayoutEditorEvent.LayoutEditorEventType.RESTORE_ERROR_PANEL, studioEvent.getLayoutEditorEvent().getType());
}
use of com.google.wireless.android.sdk.stats.AndroidStudioEvent in project android by JetBrains.
the class NlUsageTrackerManagerTest method testRenderLogging.
public void testRenderLogging() {
UsageTracker usageTracker = mock(UsageTracker.class);
LinkedList<AndroidStudioEvent> logCalls = new LinkedList<>();
doAnswer(invocation -> {
logCalls.add(((AndroidStudioEvent.Builder) invocation.getArguments()[0]).build());
return null;
}).when(usageTracker).log(any());
DesignSurface surface = mock(DesignSurface.class);
when(surface.getLayoutType()).thenReturn(NlLayoutType.LAYOUT);
when(surface.getScreenMode()).thenReturn(DesignSurface.ScreenMode.BOTH);
when(surface.getScale()).thenReturn(0.50);
Configuration configuration = getConfigurationMock();
when(surface.getConfiguration()).thenReturn(configuration);
NlUsageTracker tracker = new NlUsageTrackerManager(SYNC_EXECUTOR, surface, usageTracker) {
@Override
boolean shouldLog(int percent) {
// Log everything in tests
return true;
}
};
Result renderResult = mock(Result.class);
when(renderResult.getStatus()).thenReturn(Result.Status.SUCCESS);
HtmlLinkManager linkManager = mock(HtmlLinkManager.class);
RenderLogger logger = mock(RenderLogger.class);
when(logger.getLinkManager()).thenReturn(linkManager);
ImmutableMap<String, Throwable> brokenClasses = ImmutableMap.of("com.test.mock", new Throwable("mock error"));
when(logger.getBrokenClasses()).thenReturn(brokenClasses);
RenderResult result = mock(RenderResult.class);
ViewInfo rootView = new ViewInfo("ConstraintLayout", null, 0, 0, 50, 50);
rootView.setChildren(ImmutableList.of(new ViewInfo("TextView", null, 0, 0, 30, 20)));
;
when(result.getRootViews()).thenReturn(ImmutableList.of(rootView));
when(result.getRenderResult()).thenReturn(renderResult);
when(result.getLogger()).thenReturn(logger);
when(result.getModule()).thenReturn(new MockModule(getProject(), getTestRootDisposable()));
tracker.logRenderResult(NlModel.ChangeType.EDIT, result, 230);
assertEquals(1, logCalls.size());
AndroidStudioEvent studioEvent = logCalls.getFirst();
LayoutEditorRenderResult loggedResult = studioEvent.getLayoutEditorEvent().getRenderResult();
assertEquals(Result.Status.SUCCESS.ordinal(), loggedResult.getResultCode());
assertEquals(230, loggedResult.getTotalRenderTimeMs());
assertEquals(2, loggedResult.getComponentCount());
assertEquals(1, loggedResult.getTotalIssueCount());
assertEquals(1, loggedResult.getErrorCount());
assertEquals(0, loggedResult.getFidelityWarningCount());
}
Aggregations