Bug 581139 - Add a working infrastructure for e10s tests [r=mfinkle,jmaher]

This commit is contained in:
Vivien Nicolas 2010-07-28 00:51:41 +02:00
Родитель bd16943cf1
Коммит 48b3a4c4d2
8 изменённых файлов: 287 добавлений и 164 удалений

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

@ -344,7 +344,6 @@ FormAssistant.prototype = {
if (!document)
return;
let currentIndex = -1;
let documents = Util.getAllDocuments(document);
let elements = this._elements;
@ -358,9 +357,6 @@ FormAssistant.prototype = {
continue;
elements.push(node);
if (node == aElement) {
currentIndex = elements.length - 1;
}
}
}
@ -374,6 +370,15 @@ FormAssistant.prototype = {
return a.tabIndex > b.tabIndex;
}
elements = elements.sort(orderByTabIndex);
// retrieve the correct index
let currentIndex = -1;
for (let i = 0; i < elements.length; i++) {
if (elements[i] == aElement) {
currentIndex = i;
break;
}
}
return currentIndex;
},

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

@ -46,6 +46,7 @@ include $(topsrcdir)/config/rules.mk
_BROWSER_FILES = \
head.js \
remote_head.js \
browser_mainui.js \
browser_tabs.js \
browser_bookmarks.js \
@ -54,7 +55,8 @@ _BROWSER_FILES = \
browser_select.js \
browser_rect.js \
browser_click_content.js \
browser_FormAssistant.js \
browser_forms.js \
remote_forms.js \
browser_viewport.js \
browser_navigation.js \
browser_preferences_basic.js \
@ -63,7 +65,7 @@ _BROWSER_FILES = \
browser_blank_02.html \
browser_select.html \
browser_click_content.html \
browser_FormAssistant.html \
browser_forms.html \
browser_viewport_00.html \
browser_viewport_01.html \
browser_viewport_02.html \

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

