mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1034512 - Part 5: Make the spectrum (color-picker) tests execute in a toolbox host rather than content page. r=bgrins
This commit is contained in:
parent
e7612c441d
commit
7590f4e3e5
@ -7,27 +7,25 @@
|
||||
const TEST_URI = "chrome://browser/content/devtools/spectrum-frame.xhtml";
|
||||
const {Spectrum} = devtools.require("devtools/shared/widgets/Spectrum");
|
||||
|
||||
let doc;
|
||||
|
||||
function test() {
|
||||
waitForExplicitFinish();
|
||||
addTab(TEST_URI, () => {
|
||||
doc = content.document;
|
||||
startTests();
|
||||
});
|
||||
}
|
||||
|
||||
function endTests() {
|
||||
doc = null;
|
||||
add_task(function*() {
|
||||
yield promiseTab("about:blank");
|
||||
yield performTest();
|
||||
gBrowser.removeCurrentTab();
|
||||
finish();
|
||||
});
|
||||
|
||||
function* performTest() {
|
||||
let [host, win, doc] = yield createHost("bottom", TEST_URI);
|
||||
|
||||
yield testCreateAndDestroyShouldAppendAndRemoveElements(doc);
|
||||
yield testPassingAColorAtInitShouldSetThatColor(doc);
|
||||
yield testSettingAndGettingANewColor(doc);
|
||||
yield testChangingColorShouldEmitEvents(doc);
|
||||
yield testSettingColorShoudUpdateTheUI(doc);
|
||||
|
||||
host.destroy();
|
||||
}
|
||||
|
||||
function startTests() {
|
||||
testCreateAndDestroyShouldAppendAndRemoveElements();
|
||||
}
|
||||
|
||||
function testCreateAndDestroyShouldAppendAndRemoveElements() {
|
||||
function testCreateAndDestroyShouldAppendAndRemoveElements(doc) {
|
||||
let containerElement = doc.querySelector("#spectrum");
|
||||
ok(containerElement, "We have the root node to append spectrum to");
|
||||
is(containerElement.childElementCount, 0, "Root node is empty");
|
||||
@ -38,11 +36,9 @@ function testCreateAndDestroyShouldAppendAndRemoveElements() {
|
||||
|
||||
s.destroy();
|
||||
is(containerElement.childElementCount, 0, "Destroying spectrum removed all nodes");
|
||||
|
||||
testPassingAColorAtInitShouldSetThatColor();
|
||||
}
|
||||
|
||||
function testPassingAColorAtInitShouldSetThatColor() {
|
||||
function testPassingAColorAtInitShouldSetThatColor(doc) {
|
||||
let initRgba = [255, 126, 255, 1];
|
||||
|
||||
let s = new Spectrum(doc.querySelector("#spectrum"), initRgba);
|
||||
@ -56,10 +52,9 @@ function testPassingAColorAtInitShouldSetThatColor() {
|
||||
is(initRgba[3], setRgba[3], "Spectrum initialized with the right color");
|
||||
|
||||
s.destroy();
|
||||
testSettingAndGettingANewColor();
|
||||
}
|
||||
|
||||
function testSettingAndGettingANewColor() {
|
||||
function testSettingAndGettingANewColor(doc) {
|
||||
let s = new Spectrum(doc.querySelector("#spectrum"), [0, 0, 0, 1]);
|
||||
s.show();
|
||||
|
||||
@ -73,33 +68,31 @@ function testSettingAndGettingANewColor() {
|
||||
is(colorToSet[3], newColor[3], "Spectrum set with the right color");
|
||||
|
||||
s.destroy();
|
||||
testChangingColorShouldEmitEvents();
|
||||
}
|
||||
|
||||
function testChangingColorShouldEmitEvents() {
|
||||
let s = new Spectrum(doc.querySelector("#spectrum"), [255, 255, 255, 1]);
|
||||
s.show();
|
||||
function testChangingColorShouldEmitEvents(doc) {
|
||||
return new Promise(resolve => {
|
||||
let s = new Spectrum(doc.querySelector("#spectrum"), [255, 255, 255, 1]);
|
||||
s.show();
|
||||
|
||||
s.once("changed", (event, rgba, color) => {
|
||||
EventUtils.sendMouseEvent({type: "mouseup"}, s.dragger, doc.defaultView);
|
||||
s.once("changed", (event, rgba, color) => {
|
||||
ok(true, "Changed event was emitted on color change");
|
||||
is(rgba[0], 128, "New color is correct");
|
||||
is(rgba[1], 64, "New color is correct");
|
||||
is(rgba[2], 64, "New color is correct");
|
||||
is(rgba[3], 1, "New color is correct");
|
||||
is("rgba(" + rgba[0] + ", " + rgba[1] + ", " + rgba[2] + ", " + rgba[3] + ")", color, "RGBA and css color correspond");
|
||||
|
||||
ok(true, "Changed event was emitted on color change");
|
||||
is(rgba[0], 128, "New color is correct");
|
||||
is(rgba[1], 64, "New color is correct");
|
||||
is(rgba[2], 64, "New color is correct");
|
||||
is(rgba[3], 1, "New color is correct");
|
||||
is("rgba(" + rgba[0] + ", " + rgba[1] + ", " + rgba[2] + ", " + rgba[3] + ")", color, "RGBA and css color correspond");
|
||||
s.destroy();
|
||||
resolve();
|
||||
});
|
||||
|
||||
s.destroy();
|
||||
testSettingColorShoudUpdateTheUI();
|
||||
});
|
||||
|
||||
executeSoon(() => {
|
||||
EventUtils.synthesizeMouse(s.dragger, s.dragger.offsetWidth/2, s.dragger.offsetHeight/2, {}, content);
|
||||
// Simulate a drag move event by calling the handler directly.
|
||||
s.onDraggerMove(s.dragger.offsetWidth/2, s.dragger.offsetHeight/2);
|
||||
});
|
||||
}
|
||||
|
||||
function testSettingColorShoudUpdateTheUI() {
|
||||
function testSettingColorShoudUpdateTheUI(doc) {
|
||||
let s = new Spectrum(doc.querySelector("#spectrum"), [255, 255, 255, 1]);
|
||||
s.show();
|
||||
let dragHelperOriginalPos = [s.dragHelper.style.top, s.dragHelper.style.left];
|
||||
@ -118,5 +111,4 @@ function testSettingColorShoudUpdateTheUI() {
|
||||
"Alpha range UI has been updated again");
|
||||
|
||||
s.destroy();
|
||||
executeSoon(endTests);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user