OLD | NEW |
(Empty) | |
| 1 (async function() { |
| 2 InspectorTest.log('This test checks that if style sheet is removed between two
inspector launches it is not reported to frontend.'); |
| 3 var page = await InspectorTest.createPage(); |
| 4 var session = await page.createSession(); |
| 5 |
| 6 await session.evaluate(` |
| 7 function createStyleSheet(textContent) |
| 8 { |
| 9 var styleElement = document.createElement('style'); |
| 10 styleElement.textContent = textContent; |
| 11 document.head.appendChild(styleElement); |
| 12 return styleElement; |
| 13 } |
| 14 |
| 15 window.styleElement1 = createStyleSheet('body.class1 { color: red; } \\n /*#
sourceURL=foo.css */'); |
| 16 window.styleElement2 = createStyleSheet('body.class2 { color: green; } \\n /
*# sourceURL=bar.css */'); |
| 17 `); |
| 18 |
| 19 InspectorTest.log('\nRunning test'); |
| 20 InspectorTest.log('Opening front-end for the first time'); |
| 21 await runTest(session); |
| 22 InspectorTest.log('Closing inspector.'); |
| 23 InspectorTest.log('\nRemoving style sheet.\n'); |
| 24 session.evaluate('setTimeout(() => document.head.removeChild(styleElement1), 0
)'); |
| 25 await session.disconnect(); |
| 26 |
| 27 InspectorTest.log('Reopening inspector.'); |
| 28 session = await page.createSession(); |
| 29 InspectorTest.log('Running test'); |
| 30 InspectorTest.log('Opening front-end second time'); |
| 31 await runTest(session); |
| 32 InspectorTest.completeTest(); |
| 33 })(); |
| 34 |
| 35 async function runTest(session) { |
| 36 var headersAdded = []; |
| 37 session.Protocol.CSS.onStyleSheetAdded(response => headersAdded.push(response.
params.header)); |
| 38 |
| 39 var headersRemoved = []; |
| 40 session.Protocol.CSS.onStyleSheetRemoved(response => headersRemoved.push(respo
nse.params.styleSheetId)); |
| 41 |
| 42 InspectorTest.log('Enabling CSS domain.'); |
| 43 session.Protocol.DOM.enable(); |
| 44 await session.Protocol.CSS.enable(); |
| 45 |
| 46 var headers = {}; |
| 47 headersAdded.sort((a, b) => a.styleSheetId - b.styleSheetId); |
| 48 for (var header of headersAdded) { |
| 49 headers[header.styleSheetId] = header.sourceURL; |
| 50 InspectorTest.log(' - style sheet added: ' + header.sourceURL); |
| 51 } |
| 52 |
| 53 headersRemoved.sort(); |
| 54 for (var styleSheetId of headersRemoved) |
| 55 InspectorTest.log(' - style sheet removed: ' + headers[styleSheetId]); |
| 56 } |
OLD | NEW |