Bug 1188822 - Make service-workers/service-worker/fetch-request-resources.https.html pass. r=bkelly

This commit is contained in:
dimi 2016-01-25 14:18:29 +08:00
Родитель c5396e386f
Коммит c21d1ebd14
10 изменённых файлов: 173 добавлений и 62 удалений

Просмотреть файл

@ -294,7 +294,9 @@ nsScriptLoader::StartLoad(nsScriptLoadRequest *aRequest, const nsAString &aType,
aRequest->mCORSMode == CORS_NONE
? nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL
: nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS;
if (aRequest->mCORSMode == CORS_USE_CREDENTIALS) {
if (aRequest->mCORSMode == CORS_ANONYMOUS) {
securityFlags |= nsILoadInfo::SEC_COOKIES_SAME_ORIGIN;
} else if (aRequest->mCORSMode == CORS_USE_CREDENTIALS) {
securityFlags |= nsILoadInfo::SEC_COOKIES_INCLUDE;
}
securityFlags |= nsILoadInfo::SEC_ALLOW_CHROME;

Просмотреть файл

@ -324,5 +324,50 @@ InternalRequest::MapChannelToRequestMode(nsIChannel* aChannel)
return static_cast<RequestMode>(corsMode);
}
// static
RequestCredentials
InternalRequest::MapChannelToRequestCredentials(nsIChannel* aChannel)
{
MOZ_ASSERT(aChannel);
nsCOMPtr<nsILoadInfo> loadInfo;
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(aChannel->GetLoadInfo(getter_AddRefs(loadInfo))));
uint32_t securityMode;
MOZ_ALWAYS_TRUE(NS_SUCCEEDED(loadInfo->GetSecurityMode(&securityMode)));
// TODO: Remove following code after stylesheet and image support cookie policy
if (securityMode == nsILoadInfo::SEC_NORMAL) {
uint32_t loadFlags;
aChannel->GetLoadFlags(&loadFlags);
if (loadFlags & nsIRequest::LOAD_ANONYMOUS) {
return RequestCredentials::Omit;
} else {
bool includeCrossOrigin;
nsCOMPtr<nsIHttpChannelInternal> internalChannel = do_QueryInterface(aChannel);
internalChannel->GetCorsIncludeCredentials(&includeCrossOrigin);
if (includeCrossOrigin) {
return RequestCredentials::Include;
}
}
return RequestCredentials::Same_origin;
}
uint32_t cookiePolicy = loadInfo->GetCookiePolicy();
if (cookiePolicy == nsILoadInfo::SEC_COOKIES_INCLUDE) {
return RequestCredentials::Include;
} else if (cookiePolicy == nsILoadInfo::SEC_COOKIES_OMIT) {
return RequestCredentials::Omit;
} else if (cookiePolicy == nsILoadInfo::SEC_COOKIES_SAME_ORIGIN) {
return RequestCredentials::Same_origin;
}
MOZ_ASSERT_UNREACHABLE("Unexpected cookie policy!");
return RequestCredentials::Same_origin;
}
} // namespace dom
} // namespace mozilla

Просмотреть файл

@ -406,6 +406,9 @@ public:
static RequestMode
MapChannelToRequestMode(nsIChannel* aChannel);
static RequestCredentials
MapChannelToRequestCredentials(nsIChannel* aChannel);
private:
// Does not copy mBodyStream. Use fallible Clone() for complete copy.
explicit InternalRequest(const InternalRequest& aOther);

Просмотреть файл

@ -1094,15 +1094,7 @@ public:
internalChannel->GetRedirectMode(&redirectMode);
mRequestRedirect = static_cast<RequestRedirect>(redirectMode);
if (loadFlags & nsIRequest::LOAD_ANONYMOUS) {
mRequestCredentials = RequestCredentials::Omit;
} else {
bool includeCrossOrigin;
internalChannel->GetCorsIncludeCredentials(&includeCrossOrigin);
if (includeCrossOrigin) {
mRequestCredentials = RequestCredentials::Include;
}
}
mRequestCredentials = InternalRequest::MapChannelToRequestCredentials(channel);
rv = httpChannel->VisitNonDefaultRequestHeaders(this);
NS_ENSURE_SUCCESS(rv, rv);

Просмотреть файл

@ -0,0 +1,5 @@
[fetch-request-css-images.https.html]
type: testharness
[Verify FetchEvent for css images.]
expected: FAIL

Просмотреть файл

@ -1,5 +0,0 @@
[fetch-request-resources.https.html]
type: testharness
[Verify FetchEvent for resources.]
expected: FAIL

