Bug 1540028 [wpt PR 16099] - Catch more exceptions in Document-createElement-namespac...
[gecko.git] / widget / tests / test_taskbar_progress.xul
blobf5ec51653b1f38854804084128965c542a8e35b6
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"
4 type="text/css"?>
5 <window title="Taskbar Previews Test"
6 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
7 onload="loaded();">
9 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
10 <script class="testbody" type="application/javascript">
11 <![CDATA[
12 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
14 let TP = Ci.nsITaskbarProgress;
16 function IsWin7OrHigher() {
17 try {
18 var sysInfo = Cc["@mozilla.org/system-info;1"].
19 getService(Ci.nsIPropertyBag2);
20 var ver = parseFloat(sysInfo.getProperty("version"));
21 if (ver >= 6.1)
22 return true;
23 } catch (ex) { }
24 return false;
27 function winProgress() {
28 let taskbar = Cc["@mozilla.org/windows-taskbar;1"];
29 if (!taskbar) {
30 ok(false, "Taskbar service is always available");
31 return null;
33 taskbar = taskbar.getService(Ci.nsIWinTaskbar);
35 is(taskbar.available, IsWin7OrHigher(), "Expected availability of taskbar");
36 if (!taskbar.available)
37 return null;
39 // HACK from mconnor:
40 var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
41 let win = wm.getMostRecentWindow("navigator:browser");
42 let docShell = win.docShell;
44 let progress = taskbar.getTaskbarProgress(docShell);
45 isnot(progress, null, "Progress is not null");
47 try {
48 taskbar.getTaskbarProgress(null);
49 ok(false, "Got progress for null docshell");
50 } catch (e) {
51 ok(true, "Cannot get progress for null docshell");
54 return progress;
57 function macProgress() {
58 let progress = Cc["@mozilla.org/widget/macdocksupport;1"];
59 if (!progress) {
60 ok(false, "Should have gotten Mac progress service.");
61 return null;
63 return progress.getService(TP);
66 SimpleTest.waitForExplicitFinish();
68 function loaded()
70 let isWin = /Win/.test(navigator.platform);
71 let progress = isWin ? winProgress() : macProgress();
72 if (!TP || !progress) {
73 SimpleTest.finish();
74 return;
77 function shouldThrow(s,c,m) {
78 try {
79 progress.setProgressState(s,c,m);
80 return false;
81 } catch (e) {
82 return true;
86 function doesntThrow(s,c,m) {
87 return !shouldThrow(s,c,m);
90 ok(doesntThrow(TP.STATE_NO_PROGRESS, 0, 0), "No progress state can be set");
91 ok(doesntThrow(TP.STATE_INDETERMINATE, 0, 0), "Indeterminate state can be set");
92 ok(doesntThrow(TP.STATE_NORMAL, 0, 0), "Normal state can be set");
93 ok(doesntThrow(TP.STATE_ERROR, 0, 0), "Error state can be set");
94 ok(doesntThrow(TP.STATE_PAUSED, 0, 0), "Paused state can be set");
96 ok(shouldThrow(TP.STATE_NO_PROGRESS, 1, 1), "Cannot set no progress with values");
97 ok(shouldThrow(TP.STATE_INDETERMINATE, 1, 1), "Cannot set indeterminate with values");
99 // Technically passes since unsigned(-1) > 10
100 ok(shouldThrow(TP.STATE_NORMAL, -1, 10), "Cannot set negative progress");
101 todo(shouldThrow(TP.STATE_NORMAL, 1, -1), "Cannot set negative progress");
102 todo(shouldThrow(TP.STATE_NORMAL, -1, -1), "Cannot set negative progress");
103 todo(shouldThrow(TP.STATE_NORMAL, -2, -1), "Cannot set negative progress");
105 ok(shouldThrow(TP.STATE_NORMAL, 5, 3), "Cannot set progress greater than max");
107 ok(doesntThrow(TP.STATE_NORMAL, 1, 5), "Normal state can be set with values");
108 ok(doesntThrow(TP.STATE_ERROR, 3, 6), "Error state can be set with values");
109 ok(doesntThrow(TP.STATE_PAUSED, 2, 9), "Paused state can be set with values");
111 SimpleTest.finish();
114 </script>
116 <body xmlns="http://www.w3.org/1999/xhtml">
117 <p id="display"></p>
118 <div id="content" style="display: none"></div>
119 <pre id="test"></pre>
120 </body>
122 </window>