Bug 803675 - part2: Add tests.r=bz
authorTetsuharu OHZEKI <saneyuki.s.snyk@gmail.com>
Mon, 18 Feb 2013 20:27:48 +0900
changeset 122233 10f97cce1a590ff50b93bb5bf8998655c9699610
parent 122232 a71e34325926548ba83c33e0a07e9c6106db13e4
child 122234 6b7b42fdfd57276b1fb0af6e6791289078f2ca36
push id24327
push usergszorc@mozilla.com
push dateTue, 19 Feb 2013 05:22:32 +0000
treeherdermozilla-central@e8f8a3f6f1f6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbz
bugs803675
milestone21.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 803675 - part2: Add tests.r=bz
browser/base/content/test/Makefile.in
browser/base/content/test/browser_fullscreen-window-open.js
browser/base/content/test/file_fullscreen-window-open.html
--- a/browser/base/content/test/Makefile.in
+++ b/browser/base/content/test/Makefile.in
@@ -168,16 +168,18 @@ endif
                  browser_homeDrop.js \
                  browser_keywordBookmarklets.js \
                  browser_contextSearchTabPosition.js \
                  browser_ctrlTab.js \
                  browser_customize_popupNotification.js \
                  browser_disablechrome.js \
                  browser_discovery.js \
                  browser_duplicateIDs.js \
