Bug 1162330 - Prepare satchel mochitests for e10s and turn a few of them on. r=MattN

This commit is contained in:
Blake Kaplan 2015-05-28 09:55:46 -07:00
Родитель 6ff0cdd8d2
Коммит 5aab2947e9
9 изменённых файлов: 226 добавлений и 107 удалений

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

@ -1,15 +1,20 @@
[DEFAULT]
skip-if = toolkit == 'android' || buildapp == 'b2g' || os == 'linux' || e10s # linux - bug 947531
skip-if = toolkit == 'android' || buildapp == 'b2g' || os == 'linux' # linux - bug 947531
support-files =
satchel_common.js
subtst_form_submission_1.html
subtst_privbrowsing.html
parent_utils.js
[test_bug_511615.html]
skip-if = e10s # bug 1162338 (needs refactoring to talk to the autocomplete popup)
[test_bug_787624.html]
skip-if = e10s # bug 1162338 (needs refactoring to talk to the autocomplete popup)
[test_form_autocomplete.html]
skip-if = true # Test disabled for too many intermittent failures (bug 874429)
# XXX Now fails for other reasons (incl. <input type=number>)
[test_form_autocomplete_with_list.html]
skip-if = e10s # bug 1162329 (autocomplete impl. in e10s isn't complete)
[test_form_submission.html]
[test_form_submission_cap.html]
[test_form_submission_cap2.html]

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

@ -0,0 +1,120 @@
const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
Cu.import("resource://gre/modules/FormHistory.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://testing-common/ContentTaskUtils.jsm");
let gAutocompletePopup = Services.ww.activeWindow.
document.
getElementById("PopupAutoComplete");
assert.ok(gAutocompletePopup, "Got autocomplete popup");
let ParentUtils = {
getMenuEntries() {
let entries = [];
let column = gAutocompletePopup.tree.columns[0];
let numRows = gAutocompletePopup.tree.view.rowCount;
for (let i = 0; i < numRows; i++) {
entries.push(gAutocompletePopup.tree.view.getCellText(i, column));
}
return entries;
},
cleanUpFormHist() {
FormHistory.update({ op: "remove" });
},
updateFormHistory(changes) {
let handler = {
handleError: function (error) {
assert.ok(false, error);
sendAsyncMessage("formHistoryUpdated", { ok: false });
},
handleCompletion: function (reason) {
if (!reason)
sendAsyncMessage("formHistoryUpdated", { ok: true });
},
};
FormHistory.update(changes, handler);
},
popupshownListener() {
let results = this.getMenuEntries();
sendAsyncMessage("onpopupshown", { results });
},
countEntries(name, value) {
let obj = {};
if (name)
obj.fieldname = name;
if (value)
obj.value = value;
let count = 0;
let listener = {
handleResult(result) { count = result },
handleError(error) {
assert.ok(false, error);
sendAsyncMessage("entriesCounted", { ok: false });
},
handleCompletion(reason) {
if (!reason) {
sendAsyncMessage("entriesCounted", { ok: true, count });
}
}
};
FormHistory.count(obj, listener);
},
checkRowCount(expectedCount, expectedFirstValue = null) {
ContentTaskUtils.waitForCondition(() => {
return gAutocompletePopup.tree.view.rowCount === expectedCount &&
(!expectedFirstValue ||
expectedCount <= 1 ||
gAutocompletePopup.tree.view.getValueAt(0, gAutocompletePopup.tree.columns[0]) ===
expectedFirstValue);
}).then(() => {
let results = this.getMenuEntries();
sendAsyncMessage("gotMenuChange", { results });
});
},
observe(subject, topic, data) {
assert.ok(topic === "satchel-storage-changed");
sendAsyncMessage("satchel-storage-changed", { subject: null, topic, data });
},
cleanup() {
gAutocompletePopup.removeEventListener("popupshown", this._popupshownListener);
this.cleanUpFormHist();
}
};
ParentUtils._popupshownListener =
ParentUtils.popupshownListener.bind(ParentUtils);
gAutocompletePopup.addEventListener("popupshown", ParentUtils._popupshownListener);
ParentUtils.cleanUpFormHist();
addMessageListener("updateFormHistory", (msg) => {
ParentUtils.updateFormHistory(msg.changes);
});
addMessageListener("countEntries", ({ name, value }) => {
ParentUtils.countEntries(name, value);
});
addMessageListener("waitForMenuChange", ({ expectedCount, expectedFirstValue }) => {
ParentUtils.checkRowCount(expectedCount, expectedFirstValue);
});
addMessageListener("addObserver", () => {
Services.obs.addObserver(ParentUtils, "satchel-storage-changed", false);
});
addMessageListener("removeObserver", () => {
Services.obs.removeObserver(ParentUtils, "satchel-storage-changed");
});
addMessageListener("cleanup", () => {
ParentUtils.cleanup();
});

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

