| OLD | NEW |
| (Empty) |
| 1 <html> | |
| 2 <head> | |
| 3 <script src="../../../http/tests/inspector/inspector-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> | |
| 7 function test() | |
| 8 { | |
| 9 var mockContentsMap = {}; | |
| 10 var target; | |
| 11 var lastResourceId = 0; | |
| 12 var lastStyleSheetId = 0; | |
| 13 | |
| 14 InspectorTest._defaultWorkspaceEventHandler = function() {} | |
| 15 | |
| 16 function createMockStyleSheetHeader(url) | |
| 17 { | |
| 18 return { | |
| 19 styleSheetId: (++lastStyleSheetId) + "", | |
| 20 sourceURL: url, | |
| 21 sourceMapURL: "", | |
| 22 origin: "regular", | |
| 23 title: "", | |
| 24 disabled: false | |
| 25 }; | |
| 26 } | |
| 27 | |
| 28 function createResourceMock(type, content) | |
| 29 { | |
| 30 var documentURL = "http://fake.url"; | |
| 31 var resourceId = ++lastResourceId + ""; | |
| 32 var url = documentURL + "/" + resourceId; | |
| 33 var frameId = "frame-id"; | |
| 34 var loaderId = "loader-id"; | |
| 35 var mimeType; | |
| 36 switch (type) { | |
| 37 case WebInspector.resourceTypes.Document: | |
| 38 mimeType = "text/html"; | |
| 39 break; | |
| 40 case WebInspector.resourceTypes.Script: | |
| 41 mimeType = "text/javascript"; | |
| 42 break; | |
| 43 case WebInspector.resourceTypes.Stylesheet: | |
| 44 mimeType = "text/css"; | |
| 45 break; | |
| 46 } | |
| 47 | |
| 48 var resource = new WebInspector.Resource(target, null, url, documentURL,
frameId, loaderId, type, mimeType); | |
| 49 resource._content = content; | |
| 50 target.resourceTreeModel.dispatchEventToListeners(WebInspector.ResourceT
reeModel.EventTypes.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(WebInspector.DebuggerModel
.Events.ParsedScriptSource, script); | |
| 62 } | |
| 63 | |
| 64 function finishResource(resource) | |
| 65 { | |
| 66 resource.request.finished = true; | |
| 67 resource.request.dispatchEventToListeners(WebInspector.NetworkRequest.Ev
ents.FinishedLoading, resource.request); | |
| 68 } | |
| 69 | |
| 70 function createNetworkUISourceCodeProvider() | |
| 71 { | |
| 72 target = InspectorTest.createWorkspaceWithTarget(true); | |
| 73 } | |
| 74 | |
| 75 InspectorTest.runTestSuite([ | |
| 76 function testDocumentResource(next) | |
| 77 { | |
| 78 createNetworkUISourceCodeProvider(); | |
| 79 InspectorTest.addResult("Creating resource."); | |
| 80 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdd
ed); | |
| 81 createResourceMock(WebInspector.resourceTypes.Document, "<document r
esource content>"); | |
| 82 | |
| 83 function uiSourceCodeAdded(uiSourceCode) | |
| 84 { | |
| 85 // setTimeouts are necessary since same event finalizes uiSource
Code creation. | |
| 86 setTimeout(function() { InspectorTest.dumpUISourceCode(uiSourceC
ode, next); }); | |
| 87 } | |
| 88 }, | |
| 89 | |
| 90 function testScriptResource(next) | |
| 91 { | |
| 92 createNetworkUISourceCodeProvider(); | |
| 93 InspectorTest.addResult("Creating resource."); | |
| 94 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdd
ed); | |
| 95 createResourceMock(WebInspector.resourceTypes.Script, "<script resou
rce content>"); | |
| 96 | |
| 97 function uiSourceCodeAdded(uiSourceCode) | |
| 98 { | |
| 99 setTimeout(function() { InspectorTest.dumpUISourceCode(uiSourceC
ode, next); }); | |
| 100 } | |
| 101 }, | |
| 102 | |
| 103 function testVMScript(next) | |
| 104 { | |
| 105 createNetworkUISourceCodeProvider(); | |
| 106 InspectorTest.addResult("Creating script."); | |
| 107 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdd
ed); | |
| 108 createScriptMock("<script content>"); | |
| 109 | |
| 110 function uiSourceCodeAdded(uiSourceCode) | |
| 111 { | |
| 112 setTimeout(function() { InspectorTest.dumpUISourceCode(uiSourceC
ode, next); }); | |
| 113 } | |
| 114 }, | |
| 115 | |
| 116 function testStylesheetResource(next) | |
| 117 { | |
| 118 createNetworkUISourceCodeProvider(); | |
| 119 InspectorTest.addResult("Creating resource."); | |
| 120 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdd
ed); | |
| 121 createResourceMock(WebInspector.resourceTypes.Stylesheet, "<styleshe
et resource content>"); | |
| 122 | |
| 123 function uiSourceCodeAdded(uiSourceCode) | |
| 124 { | |
| 125 setTimeout(function() { InspectorTest.dumpUISourceCode(uiSourceC
ode, next); }); | |
| 126 } | |
| 127 }, | |
| 128 | |
| 129 function testRemoveStyleSheetFromModelWithComplexURL(next) | |
| 130 { | |
| 131 var mockStyleSheetHeader = createMockStyleSheetHeader("http://exampl
e.com/foo.css"); | |
| 132 testRemoveStyleSheetFromModel(mockStyleSheetHeader, next); | |
| 133 }, | |
| 134 | |
| 135 function testRemoveStyleSheetFromModelWithSimpleURL(next) | |
| 136 { | |
| 137 var mockStyleSheetHeader = createMockStyleSheetHeader("foo.css"); | |
| 138 testRemoveStyleSheetFromModel(mockStyleSheetHeader, next); | |
| 139 } | |
| 140 ]); | |
| 141 | |
| 142 function testRemoveStyleSheetFromModel(mockStyleSheetHeader, callback) | |
| 143 { | |
| 144 createNetworkUISourceCodeProvider(); | |
| 145 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded); | |
| 146 WebInspector.CSSStyleModel.fromTarget(target)._styleSheetAdded(mockStyle
SheetHeader); | |
| 147 | |
| 148 function uiSourceCodeAdded(uiSourceCode) | |
| 149 { | |
| 150 InspectorTest.addResult("Added uiSourceCode: " + InspectorTest.uiSou
rceCodeURL(uiSourceCode)); | |
| 151 InspectorTest.waitForWorkspaceUISourceCodeRemovedEvent(uiSourceCodeR
emoved); | |
| 152 WebInspector.CSSStyleModel.fromTarget(target)._styleSheetRemoved(moc
kStyleSheetHeader.styleSheetId); | |
| 153 } | |
| 154 | |
| 155 function uiSourceCodeRemoved(uiSourceCode) | |
| 156 { | |
| 157 InspectorTest.addResult("Removed uiSourceCode: " + InspectorTest.uiS
ourceCodeURL(uiSourceCode)); | |
| 158 callback(); | |
| 159 } | |
| 160 } | |
| 161 }; | |
| 162 </script> | |
| 163 </head> | |
| 164 <body onload="runTest()"> | |
| 165 <p>Tests NetworkUISourceCodeProvider class.</p> | |
| 166 </body> | |
| 167 </html> | |
| OLD | NEW |