Bug 580999 - Fix browser_viewport tests [r=mbrubeck]
authorMark Finkle <mfinkle@mozilla.com>
Thu, 22 Jul 2010 10:29:59 -0400
changeset 66382 4aa88b332feb6f60407757b1e8c7d39e2da53fc6
parent 66381 46cd5b0d688cd657ca3c8283dcea1e82e72c7f72
child 66383 fc4f8951e11c50d516a48097695e615e0aa1e1fd
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmbrubeck
bugs580999
Bug 580999 - Fix browser_viewport tests [r=mbrubeck]
mobile/chrome/tests/browser_viewport.js
--- a/mobile/chrome/tests/browser_viewport.js
+++ b/mobile/chrome/tests/browser_viewport.js
@@ -42,32 +42,46 @@
 let testURL_blank = "chrome://mochikit/content/browser/mobile/chrome/browser_blank_01.html";
 let testURL = function testURL(n) {
   return "chrome://mochikit/content/browser/mobile/chrome/browser_viewport_" +
          (n<10 ? "0" : "") + n + ".html";
 }
 
 let working_tab;
 function pageLoaded(url) {
+  dump("------- pageLoaded: " + url + "\n")
   return function() {
+    dump("------- waiting for pageLoaded: " + working_tab.browser.currentURI.spec + "\n")
     return !working_tab.isLoading() && working_tab.browser.currentURI.spec == url;
   }
 }
 
-let numberTests = 10;
+let testData = [
+  { width: 800,     scale: 1 },
+  { width: 533.33,  scale: 1.5 },
+  { width: 533.33,  scale: 1.5 },
+  { width: 533.33,  scale: 1.5,    disableZoom: true },
+  { width: 200,     scale: 4.00 },
+  { width: 2000,    scale: 1.125,  minScale: 1.125 },
+  { width: 266.67,  scale: 3,      maxScale: 3 },
+  { width: 2000,    scale: 1.125 },
+  { width: 10000,   scale: 4 },
+  { width: 533.33,  scale: 1.5,    disableZoom: true }
+];
 
 //------------------------------------------------------------------------------
 // Entry point (must be named "test")
 function test() {
   // This test is async
   waitForExplicitFinish();
 
-  working_tab = Browser.addTab("", true);
+  working_tab = Browser.addTab(testURL_blank, true);
   ok(working_tab, "Tab Opened");
-  startTest(0);
+
+  waitFor(function() { startTest(0); }, pageLoaded(testURL_blank));
 }
 
 function startTest(n) {
   BrowserUI.goToURI(testURL_blank);
   waitFor(verifyBlank(n), pageLoaded(testURL_blank));
 }
 
 function verifyBlank(n) {
@@ -103,47 +117,33 @@ function loadTest(n) {
 }
 
 function is_approx(actual, expected, fuzz, description) {
   is(Math.abs(actual - expected) <= fuzz,
      true,
      description + " [got " + actual + ", expected " + expected + "]");
 }
 
-function getMetaTag(name) {
-  let doc = working_tab.browser.contentDocument;
-  let elements = doc.querySelectorAll("meta[name=\"" + name + "\"]");
-  return elements[0] ? elements[0].getAttribute("content") : undefined;
-}
-
 function verifyTest(n) {
   return function() {
     is(window.innerWidth, 800, "Test assumes window width is 800px");
     is(Services.prefs.getIntPref("zoom.dpiScale") / 100, 1.5, "Test assumes zoom.dpiScale is 1.5");
 
     // Do sanity tests
     var uri = working_tab.browser.currentURI.spec;
     is(uri, testURL(n), "URL is "+testURL(n));
 
-    // Expected results are grabbed from the test HTML file
-    let data = (function() {
-      let result = {};
-      for (let i = 0; i < arguments.length; i++)
-        result[arguments[i]] = getMetaTag("expected-" + arguments[i]);
-
-      return result;
-    })("width", "scale", "minWidth", "maxWidth", "disableZoom");
-
+    let data = testData[n];
     let style = window.getComputedStyle(working_tab.browser, null);
     let actualWidth = parseFloat(style.width.replace(/[^\d\.]+/, ""));
-    is_approx(actualWidth, parseFloat(data.width), .01, "Viewport width="+data.width);
+    is_approx(actualWidth, parseFloat(data.width), .01, "Viewport width=" + data.width);
 
     let bv = Browser._browserView;
     let zoomLevel = bv.getZoomLevel();
-    is_approx(bv.getZoomLevel(), parseFloat(data.scale), .01, "Viewport scale="+data.scale);
+    is_approx(bv.getZoomLevel(), parseFloat(data.scale), .01, "Viewport scale=" + data.scale);
 
     // Test zooming
     if (data.disableZoom) {
       ok(!bv.allowZoom, "Zoom disabled");
 
       Browser.zoom(-1);
       is(bv.getZoomLevel(), zoomLevel, "Zoom in does nothing");
 
@@ -171,15 +171,15 @@ function verifyTest(n) {
       ok(bv.getZoomLevel() <= data.maxScale, "Zoom in limited");
     }
 
     finishTest(n);
   }
 }
 
 function finishTest(n) {
-  if (n+1 < numberTests) {
+  if (n+1 < testData.length) {
     startTest(n+1);
   } else {
     Browser.closeTab(working_tab);
     finish();
   }
 }