Bug 524223: Even in quirks mode, ignore linked stylesheets which were served with an inappropriate MIME type, if they're from a different origin than the requesting document or stylesheet.

This commit is contained in:
Zack Weinberg 2009-12-23 10:01:51 -08:00
Родитель 2df5aaba03
Коммит d86ade967d
14 изменённых файлов: 508 добавлений и 73 удалений

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

@ -798,56 +798,73 @@ SheetLoadData::OnStreamComplete(nsIUnicharStreamLoader* aLoader,
}
}
if (aDataStream) {
nsCAutoString contentType;
if (channel) {
channel->GetContentType(contentType);
}
PRBool validType = contentType.EqualsLiteral("text/css") ||
contentType.EqualsLiteral(UNKNOWN_CONTENT_TYPE) ||
contentType.IsEmpty();
if (!validType) {
nsCAutoString spec;
channelURI->GetSpec(spec);
const nsAFlatString& specUTF16 = NS_ConvertUTF8toUTF16(spec);
const nsAFlatString& ctypeUTF16 = NS_ConvertASCIItoUTF16(contentType);
const PRUnichar *strings[] = { specUTF16.get(), ctypeUTF16.get() };
const char *errorMessage;
PRUint32 errorFlag;
if (mLoader->mCompatMode == eCompatibility_NavQuirks) {
errorMessage = "MimeNotCssWarn";
errorFlag = nsIScriptError::warningFlag;
} else {
// Drop the data stream so that we do not load it
aDataStream = nsnull;
errorMessage = "MimeNotCss";
errorFlag = nsIScriptError::errorFlag;
}
nsCOMPtr<nsIURI> referrer = GetReferrerURI();
nsContentUtils::ReportToConsole(nsContentUtils::eCSS_PROPERTIES,
errorMessage,
strings, NS_ARRAY_LENGTH(strings),
referrer, EmptyString(), 0, 0, errorFlag,
"CSS Loader");
}
}
if (!aDataStream) {
LOG_WARN((" No data stream; bailing"));
mLoader->SheetComplete(this, NS_ERROR_NOT_AVAILABLE);
return NS_OK;
}
}
nsCAutoString contentType;
if (channel) {
channel->GetContentType(contentType);
}
// In standards mode, a style sheet must have one of these MIME
// types to be processed at all. In quirks mode, we accept any
// MIME type, but only if the style sheet is same-origin with the
// requesting document or parent sheet. See bug 524223.
PRBool validType = contentType.EqualsLiteral("text/css") ||
contentType.EqualsLiteral(UNKNOWN_CONTENT_TYPE) ||
contentType.IsEmpty();
if (!validType) {
const char *errorMessage;
PRUint32 errorFlag;
PRBool sameOrigin = PR_TRUE;
if (mLoaderPrincipal) {
PRBool subsumed;
result = mLoaderPrincipal->Subsumes(principal, &subsumed);
if (NS_FAILED(result) || !subsumed) {
sameOrigin = PR_FALSE;
}
}
if (sameOrigin && mLoader->mCompatMode == eCompatibility_NavQuirks) {
errorMessage = "MimeNotCssWarn";
errorFlag = nsIScriptError::warningFlag;
} else {
errorMessage = "MimeNotCss";
errorFlag = nsIScriptError::errorFlag;
}
nsCAutoString spec;
channelURI->GetSpec(spec);
const nsAFlatString& specUTF16 = NS_ConvertUTF8toUTF16(spec);
const nsAFlatString& ctypeUTF16 = NS_ConvertASCIItoUTF16(contentType);
const PRUnichar *strings[] = { specUTF16.get(), ctypeUTF16.get() };
nsCOMPtr<nsIURI> referrer = GetReferrerURI();
nsContentUtils::ReportToConsole(nsContentUtils::eCSS_PROPERTIES,
errorMessage,
strings, NS_ARRAY_LENGTH(strings),
referrer, EmptyString(), 0, 0, errorFlag,
"CSS Loader");
if (errorFlag == nsIScriptError::errorFlag) {
LOG_WARN((" Ignoring sheet with improper MIME type %s",
contentType.get()));
mLoader->SheetComplete(this, NS_ERROR_NOT_AVAILABLE);
return NS_OK;
}
}
// Enough to set the URIs on mSheet, since any sibling datas we have share
// the same mInner as mSheet and will thus get the same URI.
mSheet->SetURIs(channelURI, originalURI, channelURI);
PRBool completed;
return mLoader->ParseSheet(aDataStream, this, completed);
}

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

