| OLD | NEW |
| 1 <html> | 1 <html> |
| 2 <head> | 2 <head> |
| 3 <script src="../../../http/tests/inspector/inspector-test.js"></script> | 3 <script src="../../../http/tests/inspector/inspector-test.js"></script> |
| 4 <script src="../../../http/tests/inspector/debugger-test.js"></script> | 4 <script src="../../../http/tests/inspector/debugger-test.js"></script> |
| 5 <script src="../../../http/tests/inspector/workspace-test.js"></script> | |
| 6 <script> | 5 <script> |
| 6 function addIframe() |
| 7 { |
| 8 var iframe = document.createElement("iframe"); |
| 9 iframe.setAttribute("src", "resources/syntax-error.html"); |
| 10 document.body.appendChild(iframe); |
| 11 } |
| 12 |
| 13 function addScript() |
| 14 { |
| 15 var script = document.createElement("script"); |
| 16 script.setAttribute("src", "resources/script1.js"); |
| 17 document.head.appendChild(script); |
| 18 } |
| 19 |
| 20 function addStyleSheet() |
| 21 { |
| 22 var style = document.createElement("link"); |
| 23 style.setAttribute("rel", "stylesheet"); |
| 24 style.setAttribute("type", "text/css"); |
| 25 style.setAttribute("href", "resources/style1.css"); |
| 26 document.head.appendChild(style); |
| 27 window._style = style; |
| 28 } |
| 29 |
| 30 function removeStyleSheet() |
| 31 { |
| 32 window._style.parentNode.removeChild(window._style); |
| 33 window._style = null; |
| 34 } |
| 35 |
| 7 function test() | 36 function test() |
| 8 { | 37 { |
| 9 var mockContentsMap = {}; | 38 var target = InspectorTest.mainTarget; |
| 10 var target; | |
| 11 var lastResourceId = 0; | |
| 12 var lastStyleSheetId = 0; | |
| 13 | 39 |
| 14 InspectorTest._defaultWorkspaceEventHandler = function() {} | 40 function uiSourceCodeURL(uiSourceCode) |
| 15 | |
| 16 function createMockStyleSheetHeader(url) | |
| 17 { | 41 { |
| 18 return { | 42 return uiSourceCode.url().replace(/.*LayoutTests/, "LayoutTests"); |
| 19 styleSheetId: (++lastStyleSheetId) + "", | |
| 20 sourceURL: url, | |
| 21 sourceMapURL: "", | |
| 22 origin: "regular", | |
| 23 title: "", | |
| 24 disabled: false | |
| 25 }; | |
| 26 } | 43 } |
| 27 | 44 |
| 28 function createResourceMock(type, content) | 45 function dumpUISourceCode(uiSourceCode, callback) |
| 29 { | 46 { |
| 30 var documentURL = "http://fake.url"; | 47 InspectorTest.addResult("UISourceCode: " + uiSourceCodeURL(uiSourceCode)
); |
| 31 var resourceId = ++lastResourceId + ""; | 48 if (uiSourceCode.contentType() === Common.resourceTypes.Script || uiSour
ceCode.contentType() === Common.resourceTypes.Document) |
| 32 var url = documentURL + "/" + resourceId; | 49 InspectorTest.addResult("UISourceCode is content script: " + (uiSour
ceCode.project().type() === Workspace.projectTypes.ContentScripts)); |
| 33 var frameId = "frame-id"; | 50 uiSourceCode.requestContent().then(didRequestContent); |
| 34 var loaderId = "loader-id"; | 51 |
| 35 var mimeType; | 52 function didRequestContent(content, contentEncoded) |
| 36 switch (type) { | 53 { |
| 37 case Common.resourceTypes.Document: | 54 InspectorTest.addResult("Highlighter type: " + Bindings.NetworkProje
ct.uiSourceCodeMimeType(uiSourceCode)); |
| 38 mimeType = "text/html"; | 55 InspectorTest.addResult("UISourceCode content: " + content); |
| 39 break; | 56 callback(); |
| 40 case Common.resourceTypes.Script: | |
| 41 mimeType = "text/javascript"; | |
| 42 break; | |
| 43 case Common.resourceTypes.Stylesheet: | |
| 44 mimeType = "text/css"; | |
| 45 break; | |
| 46 } | 57 } |
| 47 | |
| 48 var resource = new SDK.Resource(target, null, url, documentURL, frameId,
loaderId, type, mimeType); | |
| 49 resource._content = content; | |
| 50 target.resourceTreeModel.dispatchEventToListeners(SDK.ResourceTreeModel.
Events.ResourceAdded, resource); | |
| 51 | |
| 52 return resource; | |
| 53 } | |
| 54 | |
| 55 function createScriptMock(content) | |
| 56 { | |
| 57 var documentURL = "http://fake.url"; | |
| 58 var resourceId = ++lastResourceId + ""; | |
| 59 var url = documentURL + "/" + resourceId; | |
| 60 var script = InspectorTest.createScriptMock(url, 0, 0, false, content, t
arget); | |
| 61 target.debuggerModel.dispatchEventToListeners(SDK.DebuggerModel.Events.P
arsedScriptSource, script); | |
| 62 } | |
| 63 | |
| 64 function finishResource(resource) | |
| 65 { | |
| 66 resource.request.finished = true; | |
| 67 resource.request.dispatchEventToListeners(SDK.NetworkRequest.Events.Fini
shedLoading, resource.request); | |
| 68 } | |
| 69 | |
| 70 function createNetworkUISourceCodeProvider() | |
| 71 { | |
| 72 target = InspectorTest.createWorkspaceWithTarget(true); | |
| 73 } | 58 } |
| 74 | 59 |
| 75 InspectorTest.runTestSuite([ | 60 InspectorTest.runTestSuite([ |
| 76 function testDocumentResource(next) | 61 function testDocumentResource(next) |
| 77 { | 62 { |
| 78 createNetworkUISourceCodeProvider(); | |
| 79 InspectorTest.addResult("Creating resource."); | 63 InspectorTest.addResult("Creating resource."); |
| 80 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdd
ed); | 64 InspectorTest.waitForUISourceCode(uiSourceCodeAdded, "resources/synt
ax-error.html"); |
| 81 createResourceMock(Common.resourceTypes.Document, "<document resourc
e content>"); | 65 InspectorTest.evaluateInPage("addIframe()"); |
| 82 | 66 |
| 83 function uiSourceCodeAdded(uiSourceCode) | 67 function uiSourceCodeAdded(uiSourceCode) |
| 84 { | 68 { |
| 85 // setTimeouts are necessary since same event finalizes uiSource
Code creation. | 69 dumpUISourceCode(uiSourceCode, next); |
| 86 setTimeout(function() { InspectorTest.dumpUISourceCode(uiSourceC
ode, next); }); | |
| 87 } | 70 } |
| 88 }, | 71 }, |
| 89 | 72 |
| 90 function testScriptResourceAndVMScript(next) | 73 function testVMScript(next) |
| 91 { | 74 { |
| 92 createNetworkUISourceCodeProvider(); | |
| 93 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdd
ed); | |
| 94 InspectorTest.addResult("Creating script resource."); | |
| 95 createResourceMock(Common.resourceTypes.Script, "<script resource co
ntent>"); | |
| 96 InspectorTest.addResult("Creating script."); | 75 InspectorTest.addResult("Creating script."); |
| 97 createScriptMock("<script content>"); | 76 InspectorTest.evaluateInPage("var foo=1;\n//# sourceURL=foo.js\n"); |
| 77 InspectorTest.waitForUISourceCode(uiSourceCodeAdded, "foo.js"); |
| 98 | 78 |
| 99 function uiSourceCodeAdded(uiSourceCode) | 79 function uiSourceCodeAdded(uiSourceCode) |
| 100 { | 80 { |
| 101 setTimeout(function() { InspectorTest.dumpUISourceCode(uiSourceC
ode, next); }); | 81 dumpUISourceCode(uiSourceCode, next); |
| 102 } | 82 } |
| 103 }, | 83 }, |
| 104 | 84 |
| 105 function testRemoveStyleSheetFromModelWithComplexURL(next) | 85 function testScriptResource(next) |
| 106 { | 86 { |
| 107 var mockStyleSheetHeader = createMockStyleSheetHeader("http://exampl
e.com/foo.css"); | 87 InspectorTest.addResult("Creating script resource."); |
| 108 testRemoveStyleSheetFromModel(mockStyleSheetHeader, next); | 88 InspectorTest.evaluateInPage("addScript()"); |
| 89 InspectorTest.waitForUISourceCode(uiSourceCodeAdded, "script1.js"); |
| 90 |
| 91 function uiSourceCodeAdded(uiSourceCode) |
| 92 { |
| 93 dumpUISourceCode(uiSourceCode, next); |
| 94 } |
| 109 }, | 95 }, |
| 110 | 96 |
| 111 function testRemoveStyleSheetFromModelWithSimpleURL(next) | 97 function testRemoveStyleSheetFromModel(next) |
| 112 { | 98 { |
| 113 var mockStyleSheetHeader = createMockStyleSheetHeader("foo.css"); | 99 InspectorTest.waitForUISourceCode(uiSourceCodeAdded, "style1.css"); |
| 114 testRemoveStyleSheetFromModel(mockStyleSheetHeader, next); | 100 InspectorTest.addResult("Creating stylesheet resource."); |
| 101 InspectorTest.evaluateInPage(`addStyleSheet()`); |
| 102 |
| 103 function uiSourceCodeAdded(uiSourceCode) |
| 104 { |
| 105 InspectorTest.addResult("Added uiSourceCode: " + uiSourceCodeURL
(uiSourceCode)); |
| 106 InspectorTest.waitForUISourceCodeRemoved(uiSourceCodeRemoved); |
| 107 InspectorTest.evaluateInPage("removeStyleSheet()"); |
| 108 } |
| 109 |
| 110 function uiSourceCodeRemoved(uiSourceCode) |
| 111 { |
| 112 InspectorTest.addResult("Removed uiSourceCode: " + uiSourceCodeU
RL(uiSourceCode)); |
| 113 next(); |
| 114 } |
| 115 } | 115 } |
| 116 ]); | 116 ]); |
| 117 | |
| 118 function testRemoveStyleSheetFromModel(mockStyleSheetHeader, callback) | |
| 119 { | |
| 120 createNetworkUISourceCodeProvider(); | |
| 121 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded); | |
| 122 InspectorTest.addResult("Creating stylesheet resource."); | |
| 123 createResourceMock(Common.resourceTypes.Stylesheet, "<stylesheet resourc
e content>"); | |
| 124 | |
| 125 SDK.CSSModel.fromTarget(target)._styleSheetAdded(mockStyleSheetHeader); | |
| 126 | |
| 127 function uiSourceCodeAdded(uiSourceCode) | |
| 128 { | |
| 129 InspectorTest.addResult("Added uiSourceCode: " + InspectorTest.uiSou
rceCodeURL(uiSourceCode)); | |
| 130 InspectorTest.waitForWorkspaceUISourceCodeRemovedEvent(uiSourceCodeR
emoved); | |
| 131 SDK.CSSModel.fromTarget(target)._styleSheetRemoved(mockStyleSheetHea
der.styleSheetId); | |
| 132 } | |
| 133 | |
| 134 function uiSourceCodeRemoved(uiSourceCode) | |
| 135 { | |
| 136 InspectorTest.addResult("Removed uiSourceCode: " + InspectorTest.uiS
ourceCodeURL(uiSourceCode)); | |
| 137 callback(); | |
| 138 } | |
| 139 } | |
| 140 }; | 117 }; |
| 141 </script> | 118 </script> |
| 142 </head> | 119 </head> |
| 143 <body onload="runTest()"> | 120 <body onload="runTest()"> |
| 144 <p>Tests NetworkUISourceCodeProvider class.</p> | 121 <p>Tests NetworkUISourceCodeProvider class.</p> |
| 145 </body> | 122 </body> |
| 146 </html> | 123 </html> |
| OLD | NEW |