StudioProfilersView extends AspectObserver implements Disposable { @NotNull public JLayeredPane getComponent() { return myLayeredPane; } StudioProfilersView(@NotNull StudioProfilers profiler, @NotNull IdeProfilerComponents ideProfilerComponents); @Override void dispose(); @VisibleForTesting void bind(@NotNull Class<S> clazz,
                                                          @NotNull BiFunction<StudioProfilersView, S, T> constructor); @VisibleForTesting @NotNull CommonButton getZoomToSelectionButton(); @VisibleForTesting HoverHyperlinkLabel getDeselectAllLabel(); @VisibleForTesting JPanel getDeselectAllToolbar(); @VisibleForTesting StageView getStageView(); @NotNull StudioProfilers getStudioProfilers(); @NotNull JLayeredPane getComponent(); void installCommonMenuItems(@NotNull JComponent component); @NotNull IdeProfilerComponents getIdeProfilerComponents(); @NotNull static final String ATTACH_LIVE; @NotNull static final String DETACH_LIVE; @NotNull static final String ZOOM_IN; @NotNull static final String ZOOM_OUT; }
@Test public void testMonitorExpansion() { myProfilerService.addSession(SESSION_O, SESSION_O_METADATA); myTimer.tick(FakeTimer.ONE_SECOND_IN_NS); myProfilers.getSessionsManager().setSession(SESSION_O); myUi.layout(); assertThat(myProfilers.getStage()).isInstanceOf(StudioMonitorStage.class); List<Point> points = new TreeWalker(myView.getComponent()).descendantStream() .filter(d -> d instanceof LineChart) .map(c -> myUi.getPosition(c)) .collect(Collectors.toList()); assertThat(points.size()).isEqualTo(4); myUi.mouse.click(points.get(0).x + 1, points.get(0).y + 1); assertThat(myProfilers.getStage()).isInstanceOf(CpuProfilerStage.class); myProfilers.setMonitoringStage(); myUi.layout(); myUi.mouse.click(points.get(1).x + 1, points.get(1).y + 1); assertThat(myProfilers.getStage()).isInstanceOf(MemoryProfilerStage.class); myProfilers.setMonitoringStage(); myUi.layout(); myUi.mouse.click(points.get(2).x + 1, points.get(2).y + 1); assertThat(myProfilers.getStage()).isInstanceOf(NetworkProfilerStage.class); myProfilers.setMonitoringStage(); myUi.layout(); myUi.mouse.click(points.get(3).x + 1, points.get(3).y + 1); assertThat(myProfilers.getStage()).isInstanceOf(EnergyProfilerStage.class); myProfilers.setMonitoringStage(); }
@Test public void testMonitorTooltip() { myProfilerService.addSession(SESSION_O, SESSION_O_METADATA); myTimer.tick(FakeTimer.ONE_SECOND_IN_NS); myProfilers.getSessionsManager().setSession(SESSION_O); myUi.layout(); assertThat(myProfilers.getStage()).isInstanceOf(StudioMonitorStage.class); StudioMonitorStage stage = (StudioMonitorStage)myProfilers.getStage(); List<Point> points = new TreeWalker(myView.getComponent()).descendantStream() .filter(d -> d instanceof LineChart) .map(c -> myUi.getPosition(c)) .collect(Collectors.toList()); assertThat(points.size()).isEqualTo(4); myUi.mouse.moveTo(points.get(0).x + 1, points.get(0).y + 1); assertThat(stage.getTooltip()).isInstanceOf(CpuMonitorTooltip.class); ProfilerMonitor cpuMonitor = ((CpuMonitorTooltip)stage.getTooltip()).getMonitor(); stage.getMonitors().forEach( monitor -> Truth.assertWithMessage("Only the CPU Monitor should be focused.") .that(monitor.isFocused()).isEqualTo(monitor == cpuMonitor)); myUi.mouse.moveTo(points.get(1).x + 1, points.get(1).y + 1); assertThat(stage.getTooltip()).isInstanceOf(MemoryMonitorTooltip.class); ProfilerMonitor memoryMonitor = ((MemoryMonitorTooltip)stage.getTooltip()).getMonitor(); stage.getMonitors().forEach( monitor -> Truth.assertWithMessage("Only the Memory Monitor should be focused.") .that(monitor.isFocused()).isEqualTo(monitor == memoryMonitor)); myUi.mouse.moveTo(points.get(2).x + 1, points.get(2).y + 1); assertThat(stage.getTooltip()).isInstanceOf(NetworkMonitorTooltip.class); ProfilerMonitor networMonitor = ((NetworkMonitorTooltip)stage.getTooltip()).getMonitor(); stage.getMonitors().forEach( monitor -> Truth.assertWithMessage("Only the Network Monitor should be focused.") .that(monitor.isFocused()).isEqualTo(monitor == networMonitor)); myUi.mouse.moveTo(points.get(3).x + 1, points.get(3).y + 1); assertThat(stage.getTooltip()).isInstanceOf(EnergyMonitorTooltip.class); ProfilerMonitor energyMonitor = ((EnergyMonitorTooltip)stage.getTooltip()).getMonitor(); stage.getMonitors().forEach( monitor -> Truth.assertWithMessage("Only the Energy Monitor should be focused.") .that(monitor.isFocused()).isEqualTo(monitor == energyMonitor)); myUi.mouse.moveTo(0, 0); assertThat(stage.getTooltip()).isNull(); stage.getMonitors().forEach(monitor -> Truth.assertWithMessage("No monitor should be focused.").that(monitor.isFocused()).isFalse()); }
@Test public void testNoStage() throws Exception { StudioProfilersView view = new StudioProfilersView(myProfilers, new FakeIdeProfilerComponents()); JLayeredPane component = view.getComponent(); new ReferenceWalker(myProfilers).assertNotReachable(view, component); }