@ -108,6 +108,7 @@ _TEST_FILES = test_acid3_test46.html \
test_cascade.html \
test_compute_data_with_start_struct.html \
test_computed_style_no_pseudo.html \
test_css_cross_domain.html \
test_css_eof_handling.html \
test_descriptor_storage.html \
test_descriptor_syntax_errors.html \
@ -156,14 +157,9 @@ _TEST_FILES = test_acid3_test46.html \
unstyled.css \
unstyled-frame.xml \
unstyled-frame.css \
redirect-1.css \
redirect.sjs \
post-redirect-1.css \
redirect-1.css^headers^ \
redirect-2.css \
post-redirect-2.css \
redirect-2.css^headers^ \
redirect-3.css \
redirect-3.css^headers^ \
post-redirect-3.css \
xbl_bindings.xml \
empty.html \
@ -174,6 +170,9 @@ _TEST_FILES = test_acid3_test46.html \
bug453896_iframe.html \
bug517224.sjs \
test_bug525952.html \
ccd-quirks.html \
ccd-standards.html \
ccd.sjs \
$(NULL)
_BROWSER_FILES = \

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

@ -0,0 +1,124 @@
<!-- Intentionally in quirks mode. -->
<html><head>
<!-- baseline -->
<style>
body, html { margin: 0; padding: 0; overflow: hidden }
div {
width: 60px;
height: 20px;
position: relative;
}
p {
position: absolute;
top: 2px; left: 2px;
width: 16px;
height: 16px;
margin: 0;
padding: 0;
}
p + p { left: 22px }
#IA1i, #IA1l, #IA2i, #IA2l, #IB1i, #IB1l, #IB2i, #IB2l,
#IC1i, #IC1l, #IC2i, #IC2l, #ID1i, #ID1l, #ID2i, #ID2l,
#JA1i, #JA1l, #JA2i, #JA2l, #JD1i, #JD1l, #JD2i, #JD2l
{ background-color: red }
#JB1i, #JB1l, #JC1i, #JC1l,
#JB2i, #JB2l, #JC2i, #JC2l
{ background-color: lime }
#IA3i, #IA3l, #IB3i, #IB3l, #IC3i, #IC3l, #ID3i, #ID3l,
#JA3i, #JA3l, #JB3i, #JB3l, #JC3i, #JC3l, #JD3i, #JD3l
{ background-color: lime }
</style>
<!-- @import rules -->
<style>
@import url("ccd.sjs?IA1iq");
@import url("ccd.sjs?IA2iq");
@import url("ccd.sjs?IA3iq");
@import url("http://example.org/tests/layout/style/test/ccd.sjs?IB1iq");
@import url("http://example.org/tests/layout/style/test/ccd.sjs?IB2iq");
@import url("http://example.org/tests/layout/style/test/ccd.sjs?IB3iq");
@import url("redirect.sjs?http://example.org/tests/layout/style/test/ccd.sjs?IC1iq");
@import url("redirect.sjs?http://example.org/tests/layout/style/test/ccd.sjs?IC2iq");
@import url("redirect.sjs?http://example.org/tests/layout/style/test/ccd.sjs?IC3iq");
@import url("http://example.org/tests/layout/style/test/redirect.sjs?ccd.sjs?ID1iq");
@import url("http://example.org/tests/layout/style/test/redirect.sjs?ccd.sjs?ID2iq");
@import url("http://example.org/tests/layout/style/test/redirect.sjs?ccd.sjs?ID3iq");
@import url("ccd.sjs?JA1iq");
@import url("ccd.sjs?JA2iq");
@import url("ccd.sjs?JA3iq");
@import url("http://example.org/tests/layout/style/test/ccd.sjs?JB1iq");
@import url("http://example.org/tests/layout/style/test/ccd.sjs?JB2iq");
@import url("http://example.org/tests/layout/style/test/ccd.sjs?JB3iq");
@import url("redirect.sjs?http://example.org/tests/layout/style/test/ccd.sjs?JC1iq");
@import url("redirect.sjs?http://example.org/tests/layout/style/test/ccd.sjs?JC2iq");
@import url("redirect.sjs?http://example.org/tests/layout/style/test/ccd.sjs?JC3iq");
@import url("http://example.org/tests/layout/style/test/redirect.sjs?http://localhost:8888/tests/layout/style/test/ccd.sjs?JD1iq");
@import url("http://example.org/tests/layout/style/test/redirect.sjs?http://localhost:8888/tests/layout/style/test/ccd.sjs?JD2iq");
@import url("http://example.org/tests/layout/style/test/redirect.sjs?http://localhost:8888/tests/layout/style/test/ccd.sjs?JD3iq");
</style>
<!-- link directives -->
<link rel="stylesheet" href="ccd.sjs?IA1lq">
<link rel="stylesheet" href="ccd.sjs?IA2lq">
<link rel="stylesheet" href="ccd.sjs?IA3lq">
<link rel="stylesheet" href="http://example.org/tests/layout/style/test/ccd.sjs?IB1lq">
<link rel="stylesheet" href="http://example.org/tests/layout/style/test/ccd.sjs?IB2lq">
<link rel="stylesheet" href="http://example.org/tests/layout/style/test/ccd.sjs?IB3lq">
<link rel="stylesheet" href="redirect.sjs?http://example.org/tests/layout/style/test/ccd.sjs?IC1lq">
<link rel="stylesheet" href="redirect.sjs?http://example.org/tests/layout/style/test/ccd.sjs?IC2lq">
<link rel="stylesheet" href="redirect.sjs?http://example.org/tests/layout/style/test/ccd.sjs?IC3lq">
<link rel="stylesheet" href="http://example.org/tests/layout/style/test/redirect.sjs?ccd.sjs?ID1lq">
<link rel="stylesheet" href="http://example.org/tests/layout/style/test/redirect.sjs?ccd.sjs?ID2lq">
<link rel="stylesheet" href="http://example.org/tests/layout/style/test/redirect.sjs?ccd.sjs?ID3lq">
<link rel="stylesheet" href="ccd.sjs?JA1lq">
<link rel="stylesheet" href="ccd.sjs?JA2lq">
<link rel="stylesheet" href="ccd.sjs?JA3lq">
<link rel="stylesheet" href="http://example.org/tests/layout/style/test/ccd.sjs?JB1lq">
<link rel="stylesheet" href="http://example.org/tests/layout/style/test/ccd.sjs?JB2lq">
<link rel="stylesheet" href="http://example.org/tests/layout/style/test/ccd.sjs?JB3lq">
<link rel="stylesheet" href="redirect.sjs?http://example.org/tests/layout/style/test/ccd.sjs?JC1lq">
<link rel="stylesheet" href="redirect.sjs?http://example.org/tests/layout/style/test/ccd.sjs?JC2lq">
<link rel="stylesheet" href="redirect.sjs?http://example.org/tests/layout/style/test/ccd.sjs?JC3lq">
<link rel="stylesheet" href="http://example.org/tests/layout/style/test/redirect.sjs?http://localhost:8888/tests/layout/style/test/ccd.sjs?JD1lq">
<link rel="stylesheet" href="http://example.org/tests/layout/style/test/redirect.sjs?http://localhost:8888/tests/layout/style/test/ccd.sjs?JD2lq">
<link rel="stylesheet" href="http://example.org/tests/layout/style/test/redirect.sjs?http://localhost:8888/tests/layout/style/test/ccd.sjs?JD3lq">
</head><body>
<div></div>
<div></div>
<div><p id="IA1i"></p><p id="IA1l"></p></div>
<div><p id="IA2i"></p><p id="IA2l"></p></div>
<div><p id="IA3i"></p><p id="IA3l"></p></div>
<div></div>
<div><p id="IB1i"></p><p id="IB1l"></p></div>
<div><p id="IB2i"></p><p id="IB2l"></p></div>
<div><p id="IB3i"></p><p id="IB3l"></p></div>
<div></div>
<div><p id="IC1i"></p><p id="IC1l"></p></div>
<div><p id="IC2i"></p><p id="IC2l"></p></div>
<div><p id="IC3i"></p><p id="IC3l"></p></div>
<div></div>
<div><p id="ID1i"></p><p id="ID1l"></p></div>
<div><p id="ID2i"></p><p id="ID2l"></p></div>
<div><p id="ID3i"></p><p id="ID3l"></p></div>
<div></div>
<div></div>
<div><p id="JA1i"></p><p id="JA1l"></p></div>
<div><p id="JA2i"></p><p id="JA2l"></p></div>
<div><p id="JA3i"></p><p id="JA3l"></p></div>
<div></div>
<div><p id="JB1i"></p><p id="JB1l"></p></div>
<div><p id="JB2i"></p><p id="JB2l"></p></div>
<div><p id="JB3i"></p><p id="JB3l"></p></div>
<div></div>
<div><p id="JC1i"></p><p id="JC1l"></p></div>
<div><p id="JC2i"></p><p id="JC2l"></p></div>
<div><p id="JC3i"></p><p id="JC3l"></p></div>
<div></div>
<div><p id="JD1i"></p><p id="JD1l"></p></div>
<div><p id="JD2i"></p><p id="JD2l"></p></div>
<div><p id="JD3i"></p><p id="JD3l"></p></div>
</body></html>

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

