Bug 1376852 - Port bounds/test_zoom{,_text}.html r=yzen
authorEitan Isaacson <eitan@monotonous.org>
Mon, 12 Jun 2017 16:26:24 -0700
changeset 416796 cd5bd8ce9e8429bda02928262b63720f41a857ba
parent 416795 b2851f5df207521a02c608e714f6a46c27de39cf
child 416797 27cbe1c0b7c5f4de90498d24e20ebf7dbf1540c9
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyzen
bugs1376852
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1376852 - Port bounds/test_zoom{,_text}.html r=yzen
accessible/moz.build
accessible/tests/browser/bounds/browser.ini
accessible/tests/browser/bounds/browser_test_zoom.js
accessible/tests/browser/bounds/browser_test_zoom_text.js
accessible/tests/browser/bounds/head.js
accessible/tests/browser/scroll/browser_test_zoom_text.js
accessible/tests/browser/scroll/head.js
accessible/tests/browser/shared-head.js
accessible/tests/mochitest/bounds/a11y.ini
accessible/tests/mochitest/bounds/test_zoom.html
accessible/tests/mochitest/bounds/test_zoom_text.html
--- a/accessible/moz.build
+++ b/accessible/moz.build
@@ -26,16 +26,17 @@ DIRS += [ 'aom',
 ]
 
 if CONFIG['MOZ_XUL']:
     DIRS += ['xul']
 
 TEST_DIRS += ['tests/mochitest']
 
 BROWSER_CHROME_MANIFESTS += [
+  'tests/browser/bounds/browser.ini',
   'tests/browser/browser.ini',
   'tests/browser/e10s/browser.ini',
   'tests/browser/scroll/browser.ini',
   'tests/browser/states/browser.ini'
 ]
 
 with Files("**"):
