widget/tests/test_taskbar_progress.xul

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

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

mercurial