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>
<head>
<style>
</style>
<script src="../../../inspector/inspector-test.js"></script>
<script src="../../../inspector/elements-test.js"></script>
<script>
// 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.
function addImportRule()
{
document.styleSheets[0].insertRule("@import url(resources/import-added-through-js-crash.css)", 0);
}
(async function() {
TestRunner.addResult(
`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([
function selectNode(next) {
ElementsTestRunner.selectNodeAndWaitForStyles('inspected', next);
......@@ -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>
<head>
<script src="../../../inspector/inspector-test.js"></script>
<script src="../../../inspector/elements-test.js"></script>
// 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(
`Verifies that CSSStyleSheetHeader.originalContentProvider() indeed returns original content.\n`);
await TestRunner.loadModule('elements_test_runner');
await TestRunner.showPanel('elements');
await TestRunner.loadHTML(`
<style>
div { color: red; }
/*# sourceURL=set-style.css */
</style>
<style>
div {}
/*# sourceURL=set-selector.css */
</style>
<style>
@media (all) { }
/*# sourceURL=set-media.css */
</style>
<style>
@keyframes animation { 100% { color: red; } }
/*# sourceURL=set-keyframe-key.css */
</style>
<style>
div {}
/*# sourceURL=add-rule.css */
</style>
<style>
div {}
/*# sourceURL=set-text.css */
</style>
<div id="inspected"></div>
`);
<script>
function test() {
TestRunner.addSniffer(SDK.CSSModel.prototype, '_originalContentRequestedForTest', onOriginalContentRequested, true);
function onOriginalContentRequested(header) {
TestRunner.addResult('original content loaded for header: ' + header.sourceURL);
......@@ -104,15 +104,4 @@ function test() {
TestRunner.addResult('== Current ==');
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:
URL=.../devtools/elements/styles/resources/stylesheet-tracking.css
URL=.../devtools/elements/styles/resources/stylesheet-tracking-main.html
origin=regular
isInline=false
isInline=true
hasSourceURL=false
URL=.../devtools/elements/styles/stylesheet-tracking.html
URL=.../devtools/elements/styles/resources/stylesheet-tracking.css
origin=regular
isInline=true
isInline=false
hasSourceURL=false
=== Adding iframe... ===
Stylesheets added:
......
<html>
<head>
<script src="../../../inspector/inspector-test.js"></script>
<script src="../../../inspector/elements-test.js"></script>
<link rel="stylesheet" href="../styles/resources/stylesheet-tracking.css" />
<style>
html {
font-size: 12px;
}
</style>
<script>
function addStyleSheet()
{
var styleElement = document.createElement("style");
styleElement.id = "style";
styleElement.type = "text/css";
styleElement.textContent = "@import url(\"resources/stylesheet-tracking-import.css\");\na { color: green; }"
document.head.appendChild(styleElement);
}
function removeImport()
{
document.getElementById("style").sheet.deleteRule(0);
}
function removeStyleSheet()
{
document.head.removeChild(document.getElementById("style"));
}
function loadIframe()
{
var iframe = document.createElement("iframe");
iframe.setAttribute("seamless", "seamless");
iframe.src = "resources/stylesheet-tracking-iframe.html";
document.body.appendChild(iframe);
}
function iframe()
{
return document.getElementsByTagName("iframe")[0];
}
function addIframeStyleSheets()
{
iframe().contentWindow.postMessage("addStyleSheets", "*");
}
function navigateIframe()
{
iframe().src = iframe().src;
}
function removeIframeStyleSheets()
{
iframe().contentWindow.postMessage("removeStyleSheets", "*");
}
function removeIframe()
{
var element = iframe();
element.parentElement.removeChild(element);
}
function test() {
// 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(
`Tests that the styleSheetAdded and styleSheetRemoved events are reported into the frontend. Bug 105828. https://bugs.webkit.org/show_bug.cgi?id=105828\n`);
await TestRunner.loadModule('elements_test_runner');
await TestRunner.showPanel('elements');
await TestRunner.navigatePromise('resources/stylesheet-tracking-main.html');
await TestRunner.addStylesheetTag('stylesheet-tracking.css');
await TestRunner.evaluateInPagePromise(`
function addStyleSheet()
{
var styleElement = document.createElement("style");
styleElement.id = "style";
styleElement.type = "text/css";
styleElement.textContent = "@import url(\\"stylesheet-tracking-import.css\\");\\na { color: green; }"
document.head.appendChild(styleElement);
}
function removeImport()
{
document.getElementById("style").sheet.deleteRule(0);
}
function removeStyleSheet()
{
document.head.removeChild(document.getElementById("style"));
}
function loadIframe()
{
var iframe = document.createElement("iframe");
iframe.setAttribute("seamless", "seamless");
iframe.src = "stylesheet-tracking-iframe.html";
document.body.appendChild(iframe);
}
function iframe()
{
return document.getElementsByTagName("iframe")[0];
}
function addIframeStyleSheets()
{
iframe().contentWindow.postMessage("addStyleSheets", "*");
}
function navigateIframe()
{
iframe().src = iframe().src;
}
function removeIframeStyleSheets()
{
iframe().contentWindow.postMessage("removeStyleSheets", "*");
}
function removeIframe()
{
var element = iframe();
element.parentElement.removeChild(element);
}
`);
var inspectedNode;
TestRunner.cssModel.addEventListener(SDK.CSSModel.Events.StyleSheetAdded, styleSheetAdded, null);
......@@ -228,16 +226,4 @@ function test() {
return url;
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