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
This commit is contained in:
Nikhil Marathe 2015-08-20 13:56:37 -07:00
parent c9a46a7f39
commit dbaa5d6878
5 changed files with 31 additions and 25 deletions

View File

@ -113,13 +113,32 @@ ServiceWorkerContainer::Register(const nsAString& aScriptURL,
return nullptr;
}
nsCOMPtr<nsPIDOMWindow> window = GetOwner();
MOZ_ASSERT(window);
nsCOMPtr<nsIURI> 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<nsPIDOMWindow> window = GetOwner();
nsCOMPtr<nsPIDOMWindow> 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<nsIURI> 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<nsPIDOMWindow> window = GetOwner();
MOZ_ASSERT(window);
aRv = swm->Register(window, scopeURI, scriptURI, getter_AddRefs(promise));
if (aRv.Failed()) {
return nullptr;

View File

@ -1,5 +0,0 @@
[controller-on-reload.https.html]
type: testharness
[controller is set upon reload after registration]
expected: FAIL

View File

@ -3,3 +3,4 @@
expected: OK
[Calling respondWith asynchronously throws an exception]
expected: FAIL

View File

@ -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

View File

@ -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);
})