widget/tests/test_taskbar_progress.xul

Thu, 15 Jan 2015 15:59:08 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 15:59:08 +0100
branch
TOR_BUG_9701
changeset 10
ac0c01689b40
permissions
-rw-r--r--

Implement a real Private Browsing Mode condition by changing the API/ABI;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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"
michael@0 4 type="text/css"?>
michael@0 5 <window title="Taskbar Previews Test"
michael@0 6 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
michael@0 7 onload="loaded();">
michael@0 8
michael@0 9 <script type="application/javascript"
michael@0 10 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
michael@0 11 <script class="testbody" type="application/javascript">
michael@0 12 <![CDATA[
michael@0 13 let Cc = Components.classes;
michael@0 14 let Ci = Components.interfaces;
michael@0 15 let Cu = Components.utils;
michael@0 16 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
michael@0 17
michael@0 18 let TP = Ci.nsITaskbarProgress;
michael@0 19
michael@0 20 function winProgress() {
michael@0 21 let taskbar = Cc["@mozilla.org/windows-taskbar;1"];
michael@0 22 if (!taskbar)
michael@0 23 return null;
michael@0 24 taskbar = taskbar.getService(Ci.nsIWinTaskbar);
michael@0 25 if (!taskbar.available)
michael@0 26 return null;
michael@0 27
michael@0 28 // HACK from mconnor:
michael@0 29 var wm = Cc["@mozilla.org/appshell/window-mediator;1"].getService(Ci.nsIWindowMediator);
michael@0 30 let win = wm.getMostRecentWindow("navigator:browser");
michael@0 31 let docShell = win.gBrowser.docShell;
michael@0 32
michael@0 33 let progress = taskbar.getTaskbarProgress(docShell);
michael@0 34 isnot(progress, null, "Progress is not null");
michael@0 35
michael@0 36 try {
michael@0 37 taskbar.getTaskbarProgress(null);
michael@0 38 ok(false, "Got progress for null docshell");
michael@0 39 } catch (e) {
michael@0 40 ok(true, "Cannot get progress for null docshell");
michael@0 41 }
michael@0 42
michael@0 43 return progress;
michael@0 44 }
michael@0 45
michael@0 46 function macProgress() {
michael@0 47 let progress = Cc["@mozilla.org/widget/macdocksupport;1"];
michael@0 48 if (!progress)
michael@0 49 return null;
michael@0 50 return progress.getService(TP);
michael@0 51 }
michael@0 52
michael@0 53 SimpleTest.waitForExplicitFinish();
michael@0 54
michael@0 55 function loaded()
michael@0 56 {
michael@0 57 let progress = winProgress() || macProgress();
michael@0 58 if (!TP)
michael@0 59 SimpleTest.finish();
michael@0 60
michael@0 61 function shouldThrow(s,c,m) {
michael@0 62 try {
michael@0 63 progress.setProgressState(s,c,m);
michael@0 64 return false;
michael@0 65 } catch (e) {
michael@0 66 return true;
michael@0 67 }
michael@0 68 }
michael@0 69
michael@0 70 function doesntThrow(s,c,m) !shouldThrow(s,c,m)
michael@0 71
michael@0 72 ok(doesntThrow(TP.STATE_NO_PROGRESS, 0, 0), "No progress state can be set");
michael@0 73 ok(doesntThrow(TP.STATE_INDETERMINATE, 0, 0), "Indeterminate state can be set");
michael@0 74 ok(doesntThrow(TP.STATE_NORMAL, 0, 0), "Normal state can be set");
michael@0 75 ok(doesntThrow(TP.STATE_ERROR, 0, 0), "Error state can be set");
michael@0 76 ok(doesntThrow(TP.STATE_PAUSED, 0, 0), "Paused state can be set");
michael@0 77
michael@0 78 ok(shouldThrow(TP.STATE_NO_PROGRESS, 1, 1), "Cannot set no progress with values");
michael@0 79 ok(shouldThrow(TP.STATE_INDETERMINATE, 1, 1), "Cannot set indeterminate with values");
michael@0 80
michael@0 81 // Technically passes since unsigned(-1) > 10
michael@0 82 ok(shouldThrow(TP.STATE_NORMAL, -1, 10), "Cannot set negative progress");
michael@0 83 todo(shouldThrow(TP.STATE_NORMAL, 1, -1), "Cannot set negative progress");
michael@0 84 todo(shouldThrow(TP.STATE_NORMAL, -1, -1), "Cannot set negative progress");
michael@0 85 todo(shouldThrow(TP.STATE_NORMAL, -2, -1), "Cannot set negative progress");
michael@0 86
michael@0 87 ok(shouldThrow(TP.STATE_NORMAL, 5, 3), "Cannot set progress greater than max");
michael@0 88
michael@0 89 ok(doesntThrow(TP.STATE_NORMAL, 1, 5), "Normal state can be set with values");
michael@0 90 ok(doesntThrow(TP.STATE_ERROR, 3, 6), "Error state can be set with values");
michael@0 91 ok(doesntThrow(TP.STATE_PAUSED, 2, 9), "Paused state can be set with values");
michael@0 92
michael@0 93 SimpleTest.finish();
michael@0 94 }
michael@0 95 ]]>
michael@0 96 </script>
michael@0 97
michael@0 98 <body xmlns="http://www.w3.org/1999/xhtml">
michael@0 99 <p id="display"></p>
michael@0 100 <div id="content" style="display: none"></div>
michael@0 101 <pre id="test"></pre>
michael@0 102 </body>
michael@0 103
michael@0 104 </window>

mercurial