@ -0,0 +1,123 @@
<!doctype html>
<html><head>
<!-- baseline -->
<style>
body, html { margin: 0; padding: 0; overflow: hidden }
div {
width: 60px;
height: 20px;
position: relative;
}
p {
position: absolute;
top: 2px; left: 2px;
width: 16px;
height: 16px;
margin: 0;
padding: 0;
}
p + p { left: 22px }
#IA1i, #IA1l, #IA2i, #IA2l, #IB1i, #IB1l, #IB2i, #IB2l,
#IC1i, #IC1l, #IC2i, #IC2l, #ID1i, #ID1l, #ID2i, #ID2l
{ background-color: red }
#JA1i, #JA1l, #JA2i, #JA2l, #JB1i, #JB1l, #JB2i, #JB2l,
#JC1i, #JC1l, #JC2i, #JC2l, #JD1i, #JD1l, #JD2i, #JD2l
{ background-color: lime }
#IA3i, #IA3l, #IB3i, #IB3l, #IC3i, #IC3l, #ID3i, #ID3l,
#JA3i, #JA3l, #JB3i, #JB3l, #JC3i, #JC3l, #JD3i, #JD3l
{ background-color: lime }
</style>
<!-- @import rules -->
<style>
@import url("ccd.sjs?IA1is");
@import url("ccd.sjs?IA2is");
@import url("ccd.sjs?IA3is");
@import url("http://example.org/tests/layout/style/test/ccd.sjs?IB1is");
@import url("http://example.org/tests/layout/style/test/ccd.sjs?IB2is");
@import url("http://example.org/tests/layout/style/test/ccd.sjs?IB3is");
@import url("redirect.sjs?http://example.org/tests/layout/style/test/ccd.sjs?IC1is");
@import url("redirect.sjs?http://example.org/tests/layout/style/test/ccd.sjs?IC2is");
@import url("redirect.sjs?http://example.org/tests/layout/style/test/ccd.sjs?IC3is");
@import url("http://example.org/tests/layout/style/test/redirect.sjs?ccd.sjs?ID1is");
@import url("http://example.org/tests/layout/style/test/redirect.sjs?ccd.sjs?ID2is");
@import url("http://example.org/tests/layout/style/test/redirect.sjs?ccd.sjs?ID3is");
@import url("ccd.sjs?JA1is");
@import url("ccd.sjs?JA2is");
@import url("ccd.sjs?JA3is");
@import url("http://example.org/tests/layout/style/test/ccd.sjs?JB1is");
@import url("http://example.org/tests/layout/style/test/ccd.sjs?JB2is");
@import url("http://example.org/tests/layout/style/test/ccd.sjs?JB3is");
@import url("redirect.sjs?http://example.org/tests/layout/style/test/ccd.sjs?JC1is");
@import url("redirect.sjs?http://example.org/tests/layout/style/test/ccd.sjs?JC2is");
@import url("redirect.sjs?http://example.org/tests/layout/style/test/ccd.sjs?JC3is");
@import url("http://example.org/tests/layout/style/test/redirect.sjs?http://localhost:8888/tests/layout/style/test/ccd.sjs?JD1is");
@import url("http://example.org/tests/layout/style/test/redirect.sjs?http://localhost:8888/tests/layout/style/test/ccd.sjs?JD2is");
@import url("http://example.org/tests/layout/style/test/redirect.sjs?http://localhost:8888/tests/layout/style/test/ccd.sjs?JD3is");
</style>
<!-- link directives -->
<link rel="stylesheet" href="ccd.sjs?IA1ls">
<link rel="stylesheet" href="ccd.sjs?IA2ls">
<link rel="stylesheet" href="ccd.sjs?IA3ls">
<link rel="stylesheet" href="http://example.org/tests/layout/style/test/ccd.sjs?IB1ls">
<link rel="stylesheet" href="http://example.org/tests/layout/style/test/ccd.sjs?IB2ls">
<link rel="stylesheet" href="http://example.org/tests/layout/style/test/ccd.sjs?IB3ls">
<link rel="stylesheet" href="redirect.sjs?http://example.org/tests/layout/style/test/ccd.sjs?IC1ls">
<link rel="stylesheet" href="redirect.sjs?http://example.org/tests/layout/style/test/ccd.sjs?IC2ls">
<link rel="stylesheet" href="redirect.sjs?http://example.org/tests/layout/style/test/ccd.sjs?IC3ls">
<link rel="stylesheet" href="http://example.org/tests/layout/style/test/redirect.sjs?ccd.sjs?ID1ls">
<link rel="stylesheet" href="http://example.org/tests/layout/style/test/redirect.sjs?ccd.sjs?ID2ls">
<link rel="stylesheet" href="http://example.org/tests/layout/style/test/redirect.sjs?ccd.sjs?ID3ls">
<link rel="stylesheet" href="ccd.sjs?JA1ls">
<link rel="stylesheet" href="ccd.sjs?JA2ls">
<link rel="stylesheet" href="ccd.sjs?JA3ls">
<link rel="stylesheet" href="http://example.org/tests/layout/style/test/ccd.sjs?JB1ls">
<link rel="stylesheet" href="http://example.org/tests/layout/style/test/ccd.sjs?JB2ls">
<link rel="stylesheet" href="http://example.org/tests/layout/style/test/ccd.sjs?JB3ls">
<link rel="stylesheet" href="redirect.sjs?http://example.org/tests/layout/style/test/ccd.sjs?JC1ls">
<link rel="stylesheet" href="redirect.sjs?http://example.org/tests/layout/style/test/ccd.sjs?JC2ls">
<link rel="stylesheet" href="redirect.sjs?http://example.org/tests/layout/style/test/ccd.sjs?JC3ls">
<link rel="stylesheet" href="http://example.org/tests/layout/style/test/redirect.sjs?http://localhost:8888/tests/layout/style/test/ccd.sjs?JD1ls">
<link rel="stylesheet" href="http://example.org/tests/layout/style/test/redirect.sjs?http://localhost:8888/tests/layout/style/test/ccd.sjs?JD2ls">
<link rel="stylesheet" href="http://example.org/tests/layout/style/test/redirect.sjs?http://localhost:8888/tests/layout/style/test/ccd.sjs?JD3ls">
</head><body>
<div></div>
<div></div>
<div><p id="IA1i"></p><p id="IA1l"></p></div>
<div><p id="IA2i"></p><p id="IA2l"></p></div>
<div><p id="IA3i"></p><p id="IA3l"></p></div>
<div></div>
<div><p id="IB1i"></p><p id="IB1l"></p></div>
<div><p id="IB2i"></p><p id="IB2l"></p></div>
<div><p id="IB3i"></p><p id="IB3l"></p></div>
<div></div>
<div><p id="IC1i"></p><p id="IC1l"></p></div>
<div><p id="IC2i"></p><p id="IC2l"></p></div>
<div><p id="IC3i"></p><p id="IC3l"></p></div>
<div></div>
<div><p id="ID1i"></p><p id="ID1l"></p></div>
<div><p id="ID2i"></p><p id="ID2l"></p></div>
<div><p id="ID3i"></p><p id="ID3l"></p></div>
<div></div>
<div></div>
<div><p id="JA1i"></p><p id="JA1l"></p></div>
<div><p id="JA2i"></p><p id="JA2l"></p></div>
<div><p id="JA3i"></p><p id="JA3l"></p></div>
<div></div>
<div><p id="JB1i"></p><p id="JB1l"></p></div>
<div><p id="JB2i"></p><p id="JB2l"></p></div>
<div><p id="JB3i"></p><p id="JB3l"></p></div>
<div></div>
<div><p id="JC1i"></p><p id="JC1l"></p></div>
<div><p id="JC2i"></p><p id="JC2l"></p></div>
<div><p id="JC3i"></p><p id="JC3l"></p></div>
<div></div>
<div><p id="JD1i"></p><p id="JD1l"></p></div>
<div><p id="JD2i"></p><p id="JD2l"></p></div>
<div><p id="JD3i"></p><p id="JD3l"></p></div>
</body></html>

