Bug 1861709 replace AudioCallbackDriver::ThreadRunning() assertions that mean to...
[gecko.git] / widget / tests / test_taskbar_progress.xhtml
blobf2494a27bbafa20255c73b4eb0b700458924a892
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 let TP = Ci.nsITaskbarProgress;
14 function IsWin7OrHigher() {
15 try {
16 var ver = parseFloat(Services.sysinfo.getProperty("version"));
17 if (ver >= 6.1)
18 return true;
19 } catch (ex) { }
20 return false;
23 function winProgress() {
24 let taskbar = Cc["@mozilla.org/windows-taskbar;1"];
25 if (!taskbar) {
26 ok(false, "Taskbar service is always available");
27 return null;
29 taskbar = taskbar.getService(Ci.nsIWinTaskbar);
31 is(taskbar.available, IsWin7OrHigher(), "Expected availability of taskbar");
32 if (!taskbar.available)
33 return null;
35 // HACK from mconnor:
36 let win = Services.wm.getMostRecentWindow("navigator:browser");
37 let docShell = win.docShell;
39 let progress = taskbar.getTaskbarProgress(docShell);
40 isnot(progress, null, "Progress is not null");
42 try {
43 taskbar.getTaskbarProgress(null);
44 ok(false, "Got progress for null docshell");
45 } catch (e) {
46 ok(true, "Cannot get progress for null docshell");
49 return progress;
52 function macProgress() {
53 let progress = Cc["@mozilla.org/widget/macdocksupport;1"];
54 if (!progress) {
55 ok(false, "Should have gotten Mac progress service.");
56 return null;
58 return progress.getService(TP);
61 SimpleTest.waitForExplicitFinish();
63 function loaded()
65 let isWin = /Win/.test(navigator.platform);
66 let progress = isWin ? winProgress() : macProgress();
67 if (!TP || !progress) {
68 SimpleTest.finish();
69 return;
72 function shouldThrow(s,c,m) {
73 try {
74 progress.setProgressState(s,c,m);
75 return false;
76 } catch (e) {
77 return true;
81 function doesntThrow(s,c,m) {
82 return !shouldThrow(s,c,m);
85 ok(doesntThrow(TP.STATE_NO_PROGRESS, 0, 0), "No progress state can be set");
86 ok(doesntThrow(TP.STATE_INDETERMINATE, 0, 0), "Indeterminate state can be set");
87 ok(doesntThrow(TP.STATE_NORMAL, 0, 0), "Normal state can be set");
88 ok(doesntThrow(TP.STATE_ERROR, 0, 0), "Error state can be set");
89 ok(doesntThrow(TP.STATE_PAUSED, 0, 0), "Paused state can be set");
91 ok(shouldThrow(TP.STATE_NO_PROGRESS, 1, 1), "Cannot set no progress with values");
92 ok(shouldThrow(TP.STATE_INDETERMINATE, 1, 1), "Cannot set indeterminate with values");
94 // Technically passes since unsigned(-1) > 10
95 ok(shouldThrow(TP.STATE_NORMAL, -1, 10), "Cannot set negative progress");
96 todo(shouldThrow(TP.STATE_NORMAL, 1, -1), "Cannot set negative progress");
97 todo(shouldThrow(TP.STATE_NORMAL, -1, -1), "Cannot set negative progress");
98 todo(shouldThrow(TP.STATE_NORMAL, -2, -1), "Cannot set negative progress");
100 ok(shouldThrow(TP.STATE_NORMAL, 5, 3), "Cannot set progress greater than max");
102 ok(doesntThrow(TP.STATE_NORMAL, 1, 5), "Normal state can be set with values");
103 ok(doesntThrow(TP.STATE_ERROR, 3, 6), "Error state can be set with values");
104 ok(doesntThrow(TP.STATE_PAUSED, 2, 9), "Paused state can be set with values");
106 SimpleTest.finish();
109 </script>
111 <body xmlns="http://www.w3.org/1999/xhtml">
112 <p id="display"></p>
113 <div id="content" style="display: none"></div>
114 <pre id="test"></pre>
115 </body>
117 </window>