-    BUG_COMPONENT = ("Core", "Disability Access APIs")
\ No newline at end of file
+    BUG_COMPONENT = ("Core", "Disability Access APIs")
new file mode 100644
--- /dev/null
+++ b/accessible/tests/browser/bounds/browser.ini
@@ -0,0 +1,12 @@
+[DEFAULT]
+skip-if = e10s && os == 'win' && release_or_beta
+support-files =
+  head.js
+  !/accessible/tests/browser/events.js
+  !/accessible/tests/browser/shared-head.js
+  !/accessible/tests/mochitest/*.js
+  !/accessible/tests/mochitest/letters.gif
+
+[browser_test_zoom.js]
+[browser_test_zoom_text.js]
+skip-if = os == 'win' # Bug 1372296
new file mode 100644
--- /dev/null
+++ b/accessible/tests/browser/bounds/browser_test_zoom.js
@@ -0,0 +1,68 @@
+/* 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/. */
+
+"use strict";
+
+/* import-globals-from ../../mochitest/layout.js */
+
+async function getContentBoundsForDOMElm(browser, id) {
+  return ContentTask.spawn(browser, id, contentId => {
+    this.ok = ok;
+    return getBoundsForDOMElm(contentId);
+  });
+}
+
+async function testContentBounds(browser, acc) {
+  let [expectedX, expectedY, expectedWidth, expectedHeight] =
+    await getContentBoundsForDOMElm(browser, getAccessibleDOMNodeID(acc));
+
+  let [x, y, width, height] = getBounds(acc);
+  let prettyAccName = prettyName(acc);
+  is(x, expectedX, "Wrong x coordinate of " + prettyAccName);
+  is(y, expectedY, "Wrong y coordinate of " + prettyAccName);
+  is(width, expectedWidth, "Wrong width of " + prettyAccName);
+  is(height, expectedHeight, "Wrong height of " + prettyAccName);
+}
+
+async function runTests(browser, accDoc) {
+  loadFrameScripts(browser, { name: 'layout.js', dir: MOCHITESTS_DIR });
+
+  let p1 = findAccessibleChildByID(accDoc, "p1");
+  let p2 = findAccessibleChildByID(accDoc, "p2");
+  let imgmap = findAccessibleChildByID(accDoc, "imgmap");
+  if (!imgmap.childCount) {
+    // An image map may not be available even after the doc and image load
+    // is complete. We don't recieve any DOM events for this change either,
+    // so we need to wait for a REORDER.
+    await waitForEvent(EVENT_REORDER, "imgmap");
+  }
+  let area = imgmap.firstChild;
+
+  await testContentBounds(browser, p1);
+  await testContentBounds(browser, p2);
+  await testContentBounds(browser, area);
+
+  await ContentTask.spawn(browser, {}, () => {
+    zoomDocument(document, 2.0);
+  });
+
+  await testContentBounds(browser, p1);
+  await testContentBounds(browser, p2);
+  await testContentBounds(browser, area);
+}
+
+/**
+ * Test accessible boundaries when page is zoomed
+ */
+addAccessibleTask(`
+<p id="p1">para 1</p><p id="p2">para 2</p>
+<map name="atoz_map" id="map">
+  <area id="area1" href="http://mozilla.org"
+        coords=17,0,30,14" alt="mozilla.org" shape="rect">
+</map>
+<img id="imgmap" width="447" height="15"
+     usemap="#atoz_map"
+     src="http://example.com/a11y/accessible/tests/mochitest/letters.gif">`,
+  runTests
+);
new file mode 100644
--- /dev/null
+++ b/accessible/tests/browser/bounds/browser_test_zoom_text.js
@@ -0,0 +1,41 @@
+/* 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/. */
+
+"use strict";
+
+/* import-globals-from ../../mochitest/layout.js */
+
+async function runTests(browser, accDoc) {
+  function testTextNode(id) {
+    let hyperTextNode = findAccessibleChildByID(accDoc, id);
+    let textNode = hyperTextNode.firstChild;
+
+    let [x, y, width, height] = getBounds(textNode);
+    testTextBounds(hyperTextNode, 0, -1, [x, y, width, height],
+                   COORDTYPE_SCREEN_RELATIVE);
+  }
+
+  loadFrameScripts(browser, { name: 'layout.js', dir: MOCHITESTS_DIR });
+
+  testTextNode("p1");
+  testTextNode("p2");
+
+  await ContentTask.spawn(browser, {}, () => {
+    zoomDocument(document, 2.0);
+  });
+
+  testTextNode("p1");
+
+  await ContentTask.spawn(browser, {}, () => {
+    zoomDocument(document, 1.0);
+  });
+}
+
+/**
+ * Test the text range boundary when page is zoomed
+ */
+addAccessibleTask(`
+  <p id='p1' style='font-family: monospace;'>Tilimilitryamdiya</p>
+  <p id='p2'>ل</p>`, runTests
+);
new file mode 100644
--- /dev/null
+++ b/accessible/tests/browser/bounds/head.js
@@ -0,0 +1,16 @@
+/* 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/. */
+
+'use strict';
+
+// Load the shared-head file first.
+/* import-globals-from ../shared-head.js */
+Services.scriptloader.loadSubScript(
+  'chrome://mochitests/content/browser/accessible/tests/browser/shared-head.js',
+  this);
+
+// Loading and common.js from accessible/tests/mochitest/ for all tests, as
+// well as events.js.
+loadScripts({ name: 'common.js', dir: MOCHITESTS_DIR },
+            { name: 'layout.js', dir: MOCHITESTS_DIR }, 'events.js');
--- a/accessible/tests/browser/scroll/browser_test_zoom_text.js
+++ b/accessible/tests/browser/scroll/browser_test_zoom_text.js
@@ -3,27 +3,31 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 'use strict';
 
 /* import-globals-from ../../mochitest/layout.js */
 loadScripts({ name: 'layout.js', dir: MOCHITESTS_DIR });
 
 async function runTests(browser, accDoc) {
+  loadFrameScripts(browser, { name: 'layout.js', dir: MOCHITESTS_DIR });
+
   let paragraph = findAccessibleChildByID(accDoc, "paragraph", [nsIAccessibleText]);
   let offset = 64; // beginning of 4th stanza
 
   let [x /*,y*/] = getPos(paragraph);
   let [docX, docY] = getPos(accDoc);
 
   paragraph.scrollSubstringToPoint(offset, offset,
                                    COORDTYPE_SCREEN_RELATIVE, docX, docY);
   testTextPos(paragraph, offset, [x, docY], COORDTYPE_SCREEN_RELATIVE);
 
-  await zoomContent(browser, 2.0);
+  await ContentTask.spawn(browser, {}, () => {
+    zoomDocument(document, 2.0);
+  });
 
   paragraph = findAccessibleChildByID(accDoc, "paragraph2", [nsIAccessibleText]);
   offset = 52; // // beginning of 4th stanza
   [x /*,y*/] = getPos(paragraph);
   paragraph.scrollSubstringToPoint(offset, offset,
                                    COORDTYPE_SCREEN_RELATIVE, docX, docY);
   testTextPos(paragraph, offset, [x, docY], COORDTYPE_SCREEN_RELATIVE);
 }