73
layout/style/test/ccd.sjs Normal file
Просмотреть файл

@ -0,0 +1,73 @@
const DEBUG_all_valid = false;
const DEBUG_all_stub = false;
function handleRequest(request, response)
{
// Decode the query string to know what test we're doing.
// character 1: 'I' = text/css response, 'J' = text/html response
let responseCSS = (request.queryString[0] == 'I');
// character 2: redirection type - we only care about whether we're
// ultimately same-origin with the requesting document ('A', 'D') or
// not ('B', 'C').
let sameOrigin = (request.queryString[1] == 'A' ||
request.queryString[1] == 'D');
// character 3: '1' = syntactically valid, '2' = invalid, '3' = http error
let malformed = (request.queryString[2] == '2');
let httpError = (request.queryString[2] == '3');
// character 4: loaded with <link> or @import (no action required)
// character 5: loading document mode: 'q' = quirks, 's' = standards
let quirksMode = (request.queryString[4] == 'q');
// Our response contains a CSS rule that selects an element whose
// ID is the first four characters of the query string.
let selector = '#' + request.queryString.substring(0,4);
// "Malformed" responses wrap the CSS rule in the construct
// <html>{} ... </html>
// This mimics what the CSS parser might see if an actual HTML
// document were fed to it. Because CSS parsers recover from
// errors by skipping tokens until they find something
// recognizable, a style rule appearing where I wrote '...' above
// will be honored!
let leader = (malformed ? '<html>{}' : '');
let trailer = (malformed ? '</html>' : '');
// Standards mode documents will ignore the style sheet if it is being
// served as text/html (regardless of its contents). Quirks mode
// documents will ignore the style sheet if it is being served as
// text/html _and_ it is not same-origin. Regardless, style sheets
// are ignored if they come as the body of an HTTP error response.
//
// Style sheets that should be ignored paint the element red; those
// that should be honored paint it lime.
let color = ((responseCSS || (quirksMode && sameOrigin)) && !httpError
? 'lime' : 'red');
// For debugging the test itself, we have the capacity to make every style
// sheet well-formed, or every style sheet do nothing.
if (DEBUG_all_valid) {
// In this mode, every test chip should turn blue.
response.setHeader('Content-Type', 'text/css');
response.write(selector + '{background-color:blue}\n');
} else if (DEBUG_all_stub) {
// In this mode, every test chip for a case where the true test
// sheet would be honored, should turn red.
response.setHeader('Content-Type', 'text/css');
response.write(selector + '{}\n');
} else {
// Normal operation.
if (httpError)
response.setStatusLine(request.httpVersion, 500,
"Internal Server Error");
response.setHeader('Content-Type',
responseCSS ? 'text/css' : 'text/html');
response.write(leader + selector +
'{background-color:' + color + '}' +
trailer + '\n');
}
}

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

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

