c74b18492b349c693abd290b5fb0d3d2c1cdc69f
[framework/web/webkit-efl.git] / LayoutTests / inspector / debugger / scripts-panel.html
1 <html>
2 <head>
3 <script src="../../http/tests/inspector/inspector-test.js"></script>
4
5 <script>
6
7 function test()
8 {
9     // Always use indentation in scripts drop box
10     WebInspector._isMac = false;
11
12     function createDebuggerPresentationModelMock()
13     {
14         var model = new WebInspector.Object();
15         model.breakpointsForUISourceCode = function() { return []; };
16         model.messagesForUISourceCode = function() { return []; };
17         model.canEditScriptSource = function() { return true; };
18         return model;
19     }
20     function createUISouceCode(url)
21     {
22         var uiSourceCode = {
23             url: url,
24             requestContent: function(callback)
25             {
26                 InspectorTest.addResult("Source requested for " + url);
27                 callback("");
28             },
29             messages: []
30         };
31         uiSourceCode.__proto__ = WebInspector.Object.prototype;
32         return uiSourceCode;
33     }
34
35     function showSourceFrame(panel, fileName)
36     {
37         var select = panel._filesSelectElement;
38         for (var i = 0; i < select.length; ++i) {
39             if (select[i].text.indexOf(fileName) === -1)
40                 continue;
41             select.selectedIndex = i;
42             panel._filesSelectChanged();
43             break;
44         }
45     }
46
47     InspectorTest.runTestSuite([
48         function testInitialLoad(next)
49         {
50             var model = createDebuggerPresentationModelMock();
51             var panel = new WebInspector.ScriptsPanel(model);
52             panel.show();
53
54             panel._uiSourceCodeAdded({ data: createUISouceCode("foo.js") });
55             panel._uiSourceCodeAdded({ data: createUISouceCode("bar.js") });
56             panel._uiSourceCodeAdded({ data: createUISouceCode("baz.js") });
57
58             InspectorTest.addResult("Dump files select:");
59             var select = panel._filesSelectElement;
60             for (var i = 0; i < select.length; ++i)
61                 InspectorTest.addResult(select[i].text.replace(/\u00a0/g, " "));
62
63             // Selected file should be "foo.js".
64             InspectorTest.assertEquals(2, select.selectedIndex);
65             InspectorTest.assertEquals("foo.js", select[2].text.replace(/\s/g, ""));
66
67             // Select "baz.js".
68             select.selectedIndex = 1;
69             panel._filesSelectChanged();
70             panel.detach();
71
72             next();
73         },
74
75         function testHistory(next)
76         {
77             var model = createDebuggerPresentationModelMock();
78             var panel = new WebInspector.ScriptsPanel(model);
79             panel.show();
80
81             var files = ["index.html", "script1.js", "script2.js", "script3.js"];
82             for (var i = 0; i < files.length; ++i)
83                 panel._uiSourceCodeAdded({ data: createUISouceCode(files[i]) });
84
85             function checkCurrentlySelectedFileName(fileName)
86             {
87                 var index = panel._filesSelectElement.selectedIndex;
88                 var text = panel._filesSelectElement[index].text;
89                 InspectorTest.assertTrue(text.indexOf(fileName) !== -1,
90                     "Wrong option text. Expected <" + fileName + ">, found <" + text + ">.");
91             }
92
93             for (var i = 0; i < files.length; ++i)
94                 showSourceFrame(panel, files[i]);
95             checkCurrentlySelectedFileName("script3.js");
96             InspectorTest.assertEquals(true, panel.forwardButton.disabled, "Forward should be disabled.");
97
98             panel.backButton.click();
99             checkCurrentlySelectedFileName("script2.js");
100             InspectorTest.assertEquals(false, panel.forwardButton.disabled, "Forward should be enabled after back button click.");
101
102             panel.forwardButton.click();
103             checkCurrentlySelectedFileName("script3.js");
104             InspectorTest.assertEquals(true, panel.forwardButton.disabled, "Forward should be disabled after forward button click.");
105
106             panel.backButton.click();
107             checkCurrentlySelectedFileName("script2.js");
108
109             panel.backButton.click();
110             checkCurrentlySelectedFileName("script1.js");
111
112             panel.backButton.click();
113             checkCurrentlySelectedFileName("index.html");
114
115             panel.forwardButton.click();
116             panel.forwardButton.click();
117             checkCurrentlySelectedFileName("script2.js");
118
119             showSourceFrame(panel, "script1.js");
120             checkCurrentlySelectedFileName("script1.js");
121             InspectorTest.assertEquals(true, panel.forwardButton.disabled);
122
123             panel.backButton.click();
124             checkCurrentlySelectedFileName("script2.js");
125
126             panel.backButton.click();
127             checkCurrentlySelectedFileName("index.html");
128
129             panel.detach();
130             next();
131         },
132
133         function testFilesSelect(next)
134         {
135             var model = createDebuggerPresentationModelMock();
136             var panel = new WebInspector.ScriptsPanel(model);
137             panel.show();
138
139             var rootURL = "http://localhost:8080/LayoutTests/inspector/debugger/";
140             var nextId = 0;
141             function addOption(url, isContentScript)
142             {
143                 panel._addOptionToFilesSelect({ id: nextId++, url: url, isContentScript: isContentScript });
144             }
145             addOption(rootURL + "foo/bar/script.js", false);
146             addOption(rootURL + "foo/bar/contentScript2.js?a=1", true);
147             addOption(rootURL + "foo/bar/script.js?a=2", false);
148             addOption(rootURL + "foo/bar/contentScript.js?a=2", true);
149             addOption(rootURL + "foo/bar/script.js?a=1", false);
150             addOption(rootURL + "foo/baz/script.js", false);
151             addOption(rootURL + "foo/bar/contentScript.js?a=1", true);
152             addOption("http://example.com/?a=b", false);
153             addOption("?a=b", false);
154             addOption("very_looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong_url", false);
155
156             var select = panel._filesSelectElement;
157             for (var i = 0; i < select.length; ++i) {
158                 var option = select[i];
159                 var text = option.text.replace(/.*LayoutTests/, "LayoutTests");
160                 text = text.replace(/\u00a0/g, " ").replace(/\u2026/g, "...");
161                 var tooltip = option.title.replace(rootURL, "<root>/");
162                 InspectorTest.addResult(text + (tooltip ? "(" + tooltip + ")" : ""));
163             }
164
165             panel.detach();
166             next();
167         },
168
169         function testSourceReplaced(next)
170         {
171             var model = createDebuggerPresentationModelMock();
172             var panel = new WebInspector.ScriptsPanel(model);
173             panel.show();
174
175             panel._uiSourceCodeAdded({ data: createUISouceCode("foo.js") });
176             var compiledSourceCode = createUISouceCode("compiled.js");
177             panel._uiSourceCodeAdded({ data: compiledSourceCode });
178
179             InspectorTest.assertEquals(2, panel._filesSelectElement.length);
180
181             // Plug compiler source mapping.
182             var source1SourceCode = createUISouceCode("source1.js");
183             var source2SourceCode = createUISouceCode("source2.js");
184             panel._uiSourceCodeReplaced({ data: { oldUISourceCodeList: [compiledSourceCode], uiSourceCodeList: [source1SourceCode, source2SourceCode] }});
185
186             InspectorTest.assertEquals(3, panel._filesSelectElement.length);
187             showSourceFrame(panel, "source2.js");
188             showSourceFrame(panel, "source1.js");
189
190             // Unplug compiler source mapping.
191             panel._uiSourceCodeReplaced({ data: { oldUISourceCodeList: [source1SourceCode, source2SourceCode], uiSourceCodeList: [compiledSourceCode] }});
192             InspectorTest.assertEquals(2, panel._filesSelectElement.length);
193
194             panel.detach();
195             next();
196         }
197     ]);
198 };
199
200 </script>
201
202 </head>
203
204 <body onload="runTest()">
205 <p>Tests that scripts panel UI elements work as intended.</p>
206
207 </body>
208 </html>