| <!DOCTYPE html> |
| <html> |
| <head> |
| <script src="../../http/tests/inspector/resources/inspector-test.js"></script> |
| <script> |
| function test() |
| { |
| let mainFrame = WI.frameResourceManager.mainFrame; |
| let childFrames = mainFrame.childFrameCollection.toArray(); |
| 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.cssStyleManager.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.cssStyleManager.singleFireEventListener(WI.CSSStyleManager.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.cssStyleManager.preferredInspectorStyleSheetForFrame(mainFrame, (styleSheet) => { |
| InspectorTest.expectThat(WI.cssStyleManager.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.cssStyleManager.singleFireEventListener(WI.CSSStyleManager.Event.StyleSheetAdded, (event) => { |
| InspectorTest.assert(false, "Should not create a new StyleSheet, should reuse the existing one"); |
| }); |
| WI.cssStyleManager.preferredInspectorStyleSheetForFrame(mainFrame, (styleSheet) => { |
| InspectorTest.expectThat(WI.cssStyleManager.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.cssStyleManager.removeEventListener(WI.CSSStyleManager.Event.StyleSheetAdded, listener, null); |
| resolve(); |
| }); |
| } |
| }); |
| |
| suite.addTestCase({ |
| name: "CreateSubFrameInspectorStyleSheet", |
| description: "First request for subframe should create inspector stylesheet.", |
| test(resolve, reject) { |
| WI.cssStyleManager.singleFireEventListener(WI.CSSStyleManager.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.cssStyleManager.preferredInspectorStyleSheetForFrame(childFrames[0], (styleSheet) => { |
| InspectorTest.expectThat(WI.cssStyleManager.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.cssStyleManager.singleFireEventListener(WI.CSSStyleManager.Event.StyleSheetAdded, (event) => { |
| InspectorTest.assert(false, "Should not create a new StyleSheet, should reuse the existing one"); |
| }); |
| WI.cssStyleManager.preferredInspectorStyleSheetForFrame(childFrames[0], (styleSheet) => { |
| InspectorTest.expectThat(WI.cssStyleManager.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.cssStyleManager.removeEventListener(WI.CSSStyleManager.Event.StyleSheetAdded, listener, null); |
| resolve(); |
| }); |
| } |
| }); |
| |
| WI.cssStyleManager.singleFireEventListener(WI.CSSStyleManager.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> |