Bug 1034512 - Part 8: Make browser/devtools/shared/test/treeWidget tests run in a toolbox host for e10s. r=bgrins

This commit is contained in:
Patrick Brosset 2015-01-26 02:36:00 -05:00
Родитель f007eff630
Коммит 6bd7345b82
4 изменённых файлов: 60 добавлений и 90 удалений

Просмотреть файл

@ -10,36 +10,26 @@ const TEST_URI = "data:text/html;charset=utf-8,<head><link rel='stylesheet' " +
"ets.css'></head><body><div></div><span></span></body>";
const {TreeWidget} = devtools.require("devtools/shared/widgets/TreeWidget");
let doc, tree;
add_task(function*() {
yield promiseTab("about:blank");
let [host, win, doc] = yield createHost("bottom", TEST_URI);
function test() {
waitForExplicitFinish();
addTab(TEST_URI, () => {
doc = content.document;
tree = new TreeWidget(doc.querySelector("div"), {
defaultType: "store"
});
startTests();
let tree = new TreeWidget(doc.querySelector("div"), {
defaultType: "store"
});
}
function endTests() {
populateTree(tree, doc);
testTreeItemInsertedCorrectly(tree, doc);
testAPI(tree, doc);
populateUnsortedTree(tree, doc);
testUnsortedTreeItemInsertedCorrectly(tree, doc);
tree.destroy();
doc = tree = null;
host.destroy();
gBrowser.removeCurrentTab();
finish();
}
});
function startTests() {
populateTree();
testTreeItemInsertedCorrectly();
testAPI();
populateUnsortedTree();
testUnsortedTreeItemInsertedCorrectly();
endTests();
}
function populateTree() {
function populateTree(tree, doc) {
tree.add([{
id: "level1",
label: "Level 1"
@ -77,7 +67,7 @@ function populateTree() {
/**
* Test if the nodes are inserted correctly in the tree.
*/
function testTreeItemInsertedCorrectly() {
function testTreeItemInsertedCorrectly(tree, doc) {
is(tree.root.children.children.length, 2, "Number of top level elements match");
is(tree.root.children.firstChild.lastChild.children.length, 3,
"Number of first second level elements match");
@ -124,7 +114,7 @@ function testTreeItemInsertedCorrectly() {
/**
* Populate the unsorted tree.
*/
function populateUnsortedTree() {
function populateUnsortedTree(tree, doc) {
tree.sorted = false;
tree.add([{ id: "g-1", label: "g-1"}])
@ -136,7 +126,7 @@ function populateUnsortedTree() {
/**
* Test if the nodes are inserted correctly in the unsorted tree.
*/
function testUnsortedTreeItemInsertedCorrectly() {
function testUnsortedTreeItemInsertedCorrectly(tree, doc) {
ok(tree.root.items.has("g-1"), "g-1 top level element exists");
is(tree.root.children.firstChild.lastChild.children.length, 3,
@ -159,7 +149,7 @@ function testUnsortedTreeItemInsertedCorrectly() {
/**
* Tests if the API exposed by TreeWidget works properly
*/
function testAPI() {
function testAPI(tree, doc) {
info("Testing TreeWidget API");
// Check if selectItem and selectedItem setter works as expected
// Nothing should be selected beforehand

Просмотреть файл

@ -9,36 +9,25 @@ const TEST_URI = "data:text/html;charset=utf-8,<head><link rel='stylesheet' " +
"rel='stylesheet' type='text/css' href='chrome://browser/skin/devtools/widg" +
"ets.css'></head><body><div></div><span></span></body>";
const {TreeWidget} = devtools.require("devtools/shared/widgets/TreeWidget");
let {Task} = devtools.require("resource://gre/modules/Task.jsm");
let {Promise} = devtools.require("resource://gre/modules/Promise.jsm");
const {Promise} = devtools.require("resource://gre/modules/Promise.jsm");
let doc, tree;
add_task(function*() {
yield promiseTab("about:blank");
let [host, win, doc] = yield createHost("bottom", TEST_URI);
function test() {
waitForExplicitFinish();
addTab(TEST_URI, () => {
doc = content.document;
tree = new TreeWidget(doc.querySelector("div"), {
defaultType: "store"
});
startTests();
let tree = new TreeWidget(doc.querySelector("div"), {
defaultType: "store"
});
}
function endTests() {
populateTree(tree, doc);
yield testKeyboardInteraction(tree, win);
tree.destroy();
doc = tree = null;
host.destroy();
gBrowser.removeCurrentTab();
finish();
}
let startTests = Task.async(function*() {
populateTree();
yield testKeyboardInteraction();
endTests();
});
function populateTree() {
function populateTree(tree, doc) {
tree.add([{
id: "level1",
label: "Level 1"
@ -87,13 +76,14 @@ function populateTree() {
// Sends a click event on the passed DOM node in an async manner
function click(node) {
executeSoon(() => EventUtils.synthesizeMouseAtCenter(node, {}, content));
let win = node.ownerDocument.defaultView;
executeSoon(() => EventUtils.synthesizeMouseAtCenter(node, {}, win));
}
/**
* Tests if pressing navigation keys on the tree items does the expected behavior
*/
let testKeyboardInteraction = Task.async(function*() {
function* testKeyboardInteraction(tree, win) {
info("Testing keyboard interaction with the tree");
let event;
let pass = (e, d, a) => event.resolve([e, d, a]);
@ -112,7 +102,7 @@ let testKeyboardInteraction = Task.async(function*() {
info("Pressing down key to select next item");
event = Promise.defer();
tree.once("select", pass);
EventUtils.sendKey("DOWN", content);
EventUtils.sendKey("DOWN", win);
let [name, data, attachment] = yield event.promise;
is(name, "select", "Select event was fired after pressing down");
is(data[0], "level1", "Correct item was selected after pressing down");
@ -123,7 +113,7 @@ let testKeyboardInteraction = Task.async(function*() {
info("Pressing down key again to select next item");
event = Promise.defer();
tree.once("select", pass);
EventUtils.sendKey("DOWN", content);
EventUtils.sendKey("DOWN", win);
[name, data, attachment] = yield event.promise;
is(data.length, 2, "Correct level item was selected after second down keypress");
is(data[0], "level1", "Correct parent level");
@ -132,7 +122,7 @@ let testKeyboardInteraction = Task.async(function*() {
info("Pressing down key again to select next item");
event = Promise.defer();
tree.once("select", pass);
EventUtils.sendKey("DOWN", content);
EventUtils.sendKey("DOWN", win);
[name, data, attachment] = yield event.promise;
is(data.length, 3, "Correct level item was selected after third down keypress");
is(data[0], "level1", "Correct parent level");
@ -142,7 +132,7 @@ let testKeyboardInteraction = Task.async(function*() {
info("Pressing down key again to select next item");
event = Promise.defer();
tree.once("select", pass);
EventUtils.sendKey("DOWN", content);
EventUtils.sendKey("DOWN", win);
[name, data, attachment] = yield event.promise;
is(data.length, 2, "Correct level item was selected after fourth down keypress");
is(data[0], "level1", "Correct parent level");
@ -159,7 +149,7 @@ let testKeyboardInteraction = Task.async(function*() {
event = Promise.defer();
node = tree._selectedLabel;
ok(node.hasAttribute("expanded"), "Item is expanded before left keypress");
EventUtils.sendKey("LEFT", content);
EventUtils.sendKey("LEFT", win);
yield event.promise;
ok(!node.hasAttribute("expanded"), "Item is not expanded after left keypress");
@ -172,7 +162,7 @@ let testKeyboardInteraction = Task.async(function*() {
// parent node should have no effect of this keypress
node = tree.root.children.firstChild.nextSibling.firstChild;
ok(node.hasAttribute("expanded"), "Parent is expanded");
EventUtils.sendKey("LEFT", content);
EventUtils.sendKey("LEFT", win);
[name, data] = yield event.promise;
is(data.length, 3, "Correct level item was selected after second left keypress");
is(data[0], "level1", "Correct parent level");
@ -185,7 +175,7 @@ let testKeyboardInteraction = Task.async(function*() {
info("Pressing down key to select next item");
event = Promise.defer();
tree.once("select", pass);
EventUtils.sendKey("DOWN", content);
EventUtils.sendKey("DOWN", win);
[name, data, attachment] = yield event.promise;
is(data.length, 2, "Correct level item was selected after fifth down keypress");
is(data[0], "level1", "Correct parent level");
@ -201,7 +191,7 @@ let testKeyboardInteraction = Task.async(function*() {
event = Promise.defer();
node = tree._selectedLabel;
ok(node.hasAttribute("expanded"), "Item is expanded before left keypress");
EventUtils.sendKey("LEFT", content);
EventUtils.sendKey("LEFT", win);
yield event.promise;
ok(!node.hasAttribute("expanded"), "Item is collapsed after left keypress");
@ -215,7 +205,7 @@ let testKeyboardInteraction = Task.async(function*() {
event = Promise.defer();
node = tree._selectedLabel;
ok(!node.hasAttribute("expanded"), "Item is collapsed before right keypress");
EventUtils.sendKey("RIGHT", content);
EventUtils.sendKey("RIGHT", win);
yield event.promise;
ok(node.hasAttribute("expanded"), "Item is expanded after right keypress");
@ -230,9 +220,9 @@ let testKeyboardInteraction = Task.async(function*() {
executeSoon(() => event.resolve(null));
});
info("Pressing down key on last item of the tree");
EventUtils.sendKey("DOWN", content);
EventUtils.sendKey("DOWN", win);
yield event.promise;
ok(tree.isSelected(["level1.1", "level2", "level3"]),
"Last item is still selected after pressing down on last item of the tree");
});
}

Просмотреть файл

@ -9,36 +9,25 @@ const TEST_URI = "data:text/html;charset=utf-8,<head><link rel='stylesheet' " +
"rel='stylesheet' type='text/css' href='chrome://browser/skin/devtools/widg" +
"ets.css'></head><body><div></div><span></span></body>";
const {TreeWidget} = devtools.require("devtools/shared/widgets/TreeWidget");
let {Task} = devtools.require("resource://gre/modules/Task.jsm");
let {Promise} = devtools.require("resource://gre/modules/Promise.jsm");
const {Promise} = devtools.require("resource://gre/modules/Promise.jsm");
let doc, tree;
add_task(function*() {
yield promiseTab("about:blank");
let [host, win, doc] = yield createHost("bottom", TEST_URI);
function test() {
waitForExplicitFinish();
addTab(TEST_URI, () => {
doc = content.document;
tree = new TreeWidget(doc.querySelector("div"), {
defaultType: "store"
});
startTests();
let tree = new TreeWidget(doc.querySelector("div"), {
defaultType: "store"
});
}
function endTests() {
populateTree(tree, doc);
yield testMouseInteraction(tree);
tree.destroy();
doc = tree = null;
host.destroy();
gBrowser.removeCurrentTab();
finish();
}
let startTests = Task.async(function*() {
populateTree();
yield testMouseInteraction();
endTests();
});
function populateTree() {
function populateTree(tree, doc) {
tree.add([{
id: "level1",
label: "Level 1"
@ -87,13 +76,14 @@ function populateTree() {
// Sends a click event on the passed DOM node in an async manner
function click(node) {
executeSoon(() => EventUtils.synthesizeMouseAtCenter(node, {}, content));
let win = node.ownerDocument.defaultView;
executeSoon(() => EventUtils.synthesizeMouseAtCenter(node, {}, win));
}
/**
* Tests if clicking the tree items does the expected behavior
*/
let testMouseInteraction = Task.async(function*() {
function* testMouseInteraction(tree) {
info("Testing mouse interaction with the tree");
let event;
let pass = (e, d, a) => event.resolve([e, d, a]);
@ -144,4 +134,4 @@ let testMouseInteraction = Task.async(function*() {
click(node2);
yield event.promise;
ok(!node2.hasAttribute("expanded"), "New node collapsed after click again");
});
}

Просмотреть файл

@ -137,7 +137,7 @@ function oneTimeObserve(name, callback) {
Services.obs.addObserver(func, name, false);
}
function* createHost(type = "bottom", src = "data:text/html;charset=utf-8,") {
let createHost = Task.async(function*(type = "bottom", src = "data:text/html;charset=utf-8,") {
let host = new Hosts[type](gBrowser.selectedTab);
let iframe = yield host.create();
@ -148,7 +148,7 @@ function* createHost(type = "bottom", src = "data:text/html;charset=utf-8,") {
});
return [host, iframe.contentWindow, iframe.contentDocument];
}
});
/**
* Load the Telemetry utils, then stub Telemetry.prototype.log in order to