@ -3,6 +3,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
var Services = SpecialPowers.Services;
var gPopupShownListener;
var gLastAutoCompleteResults;
/*
* $_
@ -44,7 +46,7 @@ function doKey(aKey, modifier) {
if (!modifier)
modifier = null;
// Window utils for sending fake sey events.
// Window utils for sending fake key events.
var wutils = SpecialPowers.getDOMWindowUtils(window);
if (wutils.sendKeyEvent("keydown", key, 0, modifier)) {
@ -53,34 +55,37 @@ function doKey(aKey, modifier) {
wutils.sendKeyEvent("keyup", key, 0, modifier);
}
function getAutocompletePopup() {
var Ci = SpecialPowers.Ci;
chromeWin = SpecialPowers.wrap(window)
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow)
.QueryInterface(Ci.nsIDOMChromeWindow);
autocompleteMenu = chromeWin.document.getElementById("PopupAutoComplete");
ok(autocompleteMenu, "Got autocomplete popup");
return autocompleteMenu;
function registerPopupShownListener(listener) {
if (gPopupShownListener) {
ok(false, "got too many popupshownlisteners");
return;
}
gPopupShownListener = listener;
}
function getMenuEntries() {
if (!gLastAutoCompleteResults) {
throw new Error("no autocomplete results");
}
function cleanUpFormHist() {
SpecialPowers.formHistory.update({ op : "remove" });
var results = gLastAutoCompleteResults;
gLastAutoCompleteResults = null;
return results;
}
cleanUpFormHist();
var checkObserver = {
verifyStack: [],
callback: null,
init() {
script.sendAsyncMessage("addObserver");
script.addMessageListener("satchel-storage-changed", this.observe.bind(this));
},
uninit() {
script.sendAsyncMessage("removeObserver");
},
waitForChecks: function(callback) {
if (this.verifyStack.length == 0)
callback();
@ -88,7 +93,7 @@ var checkObserver = {
this.callback = callback;
},
observe: function(subject, topic, data) {
observe: function({ subject, topic, data }) {
if (data != "formhistory-add" && data != "formhistory-update")
return;
ok(this.verifyStack.length > 0, "checking if saved form data was expected");
@ -120,6 +125,22 @@ function checkForSave(name, value, message) {
checkObserver.verifyStack.push({ name : name, value: value, message: message });
}
function NonE10SgetAutocompletePopup() {
var Ci = SpecialPowers.Ci;
chromeWin = SpecialPowers.wrap(window)
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow)
.QueryInterface(Ci.nsIDOMChromeWindow);
autocompleteMenu = chromeWin.document.getElementById("PopupAutoComplete");
ok(autocompleteMenu, "Got autocomplete popup");
return autocompleteMenu;
}
function getFormSubmitButton(formNum) {
var form = $("form" + formNum); // by id, not name
@ -137,28 +158,54 @@ function getFormSubmitButton(formNum) {
// Count the number of entries with the given name and value, and call then(number)
// when done. If name or value is null, then the value of that field does not matter.
function countEntries(name, value, then) {
var obj = {};
if (name !== null)
obj.fieldname = name;
if (value !== null)
obj.value = value;
script.sendAsyncMessage("countEntries", { name, value });
script.addMessageListener("entriesCounted", function counted(data) {
script.removeMessageListener("entriesCounted", counted);
if (!data.ok) {
ok(false, "Error occurred counting form history");
SimpleTest.finish();
return;
}
var count = 0;
SpecialPowers.formHistory.count(obj, SpecialPowers.wrapCallbackObject({ handleResult: function (result) { count = result },
handleError: function (error) {
ok(false, "Error occurred searching form history: " + error.message);
SimpleTest.finish();
},
handleCompletion: function (reason) { if (!reason) then(count); }
}));
then(data.count);
});
}
// Wrapper around FormHistory.update which handles errors. Calls then() when done.
function updateFormHistory(changes, then) {
SpecialPowers.formHistory.update(changes, SpecialPowers.wrapCallbackObject({ handleError: function (error) {
ok(false, "Error occurred updating form history: " + error.message);
SimpleTest.finish();
},
handleCompletion: function (reason) { if (!reason) then(); },
}));
script.sendAsyncMessage("updateFormHistory", { changes });
script.addMessageListener("formHistoryUpdated", function updated({ ok }) {
script.removeMessageListener("formHistoryUpdated", updated);
if (!ok) {
ok(false, "Error occurred updating form history");
SimpleTest.finish();
return;
}
then();
});
}
function notifyMenuChanged(expectedCount, expectedFirstValue, then) {
script.sendAsyncMessage("waitForMenuChange",
{ expectedCount,
expectedFirstValue });
script.addMessageListener("gotMenuChange", function changed({ results }) {
script.removeMessageListener("gotMenuChange", changed);
gLastAutoCompleteResults = results;
then();
});
}
var chromeURL = SimpleTest.getTestFileURL("parent_utils.js");
var script = SpecialPowers.loadChromeScript(chromeURL);
script.addMessageListener("onpopupshown", ({ results }) => {
gLastAutoCompleteResults = results;
if (gPopupShownListener)
gPopupShownListener();
});
SimpleTest.registerCleanupFunction(() => {
script.sendAsyncMessage("cleanup");
script.destroy();
});

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

@ -29,8 +29,7 @@ Form History test: form field autocomplete
<script class="testbody" type="text/javascript">
/** Test for Form History autocomplete **/
var autocompletePopup = getAutocompletePopup();
var autocompletePopup = NonE10SgetAutocompletePopup();
autocompletePopup.style.direction = "ltr";
var input = $_(1, "field1");

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

