michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: const TESTCASE_URI = TEST_BASE + "color-block.html"; michael@0: const DIV_COLOR = "#0000FF"; michael@0: michael@0: /** michael@0: * Test basic eyedropper widget functionality: michael@0: * - Opening eyedropper and pressing ESC closes the eyedropper michael@0: * - Opening eyedropper and clicking copies the center color michael@0: */ michael@0: function test() { michael@0: addTab(TESTCASE_URI).then(testEscape); michael@0: } michael@0: michael@0: function testEscape() { michael@0: let dropper = new Eyedropper(window); michael@0: michael@0: dropper.once("destroy", (event) => { michael@0: ok(true, "escape closed the eyedropper"); michael@0: michael@0: // now test selecting a color michael@0: testSelect(); michael@0: }); michael@0: michael@0: inspectPage(dropper, false).then(pressESC); michael@0: } michael@0: michael@0: function testSelect() { michael@0: let dropper = new Eyedropper(window); michael@0: michael@0: dropper.once("select", (event, color) => { michael@0: is(color, DIV_COLOR, "correct color selected"); michael@0: }); michael@0: michael@0: // wait for DIV_COLOR to be copied to the clipboard then finish the test. michael@0: waitForClipboard(DIV_COLOR, () => { michael@0: inspectPage(dropper); // setup: inspect the page michael@0: }, finish, finish); michael@0: } michael@0: michael@0: /* Helpers */ michael@0: michael@0: function inspectPage(dropper, click=true) { michael@0: dropper.open(); michael@0: michael@0: let target = content.document.getElementById("test"); michael@0: let win = content.window; michael@0: michael@0: EventUtils.synthesizeMouse(target, 20, 20, { type: "mousemove" }, win); michael@0: michael@0: return dropperLoaded(dropper).then(() => { michael@0: EventUtils.synthesizeMouse(target, 30, 30, { type: "mousemove" }, win); michael@0: michael@0: if (click) { michael@0: EventUtils.synthesizeMouse(target, 30, 30, {}, win); michael@0: } michael@0: }); michael@0: } michael@0: michael@0: function pressESC() { michael@0: EventUtils.synthesizeKey("VK_ESCAPE", { }); michael@0: }