Bug 1213975 - add WebExtension tabs.onUpdated test case. r=billm

This commit is contained in:
Luca Greco 2015-10-26 04:54:00 +01:00
Родитель 8a4dea3875
Коммит a9764f9ff5
6 изменённых файлов: 132 добавлений и 18 удалений

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

@ -3,6 +3,8 @@ support-files =
head.js
context.html
ctxmenu-image.png
context_tabs_onUpdated_page.html
context_tabs_onUpdated_iframe.html
[browser_ext_simple.js]
[browser_ext_currentWindow.js]
@ -16,6 +18,7 @@ support-files =
[browser_ext_tabs_executeScript.js]
[browser_ext_tabs_query.js]
[browser_ext_tabs_update.js]
[browser_ext_tabs_onUpdated.js]
[browser_ext_tabs_sendMessage.js]
[browser_ext_windows_update.js]
[browser_ext_contentscript_connect.js]

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

@ -1,21 +1,3 @@
function* focusWindow(win)
{
let fm = Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager);
if (fm.activeWindow == win) {
return;
}
let promise = new Promise(resolve => {
win.addEventListener("focus", function listener() {
win.removeEventListener("focus", listener, true);
resolve();
}, true);
});
win.focus();
yield promise;
}
function genericChecker()
{
var kind = "background";

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

@ -0,0 +1,78 @@
add_task(function* () {
let win1 = yield BrowserTestUtils.openNewBrowserWindow();
yield focusWindow(win1);
let extension = ExtensionTestUtils.loadExtension({
manifest: {
"permissions": ["tabs"],
"content_scripts": [{
"matches": ["http://mochi.test/*/context_tabs_onUpdated_page.html"],
"js": ["content-script.js"],
"run_at": "document_start"
},],
},
background: function() {
var pageURL = "http://mochi.test:8888/browser/browser/components/extensions/test/browser/context_tabs_onUpdated_page.html";
var expectedSequence = [
{ status: "loading" },
{ status: "loading", url: pageURL },
{ status: "complete" }
];
var collectedSequence = [];
browser.tabs.onUpdated.addListener(function (tabId, updatedInfo) {
collectedSequence.push(updatedInfo);
});
browser.runtime.onMessage.addListener(function () {
if (collectedSequence.length !== expectedSequence.length) {
browser.test.assertEq(
JSON.stringify(expectedSequence),
JSON.stringify(collectedSequence),
"got unexpected number of updateInfo data"
);
} else {
for (var i = 0; i < expectedSequence.length; i++) {
browser.test.assertEq(
expectedSequence[i].status,
collectedSequence[i].status,
"check updatedInfo status"
);
if (expectedSequence[i].url || collectedSequence[i].url) {
browser.test.assertEq(
expectedSequence[i].url,
collectedSequence[i].url,
"check updatedInfo url"
);
}
}
}
browser.test.notifyPass("tabs.onUpdated");
});
browser.tabs.create({ url: pageURL });
},
files: {
"content-script.js": `
window.addEventListener("message", function(evt) {
if (evt.data == "frame-updated") {
browser.runtime.sendMessage("load-completed");
}
}, true);
`,
}
});
yield Promise.all([
extension.startup(),
extension.awaitFinish("tabs.onUpdated")
]);
yield extension.unload();
yield BrowserTestUtils.closeWindow(win1);
});

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

@ -0,0 +1,17 @@
<html>
<body>
<h3>test iframe</h3>
<script>
window.onload = function() {
window.onhashchange = function() {
window.parent.postMessage("updated-iframe-url", "*");
}
// NOTE: without the this setTimeout the location change is not fired
// even without the "fire only for top level windows" fix
setTimeout(function() {
window.location.hash="updated-iframe-url";
}, 0);
}
</script>
</body>
</html>

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

@ -0,0 +1,16 @@
<html>
<body>
<h3>test page</h3>
<iframe src="about:blank"></iframe>
<script>
window.onmessage = function(evt) {
if (evt.data === "updated-iframe-url") {
window.postMessage("frame-updated", "*");
}
};
window.onload = function() {
document.querySelector('iframe').setAttribute("src", "context_tabs_onUpdated_iframe.html");
};
</script>
</body>
</html>

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

@ -5,3 +5,21 @@ function makeWidgetId(id)
id = id.toLowerCase();
return id.replace(/[^a-z0-9_-]/g, "_");
}
function* focusWindow(win)
{
let fm = Cc["@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager);
if (fm.activeWindow == win) {
return;
}
let promise = new Promise(resolve => {
win.addEventListener("focus", function listener() {
win.removeEventListener("focus", listener, true);
resolve();
}, true);
});
win.focus();
yield promise;
}