Bug 1005588. Fix getBoxQuads test to work when the feature prefs are disabled by default. r=matspal
authorRobert O'Callahan <robert@ocallahan.org>
Tue, 03 Jun 2014 13:54:20 +1200
changeset 206266 74f132824fdaee3b9d3ffaa88a072d4594559c7b
parent 206265 3f549afdb1b725cfbec523701706256d7985650d
child 206267 87fc79cf3fe18bd9b6975eeec849cf350a8846e1
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmatspal
bugs1005588
milestone32.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 1005588. Fix getBoxQuads test to work when the feature prefs are disabled by default. r=matspal
layout/base/tests/test_getBoxQuads_convertPointRectQuad.html
--- a/layout/base/tests/test_getBoxQuads_convertPointRectQuad.html
+++ b/layout/base/tests/test_getBoxQuads_convertPointRectQuad.html
@@ -11,19 +11,19 @@
 // Global variables we want eval() to be able to reference from anywhere
 var f1d;
 var text;
 var suppressedText;
 var suppressedText2;
 var comment;
 var fragment;
 var openedWindow;
-var zeroPoint = new DOMPoint(0,0);
-var zeroRect = new DOMRect(0,0,0,0);
-var zeroQuad = new DOMQuad(zeroRect);
+var zeroPoint;
+var zeroRect;
+var zeroQuad;
 var notInDocument = document.createElement('div');
 
 function isEval(expr, b) {
   is(eval(expr), b, expr);
 }
 
 function isApprox(a, b, msg, options) {
   if (a != b && 'tolerance' in options &&
@@ -350,20 +350,50 @@ TextTextTextTextTextTextTextTextTextText
 SimpleTest.waitForExplicitFinish();
 
 window.scrollTo(0,0);
 
 function startTest() {
   SpecialPowers.pushPrefEnv({"set": [["layout.css.DOMPoint.enabled", true],
                                      ["layout.css.DOMQuad.enabled", true],
                                      ["layout.css.getBoxQuads.enabled", true],
-                                     ["layout.css.convertFromNode.enabled", true]]}, runTest);
+                                     ["layout.css.convertFromNode.enabled", true]]}, grabFeatures);
+}
+
+// This is a bit of a hack but it works. Our Window object was set up while
+// the prefs might have been false so it may not have the features we're
+// testing. Create an <iframe> whose Window is initialized while the prefs are
+// true, and we can steal the features from that Window.
+// When these prefs are enabled on all builds by default, we can skip this step.
+function grabFeatures() {
+  var x = document.createElement('iframe');
+  x.src = "about:blank";
+  document.body.appendChild(x);
+  function setupFeatures(w) {
+    for (var name of ["getBoxQuads", "convertQuadFromNode", "convertRectFromNode", "convertPointFromNode"]) {
+      w.Text.prototype[name] = x.contentWindow.Text.prototype[name];
+      w.Element.prototype[name] = x.contentWindow.Element.prototype[name];
+      w.Document.prototype[name] = x.contentWindow.Document.prototype[name];
+    }
+    for (var name of ["DOMPoint", "DOMQuad"]) {
+      w[name] = x.contentWindow[name];
+    }
+  }
+  x.onload = function() {
+    setupFeatures(window);
+    setupFeatures(f1.contentWindow);
+    runTest();
+  };
 }
 
 function runTest() {
+  zeroPoint = new DOMPoint(0,0);
+  zeroRect = new DOMRect(0,0,0,0);
+  zeroQuad = new DOMQuad(zeroRect);
+
   // Setup globals
   f1d = f1.contentWindow.f1d;
   text = textContainer.firstChild;
   suppressedText = suppressedTextContainer.firstChild;
   suppressedText2 = suppressedTextContainer2.firstChild;
   comment = commentContainer.firstChild;
   fragment = document.createDocumentFragment();