| Index: third_party/WebKit/LayoutTests/inspector/sass/test-workspace-adapter.html
|
| diff --git a/third_party/WebKit/LayoutTests/inspector/sass/test-workspace-adapter.html b/third_party/WebKit/LayoutTests/inspector/sass/test-workspace-adapter.html
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..88c325aa7b9ce0f9505629f2ce30d880ecb12c42
|
| --- /dev/null
|
| +++ b/third_party/WebKit/LayoutTests/inspector/sass/test-workspace-adapter.html
|
| @@ -0,0 +1,184 @@
|
| +<html>
|
| +<head>
|
| +
|
| +<script src="../../http/tests/inspector/inspector-test.js"></script>
|
| +<script src="../../http/tests/inspector/debugger-test.js"></script>
|
| +<script src="../../http/tests/inspector/isolated-filesystem-test.js"></script>
|
| +<script src="./sass-test.js"></script>
|
| +<script>
|
| +
|
| +var styles = [];
|
| +function addStyleSheets()
|
| +{
|
| + for (var i = 0; i < 2; ++i) {
|
| + var style = document.createElement("style");
|
| + style.textContent = "<all.css content>\n/*# sourceURL=all.css */";
|
| + document.head.appendChild(style);
|
| + styles.push(style);
|
| + }
|
| +
|
| + var style = document.createElement("style");
|
| + style.textContent = "<print.css content>\n/*# sourceURL=print.css */";
|
| + document.head.appendChild(style);
|
| + styles.push(style);
|
| +}
|
| +
|
| +function removeStyles()
|
| +{
|
| + for (var style of styles)
|
| + style.remove();
|
| +}
|
| +
|
| +function test()
|
| +{
|
| + function createClient(clientName, cssURL, sassURLs)
|
| + {
|
| + var sources = sassURLs;
|
| + var fakeSourceMap = {
|
| + sources: () => sources,
|
| + compiledURL: () => cssURL
|
| + };
|
| + var client = InspectorTest.sassWorkspaceAdapter().trackSources(fakeSourceMap);
|
| + client.__NAME = clientName;
|
| + client.addEventListener(WebInspector.SASSWorkspaceAdapter.ClientEvents.SourceChanged, onSourceChanged);
|
| + client.addEventListener(WebInspector.SASSWorkspaceAdapter.ClientEvents.TrackingStopped, onTrackingStopped);
|
| + return client;
|
| +
|
| + function onSourceChanged(event)
|
| + {
|
| + InspectorTest.addResult(" -- " + event.target.__NAME + " -- SourceChanged event: " + event.data);
|
| + }
|
| +
|
| + function onTrackingStopped(event)
|
| + {
|
| + InspectorTest.addResult(" -- " + event.target.__NAME + " -- TrackingStopped");
|
| + }
|
| + }
|
| +
|
| + var fileSystemPrefix = "file:///var/www";
|
| + var css1 = "all.css";
|
| + var css2 = "print.css";
|
| + var sass1 = fileSystemPrefix + "/a.scss";
|
| + var sass2 = fileSystemPrefix + "/b.scss";
|
| + var sassCommon = fileSystemPrefix + "/common.scss";
|
| + var client1 = createClient("CLIENT 1", css1, [sass1, sassCommon]);
|
| + var client2 = createClient("CLIENT 2", css2, [sass2, sassCommon]);
|
| +
|
| + InspectorTest.runTestSuite([
|
| + function loadFileSystemResources(next)
|
| + {
|
| + var fs = new InspectorTest.TestFileSystem(fileSystemPrefix);
|
| + fs.addFileMapping(fileSystemPrefix, "/");
|
| + fs.root.addFile("common.scss", "<common.scss content>");
|
| + fs.root.addFile("a.scss", "<a.scss content>");
|
| + fs.root.addFile("b.scss", "<b.scss content>");
|
| + fs.reportCreated(next);
|
| + },
|
| +
|
| + function loadCSSResources(next)
|
| + {
|
| + InspectorTest.evaluateInPage("addStyleSheets()", next);
|
| + },
|
| +
|
| + function mutateCSS(next)
|
| + {
|
| + InspectorTest.updateCSSText(css1, "<all.css update 1>")
|
| + .then(checkOutdated)
|
| + .then(() => InspectorTest.updateCSSText(css2, "<print.css update 1>"))
|
| + .then(checkOutdated)
|
| + .then(() => requestContent([css1], [css2]))
|
| + .then(checkOutdated)
|
| + .then(next);
|
| + },
|
| +
|
| + function mutateSASS(next)
|
| + {
|
| + InspectorTest.updateSASSText(sass1, "<a.scss update 1>");
|
| + checkOutdated();
|
| + InspectorTest.updateSASSText(sass2, "<b.scss update 1>");
|
| + checkOutdated();
|
| + requestContent([sass1], [sass2])
|
| + .then(checkOutdated)
|
| + .then(next);
|
| + },
|
| +
|
| + function mutateSASSCommon(next)
|
| + {
|
| + InspectorTest.updateSASSText(sassCommon, "<common.scss update 1>");
|
| + checkOutdated();
|
| + requestContent([sassCommon], [sassCommon])
|
| + .then(checkOutdated)
|
| + .then(next);
|
| + },
|
| +
|
| + function clientSetCSS(next)
|
| + {
|
| + var result = client1.setCSSText("<all.css CLIENT 1>", []);
|
| + InspectorTest.addResult("client1.setCSSText result: " + result);
|
| + var result = client2.setCSSText("<print.css CLIENT 2>", []);
|
| + InspectorTest.addResult("client2.setCSSText result: " + result);
|
| + requestContent([css1], [css2])
|
| + .then(next);
|
| + },
|
| +
|
| + function clientSetSASSCommon(next)
|
| + {
|
| + var result = client1.setSASSText(sassCommon, "<common.scss CLIENT 1>");
|
| + InspectorTest.addResult("client1.setSASSText result: " + result);
|
| + awaitSourceChanges(client2, sassCommon)
|
| + .then(checkOutdated)
|
| + .then(next);
|
| + },
|
| +
|
| + function removeStyleSheets(next)
|
| + {
|
| + InspectorTest.evaluateInPage("removeStyles()", next);
|
| + },
|
| + ]);
|
| +
|
| + function awaitSourceChanges(client, url)
|
| + {
|
| + var callback;
|
| + var promise = new Promise(fulfill => callback = fulfill);
|
| + client.addEventListener(WebInspector.SASSWorkspaceAdapter.ClientEvents.SourceChanged, onSourceChanged);
|
| + return promise;
|
| +
|
| + function onSourceChanged(event)
|
| + {
|
| + if (event.data !== url)
|
| + return;
|
| + client.removeEventListener(WebInspector.SASSWorkspaceAdapter.ClientEvents.SourceChanged, onSourceChanged);
|
| + callback();
|
| + }
|
| + }
|
| +
|
| + function checkOutdated()
|
| + {
|
| + InspectorTest.addResult("== Outdated ==");
|
| + InspectorTest.addResult(client1.__NAME + ": " + client1.isOutdated());
|
| + InspectorTest.addResult(client2.__NAME + ": " + client2.isOutdated());
|
| + }
|
| +
|
| + function requestContent(urls1, urls2)
|
| + {
|
| + InspectorTest.addResult("== Contents ==");
|
| + urls1 = urls1 || [];
|
| + urls2 = urls2 || [];
|
| + var onContent = (url, content) => InspectorTest.addResult("content of " + url + ": " + content);
|
| + var promises = [];
|
| + for (var url of urls1)
|
| + promises.push(client1.content(url).then(text => onContent(url, text)));
|
| + for (var url of urls2)
|
| + promises.push(client2.content(url).then(text => onContent(url, text)));
|
| + return Promise.all(promises);
|
| + }
|
| +}
|
| +
|
| +</script>
|
| +
|
| +</head>
|
| +
|
| +<body onload="runTest()">
|
| +<p>Verify SASSWorkspaceAdapter.Clients handle external resource changes correctly.</p>
|
| +</body>
|
| +</html>
|
|
|