Просмотреть файл

@ -0,0 +1,99 @@
<!DOCTYPE html>
<title>Service Worker: FetchEvent for css image</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="resources/get-host-info.sub.js"></script>
<script src="resources/test-helpers.sub.js?pipe=sub"></script>
<script>
var url_count = 0;
var expected_results = {};
function css_image_test(frame, url, type, expexted_mode,
expected_credentials) {
var actual_url = url + (++url_count);
expected_results[actual_url] = {
url: actual_url,
mode: expexted_mode,
credentials: expected_credentials,
message: 'CSSImage load (url:' + actual_url + ' type:' + type + ')'
};
return frame.contentWindow.load_css_image(actual_url, type);
}
function css_image_set_test(frame, url, type, expexted_mode,
expected_credentials) {
var actual_url = url + (++url_count);
expected_results[actual_url] = {
url: actual_url,
mode: expexted_mode,
credentials: expected_credentials,
message: 'CSSImageSet load (url:' + actual_url + ' type:' + type + ')'
};
return frame.contentWindow.load_css_image_set(actual_url, type);
}
async_test(function(t) {
var SCOPE = 'resources/fetch-request-resources-iframe.https.html';
var SCRIPT = 'resources/fetch-request-resources-worker.js';
var host_info = get_host_info();
var LOCAL_URL =
host_info['HTTPS_ORIGIN'] + base_path() + 'resources/dummy?test';
var REMOTE_URL =
host_info['HTTPS_REMOTE_ORIGIN'] + base_path() + 'resources/dummy?test';
var worker;
var frame;
service_worker_unregister_and_register(t, SCRIPT, SCOPE)
.then(function(registration) {
worker = registration.installing;
return wait_for_state(t, worker, 'activated');
})
.then(function() {
return new Promise(function(resolve) {
var channel = new MessageChannel();
channel.port1.onmessage = t.step_func(function(msg) {
if (msg.data.ready) {
resolve();
return;
}
var result = msg.data;
var expected = expected_results[result.url];
if (!expected) {
return;
}
assert_equals(
result.mode, expected.mode,
'mode of ' + expected.message + ' must be ' +
expected.mode + '.');
assert_equals(
result.credentials, expected.credentials,
'credentials of ' + expected.message + ' must be ' +
expected.credentials + '.');
--url_count;
delete expected_results[result.url];
if (url_count == 0) {
frame.remove();
service_worker_unregister_and_done(t, SCOPE);
}
});
worker.postMessage(
{port: channel.port2}, [channel.port2]);
});
})
.then(function() { return with_iframe(SCOPE); })
.then(function(f) {
frame = f;
css_image_test(f, LOCAL_URL, 'backgroundImage', 'no-cors', 'include');
css_image_test(f, REMOTE_URL, 'backgroundImage', 'no-cors', 'include');
css_image_test(f, LOCAL_URL, 'shapeOutside', 'cors', 'same-origin');
css_image_test(f, REMOTE_URL, 'shapeOutside', 'cors', 'same-origin');
css_image_set_test(f, LOCAL_URL, 'backgroundImage', 'no-cors', 'include');
css_image_set_test(f, REMOTE_URL, 'backgroundImage', 'no-cors', 'include');
css_image_set_test(f, LOCAL_URL, 'shapeOutside', 'cors', 'same-origin');
css_image_set_test(f, REMOTE_URL, 'shapeOutside', 'cors', 'same-origin');
})
.catch(unreached_rejection(t));
}, 'Verify FetchEvent for resources.');
</script>

Просмотреть файл