@ -1,158 +0,0 @@
let testURL = "chrome://mochikit/content/browser/mobile/chrome/browser_FormAssistant.html";
let newTab = null;
let container = null;
let isLoading = function() {
return !newTab.isLoading() && newTab.browser.currentURI.spec != "about:blank";
};
function test() {
// This test is async
waitForExplicitFinish();
// Add new tab to hold the <FormAssistant> page
newTab = Browser.addTab(testURL, true);
BrowserUI.closeAutoComplete(true);
// Wait for the tab to load, then do the test
waitFor(onTabLoaded, isLoading);
}
function onTabLoaded() {
container = document.getElementById("form-helper-container");
testMouseEvents();
}
function testMouseEvents() {
// Sending a synthesized event directly on content should not work - we
// don't want web content to be able to open the form helper without the
// user consent, so we have to pass throught the canvas tile-container
EventUtils.sendMouseEvent({type: "click"}, "root", newTab.browser.contentWindow);
is(FormHelper._open, false, "Form Assistant should stay closed");
let element = newTab.browser.contentDocument.querySelector("*[tabindex='0']");
EventUtils.synthesizeMouseForContent(element, 1, 1, {}, window);
// XXX because InputHandler hold us for at least 400ms we should wait a bit here
setTimeout (function() {
ok(FormHelper._open, "Form Assistant should be open");
testShowUIForElements();
}, 1700);
};
function testShowUIForElements() {
let doc = newTab.browser.contentDocument;
/* XXX FormHelper.canShowUIFor is now BasicWrapper.canAssist
ok(FormHelper.canShowUIFor(doc.querySelector("*[tabindex='1']")), "canShowUI for input type='text'");
ok(FormHelper.canShowUIFor(doc.querySelector("*[tabindex='2']")), "canShowUI for input type='password'");
is(FormHelper.canShowUIFor(doc.querySelector("*[tabindex='3']")), false, "!canShowUI for input type='submit'");
is(FormHelper.canShowUIFor(doc.querySelector("*[tabindex='4']")), false, "!canShowUI for input type='file'");
is(FormHelper.canShowUIFor(doc.querySelector("*[tabindex='5']")), false, "!canShowUI for input button type='submit'");
is(FormHelper.canShowUIFor(doc.querySelector("*[tabindex='6']")), false, "!canShowUI for div@role='button'");
is(FormHelper.canShowUIFor(doc.querySelector("*[tabindex='7']")), false, "!canShowUI for input type='image'");
*/
// XXX: FormHelper.open is now triggered by a message from content.
finish();
//testTabIndexNavigation();
};
function testTabIndexNavigation() {
// Open the Form Helper
let firstElement = newTab.browser.contentDocument.getElementById("root");
FormHelper.open(firstElement);
is(container.hidden, false, "Form Assistant should be open");
FormHelper.goToPrevious();
let element = newTab.browser.contentDocument.querySelector("*[tabindex='0']");
isnot(FormHelper.getCurrentElement(), element, "Focus should not have changed");
FormHelper.goToNext();
element = newTab.browser.contentDocument.querySelector("*[tabindex='2']");
is(FormHelper.getCurrentElement(), element, "Focus should be on element with tab-index : 2");
FormHelper.goToPrevious();
element = newTab.browser.contentDocument.querySelector("*[tabindex='1']");
is(FormHelper.getCurrentElement(), element, "Focus should be on element with tab-index : 1");
FormHelper.goToNext();
FormHelper.goToNext();
FormHelper.goToNext();
FormHelper.goToNext();
FormHelper.goToNext();
FormHelper.goToNext();
element = newTab.browser.contentDocument.querySelector("*[tabindex='7']");
is(FormHelper.getCurrentElement(), element, "Focus should be on element with tab-index : 7");
FormHelper.goToNext();
element = newTab.browser.contentDocument.querySelector("*[tabindex='0']");
is(FormHelper.getCurrentElement(), element, "Focus should be on element with tab-index : 0");
FormHelper.goToNext();
element = newTab.browser.contentDocument.getElementById("next");
is(FormHelper.getCurrentElement(), element, "Focus should be on element with #id: next");
FormHelper.goToNext();
is(FormHelper.getCurrentElement().id, "select", "Focus should be on element with #id: select");
FormHelper.goToNext();
is(FormHelper.getCurrentElement().id, "dumb", "Focus should be on element with #id: dumb");
FormHelper.goToNext();
is(FormHelper.getCurrentElement().id, "reset", "Focus should be on element with #id: reset");
FormHelper.goToNext();
is(FormHelper.getCurrentElement().id, "checkbox", "Focus should be on element with #id: checkbox");
FormHelper.goToNext();
is(FormHelper.getCurrentElement().id, "radio0", "Focus should be on element with #id: radio0");
FormHelper.goToNext();
is(FormHelper.getCurrentElement().id, "radio4", "Focus should be on element with #id: radio4");
FormHelper.goToNext();
element = newTab.browser.contentDocument.getElementById("last");
is(FormHelper.getCurrentElement(), element, "Focus should be on element with #id: last");
FormHelper.goToNext();
is(FormHelper.getCurrentElement(), element, "Focus should be on element with #id: last");
FormHelper.close();
is(container.hidden, true, "Form Assistant should be close");
navigateIntoNestedFrames();
};
function navigateIntoNestedFrames() {
let doc = newTab.browser.contentDocument;
let iframe = doc.createElement("iframe");
iframe.setAttribute("src", "data:text/html;charset=utf-8,%3Ciframe%20src%3D%22data%3Atext/html%3Bcharset%3Dutf-8%2C%253Cinput%253E%253Cbr%253E%253Cinput%253E%250A%22%3E%3C/iframe%3E");
iframe.setAttribute("width", "300");
iframe.setAttribute("height", "100");
iframe.addEventListener("load", function() {
iframe.removeEventListener("load", arguments.callee, false);
let elements = iframe.contentDocument
.querySelector("iframe").contentDocument
.getElementsByTagName("input");
FormHelper.open(elements[0]);
ok(FormHelper._getPrevious(), "It should be possible to access to the previous field");
ok(FormHelper._getNext(), "It should be possible to access to the next field");
FormHelper.goToNext();
ok(!FormHelper._getNext(), "It should not be possible to access to the next field");
doc.body.removeChild(iframe);
// Close the form assistant
FormHelper.close();
// Close our tab when finished
Browser.closeTab(newTab);
// We must finialize the tests
finish();
}, false);
doc.body.appendChild(iframe);
};

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

