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>
9 var mockContentsMap
= {};
11 var lastResourceId
= 0;
12 var lastStyleSheetId
= 0;
14 InspectorTest
._defaultWorkspaceEventHandler = function() {}
16 function createMockStyleSheetHeader(url
)
19 styleSheetId
: (++lastStyleSheetId
) + "",
28 function createResourceMock(type
, content
)
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";
37 case WebInspector
.resourceTypes
.Document
:
38 mimeType
= "text/html";
40 case WebInspector
.resourceTypes
.Script
:
41 mimeType
= "text/javascript";
43 case WebInspector
.resourceTypes
.Stylesheet
:
44 mimeType
= "text/css";
48 var resource
= new WebInspector
.Resource(target
, null, url
, documentURL
, frameId
, loaderId
, type
, mimeType
);
49 resource
._content
= content
;
50 target
.resourceTreeModel
.dispatchEventToListeners(WebInspector
.ResourceTreeModel
.EventTypes
.ResourceAdded
, resource
);
55 function createScriptMock(content
)
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
, target
);
61 target
.debuggerModel
.dispatchEventToListeners(WebInspector
.DebuggerModel
.Events
.ParsedScriptSource
, script
);
64 function finishResource(resource
)
66 resource
.request
.finished
= true;
67 resource
.request
.dispatchEventToListeners(WebInspector
.NetworkRequest
.Events
.FinishedLoading
, resource
.request
);
70 function createNetworkUISourceCodeProvider()
72 target
= InspectorTest
.createWorkspaceWithTarget(true);
75 InspectorTest
.runTestSuite([
76 function testDocumentResource(next
)
78 createNetworkUISourceCodeProvider();
79 InspectorTest
.addResult("Creating resource.");
80 InspectorTest
.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded
);
81 createResourceMock(WebInspector
.resourceTypes
.Document
, "<document resource content>");
83 function uiSourceCodeAdded(uiSourceCode
)
85 // setTimeouts are necessary since same event finalizes uiSourceCode creation.
86 setTimeout(function() { InspectorTest
.dumpUISourceCode(uiSourceCode
, next
); });
90 function testScriptResourceAndVMScript(next
)
92 createNetworkUISourceCodeProvider();
93 InspectorTest
.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded
);
94 InspectorTest
.addResult("Creating script resource.");
95 createResourceMock(WebInspector
.resourceTypes
.Script
, "<script resource content>");
96 InspectorTest
.addResult("Creating script.");
97 createScriptMock("<script content>");
99 function uiSourceCodeAdded(uiSourceCode
)
101 setTimeout(function() { InspectorTest
.dumpUISourceCode(uiSourceCode
, next
); });
105 function testRemoveStyleSheetFromModelWithComplexURL(next
)
107 var mockStyleSheetHeader
= createMockStyleSheetHeader("http://example.com/foo.css");
108 testRemoveStyleSheetFromModel(mockStyleSheetHeader
, next
);
111 function testRemoveStyleSheetFromModelWithSimpleURL(next
)
113 var mockStyleSheetHeader
= createMockStyleSheetHeader("foo.css");
114 testRemoveStyleSheetFromModel(mockStyleSheetHeader
, next
);
118 function testRemoveStyleSheetFromModel(mockStyleSheetHeader
, callback
)
120 createNetworkUISourceCodeProvider();
121 InspectorTest
.waitForWorkspaceUISourceCodeAddedEvent(uiSourceCodeAdded
);
122 InspectorTest
.addResult("Creating stylesheet resource.");
123 createResourceMock(WebInspector
.resourceTypes
.Stylesheet
, "<stylesheet resource content>");
125 WebInspector
.CSSStyleModel
.fromTarget(target
)._styleSheetAdded(mockStyleSheetHeader
);
127 function uiSourceCodeAdded(uiSourceCode
)
129 InspectorTest
.addResult("Added uiSourceCode: " + InspectorTest
.uiSourceCodeURL(uiSourceCode
));
130 InspectorTest
.waitForWorkspaceUISourceCodeRemovedEvent(uiSourceCodeRemoved
);
131 WebInspector
.CSSStyleModel
.fromTarget(target
)._styleSheetRemoved(mockStyleSheetHeader
.styleSheetId
);
134 function uiSourceCodeRemoved(uiSourceCode
)
136 InspectorTest
.addResult("Removed uiSourceCode: " + InspectorTest
.uiSourceCodeURL(uiSourceCode
));
143 <body onload=
"runTest()">
144 <p>Tests NetworkUISourceCodeProvider class.
</p>