Commit ab9e8a36 authored by Andrew Sutherland's avatar Andrew Sutherland
Browse files

Bug 1378949 - Fix SW notification tests that assumed activated SW to wait for activation. r=bkelly

Bug 1378949 found test_notificationclick_focus.html timing out because the
ServiceWorker activation raced the creation of an iframe document that wanted
to be controlled by the serviceworker.

The documents that wanted to be controlled had a half-hearted attempt at
dealing with this by using navigator.serviceWorker.ready, but that would only
work if the SW's attempted to claim the clients if they already existed, which
they did not.

This patch cleans up the defective test and its sibling tests that follow the
same idioms.

--HG--
extra : source : fb699d88bb80f27fbfd4805afc2e8feaa55964e0
parent 1d8501ec
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=916893
</div>
<pre id="test">
</pre>
<script src="utils.js"></script>
<script type="text/javascript">
  SimpleTest.requestFlakyTimeout("Mock alert service dispatches show and click events.");

@@ -40,11 +41,13 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=916893

  function runTest() {
    MockServices.register();
    testFrame('notificationclick-otherwindow.html');
    navigator.serviceWorker.register("notificationclick.js", { scope: "notificationclick-otherwindow.html" }).then(function(reg) {
      registration = reg;
      return waitForState(reg.installing, 'activated');
    }, function(e) {
      ok(false, "registration should have passed!");
    }).then(() => {
      testFrame('notificationclick-otherwindow.html');
    });
  };

+5 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=916893
</div>
<pre id="test">
</pre>
<script src="utils.js"></script>
<script type="text/javascript">
  SimpleTest.requestFlakyTimeout("Mock alert service dispatches show and click events.");

@@ -40,11 +41,14 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=916893

  function runTest() {
    MockServices.register();
    testFrame('notificationclick.html');
    navigator.serviceWorker.register("notificationclick.js", { scope: "notificationclick.html" }).then(function(reg) {
      registration = reg;
      return waitForState(reg.installing, 'activated');
    }, function(e) {
      ok(false, "registration should have passed!");
    }).then(() => {
      // Now that we know the document will be controlled, create the frame.
      testFrame('notificationclick.html');
    });
  };

+4 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=916893
</div>
<pre id="test">
</pre>
<script src="utils.js"></script>
<script type="text/javascript">
  SimpleTest.requestFlakyTimeout("Mock alert service dispatches show and click events.");

@@ -40,11 +41,13 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=916893

  function runTest() {
    MockServices.register();
    testFrame('notificationclick_focus.html');
    navigator.serviceWorker.register("notificationclick_focus.js", { scope: "notificationclick_focus.html" }).then(function(reg) {
      registration = reg;
      return waitForState(reg.installing, 'activated');
    }, function(e) {
      ok(false, "registration should have passed!");
    }).then(() => {
      testFrame('notificationclick_focus.html');
    });
  };

+4 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1265841
</div>
<pre id="test">
</pre>
<script src="utils.js"></script>
<script type="text/javascript">
  SimpleTest.requestFlakyTimeout("Mock alert service dispatches show, click, and close events.");

@@ -40,11 +41,13 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=1265841

  function runTest() {
    MockServices.register();
    testFrame('notificationclose.html');
    navigator.serviceWorker.register("notificationclose.js", { scope: "notificationclose.html" }).then(function(reg) {
      registration = reg;
      return waitForState(reg.installing, 'activated');
    }, function(e) {
      ok(false, "registration should have passed!");
    }).then(() => {
      testFrame('notificationclose.html');
    });
  };