1 /* 2 * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2019, Red Hat Inc. All rights reserved. 4 * 5 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6 * 7 * The contents of this file are subject to the terms of either the Universal Permissive License 8 * v 1.0 as shown at http://oss.oracle.com/licenses/upl 9 * 10 * or the following license: 11 * 12 * Redistribution and use in source and binary forms, with or without modification, are permitted 13 * provided that the following conditions are met: 14 * 15 * 1. Redistributions of source code must retain the above copyright notice, this list of conditions 16 * and the following disclaimer. 17 * 18 * 2. Redistributions in binary form must reproduce the above copyright notice, this list of 19 * conditions and the following disclaimer in the documentation and/or other materials provided with 20 * the distribution. 21 * 22 * 3. Neither the name of the copyright holder nor the names of its contributors may be used to 23 * endorse or promote products derived from this software without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 26 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 27 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY 32 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 */ 34 package org.openjdk.jmc.flightrecorder.uitest; 35 36 import org.junit.Assert; 37 import org.junit.Rule; 38 import org.junit.Test; 39 import org.openjdk.jmc.test.jemmy.MCJemmyTestBase; 40 import org.openjdk.jmc.test.jemmy.MCUITestRule; 41 import org.openjdk.jmc.test.jemmy.misc.wrappers.MCChartCanvas; 42 import org.openjdk.jmc.test.jemmy.misc.wrappers.JfrNavigator; 43 import org.openjdk.jmc.test.jemmy.misc.wrappers.JfrUi; 44 import org.openjdk.jmc.test.jemmy.misc.wrappers.MCMenu; 45 import org.openjdk.jmc.test.jemmy.misc.wrappers.MCTable; 46 47 public class JfrThreadsPageTest extends MCJemmyTestBase { 48 49 private static final String PLAIN_JFR = "plain_recording.jfr"; 50 private static final String TABLE_COLUMN_HEADER = "Thread"; 51 private static final String HIDE_THREAD = org.openjdk.jmc.flightrecorder.ui.messages.internal.Messages.ThreadsPage_HIDE_THREAD_ACTION; 52 private static final String RESET_CHART = org.openjdk.jmc.flightrecorder.ui.messages.internal.Messages.ThreadsPage_RESET_CHART_TO_SELECTION_ACTION; 53 54 private static MCChartCanvas chartCanvas; 55 private static MCTable threadsTable; 56 57 @Rule 58 public MCUITestRule testRule = new MCUITestRule(verboseRuleOutput) { 59 @Override 60 public void before() { 61 JfrUi.openJfr(materialize("jfr", PLAIN_JFR, JfrThreadsPageTest.class)); 62 JfrNavigator.selectTab(JfrUi.Tabs.THREADS); 63 threadsTable = MCTable.getByColumnHeader(TABLE_COLUMN_HEADER); 64 chartCanvas = MCChartCanvas.getChartCanvas(); 65 } 66 67 @Override 68 public void after() { 69 MCMenu.closeActiveEditor(); 70 } 71 }; 72 73 @Test 74 public void testMenuItemEnablement() { 75 final int numThreads = threadsTable.getItemCount(); 76 Assert.assertTrue(numThreads > 0); 77 78 Assert.assertFalse(chartCanvas.isContextMenuItemEnabled(RESET_CHART)); 79 Assert.assertTrue(chartCanvas.isContextMenuItemEnabled(HIDE_THREAD)); 80 81 chartCanvas.clickContextMenuItem(HIDE_THREAD); 82 83 Assert.assertTrue(chartCanvas.isContextMenuItemEnabled(RESET_CHART)); 84 Assert.assertTrue(chartCanvas.isContextMenuItemEnabled(HIDE_THREAD)); 85 86 chartCanvas.clickContextMenuItem(RESET_CHART); 87 88 Assert.assertFalse(chartCanvas.isContextMenuItemEnabled(RESET_CHART)); 89 Assert.assertTrue(chartCanvas.isContextMenuItemEnabled(HIDE_THREAD)); 90 } 91 92 @Test 93 public void testHideAllThreads() { 94 final int numSelection = 7; 95 final int numThreads = threadsTable.getItemCount(); 96 Assert.assertTrue(numThreads > 0 && numThreads >= numSelection); 97 Assert.assertTrue(chartCanvas.isContextMenuItemEnabled(HIDE_THREAD)); 98 Assert.assertFalse(chartCanvas.isContextMenuItemEnabled(RESET_CHART)); 99 100 // Select a limited number of threads in the chart using the table 101 threadsTable.selectItems(0, numSelection - 1); 102 103 // Hide all the threads from the chart 104 for (int i = 0; i < numSelection; i++) { 105 chartCanvas.clickContextMenuItem(HIDE_THREAD); 106 } 107 108 // Once all threads are hidden from the chart, the hide thread menu item will be disabled 109 Assert.assertFalse(chartCanvas.isContextMenuItemEnabled(HIDE_THREAD)); 110 Assert.assertTrue(chartCanvas.isContextMenuItemEnabled(RESET_CHART)); 111 112 chartCanvas.clickContextMenuItem(RESET_CHART); 113 114 // Verify the menu item isEnabled values are back to their default values 115 Assert.assertTrue(chartCanvas.isContextMenuItemEnabled(HIDE_THREAD)); 116 Assert.assertFalse(chartCanvas.isContextMenuItemEnabled(RESET_CHART)); 117 } 118 } 119