OLD | NEW |
(Empty) | |
| 1 <html> |
| 2 <head> |
| 3 |
| 4 <script src="../../http/tests/inspector/inspector-test.js"></script> |
| 5 <script src="../../http/tests/inspector/debugger-test.js"></script> |
| 6 <script src="../../http/tests/inspector/isolated-filesystem-test.js"></script> |
| 7 <script src="./sass-test.js"></script> |
| 8 <script> |
| 9 |
| 10 var styles = []; |
| 11 function addStyleSheets() |
| 12 { |
| 13 for (var i = 0; i < 2; ++i) { |
| 14 var style = document.createElement("style"); |
| 15 style.textContent = "<all.css content>\n/*# sourceURL=all.css */"; |
| 16 document.head.appendChild(style); |
| 17 styles.push(style); |
| 18 } |
| 19 |
| 20 var style = document.createElement("style"); |
| 21 style.textContent = "<print.css content>\n/*# sourceURL=print.css */"; |
| 22 document.head.appendChild(style); |
| 23 styles.push(style); |
| 24 } |
| 25 |
| 26 function removeStyles() |
| 27 { |
| 28 for (var style of styles) |
| 29 style.remove(); |
| 30 } |
| 31 |
| 32 function test() |
| 33 { |
| 34 function createClient(clientName, cssURL, sassURLs) |
| 35 { |
| 36 var sources = sassURLs; |
| 37 var fakeSourceMap = { |
| 38 sources: () => sources, |
| 39 compiledURL: () => cssURL |
| 40 }; |
| 41 var client = InspectorTest.sassWorkspaceAdapter().trackSources(fakeSourc
eMap); |
| 42 client.__NAME = clientName; |
| 43 client.addEventListener(WebInspector.SASSWorkspaceAdapter.ClientEvents.S
ourceChanged, onSourceChanged); |
| 44 client.addEventListener(WebInspector.SASSWorkspaceAdapter.ClientEvents.T
rackingStopped, onTrackingStopped); |
| 45 return client; |
| 46 |
| 47 function onSourceChanged(event) |
| 48 { |
| 49 InspectorTest.addResult(" -- " + event.target.__NAME + " -- SourceCh
anged event: " + event.data); |
| 50 } |
| 51 |
| 52 function onTrackingStopped(event) |
| 53 { |
| 54 InspectorTest.addResult(" -- " + event.target.__NAME + " -- Tracking
Stopped"); |
| 55 } |
| 56 } |
| 57 |
| 58 var fileSystemPrefix = "file:///var/www"; |
| 59 var css1 = "all.css"; |
| 60 var css2 = "print.css"; |
| 61 var sass1 = fileSystemPrefix + "/a.scss"; |
| 62 var sass2 = fileSystemPrefix + "/b.scss"; |
| 63 var sassCommon = fileSystemPrefix + "/common.scss"; |
| 64 var client1 = createClient("CLIENT 1", css1, [sass1, sassCommon]); |
| 65 var client2 = createClient("CLIENT 2", css2, [sass2, sassCommon]); |
| 66 |
| 67 InspectorTest.runTestSuite([ |
| 68 function loadFileSystemResources(next) |
| 69 { |
| 70 var fs = new InspectorTest.TestFileSystem(fileSystemPrefix); |
| 71 fs.addFileMapping(fileSystemPrefix, "/"); |
| 72 fs.root.addFile("common.scss", "<common.scss content>"); |
| 73 fs.root.addFile("a.scss", "<a.scss content>"); |
| 74 fs.root.addFile("b.scss", "<b.scss content>"); |
| 75 fs.reportCreated(next); |
| 76 }, |
| 77 |
| 78 function loadCSSResources(next) |
| 79 { |
| 80 InspectorTest.evaluateInPage("addStyleSheets()", next); |
| 81 }, |
| 82 |
| 83 function mutateCSS(next) |
| 84 { |
| 85 InspectorTest.updateCSSText(css1, "<all.css update 1>") |
| 86 .then(checkOutdated) |
| 87 .then(() => InspectorTest.updateCSSText(css2, "<print.css update
1>")) |
| 88 .then(checkOutdated) |
| 89 .then(() => requestContent([css1], [css2])) |
| 90 .then(checkOutdated) |
| 91 .then(next); |
| 92 }, |
| 93 |
| 94 function mutateSASS(next) |
| 95 { |
| 96 InspectorTest.updateSASSText(sass1, "<a.scss update 1>"); |
| 97 checkOutdated(); |
| 98 InspectorTest.updateSASSText(sass2, "<b.scss update 1>"); |
| 99 checkOutdated(); |
| 100 requestContent([sass1], [sass2]) |
| 101 .then(checkOutdated) |
| 102 .then(next); |
| 103 }, |
| 104 |
| 105 function mutateSASSCommon(next) |
| 106 { |
| 107 InspectorTest.updateSASSText(sassCommon, "<common.scss update 1>"); |
| 108 checkOutdated(); |
| 109 requestContent([sassCommon], [sassCommon]) |
| 110 .then(checkOutdated) |
| 111 .then(next); |
| 112 }, |
| 113 |
| 114 function clientSetCSS(next) |
| 115 { |
| 116 var result = client1.setCSSText("<all.css CLIENT 1>", []); |
| 117 InspectorTest.addResult("client1.setCSSText result: " + result); |
| 118 var result = client2.setCSSText("<print.css CLIENT 2>", []); |
| 119 InspectorTest.addResult("client2.setCSSText result: " + result); |
| 120 requestContent([css1], [css2]) |
| 121 .then(next); |
| 122 }, |
| 123 |
| 124 function clientSetSASSCommon(next) |
| 125 { |
| 126 var result = client1.setSASSText(sassCommon, "<common.scss CLIENT 1>
"); |
| 127 InspectorTest.addResult("client1.setSASSText result: " + result); |
| 128 awaitSourceChanges(client2, sassCommon) |
| 129 .then(checkOutdated) |
| 130 .then(next); |
| 131 }, |
| 132 |
| 133 function removeStyleSheets(next) |
| 134 { |
| 135 InspectorTest.evaluateInPage("removeStyles()", next); |
| 136 }, |
| 137 ]); |
| 138 |
| 139 function awaitSourceChanges(client, url) |
| 140 { |
| 141 var callback; |
| 142 var promise = new Promise(fulfill => callback = fulfill); |
| 143 client.addEventListener(WebInspector.SASSWorkspaceAdapter.ClientEvents.S
ourceChanged, onSourceChanged); |
| 144 return promise; |
| 145 |
| 146 function onSourceChanged(event) |
| 147 { |
| 148 if (event.data !== url) |
| 149 return; |
| 150 client.removeEventListener(WebInspector.SASSWorkspaceAdapter.ClientE
vents.SourceChanged, onSourceChanged); |
| 151 callback(); |
| 152 } |
| 153 } |
| 154 |
| 155 function checkOutdated() |
| 156 { |
| 157 InspectorTest.addResult("== Outdated =="); |
| 158 InspectorTest.addResult(client1.__NAME + ": " + client1.isOutdated()); |
| 159 InspectorTest.addResult(client2.__NAME + ": " + client2.isOutdated()); |
| 160 } |
| 161 |
| 162 function requestContent(urls1, urls2) |
| 163 { |
| 164 InspectorTest.addResult("== Contents =="); |
| 165 urls1 = urls1 || []; |
| 166 urls2 = urls2 || []; |
| 167 var onContent = (url, content) => InspectorTest.addResult("content of "
+ url + ": " + content); |
| 168 var promises = []; |
| 169 for (var url of urls1) |
| 170 promises.push(client1.content(url).then(text => onContent(url, text)
)); |
| 171 for (var url of urls2) |
| 172 promises.push(client2.content(url).then(text => onContent(url, text)
)); |
| 173 return Promise.all(promises); |
| 174 } |
| 175 } |
| 176 |
| 177 </script> |
| 178 |
| 179 </head> |
| 180 |
| 181 <body onload="runTest()"> |
| 182 <p>Verify SASSWorkspaceAdapter.Clients handle external resource changes correctl
y.</p> |
| 183 </body> |
| 184 </html> |
OLD | NEW |