3 <script type=
"text/javascript" src=
"../http/tests/inspector-protocol/inspector-protocol-test.js"></script>
8 function createStyleSheet(textContent
)
10 var styleElement
= document
.createElement("style");
11 styleElement
.textContent
= textContent
;
12 document
.head
.appendChild(styleElement
);
16 function reopenWebInspector()
18 setTimeout(deferredReopening
, 0);
20 function deferredReopening()
22 log("Closing inspector.\n");
25 log("Removing style sheet.\n");
26 document
.head
.removeChild(styleElement1
);
27 log("Reopening inspector.");
32 function openWebInspector()
34 delete window
.didReopen
;
35 styleElement1
= createStyleSheet("body.class1 { color: red; } \n /*# sourceURL=foo.css */");
36 styleElement2
= createStyleSheet("body.class2 { color: green; } \n /*# sourceURL=bar.css */");
42 InspectorTest
.log("Running test");
43 InspectorTest
.sendCommand("Runtime.evaluate", {"expression": "window.didReopen"}, dispatch
);
45 function dispatch(response
)
47 var result
= response
.result
.result
;
48 if (result
.type
!== "number") {
49 InspectorTest
.log("Opening front-end for the first time");
50 runTests(reopenInspector
);
52 InspectorTest
.log("Opening front-end second time");
53 runTests(InspectorTest
.completeTest
.bind(InspectorTest
));
57 function reopenInspector()
59 InspectorTest
.sendCommand("Runtime.evaluate", {"expression": "reopenWebInspector()"});
62 function runTests(callback
)
64 InspectorTest
.eventHandler
["CSS.styleSheetAdded"] = styleSheetAdded
;
65 InspectorTest
.eventHandler
["CSS.styleSheetRemoved"] = styleSheetRemoved
;
66 var headersAdded
= [];
67 var headersRemoved
= [];
69 function styleSheetAdded(response
)
71 headersAdded
.push(response
.params
.header
);
74 function styleSheetRemoved(response
)
76 headersRemoved
.push(response
.params
.styleSheetId
);
79 InspectorTest
.log("Enabling CSS domain.");
80 InspectorTest
.sendCommandOrDie("DOM.enable", {});
81 InspectorTest
.sendCommand("CSS.enable", {}, wasEnabled
);
85 function compareFunction(a
, b
)
87 return a
.styleSheetId
- b
.styleSheetId
;
91 headersAdded
.sort(compareFunction
);
92 for (var i
= 0; i
< headersAdded
.length
; ++i
) {
93 var header
= headersAdded
[i
];
94 headers
[header
.styleSheetId
] = header
.sourceURL
;
95 InspectorTest
.log(" - style sheet added: " + header
.sourceURL
);
98 headersRemoved
.sort();
99 for (var i
= 0; i
< headersRemoved
.length
; ++i
)
100 InspectorTest
.log(" - style sheet removed: " + headers
[headersRemoved
[i
]]);
108 <body onload=
"openWebInspector()">
109 <p>This test checks that if style sheet is removed between two inspector launches it is not reported to frontend.
</p>