Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / inspector / workspace-test.js
1 var initialize_WorkspaceTest = function() {
2
3 InspectorTest.createWorkspace = function(ignoreEvents)
4 {
5     InspectorTest.testFileSystemMapping = new WebInspector.FileSystemMapping();
6     InspectorTest.testFileSystemMapping._fileSystemMappingSetting = new InspectorTest.MockSetting({});
7     InspectorTest.testFileSystemMapping._excludedFoldersSetting = new InspectorTest.MockSetting({});
8
9     InspectorTest.testWorkspace = new WebInspector.Workspace(InspectorTest.testFileSystemMapping);
10     InspectorTest.testNetworkWorkspaceBinding = new WebInspector.NetworkWorkspaceBinding(InspectorTest.testWorkspace);
11     if (ignoreEvents)
12         return;
13     InspectorTest.testWorkspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeAdded, InspectorTest._defaultWorkspaceEventHandler);
14     InspectorTest.testWorkspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeRemoved, InspectorTest._defaultWorkspaceEventHandler);
15 }
16
17 InspectorTest.waitForWorkspaceUISourceCodeAddedEvent = function(callback, count)
18 {
19     InspectorTest.uiSourceCodeAddedEventsLeft = count || 1;
20     InspectorTest.testWorkspace.removeEventListener(WebInspector.Workspace.Events.UISourceCodeAdded, InspectorTest._defaultWorkspaceEventHandler);
21     InspectorTest.testWorkspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeAdded, uiSourceCodeAdded);
22
23     function uiSourceCodeAdded(event)
24     {
25         if (!(--InspectorTest.uiSourceCodeAddedEventsLeft)) {
26             InspectorTest.testWorkspace.removeEventListener(WebInspector.Workspace.Events.UISourceCodeAdded, uiSourceCodeAdded);
27             InspectorTest.testWorkspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeAdded, InspectorTest._defaultWorkspaceEventHandler);
28         }
29         callback(event.data);
30     }
31 }
32
33 InspectorTest.waitForWorkspaceUISourceCodeRemovedEvent = function(callback, count)
34 {
35     InspectorTest.uiSourceCodeRemovedEventsLeft = count || 1;
36     InspectorTest.testWorkspace.removeEventListener(WebInspector.Workspace.Events.UISourceCodeRemoved, InspectorTest._defaultWorkspaceEventHandler);
37     InspectorTest.testWorkspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeRemoved, uiSourceCodeAdded);
38
39     function uiSourceCodeAdded(event)
40     {
41         if (!(--InspectorTest.uiSourceCodeRemovedEventsLeft)) {
42             InspectorTest.testWorkspace.removeEventListener(WebInspector.Workspace.Events.UISourceCodeRemoved, uiSourceCodeAdded);
43             InspectorTest.testWorkspace.addEventListener(WebInspector.Workspace.Events.UISourceCodeRemoved, InspectorTest._defaultWorkspaceEventHandler);
44         }
45         callback(event.data);
46     }
47 }
48
49 InspectorTest.addMockUISourceCodeToWorkspace = function(url, type, content)
50 {
51     var mockContentProvider = new WebInspector.StaticContentProvider(type, content);
52     InspectorTest.testNetworkWorkspaceBinding.addFileForURL(url, mockContentProvider);
53 }
54
55 InspectorTest._defaultWorkspaceEventHandler = function(event)
56 {
57     var uiSourceCode = event.data;
58     if (uiSourceCode.project().type() === WebInspector.projectTypes.Debugger && !uiSourceCode.url)
59         return;
60     throw new Error("Unexpected Workspace event: " + event.type + ": " + uiSourceCode.uri() + ".");
61 }
62
63 InspectorTest.dumpUISourceCode = function(uiSourceCode, callback)
64 {
65     var url = uiSourceCode.originURL().replace(/.*LayoutTests/, "LayoutTests");
66     InspectorTest.addResult("UISourceCode: " + url);
67     if (uiSourceCode.contentType() === WebInspector.resourceTypes.Script || uiSourceCode.contentType() === WebInspector.resourceTypes.Document)
68         InspectorTest.addResult("UISourceCode is content script: " + (uiSourceCode.project().type() === WebInspector.projectTypes.ContentScripts));
69     uiSourceCode.requestContent(didRequestContent);
70
71     function didRequestContent(content, contentEncoded)
72     {
73         InspectorTest.addResult("Highlighter type: " + uiSourceCode.highlighterType());
74         InspectorTest.addResult("UISourceCode content: " + content);
75         callback();
76     }
77 }
78
79 };