@ -0,0 +1,151 @@
let testURL = "chrome://mochikit/content/browser/mobile/chrome/browser_forms.html";
messageManager.loadFrameScript("chrome://mochikit/content/browser/mobile/chrome/remote_forms.js", true);
let newTab = null;
let isLoading = function() {
return !newTab.isLoading() && newTab.browser.currentURI.spec != "about:blank";
};
function test() {
// This test is async
waitForExplicitFinish();
// Add new tab to hold the <FormAssistant> page
newTab = Browser.addTab(testURL, true);
BrowserUI.closeAutoComplete(true);
// Wait for the tab to load, then do the test
waitFor(onTabLoaded, isLoading);
}
function onTabLoaded() {
testMouseEvents();
}
function testMouseEvents() {
// Sending a synthesized event directly on content should not work - we
// don't want web content to be able to open the form helper without the
// user consent, so we have to pass throught the canvas tile-container
AsyncTests.waitFor("Test:Click", {}, function(json) {
is(json.result, false, "Form Assistant should stay closed");
});
AsyncTests.waitFor("Test:Open", { value: "*[tabindex='0']" }, function(json) {
ok(FormHelperUI._open, "Form Assistant should be open");
testShowUIForElements();
});
};
function testShowUIForElements() {
AsyncTests.waitFor("Test:CanShowUI", { value: "*[tabindex='1']" }, function(json) {
ok(json.result, "canShowUI for input type='text'");
});
AsyncTests.waitFor("Test:CanShowUI", { value: "*[tabindex='2']" }, function(json) {
ok(json.result, "canShowUI for input type='password'");
});
AsyncTests.waitFor("Test:CanShowUI", { value: "*[tabindex='3']" }, function(json) {
is(json.result, false, "!canShowUI for input type='submit'");
});
AsyncTests.waitFor("Test:CanShowUI", { value: "*[tabindex='4']" }, function(json) {
is(json.result, false, "!canShowUI for input type='file'");
});
AsyncTests.waitFor("Test:CanShowUI", { value: "*[tabindex='5']" }, function(json) {
is(json.result, false, "!canShowUI for input button type='submit'");
});
AsyncTests.waitFor("Test:CanShowUI", { value: "*[tabindex='6']" }, function(json) {
is(json.result, false, "!canShowUI for input div@role='button'");
});
AsyncTests.waitFor("Test:CanShowUI", { value: "*[tabindex='6']" }, function(json) {
is(json.result, false, "!canShowUI for input type='image'");
});
// Open the Form Helper
AsyncTests.waitFor("Test:Open", { value: "*[tabindex='1']" }, function(json) {
ok(json.result, "Form Assistant should be open");
testTabIndexNavigation();
});
};
function testTabIndexNavigation() {
AsyncTests.waitFor("Test:Previous", { value: "*[tabindex='0']" }, function(json) {
is(json.result, false, "Focus should not have changed");
});
AsyncTests.waitFor("Test:Next", { value: "*[tabindex='2']" }, function(json) {
is(json.result, true, "Focus should be on element with tab-index : 2");
});
AsyncTests.waitFor("Test:Previous", { value: "*[tabindex='1']" }, function(json) {
is(json.result, true, "Focus should be on element with tab-index : 1");
});
AsyncTests.waitFor("Test:Next");
AsyncTests.waitFor("Test:Next");
AsyncTests.waitFor("Test:Next");
AsyncTests.waitFor("Test:Next");
AsyncTests.waitFor("Test:Next");
AsyncTests.waitFor("Test:Next", { value: "*[tabindex='7']" }, function(json) {
is(json.result, true, "Focus should be on element with tab-index : 7");
});
AsyncTests.waitFor("Test:Next", { value: "*[tabindex='0']" }, function(json) {
is(json.result, true, "Focus should be on element with tab-index : 0");
});
let ids = ["next", "select", "dumb", "reset", "checkbox", "radio0", "radio4", "last", "last"];
for (let i = 0; i < ids.length; i++) {
let id = ids[i];
AsyncTests.waitFor("Test:Next", { value: "*[id='" + id + "']" }, function(json) {
is(json.result, true, "Focus should be on element with #id: " + id + "");
});
};
FormHelperUI.hide();
let container = document.getElementById("content-navigator");
is(container.hidden, true, "Form Assistant should be close");
loadNestedIFrames();
};
function loadNestedIFrames() {
AsyncTests.waitFor("Test:Iframe", { }, function(json) {
is(json.result, true, "Iframe should have loaded");
navigateIntoNestedIFrames();
});
}
function navigateIntoNestedIFrames() {
AsyncTests.waitFor("Test:IframeOpen", { }, function(json) {
is(json.result, true, "Form Assistant should have been opened");
});
AsyncTests.waitFor("Test:IframePrevious", { value: 0 }, function(json) {
is(json.result, true, "Focus should not have move");
});
AsyncTests.waitFor("Test:IframeNext", { value: 1 }, function(json) {
is(json.result, true, "Focus should have move");
});
AsyncTests.waitFor("Test:IframeNext", { value: 1 }, function(json) {
is(json.result, true, "Focus should not have move");
// Close the form assistant
FormHelperUI.hide();
// Close our tab when finished
Browser.closeTab(newTab);
// We must finalize the tests
finish();
});
};

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

