Bug 641707 - Fix browser_viewport test timeouts [r=mfinkle, a=test-only]
authorMatt Brubeck <mbrubeck@mozilla.com>
Tue, 15 Mar 2011 01:40:17 -0700
changeset 67513 410db976129a78986767a866abf62ea93f235731
parent 67512 43b51843d114addbd392fc3f36341a1b26a8e307
child 67514 eb536d044e41af103e1d1b56ef3ebd38a2df4771
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)
reviewersmfinkle, test-only
bugs641707
Bug 641707 - Fix browser_viewport test timeouts [r=mfinkle, a=test-only]
mobile/chrome/tests/browser_viewport.js
mobile/chrome/tests/browser_viewport.sjs
--- a/mobile/chrome/tests/browser_viewport.js
+++ b/mobile/chrome/tests/browser_viewport.js
@@ -39,17 +39,20 @@
  * ***** END LICENSE BLOCK ***** */
 
 let baseURI = "http://mochi.test:8888/browser/mobile/chrome/";
 let testURL_blank = baseURI + "browser_blank_01.html";
 
 const DEFAULT_WIDTH = 800;
 
 function testURL(n) {
-  return baseURI + "browser_viewport.sjs?" + encodeURIComponent(gTestData[n].metadata);
+  return baseURI + "browser_viewport.sjs" +
+    "?metadata=" + encodeURIComponent(gTestData[n].metadata || "") +
+    "&style=" + encodeURIComponent(gTestData[n].style || "") +
+    "&xhtml=" + encodeURIComponent(!!gTestData[n].xhtml);
 }
 
 function scaleRatio(n) {
   if ("scaleRatio" in gTestData[n])
     return gTestData[n].scaleRatio;
   return 150; // Default value matches our main target hardware (N900, Nexus One, etc.)
 }
 
@@ -59,88 +62,88 @@ let loadURL = function loadURL(aPageURL,
   messageManager.addMessageListener("MozScrolledAreaChanged", function(aMessage) {
     if (aMessage.target.currentURI.spec == aPageURL) {
       messageManager.removeMessageListener(aMessage.name, arguments.callee);
 
       // HACK: Sometimes there are two MozScrolledAreaChanged messages in a
       // row, and this waitFor is the only way founded to make sure the
       // browser responds to both of them before we do.
       waitFor(aCallback, function() {
-        return aScale == aMessage.target.scale;
+        return !aScale || aScale == aMessage.target.scale;
       });
     }
   });
 
   BrowserUI.goToURI(aPageURL);
 };
 
+// XXX Tests do not yet run correctly in portrait.
+window.resizeTo(800, 480);
+
 let gTestData = [
   { metadata: "", width: DEFAULT_WIDTH, scale: 1 },
   { metadata: "width=device-width, initial-scale=1", width: 533.33, scale: 1.5 },
   { metadata: "width=device-width", width: 533.33, scale: 1.5 },
   { metadata: "width=device-width, initial-scale=1", scaleRatio: 100, width: 800, scale: 1 },
   { metadata: "width=320, initial-scale=1", width: 533.33, scale: 1.5 },
   { metadata: "initial-scale=1.0, user-scalable=no", width: 533.33, scale: 1.5, disableZoom: true },
   { metadata: "initial-scale=1.0, user-scalable=0", width: 533.33, scale: 1.5, disableZoom: true },
   { metadata: "initial-scale=1.0, user-scalable=false", width: 533.33, scale: 1.5, disableZoom: true },
   { metadata: "initial-scale=1.0, user-scalable=NO", width: 533.33, scale: 1.5, disableZoom: false }, // values are case-sensitive
   { metadata: "width=200,height=500", width: 200, scale: 4 },
   { metadata: "width=2000, minimum-scale=0.75", width: 2000, scale: 1.125, minScale: 1.125 },
   { metadata: "width=100, maximum-scale=2.0", width: 266.67, scale: 3, maxScale: 3 },
   { metadata: "width=2000, initial-scale=0.75", width: 2000, scale: 1.125 },
   { metadata: "width=20000, initial-scale=100", width: 10000, scale: 4 },
-  { metadata: "XHTML", width: 533.33, scale: 1.5, disableZoom: false },
+  { xhtml: true, width: 533.33, scale: 1.5, disableZoom: false },
   /* testing spaces between arguments (bug 572696) */
   { metadata: "width= 2000, minimum-scale=0.75", width: 2000, scale: 1.125 },
   { metadata: "width = 2000, minimum-scale=0.75", width: 2000, scale: 1.125 },
   { metadata: "width = 2000 , minimum-scale=0.75", width: 2000, scale: 1.125 },
   { metadata: "width = 2000 , minimum-scale =0.75", width: 2000, scale: 1.125 },
   { metadata: "width = 2000 , minimum-scale = 0.75", width: 2000, scale: 1.125 },
   { metadata: "width =  2000   ,    minimum-scale      =       0.75", width: 2000, scale: 1.125 },
   /* testing opening and switching between pages without a viewport */
-  { metadata: "style=width:400px;margin:0px;", width: DEFAULT_WIDTH, scale: 1 },
-  { metadata: "style=width:1000px;margin:0px;", width: 980, scale: window.innerWidth/1000 },
-  { metadata: "style=width:800px;margin:0px;", width: DEFAULT_WIDTH, scale: 1 },
+  { style: "width:400px;margin:0px;", width: DEFAULT_WIDTH, scale: 1 },
+  { style: "width:2000px;margin:0px;", width: 980, scale: window.innerWidth/2000 },
+  { style: "width:800px;margin:0px;", width: DEFAULT_WIDTH, scale: 1 },
 ];
 
 