--- a/accessible/tests/browser/scroll/head.js
+++ b/accessible/tests/browser/scroll/head.js
@@ -1,30 +1,15 @@
 /* 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/. */
 
 'use strict';
 
-/* exported zoomContent */
-
 // Load the shared-head file first.
 /* import-globals-from ../shared-head.js */
 Services.scriptloader.loadSubScript(
   'chrome://mochitests/content/browser/accessible/tests/browser/shared-head.js',
   this);
 
-async function zoomContent(browser, zoom)
-{
-  return ContentTask.spawn(browser, zoom, _zoom => {
-    let docShell = content
-      .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
-      .getInterface(Components.interfaces.nsIWebNavigation)
-      .QueryInterface(Components.interfaces.nsIDocShell);
-    let docViewer = docShell.contentViewer;
-
-    docViewer.fullZoom = _zoom;
-  });
-}
-
 // Loading and common.js from accessible/tests/mochitest/ for all tests, as
 // well as events.js.
 loadScripts({ name: 'common.js', dir: MOCHITESTS_DIR }, 'events.js');
--- a/accessible/tests/browser/shared-head.js
+++ b/accessible/tests/browser/shared-head.js
@@ -3,17 +3,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 'use strict';
 
 /* import-globals-from ../mochitest/common.js */
 /* import-globals-from events.js */
 
 /* exported Logger, MOCHITESTS_DIR, invokeSetAttribute, invokeFocus,
-            invokeSetStyle, getAccessibleDOMNodeID,
+            invokeSetStyle, getAccessibleDOMNodeID, getAccessibleTagName,
             addAccessibleTask, findAccessibleChildByID, isDefunct,
             CURRENT_CONTENT_DIR, loadScripts, loadFrameScripts, Cc, Cu */
 
 const { interfaces: Ci, utils: Cu, classes: Cc } = Components;
 
 /**
  * Current browser test directory path used to load subscripts.
  */
@@ -26,16 +26,18 @@ const CURRENT_DIR =
 const MOCHITESTS_DIR =
   'chrome://mochitests/content/a11y/accessible/tests/mochitest/';
 /**
  * A base URL for test files used in content.
  */
 const CURRENT_CONTENT_DIR =
   'http://example.com/browser/accessible/tests/browser/';
 
+const LOADED_FRAMESCRIPTS = new Map();
+
 /**
  * Used to dump debug information.
  */
 let Logger = {
   /**
    * Set up this variable to dump log messages into console.
    */
   dumpToConsole: false,
@@ -183,17 +185,27 @@ function loadFrameScripts(browser, ...sc
       } else {
         // Otherwise it is a serealized script.
         frameScript = `data:,${script}`;
       }
     } else {
       // Script is a object that has { dir, name } format.
       frameScript = `${script.dir}${script.name}`;
     }
