blob: 3411ce1fc750e1b148e2273df16c5ec8b13d06ea [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../http/tests/inspector/resources/inspector-test.js"></script>
<script>
function test()
{
let mainFrame = WI.networkManager.mainFrame;
let childFrames = Array.from(mainFrame.childFrameCollection);
InspectorTest.expectEqual(childFrames.length, 1, "Page should have a subframe.");
let suite = InspectorTest.createAsyncSuite("CSSManager.preferredInspectorStyleSheetForFrame");
suite.addTestCase({
name: "CheckNoStyleSheets",
description: "Ensure there are no stylesheets.",
test(resolve, reject) {
InspectorTest.expectThat(WI.cssManager.styleSheets.length === 0, "Should be no stylesheets.");
resolve();
}
});
suite.addTestCase({
name: "CreateMainFrameInspectorStyleSheet",
description: "First request for main frame should create inspector stylesheet.",
test(resolve, reject) {
WI.cssManager.singleFireEventListener(WI.CSSManager.Event.StyleSheetAdded, (event) => {
InspectorTest.expectThat(event.data.styleSheet.origin === WI.CSSStyleSheet.Type.Inspector, "Added StyleSheet origin should be 'inspector'.");
InspectorTest.expectThat(event.data.styleSheet.isInspectorStyleSheet(), "StyleSheet.isInspectorStyleSheet() should be true.");
InspectorTest.expectThat(event.data.styleSheet.parentFrame === mainFrame, "Added StyleSheet frame should be the main frame.");
});
WI.cssManager.preferredInspectorStyleSheetForFrame(mainFrame, (styleSheet) => {
InspectorTest.expectThat(WI.cssManager.styleSheets.length === 1, "Should be one stylesheet.");
InspectorTest.expectThat(styleSheet.origin === WI.CSSStyleSheet.Type.Inspector, "StyleSheet origin is inspector.");
InspectorTest.expectThat(styleSheet.isInspectorStyleSheet(), "StyleSheet.isInspectorStyleSheet() should be true.");
resolve();
});
}
});
suite.addTestCase({
name: "AnotherMainFrameRequestDoesNothing",
description: "Second request for main frame should not create a new stylesheet.",
test(resolve, reject) {
let listener = WI.cssManager.singleFireEventListener(WI.CSSManager.Event.StyleSheetAdded, (event) => {
InspectorTest.assert(false, "Should not create a new StyleSheet, should reuse the existing one");
});
WI.cssManager.preferredInspectorStyleSheetForFrame(mainFrame, (styleSheet) => {
InspectorTest.expectThat(WI.cssManager.styleSheets.length === 1, "Should still be one stylesheet.");
InspectorTest.expectThat(styleSheet.origin === WI.CSSStyleSheet.Type.Inspector, "StyleSheet origin should be 'inspector'.");
InspectorTest.expectThat(styleSheet.isInspectorStyleSheet(), "StyleSheet.isInspectorStyleSheet() should be true.");
WI.cssManager.removeEventListener(WI.CSSManager.Event.StyleSheetAdded, listener, null);
resolve();
});
}
});
suite.addTestCase({
name: "CreateSubFrameInspectorStyleSheet",
description: "First request for subframe should create inspector stylesheet.",
test(resolve, reject) {
WI.cssManager.singleFireEventListener(WI.CSSManager.Event.StyleSheetAdded, (event) => {
InspectorTest.expectThat(event.data.styleSheet.origin === WI.CSSStyleSheet.Type.Inspector, "Added StyleSheet origin should be 'inspector'.");
InspectorTest.expectThat(event.data.styleSheet.isInspectorStyleSheet(), "StyleSheet.isInspectorStyleSheet() should be true.");
InspectorTest.expectThat(event.data.styleSheet.parentFrame === childFrames[0], "Added StyleSheet frame should be a child frame.");
});
WI.cssManager.preferredInspectorStyleSheetForFrame(childFrames[0], (styleSheet) => {
InspectorTest.expectThat(WI.cssManager.styleSheets.length === 2, "Should be two stylesheets.");
InspectorTest.expectThat(styleSheet.origin === WI.CSSStyleSheet.Type.Inspector, "StyleSheet origin should be 'inspector'.");
InspectorTest.expectThat(styleSheet.isInspectorStyleSheet(), "StyleSheet.isInspectorStyleSheet() should be true.");
resolve();
});
}
});
suite.addTestCase({
name: "AnotherSubFrameRequestDoesNothing",
description: "Second request for main frame should not create a new stylesheet.",
test(resolve, reject) {
let listener = WI.cssManager.singleFireEventListener(WI.CSSManager.Event.StyleSheetAdded, (event) => {
InspectorTest.assert(false, "Should not create a new StyleSheet, should reuse the existing one");
});
WI.cssManager.preferredInspectorStyleSheetForFrame(childFrames[0], (styleSheet) => {
InspectorTest.expectThat(WI.cssManager.styleSheets.length === 2, "Should be two stylesheets.");
InspectorTest.expectThat(styleSheet.origin === WI.CSSStyleSheet.Type.Inspector, "StyleSheet origin should be 'inspector'.");
InspectorTest.expectThat(styleSheet.isInspectorStyleSheet(), "StyleSheet.isInspectorStyleSheet() should be true.");
WI.cssManager.removeEventListener(WI.CSSManager.Event.StyleSheetAdded, listener, null);
resolve();
});
}
});
WI.cssManager.singleFireEventListener(WI.CSSManager.Event.StyleSheetRemoved, function(event) {
InspectorTest.assert(false, "Should not be removing any StyleSheets in this test.");
});
suite.runTestCasesAndFinish();
}
</script>
</head>
<body onload="runTest()">
<p>Test CSSManager.preferredInspectorStyleSheetForFrame.</p>
<iframe src="about:blank"></iframe>
</body>
</html>