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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/base/content/test/general/browser_page_style_menu.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,67 @@
     1.4 +function test() {
     1.5 +  waitForExplicitFinish();
     1.6 +
     1.7 +  var tab = gBrowser.addTab();
     1.8 +  gBrowser.selectedTab = tab;
     1.9 +  tab.linkedBrowser.addEventListener("load", function () {
    1.10 +    tab.linkedBrowser.removeEventListener("load", arguments.callee, true);
    1.11 +    checkPageStyleMenu();
    1.12 +  }, true);
    1.13 +  let rootDir = getRootDirectory(gTestPath);
    1.14 +  content.location = rootDir + "page_style_sample.html";
    1.15 +}
    1.16 +
    1.17 +function checkPageStyleMenu() {
    1.18 +  var menupopup = document.getElementById("pageStyleMenu")
    1.19 +                          .getElementsByTagName("menupopup")[0];
    1.20 +  gPageStyleMenu.fillPopup(menupopup);
    1.21 +
    1.22 +  var items = [];
    1.23 +  var current = menupopup.getElementsByTagName("menuseparator")[0];
    1.24 +  while (current.nextSibling) {
    1.25 +    current = current.nextSibling;
    1.26 +    items.push(current);
    1.27 +  }
    1.28 +
    1.29 +  var validLinks = 0;
    1.30 +  Array.forEach(content.document.getElementsByTagName("link"), function (link) {
    1.31 +    var title = link.getAttribute("title");
    1.32 +    var rel = link.getAttribute("rel");
    1.33 +    var media = link.getAttribute("media");
    1.34 +    var idstring = "link " + (title ? title : "without title and") +
    1.35 +                   " with rel=\"" + rel + "\"" +
    1.36 +                   (media ? " and media=\"" + media + "\"" : "");
    1.37 +
    1.38 +    var item = items.filter(function (item) item.getAttribute("label") == title);
    1.39 +    var found = item.length == 1;
    1.40 +    var checked = found && (item[0].getAttribute("checked") == "true");
    1.41 +
    1.42 +    switch (link.getAttribute("data-state")) {
    1.43 +      case "0":
    1.44 +        ok(!found, idstring + " does not show up in page style menu");
    1.45 +        break;
    1.46 +      case "0-todo":
    1.47 +        validLinks++;
    1.48 +        todo(!found, idstring + " should not show up in page style menu");
    1.49 +        ok(!checked, idstring + " is not selected");
    1.50 +        break;
    1.51 +      case "1":
    1.52 +        validLinks++;
    1.53 +        ok(found, idstring + " shows up in page style menu");
    1.54 +        ok(!checked, idstring + " is not selected");
    1.55 +        break;
    1.56 +      case "2":
    1.57 +        validLinks++;
    1.58 +        ok(found, idstring + " shows up in page style menu");
    1.59 +        ok(checked, idstring + " is selected");
    1.60 +        break;
    1.61 +      default:
    1.62 +        throw "data-state attribute is missing or has invalid value";
    1.63 +    }
    1.64 +  });
    1.65 +
    1.66 +  is(validLinks, items.length, "all valid links found");
    1.67 +
    1.68 +  gBrowser.removeCurrentTab();
    1.69 +  finish();
    1.70 +}

mercurial