2014-03-31 15:26:53 -07:00
|
|
|
/* vim: set ts=2 et sw=2 tw=80: */
|
|
|
|
/* Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
|
|
|
|
const TESTCASE_URI = TEST_BASE + "color-block.html";
|
|
|
|
const DIV_COLOR = "#0000FF";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test basic eyedropper widget functionality:
|
|
|
|
* - Opening eyedropper and pressing ESC closes the eyedropper
|
|
|
|
* - Opening eyedropper and clicking copies the center color
|
|
|
|
*/
|
2014-12-15 00:37:00 -08:00
|
|
|
add_task(function*() {
|
2014-11-07 07:46:00 -08:00
|
|
|
yield addTab(TESTCASE_URI);
|
|
|
|
|
|
|
|
info("added tab");
|
|
|
|
|
|
|
|
yield testEscape();
|
|
|
|
|
|
|
|
info("testing selecting a color");
|
|
|
|
|
|
|
|
yield testSelect();
|
|
|
|
});
|
2014-03-31 15:26:53 -07:00
|
|
|
|
2014-11-07 07:46:00 -08:00
|
|
|
function* testEscape() {
|
2014-03-31 15:26:53 -07:00
|
|
|
let dropper = new Eyedropper(window);
|
|
|
|
|
2014-11-07 07:46:00 -08:00
|
|
|
yield inspectPage(dropper, false);
|
2014-03-31 15:26:53 -07:00
|
|
|
|
2014-11-07 07:46:00 -08:00
|
|
|
let destroyed = dropper.once("destroy");
|
|
|
|
pressESC();
|
|
|
|
yield destroyed;
|
2014-03-31 15:26:53 -07:00
|
|
|
|
2014-11-07 07:46:00 -08:00
|
|
|
ok(true, "escape closed the eyedropper");
|
2014-03-31 15:26:53 -07:00
|
|
|
}
|
|
|
|
|
2014-11-07 07:46:00 -08:00
|
|
|
function* testSelect() {
|
2014-03-31 15:26:53 -07:00
|
|
|
let dropper = new Eyedropper(window);
|
|
|
|
|
2014-11-07 07:46:00 -08:00
|
|
|
let selected = dropper.once("select");
|
|
|
|
let copied = waitForClipboard(() => {}, DIV_COLOR);
|
2014-03-31 15:26:53 -07:00
|
|
|
|
2014-11-07 07:46:00 -08:00
|
|
|
yield inspectPage(dropper);
|
|
|
|
|
|
|
|
let color = yield selected;
|
|
|
|
is(color, DIV_COLOR, "correct color selected");
|
|
|
|
|
|
|
|
// wait for DIV_COLOR to be copied to the clipboard
|
|
|
|
yield copied;
|
2014-03-31 15:26:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Helpers */
|
|
|
|
|
2014-11-07 07:46:00 -08:00
|
|
|
function* inspectPage(dropper, click=true) {
|
|
|
|
yield dropper.open();
|
|
|
|
|
|
|
|
info("dropper opened");
|
|
|
|
|
|
|
|
let target = document.documentElement;
|
|
|
|
let win = window;
|
|
|
|
|
|
|
|
// get location of the <div> in the content, offset from browser window
|
2014-12-15 13:05:46 -08:00
|
|
|
let box = gBrowser.selectedBrowser.getBoundingClientRect();
|
2014-11-07 07:46:00 -08:00
|
|
|
let x = box.left + 100;
|
|
|
|
let y = box.top + 100;
|
2014-03-31 15:26:53 -07:00
|
|
|
|
2014-11-07 07:46:00 -08:00
|
|
|
EventUtils.synthesizeMouse(target, x, y, { type: "mousemove" }, win);
|
2014-03-31 15:26:53 -07:00
|
|
|
|
2014-11-07 07:46:00 -08:00
|
|
|
yield dropperLoaded(dropper);
|
2014-03-31 15:26:53 -07:00
|
|
|
|
2014-11-07 07:46:00 -08:00
|
|
|
EventUtils.synthesizeMouse(target, x + 10, y + 10, { type: "mousemove" }, win);
|
2014-03-31 15:26:53 -07:00
|
|
|
|
2014-11-07 07:46:00 -08:00
|
|
|
if (click) {
|
|
|
|
EventUtils.synthesizeMouse(target, x + 10, y + 10, {}, win);
|
|
|
|
}
|
2014-03-31 15:26:53 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function pressESC() {
|
|
|
|
EventUtils.synthesizeKey("VK_ESCAPE", { });
|
|
|
|
}
|