Bug 1125527 - merge the common code of tests. r=margaret
authorKuoE0 <kuoe0@mozilla.com>
Mon, 09 Feb 2015 18:40:00 +0100
changeset 242065 276be70d7b06c0bef84419d3adf85a1d7a7e5e10
parent 242064 34aa284f06a17fe5d3096f1bcac68cf59365bf59
child 242066 acbdb86043f320b69e98baea0f47c3f8447173c8
push id634
push usermozilla@noorenberghe.ca
push dateTue, 10 Feb 2015 22:34:30 +0000
reviewersmargaret
bugs1125527
milestone38.0a1
Bug 1125527 - merge the common code of tests. r=margaret
mobile/android/base/tests/roboextender/SelectionUtils.js
mobile/android/base/tests/roboextender/testInputSelections.html
mobile/android/base/tests/roboextender/testSelectionHandler.html
mobile/android/base/tests/roboextender/testTextareaSelections.html
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/tests/roboextender/SelectionUtils.js
@@ -0,0 +1,126 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+
+const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
+Cu.import("resource://gre/modules/Messaging.jsm");
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import('resource://gre/modules/Geometry.jsm');
+
+/* ============================== Utility functions ================================================
+ *
+ * Common functions available to all tests.
+ *
+ */
+function getSelectionHandler() {
+  return (!this._selectionHandler) ?
+    this._selectionHandler = Services.wm.getMostRecentWindow("navigator:browser").SelectionHandler :
+    this._selectionHandler;
+}
+
+function todo(result, msg) {
+  return Messaging.sendRequestForResult({
+    type: TYPE_NAME,
+    todo: result,
+    msg: msg
+  });
+}
+
+function ok(result, msg) {
+  return Messaging.sendRequestForResult({
+    type: TYPE_NAME,
+    result: result,
+    msg: msg
+  });
+}
+
+function is(one, two, msg) {
+  return Messaging.sendRequestForResult({
+    type: TYPE_NAME,
+    result: one === two,
+    msg: msg + " : " + one + " === " + two
+  });
+}
+
+function isNot(one, two, msg) {
+  return Messaging.sendRequestForResult({
+    type: TYPE_NAME,
+    result: one !== two,
+    msg: msg + " : " + one + " !== " + two
+  });
+}
+
+function lessThan(n1, n2, msg) {
+  return Messaging.sendRequestForResult({
+    type: TYPE_NAME,
+    result: n1 < n2,
+    msg: msg + " : " + n1 + " < " + n2
+  });
+}
+
+function greaterThan(n1, n2, msg) {
+  return Messaging.sendRequestForResult({
+    type: TYPE_NAME,
+    result: n1 > n2,
+    msg: msg + " : " + n1 + " > " + n2
+  });
+}
+
+// Use fuzzy logic to compare screen coords.
+function truncPoint(point) {
+  return new Point(Math.trunc(point.x), Math.trunc(point.y));
+}
+
+function pointEquals(p1, p2, msg) {
+  return Messaging.sendRequestForResult({
+    type: TYPE_NAME,
+    result: truncPoint(p1).equals(truncPoint(p2)),
+    msg: msg + " : " + p1.toString() + " == " + p2.toString()
+  });
+}
+
+function pointNotEquals(p1, p2, msg) {
+  return Messaging.sendRequestForResult({
+    type: TYPE_NAME,
+    result: !truncPoint(p1).equals(truncPoint(p2)),
+    msg: msg + " : " + p1.toString() + " == " + p2.toString()
+  });
+}
+
+function selectionExists(selection, msg) {
+  return Messaging.sendRequestForResult({
+    type: TYPE_NAME,
+    result: !truncPoint(selection.anchorPt).equals(truncPoint(selection.focusPt)),
+    msg: msg + " : anchor:" + selection.anchorPt.toString() +
+      " focus:" + selection.focusPt.toString()
+  });
+}
+
+function selectionEquals(s1, s2, msg) {
+  return Messaging.sendRequestForResult({
+    type: TYPE_NAME,
+    result: truncPoint(s1.anchorPt).equals(truncPoint(s2.anchorPt)) &&
+      truncPoint(s1.focusPt).equals(truncPoint(s2.focusPt)),
+    msg: msg
+  });
+}
+
+/* =================================================================================================
+ *
+ * After finish of all selection tests, wrap up and go home.
+ *
+ */
+function finishTests() {
+  Messaging.sendRequest({
+    type: TYPE_NAME,
+    result: true,
+    msg: "Done!",
+    done: true
+  });
+}
+
--- a/mobile/android/base/tests/roboextender/testInputSelections.html
+++ b/mobile/android/base/tests/roboextender/testInputSelections.html
@@ -1,37 +1,36 @@
 <html>
   <head>
     <title>Automated RTL/LTR Text Selection tests for Input elements</title>
     <meta name="viewport" content="initial-scale=1.0"/>
     <script type="application/javascript"
       src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
