Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* vim: set ts=2 et sw=2 tw=80: */
2 /* Any copyright is dedicated to the Public Domain.
3 http://creativecommons.org/publicdomain/zero/1.0/ */
5 // Tests that the spectrum color picker works correctly
7 const TEST_URI = "chrome://browser/content/devtools/spectrum-frame.xhtml";
8 const {Spectrum} = devtools.require("devtools/shared/widgets/Spectrum");
10 let doc;
12 function test() {
13 waitForExplicitFinish();
14 addTab(TEST_URI, () => {
15 doc = content.document;
16 startTests();
17 });
18 }
20 function endTests() {
21 doc = null;
22 gBrowser.removeCurrentTab();
23 finish();
24 }
26 function startTests() {
27 testCreateAndDestroyShouldAppendAndRemoveElements();
28 }
30 function testCreateAndDestroyShouldAppendAndRemoveElements() {
31 let containerElement = doc.querySelector("#spectrum");
32 ok(containerElement, "We have the root node to append spectrum to");
33 is(containerElement.childElementCount, 0, "Root node is empty");
35 let s = new Spectrum(containerElement, [255, 126, 255, 1]);
36 s.show();
37 ok(containerElement.childElementCount > 0, "Spectrum has appended elements");
39 s.destroy();
40 is(containerElement.childElementCount, 0, "Destroying spectrum removed all nodes");
42 testPassingAColorAtInitShouldSetThatColor();
43 }
45 function testPassingAColorAtInitShouldSetThatColor() {
46 let initRgba = [255, 126, 255, 1];
48 let s = new Spectrum(doc.querySelector("#spectrum"), initRgba);
49 s.show();
51 let setRgba = s.rgb;
53 is(initRgba[0], setRgba[0], "Spectrum initialized with the right color");
54 is(initRgba[1], setRgba[1], "Spectrum initialized with the right color");
55 is(initRgba[2], setRgba[2], "Spectrum initialized with the right color");
56 is(initRgba[3], setRgba[3], "Spectrum initialized with the right color");
58 s.destroy();
59 testSettingAndGettingANewColor();
60 }
62 function testSettingAndGettingANewColor() {
63 let s = new Spectrum(doc.querySelector("#spectrum"), [0, 0, 0, 1]);
64 s.show();
66 let colorToSet = [255, 255, 255, 1];
67 s.rgb = colorToSet;
68 let newColor = s.rgb;
70 is(colorToSet[0], newColor[0], "Spectrum set with the right color");
71 is(colorToSet[1], newColor[1], "Spectrum set with the right color");
72 is(colorToSet[2], newColor[2], "Spectrum set with the right color");
73 is(colorToSet[3], newColor[3], "Spectrum set with the right color");
75 s.destroy();
76 testChangingColorShouldEmitEvents();
77 }
79 function testChangingColorShouldEmitEvents() {
80 let s = new Spectrum(doc.querySelector("#spectrum"), [255, 255, 255, 1]);
81 s.show();
83 s.once("changed", (event, rgba, color) => {
84 EventUtils.sendMouseEvent({type: "mouseup"}, s.dragger, doc.defaultView);
86 ok(true, "Changed event was emitted on color change");
87 is(rgba[0], 128, "New color is correct");
88 is(rgba[1], 64, "New color is correct");
89 is(rgba[2], 64, "New color is correct");
90 is(rgba[3], 1, "New color is correct");
91 is("rgba(" + rgba[0] + ", " + rgba[1] + ", " + rgba[2] + ", " + rgba[3] + ")", color, "RGBA and css color correspond");
93 s.destroy();
94 testSettingColorShoudUpdateTheUI();
95 });
97 executeSoon(() => {
98 EventUtils.synthesizeMouse(s.dragger, s.dragger.offsetWidth/2, s.dragger.offsetHeight/2, {}, content);
99 });
100 }
102 function testSettingColorShoudUpdateTheUI() {
103 let s = new Spectrum(doc.querySelector("#spectrum"), [255, 255, 255, 1]);
104 s.show();
105 let dragHelperOriginalPos = [s.dragHelper.style.top, s.dragHelper.style.left];
106 let alphaHelperOriginalPos = s.alphaSliderHelper.style.left;
108 s.rgb = [50, 240, 234, .2];
109 s.updateUI();
111 ok(s.alphaSliderHelper.style.left != alphaHelperOriginalPos, "Alpha helper has moved");
112 ok(s.dragHelper.style.top !== dragHelperOriginalPos[0], "Drag helper has moved");
113 ok(s.dragHelper.style.left !== dragHelperOriginalPos[1], "Drag helper has moved");
115 s.rgb = [240, 32, 124, 0];
116 s.updateUI();
117 is(s.alphaSliderHelper.style.left, - (s.alphaSliderHelper.offsetWidth/2) + "px",
118 "Alpha range UI has been updated again");
120 s.destroy();
121 executeSoon(endTests);
122 }