blob: bfa4aa3aec08b21774dc7eb276159284dcf5d0b0 [file] [log] [blame]
<html>
<head>
<script src="../../http/tests/inspector/inspector-test.js"></script>
<script src="../../http/tests/inspector/debugger-test.js"></script>
<style>
body {
color: green;
}
/*# sourceURL=inlineStyleSheet.css */
</style>
<script>
function addInlineStyleSheet()
{
var styleElement = document.createElement("style");
styleElement.textContent = "body { color: black; }\n/*# sourceURL=css/addedInlineStylesheet.css */";
document.head.appendChild(styleElement);
}
function addInlineStyleSheetDeprecated()
{
var styleElement = document.createElement("style");
styleElement.textContent = "body { color: black; }\n/*@ sourceURL=css/addedInlineStylesheetDeprecated.css */";
document.head.appendChild(styleElement);
}
function addInlineStyleSheetNonRelative()
{
var styleElement = document.createElement("style");
styleElement.textContent = "body { color: red; }\n/*# sourceURL=/css/nonRelativeInlineStylesheet.css */";
document.head.appendChild(styleElement);
}
function test()
{
function forEachHeaderMatchingURL(url, handler)
{
var headers = WebInspector.cssModel.styleSheetHeaders();
for (var i = 0; i < headers.length; ++i) {
if (headers[i].sourceURL.indexOf(url) !== -1)
handler(headers[i]);
}
}
function checkHeaderHasSourceURL(header)
{
InspectorTest.assertTrue(header.hasSourceURL);
}
InspectorTest.runTestSuite([
function testSourceURLCommentInInlineScript(next)
{
InspectorTest.showScriptSource("stylesheet-source-url-comment.html", didShowSource);
function didShowSource(sourceFrame)
{
function checkHeaderDoesNotHaveSourceURL(header)
{
InspectorTest.assertTrue(!header.hasSourceURL, "hasSourceURL flag is set for inline stylesheet");
}
forEachHeaderMatchingURL("source-url-comment.html", checkHeaderDoesNotHaveSourceURL);
next();
}
},
function testSourceURLComment(next)
{
InspectorTest.showScriptSource("css/addedInlineStylesheet.css", didShowSource);
InspectorTest.evaluateInPage("setTimeout(addInlineStyleSheet, 0)");
function didShowSource(sourceFrame)
{
InspectorTest.addResult(sourceFrame.textEditor.text());
forEachHeaderMatchingURL("addedInlineStylesheet", checkHeaderHasSourceURL);
next();
}
},
function testDeprecatedSourceURLComment(next)
{
InspectorTest.showScriptSource("css/addedInlineStylesheetDeprecated.css", didShowSource);
InspectorTest.evaluateInPage("setTimeout(addInlineStyleSheetDeprecated, 0)");
function didShowSource(sourceFrame)
{
InspectorTest.addResult(sourceFrame.textEditor.text());
forEachHeaderMatchingURL("addedInlineStylesheetDeprecated", checkHeaderHasSourceURL);
next();
}
},
function testNonRelativeURL(next)
{
InspectorTest.showScriptSource("/css/nonRelativeInlineStylesheet.css", didShowSource);
InspectorTest.evaluateInPage("setTimeout(addInlineStyleSheetNonRelative, 0)");
function didShowSource(sourceFrame)
{
InspectorTest.addResult(sourceFrame.textEditor.text());
forEachHeaderMatchingURL("nonRelativeInlineStyleSheet.css", checkHeaderHasSourceURL);
next();
}
}
]);
};
</script>
</head>
<body onload="runTest()">
<p>Tests that stylesheets with sourceURL comment are shown in the Sources panel.</p>
</body>
</html>