зеркало из https://github.com/mozilla/gecko-dev.git
Bug 985954 - Remove deprecated promise.js usage in the testing framework. r=ted
This commit is contained in:
Родитель
6ce210f9f5
Коммит
fbdf098874
|
@ -22,7 +22,7 @@ const Test = routine => () => {
|
|||
// Returns promise for the observer notification subject for
|
||||
// the given topic. If `receive("foo")` is called `n` times
|
||||
// nth promise is resolved on an `nth` "foo" notification.
|
||||
const receive = (topic, p) => {
|
||||
const receive = (topic, p, syncCallback) => {
|
||||
const { promise, resolve, reject } = Promise.defer();
|
||||
const { queue } = receive;
|
||||
const timeout = () => {
|
||||
|
@ -43,6 +43,10 @@ const receive = (topic, p) => {
|
|||
removeObserver(observer, topic);
|
||||
clearTimeout(id, reject);
|
||||
queue.splice(index, 2);
|
||||
// Some tests need to be executed synchronously when the event is fired.
|
||||
if (syncCallback) {
|
||||
syncCallback(subject);
|
||||
}
|
||||
resolve(subject);
|
||||
}
|
||||
}
|
||||
|
@ -73,7 +77,11 @@ const uri3 = "data:text/html;charset=utf-8,<h1>3</h1>";
|
|||
const uri4 = "chrome://browser/content/license.html";
|
||||
|
||||
const test = Test(function*() {
|
||||
let documentInteractive = receive("content-document-interactive", isData);
|
||||
let documentInteractive = receive("content-document-interactive", isData, d => {
|
||||
// This test is executed synchronously when the event is received.
|
||||
is(d.readyState, "interactive", "document is interactive");
|
||||
is(d.URL, uri1, "document.URL matches tab url");
|
||||
});
|
||||
let documentLoaded = receive("content-document-loaded", isData);
|
||||
let pageShown = receive("content-page-shown", isData);
|
||||
|
||||
|
@ -82,8 +90,6 @@ const test = Test(function*() {
|
|||
const browser1 = gBrowser.getBrowserForTab(tab1);
|
||||
|
||||
let interactiveDocument1 = yield documentInteractive;
|
||||
is(interactiveDocument1.readyState, "interactive", "document is interactive");
|
||||
is(interactiveDocument1.URL, uri1, "document.URL matches tab url");
|
||||
|
||||
let loadedDocument1 = yield documentLoaded;
|
||||
is(loadedDocument1.readyState, "complete", "document is loaded");
|
||||
|
@ -97,7 +103,11 @@ const test = Test(function*() {
|
|||
|
||||
info("load uri#2");
|
||||
|
||||
documentInteractive = receive("content-document-interactive", isData);
|
||||
documentInteractive = receive("content-document-interactive", isData, d => {
|
||||
// This test is executed synchronously when the event is received.
|
||||
is(d.readyState, "interactive", "document is interactive");
|
||||
is(d.URL, uri2, "document.URL matches URL loaded");
|
||||
});
|
||||
documentLoaded = receive("content-document-loaded", isData);
|
||||
pageShown = receive("content-page-shown", isData);
|
||||
let pageHidden = receive("content-page-hidden", isData);
|
||||
|
@ -108,8 +118,6 @@ const test = Test(function*() {
|
|||
is(interactiveDocument1, hiddenPage, "loaded document is hidden");
|
||||
|
||||
let interactiveDocument2 = yield documentInteractive;
|
||||
is(interactiveDocument2.readyState, "interactive", "document is interactive");
|
||||
is(interactiveDocument2.URL, uri2, "document.URL matches URL loaded");
|
||||
|
||||
let loadedDocument2 = yield documentLoaded;
|
||||
is(loadedDocument2.readyState, "complete", "document is loaded");
|
||||
|
@ -121,7 +129,11 @@ const test = Test(function*() {
|
|||
info("go back to uri#1");
|
||||
|
||||
|
||||
documentInteractive = receive("content-document-interactive", isData);
|
||||
documentInteractive = receive("content-document-interactive", isData, d => {
|
||||
// This test is executed synchronously when the event is received.
|
||||
is(d.readyState, "interactive", "document is interactive");
|
||||
is(d.URL, uri3, "document.URL matches URL loaded");
|
||||
});
|
||||
documentLoaded = receive("content-document-loaded", isData);
|
||||
pageShown = receive("content-page-shown", isData);
|
||||
pageHidden = receive("content-page-hidden", isData);
|
||||
|
@ -139,8 +151,6 @@ const test = Test(function*() {
|
|||
pageShown = receive("content-page-shown", isData);
|
||||
|
||||
let interactiveDocument3 = yield documentInteractive;
|
||||
is(interactiveDocument3.readyState, "interactive", "document is interactive");
|
||||
is(interactiveDocument3.URL, uri3, "document.URL matches URL loaded");
|
||||
|
||||
let loadedDocument3 = yield documentLoaded;
|
||||
is(loadedDocument3.readyState, "complete", "document is loaded");
|
||||
|
@ -154,13 +164,15 @@ const test = Test(function*() {
|
|||
info("load chrome uri");
|
||||
|
||||
const tab2 = openTab(uri4);
|
||||
documentInteractive = receive("chrome-document-interactive");
|
||||
documentInteractive = receive("chrome-document-interactive", null, d => {
|
||||
// This test is executed synchronously when the event is received.
|
||||
is(d.readyState, "interactive", "document is interactive");
|
||||
is(d.URL, uri4, "document.URL matches URL loaded");
|
||||
});
|
||||
documentLoaded = receive("chrome-document-loaded");
|
||||
pageShown = receive("chrome-page-shown");
|
||||
|
||||
const interactiveDocument4 = yield documentInteractive;
|
||||
is(interactiveDocument4.readyState, "interactive", "document is interactive");
|
||||
is(interactiveDocument4.URL, uri4, "document.URL matches URL loaded");
|
||||
|
||||
let loadedDocument4 = yield documentLoaded;
|
||||
is(loadedDocument4.readyState, "complete", "document is loaded");
|
||||
|
|
|
@ -86,7 +86,7 @@ function Tester(aTests, aDumper, aCallback) {
|
|||
this.SimpleTest = simpleTestScope.SimpleTest;
|
||||
this.MemoryStats = simpleTestScope.MemoryStats;
|
||||
this.Task = Components.utils.import("resource://gre/modules/Task.jsm", null).Task;
|
||||
this.Promise = Components.utils.import("resource://gre/modules/commonjs/sdk/core/promise.js", null).Promise;
|
||||
this.Promise = Components.utils.import("resource://gre/modules/Promise.jsm", null).Promise;
|
||||
this.Assert = Components.utils.import("resource://testing-common/Assert.jsm", null).Assert;
|
||||
}
|
||||
Tester.prototype = {
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<script type="application/javascript" src="chrome://mochikit/content/chrome-harness.js"></script>
|
||||
<script type="application/javascript">
|
||||
<![CDATA[
|
||||
let {Promise} = Components.utils.import("resource://gre/modules/commonjs/sdk/core/promise.js");
|
||||
let {Promise} = Components.utils.import("resource://gre/modules/Promise.jsm");
|
||||
Components.utils.import("resource://gre/modules/osfile.jsm");
|
||||
let decoder = new TextDecoder();
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
function test() {
|
||||
let {Promise} = Components.utils.import("resource://gre/modules/commonjs/sdk/core/promise.js");
|
||||
let {Promise} = Components.utils.import("resource://gre/modules/Promise.jsm");
|
||||
Components.utils.import("resource://gre/modules/osfile.jsm");
|
||||
let decoder = new TextDecoder();
|
||||
|
||||
|
|
|
@ -186,12 +186,16 @@ function promise_window_close(aWindow) {
|
|||
function promise_page(aWindow, aPageId) {
|
||||
let deferred = Promise.defer();
|
||||
var page = aWindow.document.getElementById(aPageId);
|
||||
page.addEventListener("pageshow", function() {
|
||||
page.removeEventListener("pageshow", arguments.callee, false);
|
||||
executeSoon(function() {
|
||||
deferred.resolve(aWindow);
|
||||
});
|
||||
}, false);
|
||||
if (aWindow.document.getElementById("updateWizard").currentPage === page) {
|
||||
deferred.resolve(aWindow);
|
||||
} else {
|
||||
page.addEventListener("pageshow", function() {
|
||||
page.removeEventListener("pageshow", arguments.callee, false);
|
||||
executeSoon(function() {
|
||||
deferred.resolve(aWindow);
|
||||
});
|
||||
}, false);
|
||||
}
|
||||
return deferred.promise;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче