toolkit/content/tests/chrome/test_tabbox.xul

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 <?xml version="1.0"?>
michael@0 2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
michael@0 3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
michael@0 4 <!--
michael@0 5 XUL Widget Test for tabboxes
michael@0 6 -->
michael@0 7 <window title="Tabbox Test" width="500" height="600"
michael@0 8 onload="setTimeout(test_tabbox, 0);"
michael@0 9 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
michael@0 10 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
michael@0 11 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
michael@0 12 <script type="application/javascript" src="xul_selectcontrol.js"/>
michael@0 13
michael@0 14 <vbox id="tabboxes">
michael@0 15
michael@0 16 <tabbox id="tabbox">
michael@0 17 <tabs id="tabs">
michael@0 18 <tab id="tab1" label="Tab 1"/>
michael@0 19 <tab id="tab2" label="Tab 2"/>
michael@0 20 </tabs>
michael@0 21 <tabpanels id="tabpanels">
michael@0 22 <button id="panel1" label="Panel 1"/>
michael@0 23 <button id="panel2" label="Panel 2"/>
michael@0 24 </tabpanels>
michael@0 25 </tabbox>
michael@0 26
michael@0 27 <tabbox id="tabbox-initwithvalue">
michael@0 28 <tabs id="tabs-initwithvalue" value="two">
michael@0 29 <tab label="Tab 1" value="one"/>
michael@0 30 <tab label="Tab 2" value="two"/>
michael@0 31 <tab label="Tab 3" value="three"/>
michael@0 32 </tabs>
michael@0 33 <tabpanels id="tabpanels-initwithvalue">
michael@0 34 <button label="Panel 1"/>
michael@0 35 <button label="Panel 2"/>
michael@0 36 <button label="Panel 3"/>
michael@0 37 </tabpanels>
michael@0 38 </tabbox>
michael@0 39
michael@0 40 <tabbox id="tabbox-initwithselected">
michael@0 41 <tabs id="tabs-initwithselected" value="two">
michael@0 42 <tab label="Tab 1" value="one"/>
michael@0 43 <tab label="Tab 2" value="two"/>
michael@0 44 <tab label="Tab 3" value="three" selected="true"/>
michael@0 45 </tabs>
michael@0 46 <tabpanels id="tabpanels-initwithselected">
michael@0 47 <button label="Panel 1"/>
michael@0 48 <button label="Panel 2"/>
michael@0 49 <button label="Panel 3"/>
michael@0 50 </tabpanels>
michael@0 51 </tabbox>
michael@0 52
michael@0 53 </vbox>
michael@0 54
michael@0 55 <tabbox id="tabbox-nofocus">
michael@0 56 <textbox id="textbox-extra" hidden="true"/>
michael@0 57 <tabs>
michael@0 58 <tab label="Tab 1" value="one"/>
michael@0 59 <tab id="tab-nofocus" label="Tab 2" value="two"/>
michael@0 60 </tabs>
michael@0 61 <tabpanels>
michael@0 62 <tabpanel>
michael@0 63 <button id="tab-nofocus-button" label="Label"/>
michael@0 64 </tabpanel>
michael@0 65 <tabpanel id="tabpanel-nofocusinpaneltab">
michael@0 66 <label id="tablabel" value="Label"/>
michael@0 67 </tabpanel>
michael@0 68 </tabpanels>
michael@0 69 </tabbox>
michael@0 70
michael@0 71 <!-- test results are displayed in the html:body -->
michael@0 72 <body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"/>
michael@0 73
michael@0 74 <!-- test code goes here -->
michael@0 75 <script type="application/javascript"><![CDATA[
michael@0 76
michael@0 77 SimpleTest.waitForExplicitFinish();
michael@0 78
michael@0 79 function test_tabbox()
michael@0 80 {
michael@0 81 var tabbox = document.getElementById("tabbox");
michael@0 82 var tabs = document.getElementById("tabs");
michael@0 83 var tabpanels = document.getElementById("tabpanels");
michael@0 84
michael@0 85 test_tabbox_State(tabbox, "tabbox initial", 0, tabs.firstChild, tabpanels.firstChild);
michael@0 86
michael@0 87 // check the selectedIndex property
michael@0 88 tabbox.selectedIndex = 1;
michael@0 89 test_tabbox_State(tabbox, "tabbox selectedIndex 1", 1, tabs.lastChild, tabpanels.lastChild);
michael@0 90
michael@0 91 tabbox.selectedIndex = 2;
michael@0 92 test_tabbox_State(tabbox, "tabbox selectedIndex 2", 1, tabs.lastChild, tabpanels.lastChild);
michael@0 93
michael@0 94 // tabbox must have a selection, so setting to -1 should do nothing
michael@0 95 tabbox.selectedIndex = -1;
michael@0 96 test_tabbox_State(tabbox, "tabbox selectedIndex -1", 1, tabs.lastChild, tabpanels.lastChild);
michael@0 97
michael@0 98 // check the selectedTab property
michael@0 99 tabbox.selectedTab = tabs.firstChild;
michael@0 100 test_tabbox_State(tabbox, "tabbox selected", 0, tabs.firstChild, tabpanels.firstChild);
michael@0 101
michael@0 102 // setting selectedTab to null should not do anything
michael@0 103 tabbox.selectedTab = null;
michael@0 104 test_tabbox_State(tabbox, "tabbox selectedTab null", 0, tabs.firstChild, tabpanels.firstChild);
michael@0 105
michael@0 106 // check the selectedPanel property
michael@0 107 tabbox.selectedPanel = tabpanels.lastChild;
michael@0 108 test_tabbox_State(tabbox, "tabbox selectedPanel", 0, tabs.firstChild, tabpanels.lastChild);
michael@0 109
michael@0 110 // setting selectedPanel to null should not do anything
michael@0 111 tabbox.selectedPanel = null;
michael@0 112 test_tabbox_State(tabbox, "tabbox selectedPanel null", 0, tabs.firstChild, tabpanels.lastChild);
michael@0 113
michael@0 114 tabbox.selectedIndex = 0;
michael@0 115 test_tabpanels(tabpanels, tabbox);
michael@0 116
michael@0 117 tabs.removeChild(tabs.firstChild);
michael@0 118 tabs.removeChild(tabs.firstChild);
michael@0 119
michael@0 120 test_tabs(tabs);
michael@0 121
michael@0 122 test_tabbox_focus();
michael@0 123 }
michael@0 124
michael@0 125 function test_tabpanels(tabpanels, tabbox)
michael@0 126 {
michael@0 127 var tab = tabbox.selectedTab;
michael@0 128
michael@0 129 // changing the selection on the tabpanels should not affect the tabbox
michael@0 130 // or tabs within
michael@0 131 // check the selectedIndex property
michael@0 132 tabpanels.selectedIndex = 1;
michael@0 133 test_tabbox_State(tabbox, "tabpanels tabbox selectedIndex 1", 0, tab, tabpanels.lastChild);
michael@0 134 test_tabpanels_State(tabpanels, "tabpanels selectedIndex 1", 1, tabpanels.lastChild);
michael@0 135
michael@0 136 tabpanels.selectedIndex = 0;
michael@0 137 test_tabbox_State(tabbox, "tabpanels tabbox selectedIndex 2", 0, tab, tabpanels.firstChild);
michael@0 138 test_tabpanels_State(tabpanels, "tabpanels selectedIndex 2", 0, tabpanels.firstChild);
michael@0 139
michael@0 140 // setting selectedIndex to -1 should do nothing
michael@0 141 tabpanels.selectedIndex = 1;
michael@0 142 tabpanels.selectedIndex = -1;
michael@0 143 test_tabbox_State(tabbox, "tabpanels tabbox selectedIndex -1", 0, tab, tabpanels.lastChild);
michael@0 144 test_tabpanels_State(tabpanels, "tabpanels selectedIndex -1", 1, tabpanels.lastChild);
michael@0 145
michael@0 146 // check the tabpanels.selectedPanel property
michael@0 147 tabpanels.selectedPanel = tabpanels.lastChild;
michael@0 148 test_tabbox_State(tabbox, "tabpanels tabbox selectedPanel", 0, tab, tabpanels.lastChild);
michael@0 149 test_tabpanels_State(tabpanels, "tabpanels selectedPanel", 1, tabpanels.lastChild);
michael@0 150
michael@0 151 // check setting the tabpanels.selectedPanel property to null
michael@0 152 tabpanels.selectedPanel = null;
michael@0 153 test_tabbox_State(tabbox, "tabpanels selectedPanel null", 0, tab, tabpanels.lastChild);
michael@0 154 }
michael@0 155
michael@0 156 function test_tabs(tabs)
michael@0 157 {
michael@0 158 test_nsIDOMXULSelectControlElement(tabs, "tab", "tabs");
michael@0 159 // XXXndeakin would test the UI aspect of tabs, but the mouse
michael@0 160 // events on tabs are fired in a timeout causing the generic
michael@0 161 // test_nsIDOMXULSelectControlElement_UI method not to work
michael@0 162 // test_nsIDOMXULSelectControlElement_UI(tabs, null);
michael@0 163 }
michael@0 164
michael@0 165 function test_tabbox_State(tabbox, testid, index, tab, panel)
michael@0 166 {
michael@0 167 is(tabbox.selectedIndex, index, testid + " selectedIndex");
michael@0 168 is(tabbox.selectedTab, tab, testid + " selectedTab");
michael@0 169 is(tabbox.selectedPanel, panel, testid + " selectedPanel");
michael@0 170 }
michael@0 171
michael@0 172 function test_tabpanels_State(tabpanels, testid, index, panel)
michael@0 173 {
michael@0 174 is(tabpanels.selectedIndex, index, testid + " selectedIndex");
michael@0 175 is(tabpanels.selectedPanel, panel, testid + " selectedPanel");
michael@0 176 }
michael@0 177
michael@0 178 function test_tabbox_focus()
michael@0 179 {
michael@0 180 $("tabboxes").hidden = true;
michael@0 181 $(document.activeElement).blur();
michael@0 182
michael@0 183 var tabbox = $("tabbox-nofocus");
michael@0 184 var tab = $("tab-nofocus");
michael@0 185
michael@0 186 when_tab_focused(tab, function () {
michael@0 187 ok(document.activeElement, tab, "focus in tab with no focusable elements");
michael@0 188
michael@0 189 tabbox.selectedIndex = 0;
michael@0 190 $("tab-nofocus-button").focus();
michael@0 191
michael@0 192 when_tab_focused(tab, function () {
michael@0 193 ok(document.activeElement, tab, "focus in tab with no focusable elements, but with something in another tab focused");
michael@0 194
michael@0 195 var textboxExtra = $("textbox-extra");
michael@0 196 textboxExtra.addEventListener("focus", function () {
michael@0 197 textboxExtra.removeEventListener("focus", arguments.callee, true);
michael@0 198 ok(document.activeElement, textboxExtra, "focus in tab with focus currently in textbox that is sibling of tabs");
michael@0 199
michael@0 200 SimpleTest.finish();
michael@0 201 }, true);
michael@0 202
michael@0 203 tabbox.selectedIndex = 0;
michael@0 204 textboxExtra.hidden = false;
michael@0 205 synthesizeMouseAtCenter(tab, { });
michael@0 206 });
michael@0 207
michael@0 208 synthesizeMouseAtCenter(tab, { });
michael@0 209 });
michael@0 210
michael@0 211 synthesizeMouseAtCenter(tab, { });
michael@0 212 }
michael@0 213
michael@0 214 function when_tab_focused(tab, callback) {
michael@0 215 tab.addEventListener("focus", function onFocused() {
michael@0 216 tab.removeEventListener("focus", onFocused, true);
michael@0 217 SimpleTest.executeSoon(callback);
michael@0 218 }, true);
michael@0 219 }
michael@0 220
michael@0 221 ]]>
michael@0 222 </script>
michael@0 223
michael@0 224 </window>

mercurial