mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-21 01:05:45 +00:00
Backed out changeset bf79d5b1b4b0 (bug 1404946)
This commit is contained in:
parent
3b0bd340dc
commit
c9b41f4cb7
@ -47,10 +47,7 @@ Cu.import("chrome://marionette/content/modal.js");
|
||||
Cu.import("chrome://marionette/content/proxy.js");
|
||||
Cu.import("chrome://marionette/content/reftest.js");
|
||||
Cu.import("chrome://marionette/content/session.js");
|
||||
const {
|
||||
PollPromise,
|
||||
TimedPromise,
|
||||
} = Cu.import("chrome://marionette/content/sync.js", {});
|
||||
const {wait, TimedPromise} = Cu.import("chrome://marionette/content/sync.js", {});
|
||||
|
||||
Cu.importGlobalProperties(["URL"]);
|
||||
|
||||
@ -1491,7 +1488,7 @@ GeckoDriver.prototype.setWindowRect = async function(cmd) {
|
||||
// user-requested window size as this may not be achievable on the
|
||||
// current system.
|
||||
const windowResizeChange = async () => {
|
||||
return new PollPromise((resolve, reject) => {
|
||||
return wait.until((resolve, reject) => {
|
||||
let curRect = this.curBrowser.rect;
|
||||
if (curRect.width != origRect.width &&
|
||||
curRect.height != origRect.height) {
|
||||
@ -1504,7 +1501,7 @@ GeckoDriver.prototype.setWindowRect = async function(cmd) {
|
||||
|
||||
// Wait for the window position to change.
|
||||
async function windowPosition(x, y) {
|
||||
return new PollPromise((resolve, reject) => {
|
||||
return wait.until((resolve, reject) => {
|
||||
if ((x == win.screenX && y == win.screenY) ||
|
||||
(win.screenX != origRect.x || win.screenY != origRect.y)) {
|
||||
resolve();
|
||||
@ -3051,8 +3048,8 @@ GeckoDriver.prototype.maximizeWindow = async function() {
|
||||
};
|
||||
|
||||
// Wait for the window size to change.
|
||||
async function windowSizeChange(f) {
|
||||
return new PollPromise((resolve, reject) => {
|
||||
async function windowSizeChange() {
|
||||
return wait.until((resolve, reject) => {
|
||||
let curSize = {
|
||||
outerWidth: win.outerWidth,
|
||||
outerHeight: win.outerHeight,
|
||||
|
@ -15,7 +15,7 @@ const {
|
||||
pprint,
|
||||
StaleElementReferenceError,
|
||||
} = Cu.import("chrome://marionette/content/error.js", {});
|
||||
const {PollPromise} = Cu.import("chrome://marionette/content/sync.js", {});
|
||||
Cu.import("chrome://marionette/content/sync.js");
|
||||
|
||||
this.EXPORTED_SYMBOLS = ["element"];
|
||||
|
||||
@ -249,7 +249,7 @@ element.find = function(container, strategy, selector, opts = {}) {
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
let findElements = new PollPromise((resolve, reject) => {
|
||||
let findElements = wait.until((resolve, reject) => {
|
||||
let res = find_(container, strategy, selector, searchFn, opts);
|
||||
if (res.length > 0) {
|
||||
resolve(Array.from(res));
|
||||
|
@ -12,7 +12,14 @@ const {
|
||||
} = Cu.import("chrome://marionette/content/error.js", {});
|
||||
|
||||
/* exported TimedPromise */
|
||||
this.EXPORTED_SYMBOLS = ["PollPromise", "TimedPromise"];
|
||||
this.EXPORTED_SYMBOLS = ["wait", "TimedPromise"];
|
||||
|
||||
/**
|
||||
* Poll-waiting utilities.
|
||||
*
|
||||
* @namespace
|
||||
*/
|
||||
this.wait = {};
|
||||
|
||||
const {TYPE_ONE_SHOT, TYPE_REPEATING_SLACK} = Ci.nsITimer;
|
||||
|
||||
@ -55,7 +62,7 @@ const {TYPE_ONE_SHOT, TYPE_REPEATING_SLACK} = Ci.nsITimer;
|
||||
* Usage:
|
||||
*
|
||||
* <pre><code>
|
||||
* let els = new PollPromise((resolve, reject) => {
|
||||
* let els = wait.until((resolve, reject) => {
|
||||
* let res = document.querySelectorAll("p");
|
||||
* if (res.length > 0) {
|
||||
* resolve(Array.from(res));
|
||||
@ -82,7 +89,7 @@ const {TYPE_ONE_SHOT, TYPE_REPEATING_SLACK} = Ci.nsITimer;
|
||||
* @throws {*}
|
||||
* If <var>func</var> throws, its error is propagated.
|
||||
*/
|
||||
function PollPromise(func, timeout = 2000, interval = 10) {
|
||||
wait.until = function(func, timeout = 2000, interval = 10) {
|
||||
const timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
@ -116,7 +123,7 @@ function PollPromise(func, timeout = 2000, interval = 10) {
|
||||
timer.cancel();
|
||||
throw err;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* The <code>TimedPromise</code> object represents the timed, eventual
|
||||
|
@ -4,20 +4,20 @@
|
||||
|
||||
const {utils: Cu} = Components;
|
||||
|
||||
const {PollPromise} = Cu.import("chrome://marionette/content/sync.js", {});
|
||||
Cu.import("chrome://marionette/content/sync.js");
|
||||
|
||||
const DEFAULT_TIMEOUT = 2000;
|
||||
|
||||
add_task(async function test_PollPromise_types() {
|
||||
add_task(async function test_until_types() {
|
||||
for (let typ of [true, false, "foo", 42, [], {}]) {
|
||||
strictEqual(typ, await new PollPromise(resolve => resolve(typ)));
|
||||
strictEqual(typ, await wait.until(resolve => resolve(typ)));
|
||||
}
|
||||
});
|
||||
|
||||
add_task(async function test_PollPromise_timeoutElapse() {
|
||||
add_task(async function test_until_timeoutElapse() {
|
||||
let nevals = 0;
|
||||
let start = new Date().getTime();
|
||||
await new PollPromise((resolve, reject) => {
|
||||
await wait.until((resolve, reject) => {
|
||||
++nevals;
|
||||
reject();
|
||||
});
|
||||
@ -26,11 +26,11 @@ add_task(async function test_PollPromise_timeoutElapse() {
|
||||
greaterOrEqual(nevals, 15);
|
||||
});
|
||||
|
||||
add_task(async function test_PollPromise_rethrowError() {
|
||||
add_task(async function test_until_rethrowError() {
|
||||
let nevals = 0;
|
||||
let err;
|
||||
try {
|
||||
await PollPromise(() => {
|
||||
await wait.until(() => {
|
||||
++nevals;
|
||||
throw new Error();
|
||||
});
|
||||
@ -41,11 +41,11 @@ add_task(async function test_PollPromise_rethrowError() {
|
||||
ok(err instanceof Error);
|
||||
});
|
||||
|
||||
add_task(async function test_PollPromise_noTimeout() {
|
||||
add_task(async function test_until_noTimeout() {
|
||||
// run at least once when timeout is 0
|
||||
let nevals = 0;
|
||||
let start = new Date().getTime();
|
||||
await new PollPromise((resolve, reject) => {
|
||||
await wait.until((resolve, reject) => {
|
||||
++nevals;
|
||||
reject();
|
||||
}, 0);
|
||||
@ -54,10 +54,10 @@ add_task(async function test_PollPromise_noTimeout() {
|
||||
less((end - start), DEFAULT_TIMEOUT);
|
||||
});
|
||||
|
||||
add_task(async function test_PollPromise_timeout() {
|
||||
add_task(async function test_until_timeout() {
|
||||
let nevals = 0;
|
||||
let start = new Date().getTime();
|
||||
await new PollPromise((resolve, reject) => {
|
||||
await wait.until((resolve, reject) => {
|
||||
++nevals;
|
||||
reject();
|
||||
}, 100);
|
||||
@ -66,9 +66,9 @@ add_task(async function test_PollPromise_timeout() {
|
||||
greaterOrEqual((end - start), 100);
|
||||
});
|
||||
|
||||
add_task(async function test_PollPromise_interval() {
|
||||
add_task(async function test_until_interval() {
|
||||
let nevals = 0;
|
||||
await new PollPromise((resolve, reject) => {
|
||||
await wait.until((resolve, reject) => {
|
||||
++nevals;
|
||||
reject();
|
||||
}, 100, 100);
|
||||
|
Loading…
Reference in New Issue
Block a user