PageRenderTime 24ms CodeModel.GetById 18ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/toolkit/content/tests/chrome/test_menuchecks.xul

http://github.com/zpao/v8monkey
Unknown | 149 lines | 134 code | 15 blank | 0 comment | 0 complexity | 57e0fb42c9f8fa88d2d859d021494c36 MD5 | raw file
  1<?xml version="1.0"?>
  2<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
  3<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
  4
  5<window title="Menu Checkbox and Radio Tests"
  6  onload="runTest()"
  7  xmlns:html="http://www.w3.org/1999/xhtml"
  8  xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  9
 10  <title>Menu Checkbox and Radio Tests</title>
 11  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
 12  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>      
 13
 14  <hbox>
 15    <button id="menu" type="menu" label="View">
 16      <menupopup id="popup" onpopupshown="popupShown()" onpopuphidden="popupHidden()">
 17        <menuitem id="toolbar" label="Show Toolbar" type="checkbox"/>
 18        <menuitem id="statusbar" label="Show Status Bar" type="checkbox" checked="true"/>
 19        <menuitem id="bookmarks" label="Show Bookmarks" type="checkbox" autocheck="false"/>
 20        <menuitem id="history" label="Show History" type="checkbox" autocheck="false" checked="true"/>
 21        <menuseparator/>
 22        <menuitem id="byname" label="By Name" type="radio" name="sort"/>
 23        <menuitem id="bydate" label="By Date" type="radio" name="sort" checked="true"/>
 24        <menuseparator/>
 25        <menuitem id="ascending" label="Ascending" type="radio" name="order" checked="true"/>
 26        <menuitem id="descending" label="Descending" type="radio" name="order" autocheck="false"/>
 27        <menuitem id="bysubject" label="By Subject" type="radio" name="sort"/>
 28      </menupopup>
 29    </button>
 30
 31  </hbox>
 32
 33  <!--
 34  This test checks that checkbox and radio menu items work properly
 35  -->
 36  <script class="testbody" type="application/javascript">
 37  <![CDATA[
 38
 39  SimpleTest.waitForExplicitFinish();
 40  var gTestIndex = 0;
 41
 42  // tests to perform
 43  var tests = [
 44    {
 45      testname: "select unchecked checkbox",
 46      item: "toolbar",
 47      checked: ["toolbar", "statusbar", "history", "bydate", "ascending"]
 48    },
 49    {
 50      testname: "select checked checkbox",
 51      item: "statusbar",
 52      checked: ["toolbar", "history", "bydate", "ascending"]
 53    },
 54    {
 55      testname: "select unchecked autocheck checkbox",
 56      item: "bookmarks",
 57      checked: ["toolbar", "history", "bydate", "ascending"]
 58    },
 59    {
 60      testname: "select checked autocheck checkbox",
 61      item: "history",
 62      checked: ["toolbar", "history", "bydate", "ascending"]
 63    },
 64    {
 65      testname: "select unchecked radio",
 66      item: "byname",
 67      checked: ["toolbar", "history", "byname", "ascending"]
 68    },
 69    {
 70      testname: "select checked radio",
 71      item: "byname",
 72      checked: ["toolbar", "history", "byname", "ascending"]
 73    },
 74    {
 75      testname: "select out of order checked radio",
 76      item: "bysubject",
 77      checked: ["toolbar", "history", "bysubject", "ascending"]
 78    },
 79    {
 80      testname: "select first radio again",
 81      item: "byname",
 82      checked: ["toolbar", "history", "byname", "ascending"]
 83    },
 84    {
 85      testname: "select autocheck radio",
 86      item: "descending",
 87      checked: ["toolbar", "history", "byname", "ascending"]
 88    }
 89  ];
 90
 91  function runTest()
 92  {
 93    checkMenus(["statusbar", "history", "bydate", "ascending"], "initial");
 94    document.getElementById("menu").open = true;
 95  }
 96
 97  function checkMenus(checkedItems, testname)
 98  {
 99    var isok = true;
100    var children = document.getElementById("popup").childNodes;
101    for (var c = 0; c < children.length; c++) {
102      var child = children[c];
103      if ((checkedItems.indexOf(child.id) != -1 && child.getAttribute("checked") != "true") ||
104          (checkedItems.indexOf(child.id) == -1 && child.hasAttribute("checked"))) {
105        isok = false;
106        break;
107      }
108    }
109
110    ok(isok, testname);
111  }
112
113  function popupShown()
114  {
115    var test = tests[gTestIndex];
116    synthesizeMouse(document.getElementById(test.item), 4, 4, { });
117  }
118
119  function popupHidden()
120  {
121    if (gTestIndex < tests.length) {
122      var test = tests[gTestIndex];
123      checkMenus(test.checked, test.testname);
124      gTestIndex++;
125      if (gTestIndex < tests.length) {
126        document.getElementById("menu").open = true;
127      }
128      else {
129        // manually setting the checkbox should also update the radio state
130        document.getElementById("bydate").setAttribute("checked", "true");
131        checkMenus(["toolbar", "history", "bydate", "ascending"], "set checked attribute on radio");
132        SimpleTest.finish();
133      }
134    }
135  }
136
137  ]]>
138  </script>
139
140<body xmlns="http://www.w3.org/1999/xhtml">
141<p id="display">
142</p>
143<div id="content" style="display: none">
144</div>
145<pre id="test">
146</pre>
147</body>
148
149</window>