Bug 1445385 - migrate test_unknownContentType_delayedbutton.xul to browser-chrome. r=paolo, a=test-only
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/downloads/tests/browser/.eslintrc.js
@@ -0,0 +1,9 @@
+"use strict";
+
+module.exports = {
+ "extends": [
+ "plugin:mozilla/browser-test",
+ "plugin:mozilla/mochitest-test",
+ ]
+};
+
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/downloads/tests/browser/browser.ini
@@ -0,0 +1,9 @@
+[DEFAULT]
+support-files =
+ unknownContentType_dialog_layout_data.pif
+ unknownContentType_dialog_layout_data.pif^headers^
+ unknownContentType_dialog_layout_data.txt
+ unknownContentType_dialog_layout_data.txt^headers^
+
+[browser_unknownContentType_delayedbutton.js]
+[browser_unknownContentType_dialog_layout.js]
\ No newline at end of file
rename from toolkit/mozapps/downloads/tests/chrome/test_unknownContentType_delayedbutton.xul
rename to toolkit/mozapps/downloads/tests/browser/browser_unknownContentType_delayedbutton.js
--- a/toolkit/mozapps/downloads/tests/chrome/test_unknownContentType_delayedbutton.xul
+++ b/toolkit/mozapps/downloads/tests/browser/browser_unknownContentType_delayedbutton.js
@@ -1,114 +1,83 @@
-<?xml version="1.0"?>
-<!-- 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/. -->
-<!--
- * The unknownContentType popup can have two different layouts depending on
- * whether a helper application can be selected or not.
- * This tests that both layouts have correct collapsed elements.
--->
+/* 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/. */
+
+ChromeUtils.import("resource://gre/modules/PromiseUtils.jsm", this);
+
+const UCT_URI = "chrome://mozapps/content/downloads/unknownContentType.xul";
+const LOAD_URI = "http://mochi.test:8888/browser/toolkit/mozapps/downloads/tests/browser/unknownContentType_dialog_layout_data.txt";
-<window title="Unknown Content Type Dialog Test"
- xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
- onload="doTest()">
-
- <script type="application/javascript"
- src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+const DIALOG_DELAY = Services.prefs.getIntPref("security.dialog_enable_delay") + 200;
- <script type="application/javascript"><![CDATA[
- ChromeUtils.import("resource://gre/modules/Services.jsm");
- ChromeUtils.import("resource://gre/modules/Promise.jsm");
+let UCTObserver = {
+ opened: PromiseUtils.defer(),
+ closed: PromiseUtils.defer(),
- const UCT_URI = "chrome://mozapps/content/downloads/unknownContentType.xul";
- const LOAD_URI = "http://mochi.test:8888/chrome/toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.txt";
-
- const DIALOG_DELAY = Services.prefs.getIntPref("security.dialog_enable_delay") + 200;
+ observe(aSubject, aTopic, aData) {
+ let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget);
- let UCTObserver = {
- opened: Promise.defer(),
- closed: Promise.defer(),
-
- observe: function(aSubject, aTopic, aData) {
- let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget);
-
- switch (aTopic) {
- case "domwindowopened":
- win.addEventListener("load", function onLoad(event) {
- win.removeEventListener("load", onLoad, false);
+ switch (aTopic) {
+ case "domwindowopened":
+ win.addEventListener("load", function onLoad(event) {
+ // Let the dialog initialize
+ SimpleTest.executeSoon(function() {
+ UCTObserver.opened.resolve(win);
+ });
+ }, {once: true});
+ break;
- // Let the dialog initialize
- SimpleTest.executeSoon(function() {
- UCTObserver.opened.resolve(win);
- });
- }, false);
- break;
-
- case "domwindowclosed":
- if (win.location == UCT_URI) {
- this.closed.resolve();
- }
- break;
+ case "domwindowclosed":
+ if (win.location == UCT_URI) {
+ this.closed.resolve();
}
- }
- };
+ break;
+ }
+ }
+};
- Services.ww.registerNotification(UCTObserver);
- SimpleTest.waitForExplicitFinish();
- SimpleTest.requestFlakyTimeout("This test is testing a timing-based feature, so it really needs to wait a certain amount of time to verify that the feature worked.");
+function waitDelay(delay) {
+ return new Promise((resolve, reject) => {
+ /* eslint-disable mozilla/no-arbitrary-setTimeout */
+ window.setTimeout(resolve, delay);
+ });
+}
- function waitDelay(delay) {
- return new Promise((resolve, reject) => {
- window.setTimeout(resolve, delay);
- });
- }
-
- function doTest() {
- (async function test_aboutCrashed() {
- let frame = document.getElementById("testframe");
- frame.setAttribute("src", LOAD_URI);
+add_task(async function test_unknownContentType_delayedbutton() {
+ Services.ww.registerNotification(UCTObserver);
- let uctWindow = await UCTObserver.opened.promise;
- let ok = uctWindow.document.documentElement.getButton("accept");
-
- SimpleTest.is(ok.disabled, true, "button started disabled");
-
- await waitDelay(DIALOG_DELAY);
+ await BrowserTestUtils.withNewTab({
+ gBrowser,
+ url: LOAD_URI,
+ }, async function() {
+ let uctWindow = await UCTObserver.opened.promise;
+ let ok = uctWindow.document.documentElement.getButton("accept");
- SimpleTest.is(ok.disabled, false, "button was enabled");
+ SimpleTest.is(ok.disabled, true, "button started disabled");
- focusOutOfDialog = SimpleTest.promiseFocus(window);
- window.focus();
- await focusOutOfDialog;
+ await waitDelay(DIALOG_DELAY);
- SimpleTest.is(ok.disabled, true, "button was disabled");
+ SimpleTest.is(ok.disabled, false, "button was enabled");
- focusOnDialog = SimpleTest.promiseFocus(uctWindow);
- uctWindow.focus();
- await focusOnDialog;
+ let focusOutOfDialog = SimpleTest.promiseFocus(window);
+ window.focus();
+ await focusOutOfDialog;
- SimpleTest.is(ok.disabled, true, "button remained disabled");
+ SimpleTest.is(ok.disabled, true, "button was disabled");
- await waitDelay(DIALOG_DELAY);
- SimpleTest.is(ok.disabled, false, "button re-enabled after delay");
+ let focusOnDialog = SimpleTest.promiseFocus(uctWindow);
+ uctWindow.focus();
+ await focusOnDialog;
- uctWindow.document.documentElement.cancelDialog();
- await UCTObserver.closed.promise;
+ SimpleTest.is(ok.disabled, true, "button remained disabled");
- Services.ww.unregisterNotification(UCTObserver);
- uctWindow = null;
- UCTObserver = null;
- SimpleTest.finish();
- })();
- }
- ]]></script>
+ await waitDelay(DIALOG_DELAY);
+ SimpleTest.is(ok.disabled, false, "button re-enabled after delay");
+
+ uctWindow.document.documentElement.cancelDialog();
+ await UCTObserver.closed.promise;
- <body xmlns="http://www.w3.org/1999/xhtml">
- <p id="display"></p>
- <div id="content" style="display:none;"></div>
- <pre id="test"></pre>
- </body>
-
- <iframe xmlns="http://www.w3.org/1999/xhtml"
- id="testframe">
- </iframe>
-</window>
+ Services.ww.unregisterNotification(UCTObserver);
+ uctWindow = null;
+ UCTObserver = null;
+ });
+});
rename from toolkit/mozapps/downloads/tests/chrome/test_unknownContentType_dialog_layout.xul
rename to toolkit/mozapps/downloads/tests/browser/browser_unknownContentType_dialog_layout.js
--- a/toolkit/mozapps/downloads/tests/chrome/test_unknownContentType_dialog_layout.xul
+++ b/toolkit/mozapps/downloads/tests/browser/browser_unknownContentType_dialog_layout.js
@@ -1,106 +1,82 @@
-<?xml version="1.0"?>
-<!-- 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/. -->
-<!--
+/* 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/. */
+
+/*
* The unknownContentType popup can have two different layouts depending on
* whether a helper application can be selected or not.
* This tests that both layouts have correct collapsed elements.
--->
-
-<window title="Unknown Content Type Dialog Test"
- xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
- onload="init()">
+ */
- <script type="application/javascript"
- src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
-
- <script type="application/javascript">
- <![CDATA[
const UCT_URI = "chrome://mozapps/content/downloads/unknownContentType.xul";
-let testIndex = -1;
let tests = [
{ // This URL will trigger the simple UI, where only the Save an Cancel buttons are available
- url: "http://mochi.test:8888/chrome/toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.pif",
+ url: "http://mochi.test:8888/browser/toolkit/mozapps/downloads/tests/browser/unknownContentType_dialog_layout_data.pif",
elements: {
basicBox: { collapsed: false },
normalBox: { collapsed: true }
}
},
{ // This URL will trigger the full UI
- url: "http://mochi.test:8888/chrome/toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.txt",
+ url: "http://mochi.test:8888/browser/toolkit/mozapps/downloads/tests/browser/unknownContentType_dialog_layout_data.txt",
elements: {
basicBox: { collapsed: true },
normalBox: { collapsed: false }
}
}
];
-let ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
- getService(Ci.nsIWindowWatcher);
-
-SimpleTest.waitForExplicitFinish();
+add_task(async function test_unknownContentType_dialog_layout() {
+ for (let test of tests) {
+ let UCTObserver = {
+ opened: PromiseUtils.defer(),
+ closed: PromiseUtils.defer(),
-let windowObserver = {
- observe: function(aSubject, aTopic, aData) {
- let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget);
-
- if (aTopic == "domwindowclosed") {
- if (win.location == UCT_URI)
- loadNextTest();
- return;
- }
+ observe(aSubject, aTopic, aData) {
+ let win = aSubject.QueryInterface(Ci.nsIDOMEventTarget);
- // domwindowopened
- win.addEventListener("load", function onLoad(event) {
- win.removeEventListener("load", onLoad, false);
-
- // Let the dialog initialize
- SimpleTest.executeSoon(function() {
- checkWindow(win);
- });
- }, false);
- }
-};
-
-function init() {
- ww.registerNotification(windowObserver);
- loadNextTest();
-}
+ switch (aTopic) {
+ case "domwindowopened":
+ win.addEventListener("load", function onLoad(event) {
+ // Let the dialog initialize
+ SimpleTest.executeSoon(function() {
+ UCTObserver.opened.resolve(win);
+ });
+ }, {once: true});
+ break;
-function loadNextTest() {
- if (!tests[++testIndex]) {
- ww.unregisterNotification(windowObserver);
- SimpleTest.finish();
- return;
- }
- let frame = document.getElementById("testframe");
- frame.setAttribute("src", tests[testIndex].url);
-}
+ case "domwindowclosed":
+ if (win.location == UCT_URI) {
+ this.closed.resolve();
+ }
+ break;
+ }
+ }
+ };
+
+ Services.ww.registerNotification(UCTObserver);
+ await BrowserTestUtils.withNewTab({
+ gBrowser,
+ url: test.url,
+ }, async function() {
+ let uctWindow = await UCTObserver.opened.promise;
-function checkWindow(win) {
- for (let [id, props] of Object.entries(tests[testIndex].elements)) {
- let elem = win.dialog.dialogElement(id);
- for (let [prop, value] of Object.entries(props)) {
- is(elem[prop], value,
- "Element with id " + id + " has property " +
- prop + " set to " + value);
- }
- }
- win.document.documentElement.cancelDialog();
-}
+ for (let [id, props] of Object.entries(test.elements)) {
+ let elem = uctWindow.dialog.dialogElement(id);
+ for (let [prop, value] of Object.entries(props)) {
+ SimpleTest.is(elem[prop], value,
+ "Element with id " + id + " has property " +
+ prop + " set to " + value);
+ }
+ }
+ let focusOnDialog = SimpleTest.promiseFocus(uctWindow);
+ uctWindow.focus();
+ await focusOnDialog;
- ]]>
- </script>
-
- <body xmlns="http://www.w3.org/1999/xhtml">
- <p id="display"></p>
- <div id="content" style="display:none;"></div>
- <pre id="test"></pre>
- </body>
-
- <iframe xmlns="http://www.w3.org/1999/xhtml"
- id="testframe">
- </iframe>
-</window>
+ uctWindow.document.documentElement.cancelDialog();
+ uctWindow = null;
+ Services.ww.unregisterNotification(UCTObserver);
+ });
+ }
+});
rename from toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.pif
rename to toolkit/mozapps/downloads/tests/browser/unknownContentType_dialog_layout_data.pif
rename from toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.pif^headers^
rename to toolkit/mozapps/downloads/tests/browser/unknownContentType_dialog_layout_data.pif^headers^
rename from toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.txt
rename to toolkit/mozapps/downloads/tests/browser/unknownContentType_dialog_layout_data.txt
rename from toolkit/mozapps/downloads/tests/chrome/unknownContentType_dialog_layout_data.txt^headers^
rename to toolkit/mozapps/downloads/tests/browser/unknownContentType_dialog_layout_data.txt^headers^
deleted file mode 100644
--- a/toolkit/mozapps/downloads/tests/chrome/.eslintrc.js
+++ /dev/null
@@ -1,7 +0,0 @@
-"use strict";
-
-module.exports = {
- "extends": [
- "plugin:mozilla/chrome-test"
- ]
-};
deleted file mode 100644
--- a/toolkit/mozapps/downloads/tests/chrome/chrome.ini
+++ /dev/null
@@ -1,10 +0,0 @@
-[DEFAULT]
-skip-if = os == 'android'
-support-files =
- unknownContentType_dialog_layout_data.pif
- unknownContentType_dialog_layout_data.pif^headers^
- unknownContentType_dialog_layout_data.txt
- unknownContentType_dialog_layout_data.txt^headers^
-
-[test_unknownContentType_delayedbutton.xul]
-[test_unknownContentType_dialog_layout.xul]
--- a/toolkit/mozapps/downloads/tests/moz.build
+++ b/toolkit/mozapps/downloads/tests/moz.build
@@ -1,8 +1,8 @@
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
# vim: set filetype=python:
# 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/.
XPCSHELL_TESTS_MANIFESTS += ['unit/xpcshell.ini']
-MOCHITEST_CHROME_MANIFESTS += ['chrome/chrome.ini']
+BROWSER_CHROME_MANIFESTS += ['browser/browser.ini']