Bug 960762 - Fix intermittence of Notification mochitests. r=mhenretty, a=test-only
authorAlexandre Lissy <lissyx@lissyx.dyndns.org>
Mon, 18 May 2015 09:49:00 +0200
changeset 260535 fe2c942655ec
parent 260534 cda517b321ee
child 260536 c163f5453215
push id811
push userryanvm@gmail.com
push date2015-05-20 14:59 +0000
treeherdermozilla-release@aa884d29e93c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmhenretty, test-only
bugs960762
milestone38.0.5
Bug 960762 - Fix intermittence of Notification mochitests. r=mhenretty, a=test-only
dom/notification/Notification.cpp
dom/tests/mochitest/notification/mochitest.ini
dom/tests/mochitest/notification/test_bug931307.html
dom/tests/mochitest/notification/test_notification_storage.html
--- a/dom/notification/Notification.cpp
+++ b/dom/notification/Notification.cpp
@@ -363,17 +363,16 @@ NotificationObserver::Observe(nsISupport
 {
   nsCOMPtr<nsPIDOMWindow> window = mNotification->GetOwner();
   if (!window || !window->IsCurrentInnerWindow()) {
     // Window has been closed, this observer is not valid anymore
     return NS_ERROR_FAILURE;
   }
 
   if (!strcmp("alertclickcallback", aTopic)) {
-
     nsCOMPtr<nsIDOMEvent> event;
     NS_NewDOMEvent(getter_AddRefs(event), mNotification, nullptr, nullptr);
     nsresult rv = event->InitEvent(NS_LITERAL_STRING("click"), false, true);
     NS_ENSURE_SUCCESS(rv, rv);
     event->SetTrusted(true);
     WantsPopupControlCheck popupControlCheck(event);
     bool doDefaultAction = true;
     mNotification->DispatchEvent(event, &doDefaultAction);
--- a/dom/tests/mochitest/notification/mochitest.ini
+++ b/dom/tests/mochitest/notification/mochitest.ini
@@ -1,12 +1,10 @@
 [DEFAULT]
 skip-if = e10s || buildapp == 'mulet'
 support-files =
   MockServices.js
   NotificationTest.js
 
 [test_notification_basics.html]
 [test_notification_storage.html]
-skip-if = toolkit == 'android' || toolkit == 'gonk' #bug 960762
 [test_bug931307.html]
-skip-if = (toolkit == 'gonk' && debug) #debug-only timeout
 [test_notification_resend.html]
--- a/dom/tests/mochitest/notification/test_bug931307.html
+++ b/dom/tests/mochitest/notification/test_bug931307.html
@@ -12,22 +12,23 @@
 <pre id="test">
 <script type="application/javascript"><!--
 
 SimpleTest.waitForExplicitFinish();
 var notification = new Notification("");
 var promise = Notification.get();
 promise.then(
   function onSuccess() {
-    ok(true, "No crash!");
-    notification.close();
-    SimpleTest.finish();
+    ok(true, "No error when creating a notification without title");
   },
   function onFailure() {
-    ok(false, "Should not get an error in promise callback");
-    notification.close();
+    ok(false, "Should not throw error when creating a notification without title");
   }
-);
+).then(() => {
+  notification.close();
+}).then(() => {
+  SimpleTest.finish();
+});
 
 </script>
 </pre>
 </body>
 </html>
--- a/dom/tests/mochitest/notification/test_notification_storage.html
+++ b/dom/tests/mochitest/notification/test_notification_storage.html
@@ -10,22 +10,23 @@
 <body>
 <p id="display"></p>
 <div id="content" style="display: none"></div>
 <pre id="test"></pre>
 <script type="text/javascript">
 
   SimpleTest.requestFlakyTimeout("untriaged");
 
-  function deleteAllNotifications() {
+  function deleteAllNotifications(done) {
     var promise = Notification.get();
     promise.then(function (notifications) {
       notifications.forEach(function(notification) {
         notification.close();
       });
+      done();
     });
   }
 
   var info = NotificationTest.info;
 
   var steps = [
     function (done) {
       info("Test that Notifcation.get fulfills the promise");
@@ -115,37 +116,41 @@
     function (done) {
       info("Testing fetching multiple notifications");
       var n1 = new Notification("title1");
       var n2 = new Notification("title2");
       var n3 = new Notification("title3");
       var promise = Notification.get();
       promise.then(function (notifications) {
         is(notifications.length, 3, "should return 3 notifications");
-        done();
         n1.close();
         n2.close();
         n3.close();
+        done();
       });
     },
 
     deleteAllNotifications,
 
     function (done) {
       info("Testing 'alertfinished' removes the notification from DB");
       var n = new Notification("test-title" + Math.random());
       n.onclose = function() {
         Notification.get().then(function(notifications) {
-            is(notifications.length, 0, "should return 0 notifications");
-            done();
+          is(notifications.length, 0, "should return 0 notifications");
+          done();
         });
-      }
-      window.setTimeout(function() {
+      };
+      info("Installing 'onshow' for " + n.title);
+      n.onshow = function() {
+        info("Triggered 'onshow' for " + n.title);
+        window.setTimeout(function() {
           NotificationTest.fireCloseEvent(n.title);
-      }, 100);
+        }, 100);
+      };
     }
   ];
 
   MockServices.register();
   NotificationTest.run(steps, function () {
     MockServices.unregister();
   });
 </script>