+    <script type="application/javascript" src="SelectionUtils.js"></script>
     <script type="application/javascript;version=1.8">
 
+// Name of this test.
+const TYPE_NAME = "Robocop:testInputSelections";
+
 // Used to create handle movement events for SelectionHandler.
 const ANCHOR = "ANCHOR";
 const FOCUS = "FOCUS";
 
 // Types of DOM nodes that serve as Selection Anchor/Focus nodes.
 const DIV_NODE = "DIV";
 const TEXT_NODE = "#text";
 
 // Used to specifiy midpoint selection text left/right of center.
 const EST_SEL_TEXT_BOUND_CHARS = 5;
 
 // Used to create test scenarios, and verify results.
 const LTR_INPUT_TEXT_VALUE = "This input text is one character short of it's maxmimum.";
 const RTL_INPUT_TEXT_VALUE = "טקסט קלט זה קצר תו אחד של זה גדול.";
 
 
-const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
-Cu.import("resource://gre/modules/Messaging.jsm");
-Cu.import("resource://gre/modules/Services.jsm");
-Cu.import('resource://gre/modules/Geometry.jsm');
-
 /* =================================================================================
  *
  * Start of all text selection tests, check initialization state.
  */
 function startTests() {
   testLTR_selectAll().
     then(testRTL_selectAll).
 
@@ -413,133 +412,16 @@ function testRTL_dragAnchorHandleToSelf(
     selectionEquals(anchorDraggedSelection, initialSelection,
       "RTL Selection points after anchor drag " +
       "should match initial selection points."),
 
     ok(true, "testRTL_dragAnchorHandleToSelf - Test Finishes."),
   ]);
 }
 
-/* =================================================================================
- *
- * After finish of all selection tests, wrap up and go home.
- *
- */
-function finishTests() {
-  Messaging.sendRequest({
-    type: "Robocop:testInputSelections",
-    result: true,
-    msg: "Done!",
-    done: true
-  });
-}
-
-/* ============================== Utility functions ======================
- *
- * Common functions available to all tests.
- *
- */
-function getSelectionHandler() {
-  return (!this._selectionHandler) ?
-    this._selectionHandler = Services.wm.getMostRecentWindow("navigator:browser").SelectionHandler :
-    this._selectionHandler;
-}
-
-function todo(result, msg) {
-  return Messaging.sendRequestForResult({
-    type: "Robocop:testInputSelections",
-    todo: result,
-    msg: msg
-  });
-}
-
-function ok(result, msg) {
-  return Messaging.sendRequestForResult({
-    type: "Robocop:testInputSelections",
-    result: result,
-    msg: msg
-  });
-}
-
-function is(one, two, msg) {
-  return Messaging.sendRequestForResult({
-    type: "Robocop:testInputSelections",
-    result: one === two,
-    msg: msg + " : " + one + " === " + two
-  });
-}
-
-function isNot(one, two, msg) {
-  return Messaging.sendRequestForResult({
-    type: "Robocop:testInputSelections",
-    result: one !== two,
-    msg: msg + " : " + one + " !== " + two
-  });
-}
-
-function lessThan(n1, n2, msg) {
-  return Messaging.sendRequestForResult({
-    type: "Robocop:testInputSelections",
-    result: n1 < n2,
-    msg: msg + " : " + n1 + " < " + n2
-  });
-}
-
-function greaterThan(n1, n2, msg) {
-  return Messaging.sendRequestForResult({
-    type: "Robocop:testInputSelections",
-    result: n1 > n2,
-    msg: msg + " : " + n1 + " > " + n2
-  });
-}
-
-// Use fuzzy logic to compare screen coords.
-function truncPoint(point) {
-  return new Point(Math.trunc(point.x), Math.trunc(point.y));
-}
-
-function pointEquals(p1, p2, msg) {
-  return Messaging.sendRequestForResult({
-    type: "Robocop:testInputSelections",
-    result: truncPoint(p1).equals(truncPoint(p2)),
-    msg: msg + " : " + p1.toString() + " == " + p2.toString()
-  });
-}
-
-function pointNotEquals(p1, p2, msg) {
-  return Messaging.sendRequestForResult({
-    type: "Robocop:testInputSelections",
-    result: !truncPoint(p1).equals(truncPoint(p2)),
-    msg: msg + " : " + p1.toString() + " == " + p2.toString()
-  });
-}
-
-function selectionExists(selection, msg) {
-  return Messaging.sendRequestForResult({
-    type: "Robocop:testInputSelections",
-    result: !truncPoint(selection.anchorPt).equals(truncPoint(selection.focusPt)),
-    msg: msg + " : anchor:" + selection.anchorPt.toString() +
-      " focus:" + selection.focusPt.toString()
-  });
-}
-
-function selectionEquals(s1, s2, msg) {
-  return Messaging.sendRequestForResult({
-    type: "Robocop:testInputSelections",
-    result: truncPoint(s1.anchorPt).equals(truncPoint(s2.anchorPt)) &&
-            truncPoint(s1.focusPt).equals(truncPoint(s2.focusPt)),
-    msg: msg
-  });
-}
-
-/* =================================================================================
- *
- * Page definition for all tests.
- *
- */
     </script>
   </head>
 
   <body onload="startTests();">
     <input id="LTRInput" dir="ltr" type="text" maxlength="57" size="57" value="">
     <br>
     <input id="RTLInput" dir="rtl" type="text" maxlength="35" size="35" value="">
   </body>