@ -1,2 +0,0 @@
HTTP 302 Found
Location: http://example.org/tests/layout/style/test/post-redirect-1.css

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

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

@ -1,2 +0,0 @@
HTTP 302 Found
Location: http://example.org/tests/layout/style/test/post-redirect-2.css

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

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

@ -1,2 +0,0 @@
HTTP 302 Found
Location: http://example.org/tests/layout/style/test/post-redirect-3.css

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

@ -0,0 +1,5 @@
function handleRequest(request, response)
{
response.setStatusLine(request.httpVersion, 301, "Moved Permanently");
response.setHeader("Location", request.queryString, false);
}

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

@ -9,13 +9,13 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=397427
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<style id="a">
@import url("redirect-1.css");
@import url("redirect-2.css");
@import url("redirect.sjs?http://example.org/tests/layout/style/test/post-redirect-1.css");
@import url("redirect.sjs?http://example.org/tests/layout/style/test/post-redirect-2.css");
.test { color: red }
</style>
<link id="b" rel="stylesheet" href="http://example.com">
<link id="c" rel="stylesheet" href="redirect-2.css">
<link id="d" rel="stylesheet" href="redirect-3.css">
<link id="c" rel="stylesheet" href="redirect.sjs?http://example.org/tests/layout/style/test/post-redirect-2.css">
<link id="d" rel="stylesheet" href="redirect.sjs?http://example.org/tests/layout/style/test/post-redirect-3.css">
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=397427">Mozilla Bug 397427</a>
@ -55,30 +55,30 @@ addLoadEvent(function() {
"Redirect 3 did not get right base URI");
var ruleList = $("a").sheet.cssRules;
is(ruleList[0].styleSheet.href,
window.location.href.replace(/test_bug397427.html$/, "redirect-1.css"),
var redirHrefBase =
window.location.href.replace(/test_bug397427.html$/,
"redirect.sjs?http://example.org/tests/layout/style/test/post-");
is(ruleList[0].styleSheet.href, redirHrefBase + "redirect-1.css",
"Unexpected href for imported sheet");
todo(ruleList[0].href == window.location.href.replace(/test_bug397427.html$/, "redirect-1.css"),
"Rule href should be absolute");
is(ruleList[1].styleSheet.href,
window.location.href.replace(/test_bug397427.html$/, "redirect-2.css"),
todo_is(ruleList[0].href, redirHrefBase + "redirect-1.css",
"Rule href should be absolute");
is(ruleList[1].styleSheet.href, redirHrefBase + "redirect-2.css",
"Unexpected href for imported sheet");
todo(ruleList[1].href == window.location.href.replace(/test_bug397427.html$/, "redirect-2.css"),
"Rule href should be absolute");
todo_is(ruleList[1].href, redirHrefBase + "redirect-2.css",
"Rule href should be absolute");
is($("b").href, "http://example.com/", "Unexpected href one");
is($("b").href, $("b").sheet.href,
"Should have the same href when not redirecing");
"Should have the same href when not redirecting");
is($("c").href,
window.location.href.replace(/test_bug397427.html$/, "redirect-2.css"),
is($("c").href, redirHrefBase + "redirect-2.css",
"Unexpected href two");
is($("c").href, $("c").sheet.href,
"Should have the same href when redirecting");
is($("d").href,
window.location.href.replace(/test_bug397427.html$/, "redirect-3.css"),
is($("d").href, redirHrefBase + "redirect-3.css",
"Unexpected href three");
is($("d").href, $("d").sheet.href,
"Should have the same href when redirecting again");

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

@ -0,0 +1,100 @@
<!DOCTYPE HTML>
<html>
<!-- https://bugzilla.mozilla.org/show_bug.cgi?id=524223 -->
<head>
<title>Test cross-domain CSS loading</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript"
src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css"
href="/tests/SimpleTest/test.css"/>
<style type="text/css">
hr { border: none; clear: both }
.column {
margin: 10px;
float: left;
}
iframe {
width: 40px;
height: 680px;
border: none;
margin: 0;
padding: 0;
}
h2 { font-weight: normal; padding: 0 }
ol, h2 { font-size: 13px; line-height: 20px; }
ol { padding-left: 1em;
list-style-type: upper-roman }
ol ol { list-style-type: upper-alpha }
ol ol ol { list-style-type: decimal }
</style>
</head>
<body>
<a target="_blank"
href="https://bugzilla.mozilla.org/show_bug.cgi?id=524223">Mozilla
Bug 524223</a>
<hr/>
<div class="column">
<h2>&nbsp;</h2>
<ol><li>text/css<ol><li>same origin<ol><li>valid</li>
<li>malformed</li>
<li>http error</li></ol></li>
<li>cross origin<ol><li>valid</li>
<li>malformed</li>
<li>http error</li></ol></li>
<li>same to cross<ol><li>valid</li>
<li>malformed</li>
<li>http error</li></ol></li>
<li>cross to same<ol><li>valid</li>
<li>malformed</li>
<li>http error</li></ol></li></ol></li>
<li>text/html<ol><li>same origin<ol><li>valid</li>
<li>malformed</li>
<li>http error</li></ol></li>
<li>cross origin<ol><li>valid</li>
<li>malformed</li>
<li>http error</li></ol></li>
<li>same to cross<ol><li>valid</li>
<li>malformed</li>
<li>http error</li></ol></li>
<li>cross to same<ol><li>valid</li>
<li>malformed</li>
<li>http error</li></ol></li></ol></li>
</ol>
</div>
<div class="column">
<h2>Quirks</h2>
<iframe id="quirks" src="ccd-quirks.html"></iframe>
</div>
<div class="column">
<h2>Standards</h2>
<iframe id="standards" src="ccd-standards.html"></iframe>
</div>
<script type="application/javascript">
/** Test for Bug 524223 **/
function check_iframe(ifr) {
var doc = ifr.contentDocument;
var cases = doc.getElementsByTagName("p");
for (var i = 0; i < cases.length; i++) {
var color = doc.defaultView.getComputedStyle(cases[i], "")
.getPropertyValue("background-color");
is(color, "rgb(0, 255, 0)", ifr.id + " " + cases[i].id);
}
}
SimpleTest.waitForExplicitFinish();
window.onload = function() {
check_iframe(document.getElementById("quirks"));
check_iframe(document.getElementById("standards"));
SimpleTest.finish();
};
</script>
</body>
</html>