gecko/browser/base/content/test/browser_page_style_menu.js

68 lines
2.2 KiB
JavaScript
Raw Normal View History

2008-08-08 03:45:13 -07:00
function test() {
waitForExplicitFinish();
var tab = gBrowser.addTab();
gBrowser.selectedTab = tab;
tab.linkedBrowser.addEventListener("load", function () {
tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
checkPageStyleMenu();
}, true);
let rootDir = getRootDirectory(gTestPath);
content.location = rootDir + "page_style_sample.html";
2008-08-08 03:45:13 -07:00
}
function checkPageStyleMenu() {
var menupopup = document.getElementById("pageStyleMenu")
.getElementsByTagName("menupopup")[0];
gPageStyleMenu.fillPopup(menupopup);
2008-08-08 03:45:13 -07:00
var items = [];
var current = menupopup.getElementsByTagName("menuseparator")[0];
while (current.nextSibling) {
current = current.nextSibling;
items.push(current);
}
var validLinks = 0;
Array.forEach(content.document.getElementsByTagName("link"), function (link) {
var title = link.getAttribute("title");
var rel = link.getAttribute("rel");
var media = link.getAttribute("media");
var idstring = "link " + (title ? title : "without title and") +
" with rel=\"" + rel + "\"" +
(media ? " and media=\"" + media + "\"" : "");
var item = items.filter(function (item) item.getAttribute("label") == title);
2008-08-08 03:45:13 -07:00
var found = item.length == 1;
var checked = found && (item[0].getAttribute("checked") == "true");
switch (link.getAttribute("data-state")) {
case "0":
ok(!found, idstring + " does not show up in page style menu");
break;
case "0-todo":
validLinks++;
todo(!found, idstring + " should not show up in page style menu");
ok(!checked, idstring + " is not selected");
break;
case "1":
validLinks++;
ok(found, idstring + " shows up in page style menu");
ok(!checked, idstring + " is not selected");
break;
case "2":
validLinks++;
ok(found, idstring + " shows up in page style menu");
ok(checked, idstring + " is selected");
break;
default:
throw "data-state attribute is missing or has invalid value";
}
});
is(validLinks, items.length, "all valid links found");
gBrowser.removeCurrentTab();
finish();
}