|
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/ */ |
|
4 |
|
5 const TESTCASE_URI = TEST_BASE + "color-block.html"; |
|
6 const DIV_COLOR = "#0000FF"; |
|
7 |
|
8 /** |
|
9 * Test basic eyedropper widget functionality: |
|
10 * - Opening eyedropper and pressing ESC closes the eyedropper |
|
11 * - Opening eyedropper and clicking copies the center color |
|
12 */ |
|
13 function test() { |
|
14 addTab(TESTCASE_URI).then(testEscape); |
|
15 } |
|
16 |
|
17 function testEscape() { |
|
18 let dropper = new Eyedropper(window); |
|
19 |
|
20 dropper.once("destroy", (event) => { |
|
21 ok(true, "escape closed the eyedropper"); |
|
22 |
|
23 // now test selecting a color |
|
24 testSelect(); |
|
25 }); |
|
26 |
|
27 inspectPage(dropper, false).then(pressESC); |
|
28 } |
|
29 |
|
30 function testSelect() { |
|
31 let dropper = new Eyedropper(window); |
|
32 |
|
33 dropper.once("select", (event, color) => { |
|
34 is(color, DIV_COLOR, "correct color selected"); |
|
35 }); |
|
36 |
|
37 // wait for DIV_COLOR to be copied to the clipboard then finish the test. |
|
38 waitForClipboard(DIV_COLOR, () => { |
|
39 inspectPage(dropper); // setup: inspect the page |
|
40 }, finish, finish); |
|
41 } |
|
42 |
|
43 /* Helpers */ |
|
44 |
|
45 function inspectPage(dropper, click=true) { |
|
46 dropper.open(); |
|
47 |
|
48 let target = content.document.getElementById("test"); |
|
49 let win = content.window; |
|
50 |
|
51 EventUtils.synthesizeMouse(target, 20, 20, { type: "mousemove" }, win); |
|
52 |
|
53 return dropperLoaded(dropper).then(() => { |
|
54 EventUtils.synthesizeMouse(target, 30, 30, { type: "mousemove" }, win); |
|
55 |
|
56 if (click) { |
|
57 EventUtils.synthesizeMouse(target, 30, 30, {}, win); |
|
58 } |
|
59 }); |
|
60 } |
|
61 |
|
62 function pressESC() { |
|
63 EventUtils.synthesizeKey("VK_ESCAPE", { }); |
|
64 } |