Bug 1006234 - Fix some timeout problems with test_hangui. r=bsmedberg
authorAaron Klotz <aklotz@mozilla.com>
Wed, 27 Aug 2014 12:03:00 -0400
changeset 202067 3609f063724302d964856178d9086c091750a26f
parent 202000 f1dcee21269703bb8322b0cb91a0d6d0b50a2764
child 202068 cd0b358f86fc536aea6143e7565306a9a479c232
push id27390
push usercbook@mozilla.com
push dateThu, 28 Aug 2014 11:07:34 +0000
treeherdermozilla-central@2a15dc07ddaa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs1006234
milestone34.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1006234 - Fix some timeout problems with test_hangui. r=bsmedberg
dom/plugins/test/mochitest/dialog_watcher.js
dom/plugins/test/mochitest/test_hangui.xul
--- a/dom/plugins/test/mochitest/dialog_watcher.js
+++ b/dom/plugins/test/mochitest/dialog_watcher.js
@@ -92,22 +92,32 @@ DialogWatcher.prototype.init = function(
   if (!this.getWindowTextW) {
     this.getWindowTextW = user32.declare("GetWindowTextW",
                                          ctypes.winapi_abi,
                                          ctypes.int,
                                          ctypes.uintptr_t,
                                          ctypes.jschar.ptr,
                                          ctypes.int);
   }
+  if (!this.messageBox) {
+    // Handy for debugging this code
+    this.messageBox = user32.declare("MessageBoxW",
+                                     ctypes.winapi_abi,
+                                     ctypes.int,
+                                     ctypes.uintptr_t,
+                                     ctypes.jschar.ptr,
+                                     ctypes.jschar.ptr,
+                                     ctypes.uint32_t);
+  }
 };
 
 DialogWatcher.prototype.getWindowText = function(hwnd) {
   var bufType = ctypes.ArrayType(ctypes.jschar);
   var buffer = new bufType(256);
-  
+
   if (this.getWindowTextW(hwnd, buffer, buffer.length)) {
     return buffer.readString();
   }
 };
 
 DialogWatcher.prototype.processWindowEvents = function(timeout) {
   var onWinEvent = function(self, hook, event, hwnd, idObject, idChild, dwEventThread, dwmsEventTime) {
     var nhwnd = Number(hwnd)
@@ -149,23 +159,25 @@ DialogWatcher.prototype.processWindowEve
   }
 
   if (!timeout) {
     timeout = INFINITE;
   }
 
   var waitStatus = WAIT_OBJECT_0;
   var expectingStart = this.onDialogStart && this.hwnd === undefined;
+  var startWaitTime = Date.now();
   while (this.hwnd === undefined || this.onDialogEnd && this.hwnd) {
     waitStatus = this.msgWaitForMultipleObjects(0, null, 0, expectingStart ?
                                                             INFINITE : timeout, 0);
     if (waitStatus == WAIT_OBJECT_0) {
       var msg = new this.msgType;
       this.peekMessage(msg.address(), 0, 0, 0, PM_NOREMOVE);
-    } else if (waitStatus == WAIT_TIMEOUT) {
+    }
+    if (waitStatus == WAIT_TIMEOUT || (Date.now() - startWaitTime) >= timeout) {
       break;
     }
   }
 
   this.unhookWinEvent(hook);
   // Returns true if the hook was successful, something was found, and we never timed out
   return this.hwnd !== undefined && waitStatus == WAIT_OBJECT_0;
 };
--- a/dom/plugins/test/mochitest/test_hangui.xul
+++ b/dom/plugins/test/mochitest/test_hangui.xul
@@ -4,26 +4,29 @@
                  type="text/css"?>
 <window title="Basic Plugin Tests"
   xmlns:html="http://www.w3.org/1999/xhtml"
   xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
   <title>Plugin Hang UI Test</title>
   <script type="application/javascript"
           src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
   <script type="application/javascript"
+          src="utils.js" />
+  <script type="application/javascript"
           src="http://mochi.test:8888/chrome/dom/plugins/test/mochitest/hang_test.js" />
   <script type="application/javascript"
           src="http://mochi.test:8888/chrome/dom/plugins/test/mochitest/hangui_common.js" />
 
 <body xmlns="http://www.w3.org/1999/xhtml">
   <iframe id="iframe1" src="hangui_subpage.html" width="400" height="400"></iframe>
 </body>
 <script class="testbody" type="application/javascript">
 <![CDATA[
 SimpleTest.waitForExplicitFinish();
+setTestPluginEnabledState(SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED);
 
 Components.utils.import("resource://gre/modules/Services.jsm");
 
 const hangUITimeoutPref = "dom.ipc.plugins.hangUITimeoutSecs";
 const hangUIMinDisplayPref = "dom.ipc.plugins.hangUIMinDisplaySecs";
 const timeoutPref = "dom.ipc.plugins.timeoutSecs";
 
 var worker = new ChromeWorker("hangui_iface.js");
@@ -95,17 +98,18 @@ function finishTest() {
 function runTests() {
   if (!SimpleTest.testPluginIsOOP()) {
     ok(true, "Skipping this test when test plugin is not OOP.");
     SimpleTest.finish();
   }
 
   resetVars();
 
-  hanguiExpect("Prime ChromeWorker", false, false, "test1");
+  hanguiOperation("Prime ChromeWorker", 0, false, false, HANGUIOP_NOTHING, 0,
+                  false, "test1");
 }
 
 window.frameLoaded = runTests;
 
 var obsCount = 0;
 
 function onPluginCrashedHangUI(aEvent) {
   ok(true, "Plugin crashed notification received");
@@ -239,17 +243,17 @@ function test4() {
 }
 
 function test3() {
   hanguiContinue("test3: Continue button works", false, "test4");
   p.stall(STALL_DURATION);
 }
 
 function test2() {
-  // This test is identical to test1 because there were some bugs where the 
+  // This test is identical to test1 because there were some bugs where the
   // Hang UI would show on the first hang but not on subsequent hangs
   hanguiExpect("test2: Plugin Hang UI is showing", true, true, "test3");
   p.stall(STALL_DURATION);
 }
 
 function test1() {
   SpecialPowers.setIntPref(hangUITimeoutPref, 1);
   SpecialPowers.setIntPref(hangUIMinDisplayPref, 1);