browser/devtools/eyedropper/test/browser_eyedropper_basic.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/eyedropper/test/browser_eyedropper_basic.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,64 @@
     1.4 +/* vim: set ts=2 et sw=2 tw=80: */
     1.5 +/* Any copyright is dedicated to the Public Domain.
     1.6 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.7 +
     1.8 +const TESTCASE_URI = TEST_BASE + "color-block.html";
     1.9 +const DIV_COLOR = "#0000FF";
    1.10 +
    1.11 +/**
    1.12 + * Test basic eyedropper widget functionality:
    1.13 + *  - Opening eyedropper and pressing ESC closes the eyedropper
    1.14 + *  - Opening eyedropper and clicking copies the center color
    1.15 + */
    1.16 +function test() {
    1.17 +  addTab(TESTCASE_URI).then(testEscape);
    1.18 +}
    1.19 +
    1.20 +function testEscape() {
    1.21 +  let dropper = new Eyedropper(window);
    1.22 +
    1.23 +  dropper.once("destroy", (event) => {
    1.24 +    ok(true, "escape closed the eyedropper");
    1.25 +
    1.26 +    // now test selecting a color
    1.27 +    testSelect();
    1.28 +  });
    1.29 +
    1.30 +  inspectPage(dropper, false).then(pressESC);
    1.31 +}
    1.32 +
    1.33 +function testSelect() {
    1.34 +  let dropper = new Eyedropper(window);
    1.35 +
    1.36 +  dropper.once("select", (event, color) => {
    1.37 +    is(color, DIV_COLOR, "correct color selected");
    1.38 +  });
    1.39 +
    1.40 +  // wait for DIV_COLOR to be copied to the clipboard then finish the test.
    1.41 +  waitForClipboard(DIV_COLOR, () => {
    1.42 +    inspectPage(dropper); // setup: inspect the page
    1.43 +  }, finish, finish);
    1.44 +}
    1.45 +
    1.46 +/* Helpers */
    1.47 +
    1.48 +function inspectPage(dropper, click=true) {
    1.49 +  dropper.open();
    1.50 +
    1.51 +  let target = content.document.getElementById("test");
    1.52 +  let win = content.window;
    1.53 +
    1.54 +  EventUtils.synthesizeMouse(target, 20, 20, { type: "mousemove" }, win);
    1.55 +
    1.56 +  return dropperLoaded(dropper).then(() => {
    1.57 +    EventUtils.synthesizeMouse(target, 30, 30, { type: "mousemove" }, win);
    1.58 +
    1.59 +    if (click) {
    1.60 +      EventUtils.synthesizeMouse(target, 30, 30, {}, win);
    1.61 +    }
    1.62 +  });
    1.63 +}
    1.64 +
    1.65 +function pressESC() {
    1.66 +  EventUtils.synthesizeKey("VK_ESCAPE", { });
    1.67 +}

mercurial