@ -29,3 +29,25 @@ EventUtils.synthesizeMouseForContent = function synthesizeMouseForContent(aEleme
EventUtils.synthesizeMouse(aElement, rect.left + aOffsetX, rect.top + aOffsetY, aEvent, aWindow);
};
let AsyncTests = {
_tests: {},
waitFor: function(aMessage, aData, aCallback) {
messageManager.addMessageListener(aMessage, this);
if (!this._tests[aMessage])
this._tests[aMessage] = [];
this._tests[aMessage].push(aCallback || function() {});
Browser.selectedBrowser.messageManager.sendAsyncMessage(aMessage, aData || { });
},
receiveMessage: function(aMessage) {
let test = this._tests[aMessage.name];
let callback = test.shift();
if (callback)
callback(aMessage.json);
}
};
messageManager.loadFrameScript("chrome://mochikit/content/browser/mobile/chrome/remote_head.js", true);
messageManager.loadFrameScript("chrome://mochikit/content/tests/SimpleTest/EventUtils.js", true);

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

@ -0,0 +1,66 @@
dump("====================== Content Script Loaded =======================\n");
let assistant = contentObject._formAssistant;
AsyncTests.add("Test:Click", function(aMessage, aJson) {
sendMouseEvent({type: "click"}, "root", content);
return assistant._open;
});
AsyncTests.add("Test:Open", function(aMessage, aJson) {
let element = content.document.querySelector(aJson.value);
return assistant.open(element);
});
AsyncTests.add("Test:CanShowUI", function(aMessage, aJson) {
let element = content.document.querySelector(aJson.value);
assistant._open = false;
return assistant.open(element);
});
AsyncTests.add("Test:Previous", function(aMessage, aJson) {
let targetElement = content.document.querySelector(aJson.value);
assistant.currentIndex--;
return (assistant.currentElement == targetElement);
});
AsyncTests.add("Test:Next", function(aMessage, aJson) {
let targetElement = content.document.querySelector(aJson.value);
assistant.currentIndex++;
return (assistant.currentElement == targetElement);
});
// ============= iframe navigation ==================
let iframe = null;
let iframeInputs = null;
AsyncTests.add("Test:Iframe", function(aMessage, aJson) {
iframe = content.document.createElement("iframe");
iframe.setAttribute("src", "data:text/html;charset=utf-8,%3Ciframe%20src%3D%22data%3Atext/html%3Bcharset%3Dutf-8%2C%253Cinput%253E%253Cbr%253E%253Cinput%253E%250A%22%3E%3C/iframe%3E");
iframe.setAttribute("width", "300");
iframe.setAttribute("height", "100");
iframe.addEventListener("load", function() {
iframe.removeEventListener("load", arguments.callee, false);
iframeInputs = iframe.contentDocument
.querySelector("iframe").contentDocument
.getElementsByTagName("input");
sendAsyncMessage(aMessage, { result: true });
}, false);
content.document.body.appendChild(iframe);
});
AsyncTests.add("Test:IframeOpen", function(aMessage, aJson) {
return assistant.open(iframeInputs[0]);
});
AsyncTests.add("Test:IframePrevious", function(aMessage, aJson) {
assistant.currentIndex--;
return (assistant.currentElement == iframeInputs[aJson.value]);
});
AsyncTests.add("Test:IframeNext", function(aMessage, aJson) {
assistant.currentIndex++;
return (assistant.currentElement == iframeInputs[aJson.value]);
});

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

@ -0,0 +1,35 @@
// XXX Those constants are here because EventUtils.js need them
const window = content.document.defaultView.wrappedJSObject;
const Element = Components.interfaces.nsIDOMElement;
const netscape = window.netscape;
let AsyncTests = {
_tests: [],
add: function(aMessage, aCallback) {
addMessageListener(aMessage, this);
this._tests.push({ name: aMessage, callback: aCallback });
},
receiveMessage: function(aMessage) {
let rv = { };
let name = aMessage.name;
try {
let tests = this._tests;
for (let i = 0; i < tests.length; i++) {
if (tests[i].name == name) {
rv.result = tests[i].callback(name, aMessage.json);
break;
}
}
// Don't send test callback if rv.result == undefined, this allow to
// use a custom callback
if (rv.result != undefined)
sendAsyncMessage(name, rv);
}
catch(e) {
dump("receiveMessage: " + name + " - " + e + "\n");
}
}
};