--- a/mobile/android/base/tests/roboextender/testSelectionHandler.html
+++ b/mobile/android/base/tests/roboextender/testSelectionHandler.html
@@ -1,25 +1,25 @@
 <html>
   <head>
     <title>Automated Text Selection tests for Mobile</title>
     <meta name="viewport" content="initial-scale=1.0"/>
     <script type="application/javascript"
       src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
+    <script type="application/javascript" src="SelectionUtils.js"></script>
     <script type="application/javascript;version=1.8">
 
+// Name of this test.
+const TYPE_NAME = "Robocop:testSelectionHandler";
+
 const DIV_POINT_TEXT = "Under";
 const INPUT_TEXT = "Text for select all in an <input>";
 const TEXTAREA_TEXT = "Text for select all in a <textarea>";
 const READONLY_INPUT_TEXT = "readOnly text";
 
-const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
-Cu.import("resource://gre/modules/Messaging.jsm");
-Cu.import("resource://gre/modules/Services.jsm");
-
 /* =================================================================================
  *
  * Start of all text selection tests, check initialization state.
  *
  */
 function startTests() {
   testSelectAllDivs().
     then(testSelectDivAtPoint).
@@ -343,63 +343,16 @@ function testAttachCaretFail() {
       is(attachCaretResult, sh.ATTACH_ERROR_INCOMPATIBLE,
         "attachCaret() should have failed predictably."),
       is(sh._activeType, sh.TYPE_NONE,
         "Selection should not be active at end of testAttachCaretFail."),
     ]);
   });
 }
 
-
-/* =================================================================================
- *
- * After finish of all selection tests, wrap up and go home.
- *
- */
-function finishTests() {
-  Messaging.sendRequest({
-    type: "Robocop:testSelectionHandler",
-    result: true,
-    msg: "Done!",
-    done: true
-  });
-}
-
-/* ============================== Utility functions ======================
- *
- * Common functions available to all tests.
- *
- */
-function getSelectionHandler() {
-  return (!this._selectionHandler) ?
-    this._selectionHandler = Services.wm.getMostRecentWindow("navigator:browser").SelectionHandler :
-    this._selectionHandler;
-}
-
-function ok(one, msg) {
-  return Messaging.sendRequestForResult({
-    type: "Robocop:testSelectionHandler",
-    result: one,
-    msg: msg
-  });
-}
-
-function is(one, two, msg) {
-  return Messaging.sendRequestForResult({
-    type: "Robocop:testSelectionHandler",
-    result: one === two,
-    msg: msg + " : " + one + " === " + two
-  });
-}
-
-/* =================================================================================
- *
- * Page definition for all tests.
- *
- */
     </script>
   </head>
 
   <body onload="startTests();">
 
     <div id="selDiv">Under sufficiently extreme conditions, quarks may become
       deconfined and exist as free particles. In the course of asymptotic freedom,
       the strong interaction becomes weaker at higher temperatures. Eventually,
--- a/mobile/android/base/tests/roboextender/testTextareaSelections.html
+++ b/mobile/android/base/tests/roboextender/testTextareaSelections.html
@@ -1,33 +1,32 @@
 <html>
   <head>
     <title>Automated RTL/LTR Text Selection tests for Textareas</title>
     <meta name="viewport" content="initial-scale=1.0"/>
     <script type="application/javascript"
       src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
+    <script type="application/javascript" src="SelectionUtils.js"></script>
     <script type="application/javascript;version=1.8">
 
+// Name of this test.
+const TYPE_NAME = "Robocop:testTextareaSelections";
+
 // Used to create handle movement events for SelectionHandler.
 const ANCHOR = "ANCHOR";
 const FOCUS = "FOCUS";
 
 // Used to specifiy midpoint selection text left/right of center.
 const EST_SEL_TEXT_BOUND_CHARS = 5;
 
 // Used to ensure calculated coords for handle movement events get us
 // "into" the next/prev line vertically.
 const EST_SEL_LINE_CHG_PTS = 10;
 
 