@ -58,7 +58,7 @@ Form History Layout test: form field autocomplete: Bug 787624
/** Test for Form History autocomplete Layout: Bug 787624 **/
var autocompletePopup = getAutocompletePopup();
var autocompletePopup = NonE10SgetAutocompletePopup();
autocompletePopup.style.direction = "ltr";
var input = $_(1, "field1");

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

@ -176,8 +176,6 @@ function setForm(value) {
input.focus();
}
var autocompleteMenu = getAutocompletePopup();
// Restore the form to the default state.
function restoreForm() {
setForm("");
@ -210,7 +208,7 @@ function popupShownListener()
}
}
SpecialPowers.addAutoCompletePopupEventListener(window, "popupshown", popupShownListener);
registerPopupShownListener(popupShownListener);
/*
* Main section of test...
@ -980,7 +978,6 @@ function runTest() {
default:
ok(false, "Unexpected invocation of test #" + testNum);
SpecialPowers.removeAutoCompletePopupEventListener(window, "popupshown", popupShownListener);
SimpleTest.finish();
return;
}
@ -1005,16 +1002,7 @@ function waitForScroll()
function waitForMenuChange(expectedCount, expectedFirstValue)
{
if (autocompleteMenu.tree.view.rowCount != expectedCount) {
SimpleTest.executeSoon(function () waitForMenuChange(expectedCount, expectedFirstValue));
}
else if (expectedFirstValue && autocompleteMenu.tree.view.rowCount > 1 &&
autocompleteMenu.tree.view.getValueAt(0, autocompleteMenu.tree.columns[0]) != expectedFirstValue) {
SimpleTest.executeSoon(function () waitForMenuChange(expectedCount, expectedFirstValue));
}
else {
runTest();
}
notifyMenuChanged(expectedCount, expectedFirstValue, runTest);
}
function checkMenuEntries(expectedValues, testNum) {
@ -1024,19 +1012,6 @@ function checkMenuEntries(expectedValues, testNum) {
is(actualValues[i], expectedValues[i], testNum + " Checking menu entry #"+i);
}
function getMenuEntries() {
var entries = [];
// Could perhaps pull values directly from the controller, but it seems
// more reliable to test the values that are actually in the tree?
var column = autocompleteMenu.tree.columns[0];
var numRows = autocompleteMenu.tree.view.rowCount;
for (var i = 0; i < numRows; i++) {
entries.push(autocompleteMenu.tree.view.getValueAt(i, column));
}
return entries;
}
function startTest() {
setupFormHistory(function() {
runTest();

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

@ -60,8 +60,6 @@ function setForm(value) {
input.focus();
}
var autocompleteMenu = getAutocompletePopup();
// Restore the form to the default state.
function restoreForm() {
setForm("");
@ -77,14 +75,12 @@ var testNum = 0;
var prevValue;
var expectingPopup = false;
function expectPopup()
{
function expectPopup() {
info("expecting popup for test " + testNum);
expectingPopup = true;
}
function popupShownListener()
{
function popupShownListener() {
info("popup shown for test " + testNum);
if (expectingPopup) {
expectingPopup = false;
@ -95,7 +91,7 @@ function popupShownListener()
}
}
SpecialPowers.addAutoCompletePopupEventListener(window, "popupshown", popupShownListener);
registerPopupShownListener(popupShownListener);
/*
* Main section of test...
@ -445,7 +441,6 @@ function runTest() {
ok(event.bubbles, "input event should bubble");
ok(event.cancelable, "input event should be cancelable");
checkForm("Google");
SpecialPowers.removeAutoCompletePopupEventListener(window, "popupshown", popupShownListener);
SimpleTest.finish();
}, false);
@ -456,20 +451,13 @@ function runTest() {
default:
ok(false, "Unexpected invocation of test #" + testNum);
SpecialPowers.removeAutoCompletePopupEventListener(window, "popupshown", popupShownListener);
SimpleTest.finish();
return;
}
}
function waitForMenuChange(expectedCount)
{
if (autocompleteMenu.tree.view.rowCount != expectedCount) {
SimpleTest.executeSoon(function () waitForMenuChange(expectedCount));
}
else {
runTest();
}
function waitForMenuChange(expectedCount) {
notifyMenuChanged(expectedCount, null, runTest);
}
function checkMenuEntries(expectedValues, testNum) {
@ -479,19 +467,6 @@ function checkMenuEntries(expectedValues, testNum) {
is(actualValues[i], expectedValues[i], testNum + " Checking menu entry #"+i);
}
function getMenuEntries() {
var entries = [];
// Could perhaps pull values directly from the controller, but it seems
// more reliable to test the values that are actually in the tree?
var column = autocompleteMenu.tree.columns[0];
var numRows = autocompleteMenu.tree.view.rowCount;
for (var i = 0; i < numRows; i++) {
entries.push(autocompleteMenu.tree.view.getValueAt(i, column));
}
return entries;
}
function startTest() {
setupFormHistory(runTest);
}

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

@ -471,7 +471,7 @@ function submitForm(formNum)
// End the test now on SeaMonkey.
if (formNum == 21 && navigator.userAgent.match(/ SeaMonkey\//)) {
Services.obs.removeObserver(checkObserver, "satchel-storage-changed");
checkObserver.uninit();
is(numSubmittedForms, 21, "Ensuring all forms were submitted.");
todo(false, "Skipping remaining checks on SeaMonkey ftb. (Bug 589471)");
@ -493,7 +493,7 @@ function submitForm(formNum)
// End the test at the last form.
if (formNum == 110) {
is(numSubmittedForms, 35, "Ensuring all forms were submitted.");
Services.obs.removeObserver(checkObserver, "satchel-storage-changed");
checkObserver.uninit();
SimpleTest.finish();
return false; // return false to cancel current form submission
}
@ -526,7 +526,7 @@ function submitForm(formNum)
return false; // cancel current form submission
}
Services.obs.addObserver(checkObserver, "satchel-storage-changed", false);
checkObserver.init();
window.onload = checkInitialState;

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

@ -32,9 +32,7 @@ function setupFormHistory(aCallback) {
], aCallback);
}
var autocompleteMenu = getAutocompletePopup();
SpecialPowers.addAutoCompletePopupEventListener(window, "popupshown", popupShownListener);
registerPopupShownListener(popupShownListener);
function handleEnter(evt) {
if (evt.keyCode != KeyEvent.DOM_VK_RETURN) {