-
 //------------------------------------------------------------------------------
 // Entry point (must be named "test")
 function test() {
   // This test is async
   waitForExplicitFinish();
   requestLongerTimeout(2);
 
   currentTab = Browser.addTab("about:blank", true);
   ok(currentTab, "Tab Opened");
 
   startTest(0);
 }
 
 function startTest(n) {
+  info(JSON.stringify(gTestData[n]));
   BrowserUI.goToURI(testURL_blank);
-  loadURL(testURL_blank, verifyBlank(n), 1);
+  loadURL(testURL_blank, verifyBlank(n));
   Services.prefs.setIntPref("browser.viewport.scaleRatio", scaleRatio(n));
 }
 
 function verifyBlank(n) {
   return function() {
     // Do sanity tests
     let uri = currentTab.browser.currentURI.spec;
     is(uri, testURL_blank, "URL Matches blank page " + n);
 
-    // Check viewport settings
     waitFor(function() {
-      is(currentTab.browser.contentWindowWidth, DEFAULT_WIDTH, "Normal 'browser' width is " + DEFAULT_WIDTH + " pixels");
       loadURL(testURL(n), verifyTest(n), gTestData[n].scale);
     }, function() {
-      return currentTab.browser.scale == 1;
-    })
-    
+      return currentTab.browser.contentWindowWidth == DEFAULT_WIDTH;
+    });
   }
 }
 
 function is_approx(actual, expected, fuzz, description) {
   ok(Math.abs(actual - expected) <= fuzz,
      description + " [got " + actual + ", expected " + expected + "]");
 }
 
@@ -194,12 +197,13 @@ function verifyTest(n) {
   }
 }
 
 function finishTest(n) {
   Services.prefs.clearUserPref("browser.viewport.scaleRatio");
   if (n + 1 < gTestData.length) {
     startTest(n + 1);
   } else {
+    window.resizeTo(480, 800);
     Browser.closeTab(currentTab);
     finish();
   }
 }
--- a/mobile/chrome/tests/browser_viewport.sjs
+++ b/mobile/chrome/tests/browser_viewport.sjs
@@ -30,41 +30,36 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
+ function decodeQuery(query) {
+   let result = {};
+   query.split("&").forEach(function(pair) {
+     let [key, val] = pair.split("=");
+     result[key] = decodeURIComponent(val);
+   });
+   return result;
+ }
+
 function handleRequest(request, response) {
   response.setStatusLine(request.httpVersion, 200, "OK");
   response.setHeader("Content-Type", "text/html", false);
 
-  let metadata = "";
-  let style = "";
-  let xhtml = false;
-  let query = decodeURIComponent(request.queryString || "");
+  let params = decodeQuery(request.queryString || "");
 
-  switch (query) {
-    case "XHTML":
-      xhtml = true;
-      break;
-    default:
-      metadata = query;
-      break;
-  }
-  if (/^style/.test(query))
-    style = query.replace("style=", "");
-
-  if (xhtml) {
+  if (params.xhtml == "true") {
     response.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
     response.write("<!DOCTYPE html PUBLIC \"-//WAPFORUM//DTD XHTML Mobile 1.0//EN\" \"http://www.wapforum.org/DTD/xhtml-mobile10.dtd\">");
   }
   response.write("<html xmlns=\"http://www.w3.org/1999/xhtml\"><head><title>Browser Viewport Test</title>");
-  if (metadata)
-    response.write("<meta name=\"viewport\" content=\"" + metadata + "\"/>");
+  if (params.metadata)
+    response.write("<meta name=\"viewport\" content=\"" + params.metadata + "\"/>");
   response.write("</head><body");
 
-  if (style)
-    response.write(" style=\"" + style + "\"");
-  response.write(">" + query + "</body></html>");
+  if (params.style)
+    response.write(" style=\"" + params.style + "\"");
+  response.write(">&nbsp;</body></html>");
 }