8209993: Create a test for SwingSet3 ToolTipDemo
Reviewed-by: serb
Contributed-by: abdul.kolarkunnu@oracle.com
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/sanity/client/SwingSet/src/ToolTipDemoTest.java Thu Aug 30 03:01:49 2018 -0700
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import static com.sun.swingset3.demos.tooltip.ToolTipDemo.DEMO_TITLE;
+import static com.sun.swingset3.demos.tooltip.ToolTipDemo.HTML_TOOLTIP_COMP_TITLE;
+import static com.sun.swingset3.demos.tooltip.ToolTipDemo.HTML_TOOLTIP_TEXT;
+import static com.sun.swingset3.demos.tooltip.ToolTipDemo.PLAIN_TOOLTIP_COMP_TITLE;
+import static com.sun.swingset3.demos.tooltip.ToolTipDemo.PLAIN_TOOLTIP_TEXT;
+import static com.sun.swingset3.demos.tooltip.ToolTipDemo.STYLE_TOOLTIP_COMP_TITLE;
+import static com.sun.swingset3.demos.tooltip.ToolTipDemo.STYLE_TOOLTIP_TEXT;
+import static org.jemmy2ext.JemmyExt.EXACT_STRING_COMPARATOR;
+
+import java.awt.Dimension;
+import java.awt.Point;
+
+import javax.swing.ToolTipManager;
+
+import org.jtregext.GuiTestListener;
+import org.netbeans.jemmy.ClassReference;
+import org.netbeans.jemmy.operators.JComponentOperator;
+import org.netbeans.jemmy.operators.JFrameOperator;
+import org.netbeans.jemmy.operators.JLabelOperator;
+import org.netbeans.jemmy.operators.JToolTipOperator;
+import org.testng.annotations.Listeners;
+import org.testng.annotations.Test;
+
+import com.sun.swingset3.demos.tooltip.ToolTipDemo;
+
+/*
+ * @test
+ * @key headful
+ * @summary Verifies SwingSet3 ToolTipDemo page by checking whether tooltip
+ * shown or removed on user actions, tooltip text, location, number of
+ * tooltips shown at a time, with different tooltip texts plain, html and
+ * styled.
+ *
+ * @library /sanity/client/lib/jemmy/src
+ * @library /sanity/client/lib/Extensions/src
+ * @library /sanity/client/lib/SwingSet3/src
+ * @modules java.desktop
+ * java.logging
+ * @build org.jemmy2ext.JemmyExt
+ * @build com.sun.swingset3.demos.tooltip.ToolTipDemo
+ * @run testng ToolTipDemoTest
+ */
+@Listeners(GuiTestListener.class)
+public class ToolTipDemoTest {
+
+ private static int TOOLTIP_DISMISS_DELAY = 60000;
+
+ /**
+ * Testing whether tooltip shown while keeping the mouse on label, removed
+ * on mouse press, tooltip text, location, number of tooltips shown at a
+ * time with different tooltip texts plain, html and styled.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void test() throws Exception {
+ new ClassReference(ToolTipDemo.class.getCanonicalName()).startApplication();
+ JFrameOperator frameOperator = new JFrameOperator(DEMO_TITLE);
+ frameOperator.setComparator(EXACT_STRING_COMPARATOR);
+ // Setting the tooltip dismiss delay
+ ToolTipManager.sharedInstance().setDismissDelay(TOOLTIP_DISMISS_DELAY);
+
+ // Verifying the plain tooltip properties
+ checkToolTip(frameOperator, PLAIN_TOOLTIP_COMP_TITLE,
+ PLAIN_TOOLTIP_TEXT);
+ // Verifying the html tooltip properties
+ checkToolTip(frameOperator, HTML_TOOLTIP_COMP_TITLE,
+ HTML_TOOLTIP_TEXT);
+ // Verifying the styled tooltip properties
+ checkToolTip(frameOperator, STYLE_TOOLTIP_COMP_TITLE,
+ STYLE_TOOLTIP_TEXT);
+
+ // Reducing the frame size to half and verifying that tooltip shown
+ // even it goes out of the window
+ Dimension newSize = new Dimension(frameOperator.getWidth() / 2,
+ frameOperator.getHeight() / 2);
+ frameOperator.resize(newSize.width, newSize.height);
+ frameOperator.waitComponentSize(newSize);
+ checkToolTip(frameOperator, HTML_TOOLTIP_COMP_TITLE,
+ HTML_TOOLTIP_TEXT);
+ }
+
+ /**
+ * Shows the tooltip on specified component and verifies the properties
+ * tooltip text, location. And dismisses thetooltip after verification of
+ * the properties.
+ *
+ * @param frameOperator
+ * @param compTitle
+ * @param toolTipText
+ */
+ private void checkToolTip(JFrameOperator frameOperator, String compTitle,
+ String toolTipText) {
+
+ JLabelOperator toolTipHostComp =
+ new JLabelOperator(frameOperator, compTitle);
+ JToolTipOperator toolTipOperator =
+ new JToolTipOperator(toolTipHostComp.showToolTip());
+ toolTipOperator.waitTipText(toolTipText);
+ checkToolTipLocation(toolTipHostComp, toolTipOperator);
+
+ // Dismissing the tooltip by mouse click
+ toolTipHostComp.clickMouse();
+ toolTipOperator.waitComponentShowing(false);
+
+ }
+
+ private void checkToolTipLocation(JComponentOperator componentOpertor,
+ JToolTipOperator toolTipOperator) {
+ Point labelStartPoint = componentOpertor.getLocationOnScreen();
+ Dimension labelSize = componentOpertor.getSize();
+ Point labelEndPoint = new Point((labelStartPoint.x + labelSize.width),
+ (labelStartPoint.y + labelSize.height));
+ toolTipOperator.waitComponentLocationOnScreen(
+ labelStartPoint, labelEndPoint);
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/sanity/client/lib/SwingSet3/src/com/sun/swingset3/demos/tooltip/ToolTipDemo.java Thu Aug 30 03:01:49 2018 -0700
@@ -0,0 +1,160 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package com.sun.swingset3.demos.tooltip;
+
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.Rectangle;
+
+import javax.swing.JComponent;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+import com.sun.swingset3.DemoProperties;
+import com.sun.swingset3.demos.ResourceManager;
+
+/**
+ * ToolTip Demo
+ *
+ * @version 1.9 11/17/05
+ * @author Jeff Dinkins
+ */
+@DemoProperties(
+ value = "ToolTips Demo",
+ category = "General",
+ description = "Demonstrates how tooltips can be easily added to Swing GUI components",
+ sourceFiles = {
+ "com/sun/swingset3/demos/tooltip/ToolTipDemo.java",
+ "com/sun/swingset3/demos/ResourceManager.java",
+ "com/sun/swingset3/demos/tooltip/resources/ToolTipDemo.properties",
+ "com/sun/swingset3/demos/tooltip/resources/images/tooltip_background.png",
+ "com/sun/swingset3/demos/tooltip/resources/images/ToolTipDemo.gif"
+ }
+)
+public class ToolTipDemo extends JPanel {
+
+ public static final String DEMO_TITLE = ToolTipDemo.class.getAnnotation(DemoProperties.class).value();
+ private final static ResourceManager resourceManager = new ResourceManager(ToolTipDemo.class);
+ public static final String PLAIN_TOOLTIP_COMP_TITLE = resourceManager.getString("ToolTipDemo.plain");;
+ public static final String PLAIN_TOOLTIP_TEXT = "A simple one line tip.";
+ public static final String HTML_TOOLTIP_COMP_TITLE = resourceManager.getString("ToolTipDemo.html");;
+ public static final String HTML_TOOLTIP_TEXT = "<html><body bgcolor=\"#AABBFF\">In case you thought that tooltips had to be<p>" +
+ "boring, one line descriptions, the <font color=blue size=+2>Swing!</font> team<p>" +
+ "is happy to shatter your illusions.<p>" +
+ "In Swing, you can use HTML to <ul><li>Have Lists<li><b>Bold</b> text<li><em>emphasized</em>" +
+ "text<li>text with <font color=red>Color</font><li>text in different <font size=+3>sizes</font>" +
+ "<li>and <font face=AvantGarde>Fonts</font></ul>Oh, and they can be multi-line, too.</body></html>";
+ public static final String STYLE_TOOLTIP_COMP_TITLE = resourceManager.getString("ToolTipDemo.styled");
+ public static final String STYLE_TOOLTIP_TEXT = "<html>Tips can be styled to be" +
+ "<br><b>interesting</b> and <i>fun</i></html>";
+
+ /**
+ * main method allows us to run as a standalone demo.
+ */
+ public static void main(String[] args) {
+ JFrame frame = new JFrame(ToolTipDemo.class.getAnnotation(DemoProperties.class).value());
+
+ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ frame.getContentPane().add(new ToolTipDemo());
+ frame.setPreferredSize(new Dimension(800, 600));
+ frame.pack();
+ frame.setLocationRelativeTo(null);
+ frame.setVisible(true);
+ }
+
+ /**
+ * ToolTipDemo Constructor
+ */
+ public ToolTipDemo() {
+ setLayout(new BorderLayout());
+
+ // Create a panel which contains specific tooltip regions.
+ Toolbox toolbox = new Toolbox();
+
+ add(toolbox, BorderLayout.CENTER);
+ }
+
+ public class Toolbox extends JPanel {
+ private final Rectangle plainRect = new Rectangle(44, 0, 186, 128);
+ private final Rectangle htmlRect = new Rectangle(240, 134, 186, 186);
+ private final Rectangle styledRect = new Rectangle(45, 327, 188, 134);
+
+ private final JLabel background;
+ private final JComponent plainToolTipRegion;
+ private final JComponent htmlToolTipRegion;
+ private final JComponent styledToolTipRegion;
+
+ public Toolbox() {
+ setLayout(null);
+
+ background = new JLabel(resourceManager.createImageIcon("tooltip_background.png",
+ resourceManager.getString("ToolTipDemo.toolbox")));
+
+ background.setVerticalAlignment(JLabel.TOP);
+ background.setHorizontalAlignment(JLabel.LEFT);
+
+ // Note: tooltip text isn't retrieved from properties file in order
+ // to make this code easier to understand
+
+ //<snip>Create region for displaying plain tooltip
+ plainToolTipRegion = createToolTipRegion(PLAIN_TOOLTIP_COMP_TITLE);
+ plainToolTipRegion.setToolTipText(PLAIN_TOOLTIP_TEXT);
+ //</snip>
+
+ //<snip>Create region for displaying HTML tooltip
+ htmlToolTipRegion = createToolTipRegion(HTML_TOOLTIP_COMP_TITLE);
+ htmlToolTipRegion.setToolTipText(HTML_TOOLTIP_TEXT);
+ //</snip>
+
+ //<snip>Create region for displaying styled tooltip
+ styledToolTipRegion = createToolTipRegion(STYLE_TOOLTIP_COMP_TITLE);
+ styledToolTipRegion.setToolTipText(STYLE_TOOLTIP_TEXT);
+ //</snip>
+
+ add(htmlToolTipRegion);
+ add(styledToolTipRegion);
+ add(plainToolTipRegion);
+
+ add(background);
+ }
+
+ public void doLayout() {
+ background.setBounds(0, 0, getWidth(), getHeight());
+ plainToolTipRegion.setBounds(plainRect);
+ htmlToolTipRegion.setBounds(htmlRect);
+ styledToolTipRegion.setBounds(styledRect);
+ }
+
+ private JComponent createToolTipRegion(String text) {
+ JLabel region = new JLabel(text);
+ region.setForeground(Color.white);
+ region.setFont(getFont().deriveFont(18f));
+ region.setHorizontalAlignment(JLabel.CENTER);
+ region.setVerticalAlignment(JLabel.CENTER);
+ return region;
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/sanity/client/lib/SwingSet3/src/com/sun/swingset3/demos/tooltip/resources/ToolTipDemo.properties Thu Aug 30 03:01:49 2018 -0700
@@ -0,0 +1,10 @@
+### ToolTip Demo ###
+
+ToolTipDemo.accessible_description=ToolTips show short help descriptions for a component
+ToolTipDemo.tooltip=ToolTip demo
+ToolTipDemo.name=ToolTip Demo
+ToolTipDemo.toolbox=Toolbox containing tooltip regions
+ToolTipDemo.plain=<html><p align="center">Roll over here<br>to see a tooltip</p></html>
+ToolTipDemo.html=<html><p align="center">Roll over this box<br>to see a tooltip<br>in HTML</p></html>
+ToolTipDemo.styled=<html><p align="center">Roll over here\nto see a tooltip<br> in styled text</p></html>
+
Binary file test/jdk/sanity/client/lib/SwingSet3/src/com/sun/swingset3/demos/tooltip/resources/images/ToolTipDemo.gif has changed
Binary file test/jdk/sanity/client/lib/SwingSet3/src/com/sun/swingset3/demos/tooltip/resources/images/tooltip_background.png has changed