diff --git a/dom/workers/ServiceWorkerContainer.cpp b/dom/workers/ServiceWorkerContainer.cpp index ee3faddb8077..11081d84bdf9 100644 --- a/dom/workers/ServiceWorkerContainer.cpp +++ b/dom/workers/ServiceWorkerContainer.cpp @@ -113,13 +113,32 @@ ServiceWorkerContainer::Register(const nsAString& aScriptURL, return nullptr; } - nsCOMPtr window = GetOwner(); - MOZ_ASSERT(window); + nsCOMPtr baseURI; + + nsIDocument* doc = GetEntryDocument(); + if (doc) { + baseURI = doc->GetBaseURI(); + } else { + // XXXnsm. One of our devtools browser test calls register() from a content + // script where there is no valid entry document. Use the window to resolve + // the uri in that case. + nsCOMPtr window = GetOwner(); + nsCOMPtr outerWindow; + if (window && (outerWindow = window->GetOuterWindow()) && + outerWindow->GetServiceWorkersTestingEnabled()) { + baseURI = window->GetDocBaseURI(); + } + } + + + if (!baseURI) { + aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); + return nullptr; + } nsresult rv; nsCOMPtr scriptURI; - rv = NS_NewURI(getter_AddRefs(scriptURI), aScriptURL, nullptr, - window->GetDocBaseURI()); + rv = NS_NewURI(getter_AddRefs(scriptURI), aScriptURL, nullptr, baseURI); if (NS_WARN_IF(NS_FAILED(rv))) { aRv.ThrowTypeError(MSG_INVALID_URL, &aScriptURL); return nullptr; @@ -143,17 +162,19 @@ ServiceWorkerContainer::Register(const nsAString& aScriptURL, } else { // Step 5. Parse against entry settings object's base URL. rv = NS_NewURI(getter_AddRefs(scopeURI), aOptions.mScope.Value(), - nullptr, window->GetDocBaseURI()); + nullptr, baseURI); if (NS_WARN_IF(NS_FAILED(rv))) { nsAutoCString spec; - if (window->GetDocBaseURI()) { - window->GetDocBaseURI()->GetSpec(spec); - } + baseURI->GetSpec(spec); aRv.ThrowTypeError(MSG_INVALID_SCOPE, &aOptions.mScope.Value(), &spec); return nullptr; } } + // The spec says that the "client" passed to Register() must be the global + // where the ServiceWorkerContainer was retrieved from. + nsCOMPtr window = GetOwner(); + MOZ_ASSERT(window); aRv = swm->Register(window, scopeURI, scriptURI, getter_AddRefs(promise)); if (aRv.Failed()) { return nullptr; diff --git a/testing/web-platform/mozilla/meta/service-workers/service-worker/controller-on-reload.https.html.ini b/testing/web-platform/mozilla/meta/service-workers/service-worker/controller-on-reload.https.html.ini deleted file mode 100644 index b9a5b66c2327..000000000000 --- a/testing/web-platform/mozilla/meta/service-workers/service-worker/controller-on-reload.https.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[controller-on-reload.https.html] - type: testharness - [controller is set upon reload after registration] - expected: FAIL - diff --git a/testing/web-platform/mozilla/meta/service-workers/service-worker/fetch-event-async-respond-with.https.html.ini b/testing/web-platform/mozilla/meta/service-workers/service-worker/fetch-event-async-respond-with.https.html.ini index dcee8d7d5967..1755750ac752 100644 --- a/testing/web-platform/mozilla/meta/service-workers/service-worker/fetch-event-async-respond-with.https.html.ini +++ b/testing/web-platform/mozilla/meta/service-workers/service-worker/fetch-event-async-respond-with.https.html.ini @@ -3,3 +3,4 @@ expected: OK [Calling respondWith asynchronously throws an exception] expected: FAIL + diff --git a/testing/web-platform/mozilla/meta/service-workers/service-worker/registration-iframe.https.html.ini b/testing/web-platform/mozilla/meta/service-workers/service-worker/registration-iframe.https.html.ini deleted file mode 100644 index 4145809bdfdf..000000000000 --- a/testing/web-platform/mozilla/meta/service-workers/service-worker/registration-iframe.https.html.ini +++ /dev/null @@ -1,11 +0,0 @@ -[registration-iframe.https.html] - type: testharness - [Subframe's container's register method should use calling frame's document's url as a base url for parsing its script url and scope url - normal case] - expected: FAIL - - [Subframe's container's register method should use calling frame's document's url as a base url for parsing its script url and scope url - error case] - expected: FAIL - - [A scope url should start with the given script url] - expected: FAIL - diff --git a/testing/web-platform/mozilla/tests/service-workers/service-worker/registration-iframe.https.html b/testing/web-platform/mozilla/tests/service-workers/service-worker/registration-iframe.https.html index fe4f30d95a21..fb60afe84975 100644 --- a/testing/web-platform/mozilla/tests/service-workers/service-worker/registration-iframe.https.html +++ b/testing/web-platform/mozilla/tests/service-workers/service-worker/registration-iframe.https.html @@ -68,7 +68,7 @@ async_test(function(t) { assert_unreached('register() should reject'); }, function(e) { - assert_equals(e.name, 'NetworkError'); + assert_equals(e.name, 'TypeError'); frame.remove(); return service_worker_unregister_and_done(t, scope); })