Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / toolkit / spatial-navigation / tests / chrome / SpatialNavUtils.js
blob755b3edda7c9bbe791b862a2e8371c4452eae02d
1 var _moveTable;
2 var _moveTableIndex = 0;
4 var _snavEnabledOld = null;
5 var _snavXULContentEnabledOld = null;
6 var _snavModOld = null ;
7 var _snavRightKeyOld = null;
8 var _snavLeftKeyOld = null;
9 var _snavDownKeyOld = null;
10 var _snavUpKeyOld = null;
12 function prepareTest(prefs) {
14 var prefService = Components.classes["@mozilla.org/preferences-service;1"]
15 .getService(Components.interfaces.nsIPrefService);
16 var snavBranch = prefService.getBranch("snav.");
18 var i;
19 for (i = 0; i < prefs.length; i++)
21 switch (prefs[i][0])
23 case "enabled":
24 try {
25 _snavEnabledOld = snavBranch.getBoolPref("enabled");
26 } catch(e) {
27 _snavEnabledOld = false;
29 break;
30 case "xulContentEnabled":
31 try {
32 _snavXULContentEnabledOld = snavBranch.getBoolPref("xulContentEnabled");
33 } catch(e) {
34 _snavXULContentEnabledOld = false;
36 break;
37 case "keyCode.modifier":
38 try {
39 _snavModOld = snavBranch.getCharPref("keyCode.modifier");
40 } catch(e) {
41 _snavModOld = "alt+shift";
43 break;
44 case "keyCode.right" :
45 try {
46 _snavRightKeyOld = snavBranch.getIntPref("keyCode.right");
47 } catch(e) {
48 _snavRightKeyOld = Components.interfaces.nsIDOMKeyEvent.DOM_VK_RIGHT;
50 break;
51 case "keyCode.left" :
52 try {
53 _snavLeftKeyOld = snavBranch.getIntPref("keyCode.left");
54 } catch(e) {
55 _snavLeftKeyOld = Components.interfaces.nsIDOMKeyEvent.DOM_VK_LEFT;
57 break;
58 case "keyCode.down" :
59 try {
60 _snavDownKeyOld = snavBranch.getIntPref("keyCode.down");
61 } catch(e) {
62 _snavDownKeyOld = Components.interfaces.nsIDOMKeyEvent.DOM_VK_DOWN;
64 break;
65 case "keyCode.up" :
66 try {
67 _snavUpKeyOld = snavBranch.getIntPref("keyCode.up");
68 } catch(e) {
69 _snavUpKeyOld = Components.interfaces.nsIDOMKeyEvent.DOM_VK_UP;
71 break;
72 } // switch
74 if (prefs[i][1] == "bool")
75 snavBranch.setBoolPref(prefs[i][0], prefs[i][2]);
76 else if (prefs[i][1] == "int")
77 snavBranch.setIntPref(prefs[i][0], prefs[i][2]);
78 else if (prefs[i][1] == "char")
79 snavBranch.setCharPref(prefs[i][0], prefs[i][2]);
80 } // for
83 // setting pref values back.
84 function completeTest() {
86 var prefService = Components.classes["@mozilla.org/preferences-service;1"]
87 .getService(Components.interfaces.nsIPrefService);
88 var snavBranch = prefService.getBranch("snav.");
90 if (_snavEnabledOld != null)
91 snavBranch.setBoolPref("enabled", _snavEnabledOld);
92 if (_snavXULContentEnabledOld != null)
93 snavBranch.setBoolPref("xulContentEnabled", _snavXULContentEnabledOld);
94 if (_snavModOld != null)
95 snavBranch.setCharPref("keyCode.modifier", _snavModOld);
96 if (_snavRightKeyOld != null)
97 snavBranch.setIntPref("keyCode.right", _snavRightKeyOld);
98 if (_snavUpKeyOld != null)
99 snavBranch.setIntPref("keyCode.up", _snavUpKeyOld);
100 if (_snavDownKeyOld != null)
101 snavBranch.setIntPref("keyCode.down", _snavDownKeyOld);
102 if (_snavLeftKeyOld != null)
103 snavBranch.setIntPref("keyCode.left", _snavLeftKeyOld);
106 function testMoves(table) {
107 // document.addEventListener("focus", _verifyAndAdvance, true);
109 _moveTable = table;
110 _moveTableIndex = 0;
111 _move();
114 function _nextMove()
116 _moveTableIndex++;
118 // When a table ends with "DONE", call finish.
119 if (_moveTable[_moveTableIndex][0] == "DONE") {
120 completeTest ();
121 SimpleTest.finish();
122 return;
125 // when a table has an empty elment, end the moves.
126 if (_moveTable[_moveTableIndex][0] == "") {
127 return;
130 _move();
133 function _move()
135 sendKey( _moveTable[_moveTableIndex][0], document.activeElement);
136 setTimeout( _verifyAndAdvance , 100);
139 function _verifyAndAdvance()
141 var direction = _moveTable[_moveTableIndex][0];
142 var expectedID = _moveTable[_moveTableIndex][1];
144 ok(document.activeElement.getAttribute("id") == expectedID,
145 "Move " + direction + " to " + expectedID + ". Found " + document.activeElement.getAttribute("id"));
147 _nextMove();