@ -58,30 +58,6 @@ function font_face_test(frame, url, expexted_mode, expected_credentials) {
return frame.contentWindow.load_font(actual_url);
}
function css_image_test(frame, url, type, expexted_mode,
expected_credentials) {
var actual_url = url + (++url_count);
expected_results[actual_url] = {
url: actual_url,
mode: expexted_mode,
credentials: expected_credentials,
message: 'CSSImage load (url:' + actual_url + ' type:' + type + ')'
};
return frame.contentWindow.load_css_image(actual_url, type);
}
function css_image_set_test(frame, url, type, expexted_mode,
expected_credentials) {
var actual_url = url + (++url_count);
expected_results[actual_url] = {
url: actual_url,
mode: expexted_mode,
credentials: expected_credentials,
message: 'CSSImageSet load (url:' + actual_url + ' type:' + type + ')'
};
return frame.contentWindow.load_css_image_set(actual_url, type);
}
async_test(function(t) {
var SCOPE = 'resources/fetch-request-resources-iframe.https.html';
var SCRIPT = 'resources/fetch-request-resources-worker.js';
@ -132,40 +108,34 @@ async_test(function(t) {
.then(function() { return with_iframe(SCOPE); })
.then(function(f) {
frame = f;
image_test(f, LOCAL_URL, '', 'no-cors', 'same-origin');
image_test(f, LOCAL_URL, 'anonymous', 'cors', 'omit');
// TODO: Disable 'no-cors' tests for image and stylesheet until
// AsyncOpen2 and cookie policy is supported.
// image_test(f, LOCAL_URL, '', 'no-cors', 'include');
// image_test(f, REMOTE_URL, '', 'no-cors', 'include');
// css_test(f, LOCAL_URL, '', 'no-cors', 'include');
// css_test(f, REMOTE_URL, '', 'no-cors', 'include');
image_test(f, LOCAL_URL, 'anonymous', 'cors', 'same-origin');
image_test(f, LOCAL_URL, 'use-credentials', 'cors', 'include');
image_test(f, REMOTE_URL, '', 'no-cors', 'same-origin');
image_test(f, REMOTE_URL, 'anonymous', 'cors', 'omit');
image_test(f, REMOTE_URL, 'use-credentials', 'cors', 'include');
script_test(f, LOCAL_URL, '', 'no-cors', 'same-origin');
script_test(f, LOCAL_URL, 'anonymous', 'cors', 'omit');
script_test(f, LOCAL_URL, '', 'no-cors', 'include');
script_test(f, LOCAL_URL, 'anonymous', 'cors', 'same-origin');
script_test(f, LOCAL_URL, 'use-credentials', 'cors', 'include');
script_test(f, REMOTE_URL, '', 'no-cors', 'same-origin');
script_test(f, REMOTE_URL, 'anonymous', 'cors', 'omit');
script_test(f, REMOTE_URL, '', 'no-cors', 'include');
script_test(f, REMOTE_URL, 'anonymous', 'cors', 'same-origin');
script_test(f, REMOTE_URL, 'use-credentials', 'cors', 'include');
css_test(f, LOCAL_URL, '', 'no-cors', 'same-origin');
css_test(f, LOCAL_URL, 'anonymous', 'cors', 'omit');
css_test(f, LOCAL_URL, 'anonymous', 'cors', 'same-origin');
css_test(f, LOCAL_URL, 'use-credentials', 'cors', 'include');
css_test(f, REMOTE_URL, '', 'no-cors', 'same-origin');
css_test(f, REMOTE_URL, 'anonymous', 'cors', 'omit');
css_test(f, REMOTE_URL, 'use-credentials', 'cors', 'include');
font_face_test(f, LOCAL_URL, 'no-cors', 'same-origin');
font_face_test(f, LOCAL_URL, 'cors', 'same-origin');
font_face_test(f, REMOTE_URL, 'cors', 'omit');
css_image_test(f, LOCAL_URL, 'backgroundImage', 'no-cors', 'same-origin');
css_image_test(f, REMOTE_URL, 'backgroundImage', 'no-cors', 'same-origin');
css_image_test(f, LOCAL_URL, 'shapeOutside', 'cors', 'omit');
css_image_test(f, REMOTE_URL, 'shapeOutside', 'cors', 'omit');
css_image_set_test(f, LOCAL_URL, 'backgroundImage', 'no-cors', 'same-origin');
css_image_set_test(f, REMOTE_URL, 'backgroundImage', 'no-cors', 'same-origin');
css_image_set_test(f, LOCAL_URL, 'shapeOutside', 'cors', 'omit');
css_image_set_test(f, REMOTE_URL, 'shapeOutside', 'cors', 'omit');
})
.catch(unreached_rejection(t));
}, 'Verify FetchEvent for resources.');

Просмотреть файл

@ -31,7 +31,7 @@ function load_css(url, cross_origin) {
}
function load_font(url) {
var fontFace = new FontFace(url, 'url(' + url + ')');
var fontFace = new FontFace('test', 'url(' + url + ')');
fontFace.load();
}

Просмотреть файл

@ -137,7 +137,7 @@ function mode_credentials_test() {
})
.then(function(response){
assert_equals(response.mode, 'cors');
assert_equals(response.credentials, 'omit');
assert_equals(response.credentials, 'same-origin');
return xhr_send(host_info['HTTPS_REMOTE_ORIGIN'], 'GET', '', true);
})
.then(function(response){