1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/widget/tests/test_taskbar_progress.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,104 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?> 1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" 1.7 + type="text/css"?> 1.8 +<window title="Taskbar Previews Test" 1.9 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 1.10 + onload="loaded();"> 1.11 + 1.12 + <script type="application/javascript" 1.13 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" /> 1.14 + <script class="testbody" type="application/javascript"> 1.15 + <![CDATA[ 1.16 + let Cc = Components.classes; 1.17 + let Ci = Components.interfaces; 1.18 + let Cu = Components.utils; 1.19 + Cu.import("resource://gre/modules/XPCOMUtils.jsm"); 1.20 + 1.21 + let TP = Ci.nsITaskbarProgress; 1.22 + 1.23 + function winProgress() { 1.24 + let taskbar = Cc["@mozilla.org/windows-taskbar;1"]; 1.25 + if (!taskbar) 1.26 + return null; 1.27 + taskbar = taskbar.getService(Ci.nsIWinTaskbar); 1.28 + if (!taskbar.available) 1.29 + return null; 1.30 + 1.31 + // HACK from mconnor: 1.32 + var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator); 1.33 + let win = wm.getMostRecentWindow("navigator:browser"); 1.34 + let docShell = win.gBrowser.docShell; 1.35 + 1.36 + let progress = taskbar.getTaskbarProgress(docShell); 1.37 + isnot(progress, null, "Progress is not null"); 1.38 + 1.39 + try { 1.40 + taskbar.getTaskbarProgress(null); 1.41 + ok(false, "Got progress for null docshell"); 1.42 + } catch (e) { 1.43 + ok(true, "Cannot get progress for null docshell"); 1.44 + } 1.45 + 1.46 + return progress; 1.47 + } 1.48 + 1.49 + function macProgress() { 1.50 + let progress = Cc["@mozilla.org/widget/macdocksupport;1"]; 1.51 + if (!progress) 1.52 + return null; 1.53 + return progress.getService(TP); 1.54 + } 1.55 + 1.56 + SimpleTest.waitForExplicitFinish(); 1.57 + 1.58 + function loaded() 1.59 + { 1.60 + let progress = winProgress() || macProgress(); 1.61 + if (!TP) 1.62 + SimpleTest.finish(); 1.63 + 1.64 + function shouldThrow(s,c,m) { 1.65 + try { 1.66 + progress.setProgressState(s,c,m); 1.67 + return false; 1.68 + } catch (e) { 1.69 + return true; 1.70 + } 1.71 + } 1.72 + 1.73 + function doesntThrow(s,c,m) !shouldThrow(s,c,m) 1.74 + 1.75 + ok(doesntThrow(TP.STATE_NO_PROGRESS, 0, 0), "No progress state can be set"); 1.76 + ok(doesntThrow(TP.STATE_INDETERMINATE, 0, 0), "Indeterminate state can be set"); 1.77 + ok(doesntThrow(TP.STATE_NORMAL, 0, 0), "Normal state can be set"); 1.78 + ok(doesntThrow(TP.STATE_ERROR, 0, 0), "Error state can be set"); 1.79 + ok(doesntThrow(TP.STATE_PAUSED, 0, 0), "Paused state can be set"); 1.80 + 1.81 + ok(shouldThrow(TP.STATE_NO_PROGRESS, 1, 1), "Cannot set no progress with values"); 1.82 + ok(shouldThrow(TP.STATE_INDETERMINATE, 1, 1), "Cannot set indeterminate with values"); 1.83 + 1.84 + // Technically passes since unsigned(-1) > 10 1.85 + ok(shouldThrow(TP.STATE_NORMAL, -1, 10), "Cannot set negative progress"); 1.86 + todo(shouldThrow(TP.STATE_NORMAL, 1, -1), "Cannot set negative progress"); 1.87 + todo(shouldThrow(TP.STATE_NORMAL, -1, -1), "Cannot set negative progress"); 1.88 + todo(shouldThrow(TP.STATE_NORMAL, -2, -1), "Cannot set negative progress"); 1.89 + 1.90 + ok(shouldThrow(TP.STATE_NORMAL, 5, 3), "Cannot set progress greater than max"); 1.91 + 1.92 + ok(doesntThrow(TP.STATE_NORMAL, 1, 5), "Normal state can be set with values"); 1.93 + ok(doesntThrow(TP.STATE_ERROR, 3, 6), "Error state can be set with values"); 1.94 + ok(doesntThrow(TP.STATE_PAUSED, 2, 9), "Paused state can be set with values"); 1.95 + 1.96 + SimpleTest.finish(); 1.97 + } 1.98 + ]]> 1.99 + </script> 1.100 + 1.101 + <body xmlns="http://www.w3.org/1999/xhtml"> 1.102 + <p id="display"></p> 1.103 + <div id="content" style="display: none"></div> 1.104 + <pre id="test"></pre> 1.105 + </body> 1.106 + 1.107 +</window>