+
+    let loadedScriptSet = LOADED_FRAMESCRIPTS.get(frameScript);
+    if (!loadedScriptSet) {
+      loadedScriptSet = new WeakSet();
+      LOADED_FRAMESCRIPTS.set(frameScript, loadedScriptSet);
+    } else if (loadedScriptSet.has(browser)) {
+      continue;
+    }
+
     mm.loadFrameScript(frameScript, false, true);
+    loadedScriptSet.add(browser);
   }
 }
 
 /**
  * A wrapper around browser test add_task that triggers an accessible test task
  * as a new browser test task with given document, data URL or markup snippet.
  * @param  {String}                 doc  URL (relative to current directory) or
  *                                       data URL or markup snippet that is used
@@ -276,16 +288,29 @@ function isDefunct(accessible) {
     if (defunct) {
       Logger.log(`Defunct accessible: ${prettyName(accessible)}`);
     }
   }
   return defunct;
 }
 
 /**
+ * Get the DOM tag name for a given accessible.
+ * @param  {nsIAccessible}  accessible accessible
+ * @return {String?}                   tag name of associated DOM node, or null.
+ */
+function getAccessibleTagName(acc) {
+  try {
+    return acc.attributes.getStringProperty("tag");
+  } catch (e) {
+    return null;
+  }
+}
+
+/**
  * Traverses the accessible tree starting from a given accessible as a root and
  * looks for an accessible that matches based on its DOMNode id.
  * @param  {nsIAccessible}  accessible root accessible
  * @param  {String}         id         id to look up accessible for
  * @param  {Array?}         interfaces the interface or an array interfaces
  *                                     to query it/them from obtained accessible
  * @return {nsIAccessible?}            found accessible if any
  */
