changeset 36871:62d3bb5aba7a

6734341: REGTEST fails: SelectionAutoscrollTest.html Reviewed-by: serb, ssadetsky Contributed-by: Vikrant Agarwal <vikrant.v.agarwal@oracle.com>
author kshefov
date Fri, 11 Mar 2016 11:17:17 +0300
parents d6652957df27
children 16a225f7de51
files jdk/test/java/awt/TextArea/UsingWithMouse/SelectionAutoscrollTest.html jdk/test/java/awt/TextArea/UsingWithMouse/SelectionAutoscrollTest.java
diffstat 2 files changed, 36 insertions(+), 71 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/test/java/awt/TextArea/UsingWithMouse/SelectionAutoscrollTest.html	Fri Mar 11 11:02:54 2016 +0530
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-<!--
- Copyright (c) 2007, 2013, 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.
--->
-
-<html>
-<!--  
-  @test
-  @bug 6497109
-  @summary TextArea must have selection expanding, and also be autoscrolled, if mouse is dragged from inside.
-  @author Konstantin Voloshin: area=TextArea
-  @library ../../regtesthelpers
-  @build Util
-  @run applet SelectionAutoscrollTest.html
-  -->
-<head>
-<title>  </title>
-</head>
-<body>
-
-<h1>SelectionAutoscrollTest<br>Bug ID: 6497109</h1>
-
-<p> This is an AUTOMATIC test, simply wait for completion </p>
-
-<APPLET CODE="SelectionAutoscrollTest.class" WIDTH=200 HEIGHT=200></APPLET>
-</body>
-</html>
--- a/jdk/test/java/awt/TextArea/UsingWithMouse/SelectionAutoscrollTest.java	Fri Mar 11 11:02:54 2016 +0530
+++ b/jdk/test/java/awt/TextArea/UsingWithMouse/SelectionAutoscrollTest.java	Fri Mar 11 11:17:17 2016 +0300
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2007, 2016, 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
@@ -22,11 +22,13 @@
  */
 
 /*
-  test
-  @bug 6497109
+  @test
+  @bug 6497109 6734341
   @summary TextArea must have selection expanding, and also be autoscrolled, if mouse is dragged from inside.
+  @library ../../regtesthelpers
+  @build Util
   @author Konstantin Voloshin: area=TextArea
-  @run applet SelectionAutoscrollTest.html
+  @run main SelectionAutoscrollTest
 */
 
 /**
@@ -38,12 +40,10 @@
  */
 
 
-import java.applet.Applet;
 import java.awt.Frame;
 import java.awt.Panel;
 import java.awt.GridLayout;
 import java.awt.TextArea;
-
 import java.awt.Point;
 import java.awt.Dimension;
 import java.awt.event.MouseEvent;
@@ -52,16 +52,18 @@
 import test.java.awt.regtesthelpers.Util;
 
 
-public class SelectionAutoscrollTest extends Applet {
+public class SelectionAutoscrollTest {
     TextArea textArea;
     Robot robot;
     final int desiredSelectionEnd = ('z'-'a'+1)*2;  // 52
     final static int SCROLL_DELAY = 10; // ms
 
-    public void start () {
-        createObjects();
-        manipulateMouse();
-        checkResults();
+    public static void main(String[] args) {
+        SelectionAutoscrollTest selectionAutoscrollTest
+                = new SelectionAutoscrollTest();
+        selectionAutoscrollTest.createObjects();
+        selectionAutoscrollTest.manipulateMouse();
+        selectionAutoscrollTest.checkResults();
     }
 
     void createObjects() {
@@ -102,7 +104,7 @@
         robot.mousePress( MouseEvent.BUTTON1_MASK );
         Util.waitForIdle( robot );
 
-        for( int tremble=0; tremble < desiredSelectionEnd; ++tremble ) {
+        for( int tremble=0; tremble < 10; ++tremble ) {
             // Mouse is moved repeatedly here (with conservatively chosen
             // ammount of times), to give some time/chance for TextArea to
             // autoscroll and for text-selection to expand to the end.
@@ -125,7 +127,7 @@
             //   and this is probably a bug). But, starting with 2nd iteration,
             //   all events received will be mouse-dragged events.
 
-            moveMouseBelowTextArea( tremble%2!=0 );
+            moveMouseBelowTextArea( tremble );
             Util.waitForIdle( robot );
             // it is needed to add some small delay on Gnome
             waitUntilScrollIsPerformed(robot);
@@ -138,16 +140,28 @@
     void moveMouseToCenterOfTextArea() {
         Dimension d = textArea.getSize();
         Point l = textArea.getLocationOnScreen();
-        robot.mouseMove( (int)(l.x+d.width*.5), (int)(l.y+d.height*.5) );
+        Util.mouseMove(robot, l, new Point((int) (l.x + d.width * .5),
+                (int) (l.y + d.height * .5)));
     }
 
-    void moveMouseBelowTextArea( boolean shift ) {
+    void moveMouseBelowTextArea(int tremble) {
         Dimension d = textArea.getSize();
         Point l = textArea.getLocationOnScreen();
-        int x = (int)(l.x+d.width*.5);
-        int y = (int)(l.y+d.height*1.5);
-        if( shift ) y+=15;
-        robot.mouseMove( x, y );
+        Point p1;
+        if (tremble == 0) {
+            p1 = new Point((int) (l.x + d.width * .5),
+                    (int) (l.y + d.height * 0.5));
+        } else {
+            p1 = new Point((int) (l.x + d.width * .5),
+                    (int) (l.y + d.height * 1.5));
+        }
+        Point p2 = new Point((int) (l.x + d.width * .5),
+                (int) (l.y + d.height * 1.5) + 15);
+        if (tremble % 2 == 0) {
+            Util.mouseMove(robot, p1, p2);
+        } else {
+            Util.mouseMove(robot, p2, p1);
+        }
     }
 
     void waitUntilScrollIsPerformed(Robot robot) {
@@ -160,15 +174,11 @@
     }
 
     void checkResults() {
-        //try { Thread.sleep( 30*1000 ); }
-        //catch( Exception e ) { throw new RuntimeException( e ); }
-
         final int currentSelectionEnd = textArea.getSelectionEnd();
-
         System.out.println(
-            "TEST: Selection range after test is: ( "
-            + textArea.getSelectionStart() + ", "
-            + currentSelectionEnd + " )"
+                "TEST: Selection range after test is: ( "
+                + textArea.getSelectionStart() + ", "
+                + currentSelectionEnd + " )"
         );
 
         boolean resultOk = ( currentSelectionEnd == desiredSelectionEnd );