+                 browser_fullscreen-window-open.js \
+                 file_fullscreen-window-open.html \
                  browser_gestureSupport.js \
                  browser_getshortcutoruri.js \
                  browser_hide_removing.js \
                  browser_overflowScroll.js \
                  browser_locationBarCommand.js \
                  browser_locationBarExternalLoad.js \
                  browser_page_style_menu.js \
                  browser_pinnedTabs.js \
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/browser_fullscreen-window-open.js
@@ -0,0 +1,394 @@
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+Components.utils.import("resource://gre/modules/Services.jsm");
+
+let Cc = Components.classes;
+let Ci = Components.interfaces;
+
+const PREF_DISABLE_OPEN_NEW_WINDOW = "browser.link.open_newwindow.disabled_in_fullscreen";
+const isOSX = (Services.appinfo.OS === "Darwin");
+
+const TEST_FILE = "file_fullscreen-window-open.html";
+const gHttpTestRoot = getRootDirectory(gTestPath).replace("chrome://mochitests/content/",
+                                                          "http://127.0.0.1:8888/");
+
+function test () {
+  waitForExplicitFinish();
+
+  Services.prefs.setBoolPref(PREF_DISABLE_OPEN_NEW_WINDOW, true);
+
+  let newTab = gBrowser.addTab();
+  gBrowser.selectedTab = newTab;
+
+  let gTestBrowser = gBrowser.selectedBrowser;
+  gTestBrowser.addEventListener("load", function onLoad(){
+    gTestBrowser.removeEventListener("load", onLoad, true, true);
+
+    // Enter browser fullscreen mode.
+    BrowserFullScreen();
+
+    runNextTest();
+  }, true, true);
+  gTestBrowser.contentWindow.location.href = gHttpTestRoot + TEST_FILE;
+}
+
+registerCleanupFunction(function(){
+  // Exit browser fullscreen mode.
+  BrowserFullScreen();
+
+  gBrowser.removeCurrentTab();
+
+  Services.prefs.clearUserPref(PREF_DISABLE_OPEN_NEW_WINDOW);
+});
+
+let gTests = [
+  test_open,
+  test_open_with_size,
+  test_open_with_pos,
+  test_open_with_outerSize,
+  test_open_with_innerSize,
+  test_open_with_dialog,
+  test_open_when_open_new_window_by_pref,
+  test_open_with_pref_to_disable_in_fullscreen,
+  test_open_from_chrome,
+];
+
+function runNextTest () {
+  let test = gTests.shift();
+  if (test) {
+    executeSoon(test);
+  }
+  else {
+    finish();
+  }
+}
+
+
+// Test for window.open() with no feature.
+function test_open() {
+  waitForTabOpen({
+    message: {
+      title: "test_open",
+      param: "",
+    },
+    finalizeFn: function () {},
+  });
+}
+
+// Test for window.open() with width/height.
+function test_open_with_size() {
+  waitForTabOpen({
+    message: {
+      title: "test_open_with_size",
+      param: "width=400,height=400",
+    },
+    finalizeFn: function () {},
+  });
+}
+
+// Test for window.open() with top/left.
+function test_open_with_pos() {
+  waitForTabOpen({
+    message: {
+      title: "test_open_with_pos",
+      param: "top=200,left=200",
+    },
+    finalizeFn: function () {},
+  });
+}
+
+// Test for window.open() with outerWidth/Height.
+function test_open_with_outerSize() {
+  let [outerWidth, outerHeight] = [window.outerWidth, window.outerHeight];
+  waitForTabOpen({
+    message: {
+      title: "test_open_with_outerSize",
+      param: "outerWidth=200,outerHeight=200",
+    },
+    successFn: function () {
+      is(window.outerWidth, outerWidth, "Don't change window.outerWidth.");
+      is(window.outerHeight, outerHeight, "Don't change window.outerHeight.");
+    },
+    finalizeFn: function () {},
+  });
+}
+
+// Test for window.open() with innerWidth/Height.
+function test_open_with_innerSize() {
+  let [innerWidth, innerHeight] = [window.innerWidth, window.innerHeight];
+  waitForTabOpen({
+    message: {
+      title: "test_open_with_innerSize",
+      param: "innerWidth=200,innerHeight=200",
+    },
+    successFn: function () {
+      is(window.innerWidth, innerWidth, "Don't change window.innerWidth.");
+      is(window.innerHeight, innerHeight, "Don't change window.innerHeight.");
+    },
+    finalizeFn: function () {},
+  });
+}
+
+// Test for window.open() with dialog.
+function test_open_with_dialog() {
+  waitForTabOpen({
+    message: {
+      title: "test_open_with_dialog",
+      param: "dialog=yes",
+    },
+    finalizeFn: function () {},
+  });
+}
+
+// Test for window.open()
+// when "browser.link.open_newwindow" is nsIBrowserDOMWindow.OPEN_NEWWINDOW
+function test_open_when_open_new_window_by_pref() {
+  const PREF_NAME = "browser.link.open_newwindow";
+  Services.prefs.setIntPref(PREF_NAME, Ci.nsIBrowserDOMWindow.OPEN_NEWWINDOW);
+  is(Services.prefs.getIntPref(PREF_NAME), Ci.nsIBrowserDOMWindow.OPEN_NEWWINDOW,
+     PREF_NAME + " is nsIBrowserDOMWindow.OPEN_NEWWINDOW at this time");
+
+  waitForTabOpen({
+    message: {
+      title: "test_open_when_open_new_window_by_pref",
+      param: "width=400,height=400",
+    },
+    finalizeFn: function () {
+      Services.prefs.clearUserPref(PREF_NAME);
+    },
+  });
+}
+
+// Test for the pref, "browser.link.open_newwindow.disabled_in_fullscreen"
+function test_open_with_pref_to_disable_in_fullscreen() {
+  Services.prefs.setBoolPref(PREF_DISABLE_OPEN_NEW_WINDOW, false);
+
+  waitForWindowOpen({
+    message: {
+      title: "test_open_with_pref_disabled_in_fullscreen",
+      param: "width=400,height=400",
+    },
+    finalizeFn: function () {
+      Services.prefs.setBoolPref(PREF_DISABLE_OPEN_NEW_WINDOW, true);
+    },
+  });
+}
+
+
+// Test for window.open() called from chrome context.
+function test_open_from_chrome() {
+  waitForWindowOpenFromChrome({
+    message: {
+      title: "test_open_from_chrome",
+      param: "",
+    },
+    finalizeFn: function () {},
+    timeout: 10000,
+  });
+}
+
+function waitForTabOpen(aOptions) {
+  let start = Date.now();
+  let timeout = aOptions.timeout || 5000;
+  let message = aOptions.message;
+
+  if (!message.title) {
+    ok(false, "Can't get message.title.");
+    aOptions.finalizeFn();
+    runNextTest();
+    return;
+  }
+
+  info("Running test: " + message.title);
+
+  let onTabOpen = function onTabOpen(aEvent) {
+    gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen, true);
+
+    let tab = aEvent.target;
+    tab.linkedBrowser.addEventListener("load", function onLoad(ev){
+      let browser = ev.currentTarget;
+      browser.removeEventListener("load", onLoad, true, true);
+      clearTimeout(onTimeout);
+
+      is(browser.contentWindow.document.title, message.title,
+         "Opened Tab is expected: " + message.title);
+
+      if (aOptions.successFn) {
+        aOptions.successFn();
+      }
+
+      gBrowser.removeTab(tab);
+      finalize();
+    }, true, true);
+  }
+  gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen, true);
+
+  let finalize = function () {
+    aOptions.finalizeFn();
+    info("Finished: " + message.title);
+    runNextTest();
+  };
+
+  let onTimeout = setTimeout(function(){
+    gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen, true);
+
+    ok(false, "Timeout: '"+message.title + "'.");
+    finalize();
+  }, timeout);
+
+
+  const URI = "data:text/html;charset=utf-8,<!DOCTYPE html><html><head><title>"+
+              message.title +
+              "<%2Ftitle><%2Fhead><body><%2Fbody><%2Fhtml>";
+
+  executeWindowOpenInContent({
+    uri: URI,
+    title: message.title,
+    option: message.param,
+  });
+}
+
+
+function waitForWindowOpen(aOptions) {
+  let start = Date.now();
+  let timeout = aOptions.timeout || 10000;
+  let message = aOptions.message;
+  let url = aOptions.url || getBrowserURL();
+
+  if (!message.title) {
+    ok(false, "Can't get message.title");
+    aOptions.finalizeFn();
+    runNextTest();
+    return;
+  }
+
+  info("Running test: " + message.title);
+
+  let onFinalize = function () {
+    aOptions.finalizeFn();
+
+    info("Finished: " + message.title);
+    runNextTest();
+  };
+
+  let onTimeout = setTimeout(function(){
+    Services.wm.removeListener(listener);
+    ok(false, "Fail: '"+message.title + "'.");
+
+    onFinalize();
+  }, timeout);
+
+  let listener = new WindowListener(message.title, url, {
+    onSuccess: aOptions.successFn,
+    onTimeout: onTimeout,
+    onFinalize: onFinalize,
+  });
+  Services.wm.addListener(listener);
+
+  const URI = aOptions.url || "about:blank";
+
+  executeWindowOpenInContent({
+    uri: URI,
+    title: message.title,
+    option: message.param,
+  });
+}
+
+function executeWindowOpenInContent(aParam) {
+  var testWindow = gBrowser.selectedBrowser.contentWindow;
+  var testElm = testWindow.document.getElementById("test");
+
+  testElm.setAttribute("data-test-param", JSON.stringify(aParam));
+  EventUtils.synthesizeMouseAtCenter(testElm, {}, testWindow);
+}
+
+function waitForWindowOpenFromChrome(aOptions) {
+  let start = Date.now();
+  let timeout = aOptions.timeout || 10000;
+  let message = aOptions.message;
+  let url = aOptions.url || getBrowserURL();
+
+  if (!message.title) {
+    ok(false, "Can't get message.title");
+    aOptions.finalizeFn();
+    runNextTest();
+    return;
+  }
+
+  info("Running test: " + message.title);
+
+  let onFinalize = function () {
+    aOptions.finalizeFn();
+
+    info("Finished: " + message.title);
+    runNextTest();
+  };
+
+  let onTimeout = setTimeout(function(){
+    Services.wm.removeListener(listener);
+    ok(false, "Fail: '"+message.title + "'.");
+
+    testWindow.close();
+    onFinalize();
+  }, timeout);
+
+  let listener = new WindowListener(message.title, url, {
+    onSuccess: aOptions.successFn,
+    onTimeout: onTimeout,
+    onFinalize: onFinalize,
+  });
+  Services.wm.addListener(listener);
+
+
+  const URI = aOptions.url || "about:blank";
+
+  let testWindow = window.open(URI, message.title, message.option);
+}
+
+function WindowListener(aTitle, aUrl, aCallBackObj) {
+  this.test_title = aTitle;
+  this.test_url = aUrl;
+  this.callback_onSuccess = aCallBackObj.onSuccess;
+  this.callBack_onTimeout = aCallBackObj.onTimeout;
+  this.callBack_onFinalize = aCallBackObj.onFinalize;
+}
+WindowListener.prototype = {
+
+  test_title: null,
+  test_url: null,
+  callback_onSuccess: null,
+  callBack_onTimeout: null,
+  callBack_onFinalize: null,
+
+  onOpenWindow: function(aXULWindow) {
+    Services.wm.removeListener(this);
+
+    let domwindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor)
+                    .getInterface(Ci.nsIDOMWindow);
+    domwindow.addEventListener("load", function onLoad(aEvent) {
+      is(domwindow.document.location.href, this.test_url,
+        "Opened Window is expected: "+ this.test_title);
+      if (this.callback_onSuccess) {
+        this.callback_onSuccess();
+      }
+
+      domwindow.removeEventListener("load", onLoad, true);
+      clearTimeout(this.callBack_onTimeout);
+
+      // wait for trasition to fullscreen on OSX Lion later
+      if (isOSX) {
+        setTimeout(function(){
+          domwindow.close();
+          executeSoon(this.callBack_onFinalize);
+        }.bind(this), 3000);
+      }
+      else {
+        domwindow.close();
+        executeSoon(this.callBack_onFinalize);
+      }
+    }.bind(this), true);
+  },
+  onCloseWindow: function(aXULWindow) {},
+  onWindowTitleChange: function(aXULWindow, aNewTitle) {},
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIWindowMediatorListener,
+                                         Ci.nsISupports]),
+};
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/file_fullscreen-window-open.html
@@ -0,0 +1,24 @@
+<!DOCTYPE html>
+<html>
+  <head>
+    <title>Test for window.open() when browser is in fullscreen</title>
+  </head>
+  <body>
+    <script>
+      window.addEventListener("load", function onLoad() {
+        window.removeEventListener("load", onLoad, true);
+
+        document.getElementById("test").addEventListener("click", onClick, true);
+      }, true);
+
+      function onClick(aEvent) {
+        aEvent.preventDefault();
+
+        var dataStr = aEvent.target.getAttribute("data-test-param");
+        var data = JSON.parse(dataStr);
+        window.open(data.uri, data.title, data.option);
+      }
+    </script>
+    <a id="test" href="" data-test-param="">Test</a>
+  </body>
+</html>