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