From dbaa5d6878a76a815d797272841f12776ee6348b Mon Sep 17 00:00:00 2001 From: Nikhil Marathe Date: Thu, 20 Aug 2015 13:56:37 -0700 Subject: [PATCH] Bug 1181037 - Use entry settings object's base URL. r=ehsan The second test, which checks for NetworkError is incorrect. [[Update]] step 12 states: "If response is a network error or response's status is not in the range 200 to 299, then: 1. Reject p with a TypeError." which specifically converts the NetworkError (due to 404) to a TypeError. Also fixes controller-on-reload.https.html Update web-platform-tests expected data --- dom/workers/ServiceWorkerContainer.cpp | 37 +++++++++++++++---- .../controller-on-reload.https.html.ini | 5 --- ...ch-event-async-respond-with.https.html.ini | 1 + .../registration-iframe.https.html.ini | 11 ------ .../registration-iframe.https.html | 2 +- 5 files changed, 31 insertions(+), 25 deletions(-) delete mode 100644 testing/web-platform/mozilla/meta/service-workers/service-worker/controller-on-reload.https.html.ini delete mode 100644 testing/web-platform/mozilla/meta/service-workers/service-worker/registration-iframe.https.html.ini diff --git a/dom/workers/ServiceWorkerContainer.cpp b/dom/workers/ServiceWorkerContainer.cpp index ee3faddb807..11081d84bdf 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 b9a5b66c232..00000000000 --- 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 dcee8d7d596..1755750ac75 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 4145809bdfd..00000000000 --- 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 fe4f30d95a2..fb60afe8497 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); })