dom/plugins/test/mochitest/test_hangui.xul

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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="Basic Plugin Tests"
     6   xmlns:html="http://www.w3.org/1999/xhtml"
     7   xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
     8   <title>Plugin Hang UI Test</title>
     9   <script type="application/javascript"
    10           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
    11   <script type="application/javascript"
    12           src="utils.js" />
    13   <script type="application/javascript"
    14           src="http://mochi.test:8888/chrome/dom/plugins/test/mochitest/hang_test.js" />
    15   <script type="application/javascript"
    16           src="http://mochi.test:8888/chrome/dom/plugins/test/mochitest/hangui_common.js" />
    18 <body xmlns="http://www.w3.org/1999/xhtml">
    19   <iframe id="iframe1" src="hangui_subpage.html" width="400" height="400"></iframe>
    20 </body>
    21 <script class="testbody" type="application/javascript">
    22 <![CDATA[
    23 SimpleTest.waitForExplicitFinish();
    24 setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
    26 Components.utils.import("resource://gre/modules/Services.jsm");
    28 const hangUITimeoutPref = "dom.ipc.plugins.hangUITimeoutSecs";
    29 const hangUIMinDisplayPref = "dom.ipc.plugins.hangUIMinDisplaySecs";
    30 const timeoutPref = "dom.ipc.plugins.timeoutSecs";
    32 var worker = new ChromeWorker("hangui_iface.js");
    33 worker.onmessage = function(event) {
    34   var result = event.data;
    35   var params = result.params;
    36   var output = params.testName;
    37   if (result.msg) {
    38     output += ": " + result.msg;
    39   }
    40   ok(result.status, output);
    41   if (params.callback) {
    42     var cb = eval(params.callback);
    43     var timeout = setTimeout(function() { clearTimeout(timeout); cb(); }, 100);
    44   }
    45 };
    46 worker.onerror = function(event) {
    47   var output = "Error: " + event.message + " at " + event.filename + ":" + event.lineno;
    48   ok(false, output);
    49 };
    51 var iframe;
    52 var p;
    53 var os = Components.classes["@mozilla.org/observer-service;1"].getService(Components.interfaces.nsIObserverService);
    55 function hanguiOperation(testName, timeoutSec, expectFind, expectClose, opCode,
    56                          commandId, check, cb) {
    57   var timeoutMs = timeoutSec * 1000 + EPSILON_MS;
    58   worker.postMessage({ "timeoutMs": timeoutMs, "expectToFind": expectFind,
    59                        "expectToClose": expectClose, "opCode": opCode,
    60                        "commandId": commandId, "check": check,
    61                        "testName": testName, "callback": cb });
    62 }
    64 function hanguiExpect(testName, shouldBeShowing, shouldClose, cb) {
    65   var timeoutSec = Services.prefs.getIntPref(hangUITimeoutPref);
    66   if (!shouldBeShowing && !timeoutSec) {
    67     timeoutSec = Services.prefs.getIntPref(timeoutPref);
    68   }
    69   hanguiOperation(testName, timeoutSec, shouldBeShowing, shouldClose, HANGUIOP_NOTHING, 0, false, cb);
    70 }
    72 function hanguiContinue(testName, check, cb) {
    73   var timeoutSec = Services.prefs.getIntPref(hangUITimeoutPref);
    74   hanguiOperation(testName, timeoutSec, true, true, HANGUIOP_COMMAND, IDC_CONTINUE, check, cb);
    75 }
    77 function hanguiStop(testName, check, cb) {
    78   var timeoutSec = Services.prefs.getIntPref(hangUITimeoutPref);
    79   hanguiOperation(testName, timeoutSec, true, true, HANGUIOP_COMMAND, IDC_STOP, check, cb);
    80 }
    82 function hanguiCancel(testName, cb) {
    83   var timeoutSec = Services.prefs.getIntPref(hangUITimeoutPref);
    84   hanguiOperation(testName, timeoutSec, true, true, HANGUIOP_CANCEL, 0, false, cb);
    85 }
    87 function finishTest() {
    88   if (obsCount > 0) {
    89     os.removeObserver(testObserver, "plugin-crashed");
    90     --obsCount;
    91   }
    92   SpecialPowers.clearUserPref(hangUITimeoutPref);
    93   SpecialPowers.clearUserPref(hangUIMinDisplayPref);
    94   SpecialPowers.clearUserPref(timeoutPref);
    95   SimpleTest.finish();
    96 }
    98 function runTests() {
    99   if (!SimpleTest.testPluginIsOOP()) {
   100     ok(true, "Skipping this test when test plugin is not OOP.");
   101     SimpleTest.finish();
   102   }
   104   resetVars();
   106   hanguiOperation("Prime ChromeWorker", 0, false, false, HANGUIOP_NOTHING, 0,
   107                   false, "test1");
   108 }
   110 window.frameLoaded = runTests;
   112 var obsCount = 0;
   114 function onPluginCrashedHangUI(aEvent) {
   115   ok(true, "Plugin crashed notification received");
   116   is(aEvent.type, "PluginCrashed", "event is correct type");
   118   is(p, aEvent.target, "Plugin crashed event target is plugin element");
   120   ok(aEvent instanceof Components.interfaces.nsIDOMCustomEvent,
   121      "plugin crashed event has the right interface");
   123   var propBag = aEvent.detail.QueryInterface(Components.interfaces.nsIPropertyBag2);
   124   var pluginDumpID = propBag.getPropertyAsAString("pluginDumpID");
   125   isnot(pluginDumpID, "", "got a non-empty dump ID");
   126   var pluginName = propBag.getPropertyAsAString("pluginName");
   127   is(pluginName, "Test Plug-in", "got correct plugin name");
   128   var pluginFilename = propBag.getPropertyAsAString("pluginFilename");
   129   isnot(pluginFilename, "", "got a non-empty filename");
   130   var didReport = propBag.getPropertyAsBool("submittedCrashReport");
   131   // The app itself may or may not have decided to submit the report, so
   132   // allow either true or false here.
   133   ok((didReport == true || didReport == false), "event said crash report was submitted");
   134   os.removeObserver(testObserver, "plugin-crashed");
   135   --obsCount;
   136 }
   138 function resetVars() {
   139   iframe = document.getElementById('iframe1');
   140   p = iframe.contentDocument.getElementById("plugin1");
   141   if (obsCount == 0) {
   142     os.addObserver(testObserver, "plugin-crashed", true);
   143     ++obsCount;
   144   }
   145   iframe.contentDocument.addEventListener("PluginCrashed",
   146                                           onPluginCrashedHangUI,
   147                                           false);
   148 }
   150 function test9b() {
   151   hanguiExpect("test9b: Plugin Hang UI is not showing (checkbox)", false);
   152   p.stall(STALL_DURATION);
   153   hanguiExpect("test9b: Plugin Hang UI is still not showing (checkbox)", false, false, "finishTest");
   154   p.stall(STALL_DURATION);
   155 }
   157 function test9a() {
   158   resetVars();
   159   SpecialPowers.setIntPref(hangUITimeoutPref, 1);
   160   SpecialPowers.setIntPref(hangUIMinDisplayPref, 1);
   161   SpecialPowers.setIntPref(timeoutPref, 45);
   162   hanguiContinue("test9a: Continue button works with checkbox", true, "test9b");
   163   p.stall(STALL_DURATION);
   164 }
   166 function test9() {
   167   window.frameLoaded = test9a;
   168   iframe.contentWindow.location.reload();
   169 }
   171 function test8a() {
   172   resetVars();
   173   SpecialPowers.setIntPref(hangUITimeoutPref, 1);
   174   SpecialPowers.setIntPref(hangUIMinDisplayPref, 4);
   175   hanguiExpect("test8a: Plugin Hang UI is not showing (disabled due to hangUIMinDisplaySecs)", false, false, "test9");
   176   var exceptionThrown = false;
   177   try {
   178     p.hang();
   179   } catch(e) {
   180     exceptionThrown = true;
   181   }
   182   ok(exceptionThrown, "test8a: Exception thrown from hang() when plugin was terminated");
   183 }
   185 function test8() {
   186   window.frameLoaded = test8a;
   187   iframe.contentWindow.location.reload();
   188 }
   190 function test7a() {
   191   resetVars();
   192   SpecialPowers.setIntPref(hangUITimeoutPref, 0);
   193   hanguiExpect("test7a: Plugin Hang UI is not showing (disabled)", false, false, "test8");
   194   var exceptionThrown = false;
   195   try {
   196     p.hang();
   197   } catch(e) {
   198     exceptionThrown = true;
   199   }
   200   ok(exceptionThrown, "test7a: Exception thrown from hang() when plugin was terminated");
   201 }
   203 function test7() {
   204   window.frameLoaded = test7a;
   205   iframe.contentWindow.location.reload();
   206 }
   208 function test6() {
   209   SpecialPowers.setIntPref(hangUITimeoutPref, 1);
   210   SpecialPowers.setIntPref(hangUIMinDisplayPref, 1);
   211   SpecialPowers.setIntPref(timeoutPref, 3);
   212   hanguiExpect("test6: Plugin Hang UI is showing", true, true, "test7");
   213   var exceptionThrown = false;
   214   try {
   215     p.hang();
   216   } catch(e) {
   217     exceptionThrown = true;
   218   }
   219   ok(exceptionThrown, "test6: Exception thrown from hang() when plugin was terminated (child timeout)");
   220 }
   222 function test5a() {
   223   resetVars();
   224   hanguiCancel("test5a: Close button works", "test6");
   225   p.stall(STALL_DURATION);
   226 }
   228 function test5() {
   229   window.frameLoaded = test5a;
   230   iframe.contentWindow.location.reload();
   231 }
   233 function test4() {
   234   hanguiStop("test4: Stop button works", false, "test5");
   235   // We'll get an exception here because the plugin was terminated
   236   var exceptionThrown = false;
   237   try {
   238     p.hang();
   239   } catch(e) {
   240     exceptionThrown = true;
   241   }
   242   ok(exceptionThrown, "test4: Exception thrown from hang() when plugin was terminated");
   243 }
   245 function test3() {
   246   hanguiContinue("test3: Continue button works", false, "test4");
   247   p.stall(STALL_DURATION);
   248 }
   250 function test2() {
   251   // This test is identical to test1 because there were some bugs where the
   252   // Hang UI would show on the first hang but not on subsequent hangs
   253   hanguiExpect("test2: Plugin Hang UI is showing", true, true, "test3");
   254   p.stall(STALL_DURATION);
   255 }
   257 function test1() {
   258   SpecialPowers.setIntPref(hangUITimeoutPref, 1);
   259   SpecialPowers.setIntPref(hangUIMinDisplayPref, 1);
   260   SpecialPowers.setIntPref(timeoutPref, 45);
   261   hanguiExpect("test1: Plugin Hang UI is showing", true, true, "test2");
   262   p.stall(STALL_DURATION);
   263 }
   265 ]]>
   266 </script>
   267 </window>

mercurial