Update checking origin trustworthy align to spec

This commit is contained in:
CYBAI 2020-04-04 23:50:45 +09:00
parent 06803a2edb
commit 99a8ea26a1
4 changed files with 12 additions and 7 deletions

View file

@ -74,14 +74,19 @@ impl UrlHelper {
} }
// https://w3c.github.io/webappsec-secure-contexts/#is-origin-trustworthy // https://w3c.github.io/webappsec-secure-contexts/#is-origin-trustworthy
pub fn is_origin_trustworthy(url: &ServoUrl) -> bool { pub fn is_origin_trustworthy(url: &ServoUrl) -> bool {
// Step 1
if !url.origin().is_tuple() {
return false;
}
// Step 3 // Step 3
if url.scheme() == "http" || url.scheme() == "wss" { if url.scheme() == "https" || url.scheme() == "wss" {
true true
// Step 4 // Step 4
} else if url.host().is_some() { } else if url.host().is_some() {
let host = url.host_str().unwrap(); let host = url.host_str().unwrap();
host == "127.0.0.0/8" || host == "::1/128" host == "127.0.0.0/8" || host == "::1/128"
// Step 5 // Step 6
} else { } else {
url.scheme() == "file" url.scheme() == "file"
} }

View file

@ -1,4 +1,4 @@
[service-worker-registration.html] [service-worker-registration.https.html]
[Test: Throws Error when Invalid Scope] [Test: Throws Error when Invalid Scope]
expected: FAIL expected: FAIL

View file

@ -14273,8 +14273,8 @@
] ]
], ],
"service-workers": { "service-workers": {
"service-worker-registration.html": [ "service-worker-registration.https.html": [
"da46088ca92d8706c40a48fdb3805aaf28bbddd5", "949992e45de6858c336936b4f1ea4bca76db1d91",
[ [
null, null,
{} {}

View file

@ -16,7 +16,7 @@ test(function (){
promise_test(function() { promise_test(function() {
return register_sw('resources/sw.js').then(function(sw_reg) { return register_sw('resources/sw.js').then(function(sw_reg) {
assert_equals(sw_reg.active.scriptURL, location.href.replace("service-worker-registration.html", "resources/sw.js")); assert_equals(sw_reg.active.scriptURL, location.href.replace("service-worker-registration.https.html", "resources/sw.js"));
}); });
}, "Test: Active Service Worker ScriptURL property"); }, "Test: Active Service Worker ScriptURL property");
@ -30,7 +30,7 @@ promise_test(function() {
promise_test(function() { promise_test(function() {
return register_sw('resources/sw.js', './').then(function(sw_reg) { return register_sw('resources/sw.js', './').then(function(sw_reg) {
assert_equals(sw_reg.scope, location.href.replace("service-worker-registration.html", "")); assert_equals(sw_reg.scope, location.href.replace("service-worker-registration.https.html", ""));
}); });
}, "Test: Service Worker Registration property scope Url when no scope"); }, "Test: Service Worker Registration property scope Url when no scope");