-const { classes: Cc, interfaces: Ci, results: Cr, utils: Cu } = Components;
-Cu.import("resource://gre/modules/Messaging.jsm");
-Cu.import("resource://gre/modules/Services.jsm");
-Cu.import('resource://gre/modules/Geometry.jsm');
-
 // Distance between text selection lines. Reality tested, and also
 // Used to perform multi-line selection selections.
 let selectionLineHeight = 0;
 
 /* =================================================================================
  *
  * Start of all text selection tests, check initialization state.
  */
@@ -726,116 +725,16 @@ function testRTL_moveAnchorHandleDown() 
       "RTL Reversed Changed selection anchorPt.y " +
       "should be equal to Initial selection anchorPt.y"),
     greaterThan(changedSelection.focusPt.y, initialSelection.focusPt.y,
       "RTL Reversed Changed selection focusPt.y " +
       "should be greater than (below) Initial selection focusPt.y"),
   ]);
 }
 
-/* =================================================================================
- *
- * After finish of all selection tests, wrap up and go home.
- *
- */
-function finishTests() {
-  Messaging.sendRequest({
-    type: "Robocop:testTextareaSelections",
-    result: true,
-    msg: "Done!",
-    done: true
-  });
-}
-
-/* ============================== Utility functions ======================
- *
- * Common functions available to all tests.
- *
- */
-function getSelectionHandler() {
-  return (!this._selectionHandler) ?
-    this._selectionHandler = Services.wm.getMostRecentWindow("navigator:browser").SelectionHandler :
-    this._selectionHandler;
-}
-
-function todo(result, msg) {
-  return Messaging.sendRequestForResult({
-    type: "Robocop:testTextareaSelections",
-    todo: result,
-    msg: msg
-  });
-}
-
-function ok(result, msg) {
-  return Messaging.sendRequestForResult({
-    type: "Robocop:testTextareaSelections",
-    result: result,
-    msg: msg
-  });
-}
-
-function is(one, two, msg) {
-  return Messaging.sendRequestForResult({
-    type: "Robocop:testTextareaSelections",
-    result: one === two,
-    msg: msg + " : " + one + " === " + two
-  });
-}
-
-function lessThan(n1, n2, msg) {
-  return Messaging.sendRequestForResult({
-    type: "Robocop:testTextareaSelections",
-    result: n1 < n2,
-    msg: msg + " : " + n1 + " < " + n2
-  });
-}
-
-function greaterThan(n1, n2, msg) {
-  return Messaging.sendRequestForResult({
-    type: "Robocop:testTextareaSelections",
-    result: n1 > n2,
-    msg: msg + " : " + n1 + " > " + n2
-  });
-}
-
-// Use fuzzy logic to compare screen coords.
-function truncPoint(point) {
-  return new Point(Math.trunc(point.x), Math.trunc(point.y));
-}
-
-function pointEquals(p1, p2, msg) {
-  return Messaging.sendRequestForResult({
-    type: "Robocop:testTextareaSelections",
-    result: truncPoint(p1).equals(truncPoint(p2)),
-    msg: msg + " : " + p1.toString() + " == " + p2.toString()
-  });
-}
-
-function pointNotEquals(p1, p2, msg) {
-  return Messaging.sendRequestForResult({
-    type: "Robocop:testTextareaSelections",
-    result: !truncPoint(p1).equals(truncPoint(p2)),
-    msg: msg + " : " + p1.toString() + " == " + p2.toString()
-  });
-}
-
-function selectionExists(selection, msg) {
-  return Messaging.sendRequestForResult({
-    type: "Robocop:testTextareaSelections",
-    result: !truncPoint(selection.anchorPt).equals(truncPoint(selection.focusPt)),
-    msg: msg + " : anchor:" + selection.anchorPt.toString() +
-      " focus:" + selection.focusPt.toString()
-  });
-}
-
-/* =================================================================================
- *
- * Page definition for all tests.
- *
- */
     </script>
   </head>
 
   <body onload="startTests();">
     <textarea id="LTRTextarea" style="direction: ltr;" rows="10" cols="40"
       readonly="true">Under sufficiently extreme conditions, quarks may become deconfined and exist as free particles. In the course of asymptotic freedom, the strong interaction becomes weaker at higher temperatures. Eventually, color confinement would be lost and an extremely hot plasma of freely moving quarks and gluons would be formed. This theoretical phase of matter is called quark-gluon plasma.[81] The exact conditions needed to give rise to this state are unknown and have been the subject of a great deal of speculation and experimentation.</textarea>
 
     <textarea id="RTLTextarea" style="direction: rtl;" rows="10" cols="40"