--- a/accessible/tests/mochitest/bounds/a11y.ini
+++ b/accessible/tests/mochitest/bounds/a11y.ini
@@ -1,8 +1,6 @@
 [DEFAULT]
 support-files =
   !/accessible/tests/mochitest/*.js
 
 [test_list.html]
 [test_select.html]
-[test_zoom.html]
-[test_zoom_text.html]
deleted file mode 100644
--- a/accessible/tests/mochitest/bounds/test_zoom.html
+++ /dev/null
@@ -1,96 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-  <title>Accessible boundaries when page is zoomed</title>
-  <link rel="stylesheet" type="text/css"
-        href="chrome://mochikit/content/tests/SimpleTest/test.css" />
-
-  <script type="application/javascript"
-          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
-  <script type="application/javascript"
-          src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
-
-  <script type="application/javascript"
-          src="../common.js"></script>
-  <script type="application/javascript"
-          src="../role.js"></script>
-  <script type="application/javascript"
-          src="../events.js"></script>
-  <script type="application/javascript"
-          src="../layout.js"></script>
-  <script type="application/javascript"
-          src="../browser.js"></script>
-
-  <script type="application/javascript">
-    //gA11yEventDumpToConsole = true;
-    //enableLogging("tree,verbose");
-    function doPreTest()
-    {
-      var tabDocument = currentTabDocument();
-      var imgMap = tabDocument.getElementById("imgmap");
-      waitForImageMap(imgMap, doTest);
-    }
-
-    function doTest()
-    {
-      // Bug 746176: Failure of this whole test file on OS X.
-      if (MAC) {
-        todo(false, "Fix bug 746176 on Mac");
-        closeBrowserWindow();
-        SimpleTest.finish();
-        return;
-      }
-
-      var tabDocument = currentTabDocument();
-      var p1 = tabDocument.getElementById("p1");
-      var p2 = tabDocument.getElementById("p2");
-
-      var imgMap = tabDocument.getElementById("imgmap");
-      var imgMapAcc = getAccessible(imgMap);
-      var area = imgMapAcc.firstChild;
-
-      testBounds(p1);
-      testBounds(p2);
-      testBounds(area);
-
-      zoomDocument(tabDocument, 2.0);
-
-      testBounds(p1);
-      testBounds(p2);
-      testBounds(area);
-
-      closeBrowserWindow();
-      SimpleTest.finish();
-    }
-
-    var url = "data:text/html,<html><body>";
-    url += "<p id='p1'>para 1</p><p id='p2'>para 2</p>";
-    url += "<map name='atoz_map' id='map'>";
-    url += "  <area id='area1' href='http%3A%2F%2Fmozilla.org'";
-    url += "        coords=17,0,30,14' alt='mozilla.org' shape='rect'>";
-    url += "</map>";
-    url += "<img id='imgmap' width='447' height='15'";
-    url += "     usemap='%23atoz_map'";
-    url += "     src='chrome%3A%2F%2Fmochitests%2Fcontent%2Fa11y%2Faccessible%2Fletters.gif'>";
-    url += "</body></html>";
-
-    SimpleTest.waitForExplicitFinish();
-    openBrowserWindow(doPreTest,
-                      url,
-                      { left: 0, top: 0, width: 600, height: 600 });
-  </script>
-
-</head>
-<body>
-
-  <a target="_blank"
-     href="https://bugzilla.mozilla.org/show_bug.cgi?id=650241"
-     title="Location returned by accessibles incorrect when page zoomed">
-    Mozilla Bug 650241
-  </a>
-  <p id="display"></p>
-  <div id="content" style="display: none"></div>
-  <pre id="test">
-  </pre>
-</body>
-</html>
deleted file mode 100644
--- a/accessible/tests/mochitest/bounds/test_zoom_text.html
+++ /dev/null
@@ -1,77 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-  <title>The text range boundary when page is zoomed</title>
-  <meta http-equiv="Content-Type" content="text/html;charset=utf-8"></meta>
-  <link rel="stylesheet" type="text/css"
-        href="chrome://mochikit/content/tests/SimpleTest/test.css" />
-
-  <script type="application/javascript"
-          src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
-  <script type="application/javascript"
-          src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
-
-  <script type="application/javascript"
-          src="../common.js"></script>
-  <script type="application/javascript"
-          src="../role.js"></script>
-  <script type="application/javascript"
-          src="../layout.js"></script>
-  <script type="application/javascript"
-          src="../browser.js"></script>
-
-  <script type="application/javascript">
-    function testTextNode(aDoc, aContainerID)
-    {
-      var hyperTextNode = aDoc.getElementById(aContainerID);
-      var textNode = hyperTextNode.firstChild;
-
-      var [x, y, width, height] = getBounds(textNode);
-      testTextBounds(hyperTextNode, 0, -1, [x, y, width, height],
-                     COORDTYPE_SCREEN_RELATIVE);
-    }
-
-    function doTest()
-    {
-      var tabDocument = currentTabDocument();
-      testTextNode(tabDocument, "p1");
-      testTextNode(tabDocument, "p2");
-
-      zoomDocument(tabDocument, 2.0);
-
-      testTextNode(tabDocument, "p1");
-
-      zoomDocument(tabDocument, 1.0);
-
-      closeBrowserWindow();
-      SimpleTest.finish();
-    }
-
-    var url = "data:text/html,<html>" +
-      "<meta http-equiv='Content-Type' content='text/html;charset=utf-8'>" +
-      "</meta><body>" +
-      "<p id='p1' style='font-family: monospace;'>Tilimilitryamdiya</p>" +
-      "<p id='p2'>ل</p>"
-      "</body></html>";
-
-    SimpleTest.waitForExplicitFinish();
-    openBrowserWindow(doTest,
-                      url,
-                      { left: 0, top: 0, width: 600, height: 600 });
-
-  </script>
-
-</head>
-<body>
-
-  <a target="_blank"
-     href="https://bugzilla.mozilla.org/show_bug.cgi?id=727942"
-     title="Text range boundaries are incorrect when page is zoomed">
-    Mozilla Bug 727942
-  </a>
-  <p id="display"></p>
-  <div id="content" style="display: none"></div>
-  <pre id="test">
-  </pre>
-</body>
-</html>