Path: blob/master/test/jdk/sanity/client/SwingSet/src/ToolTipDemoTest.java
41153 views
/*1* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import static com.sun.swingset3.demos.tooltip.ToolTipDemo.DEMO_TITLE;24import static com.sun.swingset3.demos.tooltip.ToolTipDemo.HTML_TOOLTIP_COMP_TITLE;25import static com.sun.swingset3.demos.tooltip.ToolTipDemo.HTML_TOOLTIP_TEXT;26import static com.sun.swingset3.demos.tooltip.ToolTipDemo.PLAIN_TOOLTIP_COMP_TITLE;27import static com.sun.swingset3.demos.tooltip.ToolTipDemo.PLAIN_TOOLTIP_TEXT;28import static com.sun.swingset3.demos.tooltip.ToolTipDemo.STYLE_TOOLTIP_COMP_TITLE;29import static com.sun.swingset3.demos.tooltip.ToolTipDemo.STYLE_TOOLTIP_TEXT;30import static org.jemmy2ext.JemmyExt.EXACT_STRING_COMPARATOR;3132import java.awt.Dimension;33import java.awt.Point;3435import javax.swing.ToolTipManager;36import javax.swing.UIManager;3738import org.jtregext.GuiTestListener;39import org.netbeans.jemmy.ClassReference;40import org.netbeans.jemmy.operators.JComponentOperator;41import org.netbeans.jemmy.operators.JFrameOperator;42import org.netbeans.jemmy.operators.JLabelOperator;43import org.netbeans.jemmy.operators.JToolTipOperator;44import org.testng.annotations.Listeners;45import org.testng.annotations.Test;4647import com.sun.swingset3.demos.tooltip.ToolTipDemo;4849/*50* @test51* @key headful52* @summary Verifies SwingSet3 ToolTipDemo page by checking whether tooltip53* shown or removed on user actions, tooltip text, location, number of54* tooltips shown at a time, with different tooltip texts plain, html and55* styled.56*57* @library /sanity/client/lib/jemmy/src58* @library /sanity/client/lib/Extensions/src59* @library /sanity/client/lib/SwingSet3/src60* @modules java.desktop61* java.logging62* @build org.jemmy2ext.JemmyExt63* @build com.sun.swingset3.demos.tooltip.ToolTipDemo64* @run testng/timeout=600 ToolTipDemoTest65*/66@Listeners(GuiTestListener.class)67public class ToolTipDemoTest {6869private static int TOOLTIP_DISMISS_DELAY = 60000;7071/**72* Testing whether tooltip shown while keeping the mouse on label, removed73* on mouse press, tooltip text, location, number of tooltips shown at a74* time with different tooltip texts plain, html and styled.75*76* @throws Exception77*/78@Test(dataProvider = "availableLookAndFeels", dataProviderClass = TestHelpers.class)79public void test(String lookAndFeel) throws Exception {80UIManager.setLookAndFeel(lookAndFeel);81new ClassReference(ToolTipDemo.class.getCanonicalName()).startApplication();82JFrameOperator frameOperator = new JFrameOperator(DEMO_TITLE);83frameOperator.setComparator(EXACT_STRING_COMPARATOR);84// Setting the tooltip dismiss delay85ToolTipManager.sharedInstance().setDismissDelay(TOOLTIP_DISMISS_DELAY);8687// Verifying the plain tooltip properties88checkToolTip(frameOperator, PLAIN_TOOLTIP_COMP_TITLE,89PLAIN_TOOLTIP_TEXT);90// Verifying the html tooltip properties91checkToolTip(frameOperator, HTML_TOOLTIP_COMP_TITLE,92HTML_TOOLTIP_TEXT);93// Verifying the styled tooltip properties94checkToolTip(frameOperator, STYLE_TOOLTIP_COMP_TITLE,95STYLE_TOOLTIP_TEXT);9697// Reducing the frame size to half and verifying that tooltip shown98// even it goes out of the window99Dimension newSize = new Dimension(frameOperator.getWidth() / 2,100frameOperator.getHeight() / 2);101frameOperator.resize(newSize.width, newSize.height);102frameOperator.waitComponentSize(newSize);103checkToolTip(frameOperator, HTML_TOOLTIP_COMP_TITLE,104HTML_TOOLTIP_TEXT);105}106107/**108* Shows the tooltip on specified component and verifies the properties109* tooltip text, location. And dismisses thetooltip after verification of110* the properties.111*112* @param frameOperator113* @param compTitle114* @param toolTipText115*/116private void checkToolTip(JFrameOperator frameOperator, String compTitle,117String toolTipText) {118119JLabelOperator toolTipHostComp =120new JLabelOperator(frameOperator, compTitle);121JToolTipOperator toolTipOperator =122new JToolTipOperator(toolTipHostComp.showToolTip());123toolTipOperator.waitTipText(toolTipText);124checkToolTipLocation(toolTipHostComp, toolTipOperator);125126// Dismissing the tooltip by mouse click127toolTipHostComp.clickMouse();128toolTipOperator.waitComponentShowing(false);129130}131132private void checkToolTipLocation(JComponentOperator componentOpertor,133JToolTipOperator toolTipOperator) {134Point labelStartPoint = componentOpertor.getLocationOnScreen();135Dimension labelSize = componentOpertor.getSize();136Point labelEndPoint = new Point((labelStartPoint.x + labelSize.width),137(labelStartPoint.y + labelSize.height));138toolTipOperator.waitComponentLocationOnScreen(139labelStartPoint, labelEndPoint);140}141}142143144