Commit 99c9d01c authored by Erik Luo's avatar Erik Luo Committed by Commit Bot

DevTools: migrate styles tests in Elements

Bug: 667560
Change-Id: Id865639bba4f220cbcd2b3f4cccbada75bd70f9a
Reviewed-on: https://chromium-review.googlesource.com/802091Reviewed-by: default avatarWill Chen <chenwilliam@chromium.org>
Commit-Queue: Will Chen <chenwilliam@chromium.org>
Commit-Queue: Erik Luo <luoe@chromium.org>
Cr-Commit-Position: refs/heads/master@{#520754}
parent 05f8ea66
<html> // Copyright 2017 The Chromium Authors. All rights reserved.
<head> // Use of this source code is governed by a BSD-style license that can be
<style> // found in the LICENSE file.
</style>
<script src="../../../inspector/inspector-test.js"></script>
<script src="../../../inspector/elements-test.js"></script>
<script>
function addImportRule() (async function() {
{ TestRunner.addResult(
document.styleSheets[0].insertRule("@import url(resources/import-added-through-js-crash.css)", 0); `Tests that adding @import rules into a stylesheet through JavaScript does not crash the inspected page.\n`);
} await TestRunner.loadModule('elements_test_runner');
await TestRunner.showPanel('elements');
await TestRunner.loadHTML(`
<style>
</style>
<div>
<p id="inspected"></p>
</div>
`);
await TestRunner.evaluateInPagePromise(`
function addImportRule()
{
document.styleSheets[0].insertRule("@import url(resources/import-added-through-js-crash.css)", 0);
}
`);
function test() {
TestRunner.runTestSuite([ TestRunner.runTestSuite([
function selectNode(next) { function selectNode(next) {
ElementsTestRunner.selectNodeAndWaitForStyles('inspected', next); ElementsTestRunner.selectNodeAndWaitForStyles('inspected', next);
...@@ -27,18 +36,4 @@ function test() { ...@@ -27,18 +36,4 @@ function test() {
} }
} }
]); ]);
} })();
</script>
</head>
<body onload="runTest()">
<p>
Tests that adding @import rules into a stylesheet through JavaScript does not crash the inspected page.
</p>
<div>
<p id="inspected"></p>
</div>
</body>
</html>
<html>
<head>
<script src="../../../inspector/inspector-test.js"></script>
<script src="../../../inspector/bindings/bindings-test.js"></script>
<script>
function addStyleSheet() {
var styleTag = document.createElement('style');
styleTag.textContent = `div {color: red}
/*# sourceURL=style.css */
/*# sourceMappingURL=resources/selector-line.css.map */`;
document.head.appendChild(styleTag);
}
async function test() {
TestRunner.markStep('Adding style sheet');
await Promise.all([
TestRunner.evaluateInPagePromise('addStyleSheet()'),
BindingsTestRunner.waitForSourceMap('selector-line.css.map'),
]);
TestRunner.addResult('SourceMap successfully loaded.');
TestRunner.completeTest();
}
</script>
</head>
<body onload="runTest()">
<p>
Verify that in case of complex scenario with both sourceURL and sourceMappingURL in inline stylesheet
the sourceMap is resolved properly.
</p>
</body>
</html>
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
(async function() {
TestRunner.addResult(
`Verify that in case of complex scenario with both sourceURL and sourceMappingURL in inline stylesheet the sourceMap is resolved properly.\n`);
await TestRunner.loadModule('bindings_test_runner');
await TestRunner.showPanel('elements');
await TestRunner.evaluateInPagePromise(`
function addStyleSheet() {
var styleTag = document.createElement('style');
styleTag.textContent = \`div {color: red}
/*# sourceURL=style.css */
/*# sourceMappingURL=/devtools/elements/styles/resources/selector-line.css.map */\`;
document.head.appendChild(styleTag);
}
`);
TestRunner.markStep('Adding style sheet');
await Promise.all([
TestRunner.evaluateInPagePromise('addStyleSheet()'),
BindingsTestRunner.waitForSourceMap('selector-line.css.map'),
]);
TestRunner.addResult('SourceMap successfully loaded.');
TestRunner.completeTest();
})();
<html> // Copyright 2017 The Chromium Authors. All rights reserved.
<head> // Use of this source code is governed by a BSD-style license that can be
<script src="../../../inspector/inspector-test.js"></script> // found in the LICENSE file.
<script src="../../../inspector/elements-test.js"></script>
(async function() {
TestRunner.addResult(
`Verifies that CSSStyleSheetHeader.originalContentProvider() indeed returns original content.\n`);
await TestRunner.loadModule('elements_test_runner');
await TestRunner.showPanel('elements');
await TestRunner.loadHTML(`
<style> <style>
div { color: red; } div { color: red; }
/*# sourceURL=set-style.css */ /*# sourceURL=set-style.css */
</style> </style>
<style> <style>
div {} div {}
/*# sourceURL=set-selector.css */ /*# sourceURL=set-selector.css */
</style> </style>
<style> <style>
@media (all) { } @media (all) { }
/*# sourceURL=set-media.css */ /*# sourceURL=set-media.css */
</style> </style>
<style> <style>
@keyframes animation { 100% { color: red; } } @keyframes animation { 100% { color: red; } }
/*# sourceURL=set-keyframe-key.css */ /*# sourceURL=set-keyframe-key.css */
</style> </style>
<style> <style>
div {} div {}
/*# sourceURL=add-rule.css */ /*# sourceURL=add-rule.css */
</style> </style>
<style> <style>
div {} div {}
/*# sourceURL=set-text.css */ /*# sourceURL=set-text.css */
</style> </style>
<div id="inspected"></div>
`);
<script>
function test() {
TestRunner.addSniffer(SDK.CSSModel.prototype, '_originalContentRequestedForTest', onOriginalContentRequested, true); TestRunner.addSniffer(SDK.CSSModel.prototype, '_originalContentRequestedForTest', onOriginalContentRequested, true);
function onOriginalContentRequested(header) { function onOriginalContentRequested(header) {
TestRunner.addResult('original content loaded for header: ' + header.sourceURL); TestRunner.addResult('original content loaded for header: ' + header.sourceURL);
...@@ -104,15 +104,4 @@ function test() { ...@@ -104,15 +104,4 @@ function test() {
TestRunner.addResult('== Current =='); TestRunner.addResult('== Current ==');
TestRunner.addResult(contents[1].trim()); TestRunner.addResult(contents[1].trim());
} }
} })();
</script>
</head>
<body onload="runTest()">
<p>Verifies that CSSStyleSheetHeader.originalContentProvider() indeed returns original content.</p>
<div id="inspected"></div>
</body>
</html>
<style>
html {
font-size: 12px;
}
</style>
<div id="inspected">Text</div>
\ No newline at end of file
Tests that the styleSheetAdded and styleSheetRemoved events are reported into the frontend. Bug 105828. Tests that the styleSheetAdded and styleSheetRemoved events are reported into the frontend. Bug 105828. https://bugs.webkit.org/show_bug.cgi?id=105828
Text
2 headers known: 2 headers known:
URL=.../devtools/elements/styles/resources/stylesheet-tracking.css URL=.../devtools/elements/styles/resources/stylesheet-tracking-main.html
origin=regular origin=regular
isInline=false isInline=true
hasSourceURL=false hasSourceURL=false
URL=.../devtools/elements/styles/stylesheet-tracking.html URL=.../devtools/elements/styles/resources/stylesheet-tracking.css
origin=regular origin=regular
isInline=true isInline=false
hasSourceURL=false hasSourceURL=false
=== Adding iframe... === === Adding iframe... ===
Stylesheets added: Stylesheets added:
......
<html> // Copyright 2017 The Chromium Authors. All rights reserved.
<head> // Use of this source code is governed by a BSD-style license that can be
<script src="../../../inspector/inspector-test.js"></script> // found in the LICENSE file.
<script src="../../../inspector/elements-test.js"></script>
<link rel="stylesheet" href="../styles/resources/stylesheet-tracking.css" /> (async function() {
TestRunner.addResult(
<style> `Tests that the styleSheetAdded and styleSheetRemoved events are reported into the frontend. Bug 105828. https://bugs.webkit.org/show_bug.cgi?id=105828\n`);
html { await TestRunner.loadModule('elements_test_runner');
font-size: 12px; await TestRunner.showPanel('elements');
} await TestRunner.navigatePromise('resources/stylesheet-tracking-main.html');
</style> await TestRunner.addStylesheetTag('stylesheet-tracking.css');
await TestRunner.evaluateInPagePromise(`
<script> function addStyleSheet()
{
function addStyleSheet() var styleElement = document.createElement("style");
{ styleElement.id = "style";
var styleElement = document.createElement("style"); styleElement.type = "text/css";
styleElement.id = "style"; styleElement.textContent = "@import url(\\"stylesheet-tracking-import.css\\");\\na { color: green; }"
styleElement.type = "text/css"; document.head.appendChild(styleElement);
styleElement.textContent = "@import url(\"resources/stylesheet-tracking-import.css\");\na { color: green; }" }
document.head.appendChild(styleElement);
} function removeImport()
{
function removeImport() document.getElementById("style").sheet.deleteRule(0);
{ }
document.getElementById("style").sheet.deleteRule(0);
} function removeStyleSheet()
{
function removeStyleSheet() document.head.removeChild(document.getElementById("style"));
{ }
document.head.removeChild(document.getElementById("style"));
} function loadIframe()
{
function loadIframe() var iframe = document.createElement("iframe");
{ iframe.setAttribute("seamless", "seamless");
var iframe = document.createElement("iframe"); iframe.src = "stylesheet-tracking-iframe.html";
iframe.setAttribute("seamless", "seamless"); document.body.appendChild(iframe);
iframe.src = "resources/stylesheet-tracking-iframe.html"; }
document.body.appendChild(iframe);
} function iframe()
{
function iframe() return document.getElementsByTagName("iframe")[0];
{ }
return document.getElementsByTagName("iframe")[0];
} function addIframeStyleSheets()
{
function addIframeStyleSheets() iframe().contentWindow.postMessage("addStyleSheets", "*");
{ }
iframe().contentWindow.postMessage("addStyleSheets", "*");
} function navigateIframe()
{
function navigateIframe() iframe().src = iframe().src;
{ }
iframe().src = iframe().src;
} function removeIframeStyleSheets()
{
function removeIframeStyleSheets() iframe().contentWindow.postMessage("removeStyleSheets", "*");
{ }
iframe().contentWindow.postMessage("removeStyleSheets", "*");
} function removeIframe()
{
function removeIframe() var element = iframe();
{ element.parentElement.removeChild(element);
var element = iframe(); }
element.parentElement.removeChild(element); `);
}
function test() {
var inspectedNode; var inspectedNode;
TestRunner.cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetAdded, styleSheetAdded, null); TestRunner.cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetAdded, styleSheetAdded, null);
...@@ -228,16 +226,4 @@ function test() { ...@@ -228,16 +226,4 @@ function test() {
return url; return url;
return '.../' + url.substr(lastIndex); return '.../' + url.substr(lastIndex);
} }
} })();
</script>
</head>
<body onload="runTest()">
<p>
Tests that the styleSheetAdded and styleSheetRemoved events are reported into the frontend. <a href="https://bugs.webkit.org/show_bug.cgi?id=105828">Bug 105828</a>.
</p>
<div id="inspected">Text</div>
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment