mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-02 15:15:23 +00:00
Bug 1246677 - 1 - Make waitForSuccess work with async functions; r=miker
MozReview-Commit-ID: Ic0UyApQpB7 --HG-- extra : rebase_source : da22978c67e456ab5ba9fedecd228682cdd10ba5
This commit is contained in:
parent
7c66c16a79
commit
a932228b1a
@ -39,9 +39,9 @@ function* testPressingEnterCommitsChanges(swatch, ruleView) {
|
|||||||
widget.coordinates = [0.1, 2, 0.9, -1];
|
widget.coordinates = [0.1, 2, 0.9, -1];
|
||||||
let expected = "cubic-bezier(0.1, 2, 0.9, -1)";
|
let expected = "cubic-bezier(0.1, 2, 0.9, -1)";
|
||||||
|
|
||||||
yield waitForSuccess(() => {
|
yield waitForSuccess(function*() {
|
||||||
return content.getComputedStyle(content.document.body)
|
return content.getComputedStyle(content.document.body)
|
||||||
.transitionTimingFunction === expected;
|
.transitionTimingFunction === expected;
|
||||||
}, "Waiting for the change to be previewed on the element");
|
}, "Waiting for the change to be previewed on the element");
|
||||||
|
|
||||||
ok(getRuleViewProperty(ruleView, "body", "transition").valueSpan.textContent
|
ok(getRuleViewProperty(ruleView, "body", "transition").valueSpan.textContent
|
||||||
|
@ -78,8 +78,7 @@ function editorSelected(editor) {
|
|||||||
function verifyLinkText(text, view) {
|
function verifyLinkText(text, view) {
|
||||||
info("Verifying that the rule-view stylesheet link is " + text);
|
info("Verifying that the rule-view stylesheet link is " + text);
|
||||||
let label = getRuleViewLinkByIndex(view, 1).querySelector("label");
|
let label = getRuleViewLinkByIndex(view, 1).querySelector("label");
|
||||||
return waitForSuccess(
|
return waitForSuccess(function*() {
|
||||||
() => label.getAttribute("value") == text,
|
return label.getAttribute("value") == text;
|
||||||
"Link text changed to display correct location: " + text
|
}, "Link text changed to display correct location: " + text);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
@ -312,10 +312,10 @@ var waitForTab = Task.async(function*() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Polls a given function waiting for it to return true.
|
* Polls a given generator function waiting for it to return true.
|
||||||
*
|
*
|
||||||
* @param {Function} validatorFn
|
* @param {Function} validatorFn
|
||||||
* A validator function that returns a boolean.
|
* A validator generator function that returns a boolean.
|
||||||
* This is called every few milliseconds to check if the result is true.
|
* This is called every few milliseconds to check if the result is true.
|
||||||
* When it is true, the promise resolves.
|
* When it is true, the promise resolves.
|
||||||
* @param {String} name
|
* @param {String} name
|
||||||
@ -324,21 +324,22 @@ var waitForTab = Task.async(function*() {
|
|||||||
* @return a promise that resolves when the function returned true or rejects
|
* @return a promise that resolves when the function returned true or rejects
|
||||||
* if the timeout is reached
|
* if the timeout is reached
|
||||||
*/
|
*/
|
||||||
function waitForSuccess(validatorFn, name="untitled") {
|
var waitForSuccess = Task.async(function*(validatorFn, desc = "untitled") {
|
||||||
let def = promise.defer();
|
let i = 0;
|
||||||
|
while (true) {
|
||||||
function wait(validator) {
|
info("Checking: " + desc);
|
||||||
if (validator()) {
|
if (yield validatorFn()) {
|
||||||
ok(true, "Validator function " + name + " returned true");
|
ok(true, "Success: " + desc);
|
||||||
def.resolve();
|
break;
|
||||||
} else {
|
|
||||||
setTimeout(() => wait(validator), 200);
|
|
||||||
}
|
}
|
||||||
|
i++;
|
||||||
|
if (i > 10) {
|
||||||
|
ok(false, "Failure: " + desc);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
yield new Promise(r => setTimeout(r, 200));
|
||||||
}
|
}
|
||||||
wait(validatorFn);
|
});
|
||||||
|
|
||||||
return def.promise;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new style tag containing the given style text and append it to the
|
* Create a new style tag containing the given style text and append it to the
|
||||||
@ -525,8 +526,9 @@ var simulateColorPickerChange = Task.async(function*(ruleView, colorPicker,
|
|||||||
|
|
||||||
if (expectedChange) {
|
if (expectedChange) {
|
||||||
info("Waiting for the style to be applied on the page");
|
info("Waiting for the style to be applied on the page");
|
||||||
yield waitForSuccess(() => {
|
yield waitForSuccess(function*() {
|
||||||
let {element, name, value} = expectedChange;
|
let {element, name, value} = expectedChange;
|
||||||
|
yield getComputedStyleProperty(selector, null, name)
|
||||||
return content.getComputedStyle(element)[name] === value;
|
return content.getComputedStyle(element)[name] === value;
|
||||||
}, "Color picker change applied on the page");
|
}, "Color picker change applied on the page");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user