3 <script src="../../http/tests/inspector/inspector-test.js"></script>
9 // Always use indentation in scripts drop box
10 WebInspector._isMac = false;
12 function createDebuggerPresentationModelMock()
14 var model = new WebInspector.Object();
15 model.breakpointsForUISourceCode = function() { return []; };
16 model.messagesForUISourceCode = function() { return []; };
17 model.canEditScriptSource = function() { return true; };
20 function createUISouceCode(url)
24 requestContent: function(callback)
26 InspectorTest.addResult("Source requested for " + url);
31 uiSourceCode.__proto__ = WebInspector.Object.prototype;
35 function showSourceFrame(panel, fileName)
37 var select = panel._filesSelectElement;
38 for (var i = 0; i < select.length; ++i) {
39 if (select[i].text.indexOf(fileName) === -1)
41 select.selectedIndex = i;
42 panel._filesSelectChanged();
47 InspectorTest.runTestSuite([
48 function testInitialLoad(next)
50 var model = createDebuggerPresentationModelMock();
51 var panel = new WebInspector.ScriptsPanel(model);
54 panel._uiSourceCodeAdded({ data: createUISouceCode("foo.js") });
55 panel._uiSourceCodeAdded({ data: createUISouceCode("bar.js") });
56 panel._uiSourceCodeAdded({ data: createUISouceCode("baz.js") });
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, " "));
63 // Selected file should be "foo.js".
64 InspectorTest.assertEquals(2, select.selectedIndex);
65 InspectorTest.assertEquals("foo.js", select[2].text.replace(/\s/g, ""));
68 select.selectedIndex = 1;
69 panel._filesSelectChanged();
75 function testHistory(next)
77 var model = createDebuggerPresentationModelMock();
78 var panel = new WebInspector.ScriptsPanel(model);
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]) });
85 function checkCurrentlySelectedFileName(fileName)
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 + ">.");
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.");
98 panel.backButton.click();
99 checkCurrentlySelectedFileName("script2.js");
100 InspectorTest.assertEquals(false, panel.forwardButton.disabled, "Forward should be enabled after back button click.");
102 panel.forwardButton.click();
103 checkCurrentlySelectedFileName("script3.js");
104 InspectorTest.assertEquals(true, panel.forwardButton.disabled, "Forward should be disabled after forward button click.");
106 panel.backButton.click();
107 checkCurrentlySelectedFileName("script2.js");
109 panel.backButton.click();
110 checkCurrentlySelectedFileName("script1.js");
112 panel.backButton.click();
113 checkCurrentlySelectedFileName("index.html");
115 panel.forwardButton.click();
116 panel.forwardButton.click();
117 checkCurrentlySelectedFileName("script2.js");
119 showSourceFrame(panel, "script1.js");
120 checkCurrentlySelectedFileName("script1.js");
121 InspectorTest.assertEquals(true, panel.forwardButton.disabled);
123 panel.backButton.click();
124 checkCurrentlySelectedFileName("script2.js");
126 panel.backButton.click();
127 checkCurrentlySelectedFileName("index.html");
133 function testFilesSelect(next)
135 var model = createDebuggerPresentationModelMock();
136 var panel = new WebInspector.ScriptsPanel(model);
139 var rootURL = "http://localhost:8080/LayoutTests/inspector/debugger/";
141 function addOption(url, isContentScript)
143 panel._addOptionToFilesSelect({ id: nextId++, url: url, isContentScript: isContentScript });
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);
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 + ")" : ""));
169 function testSourceReplaced(next)
171 var model = createDebuggerPresentationModelMock();
172 var panel = new WebInspector.ScriptsPanel(model);
175 panel._uiSourceCodeAdded({ data: createUISouceCode("foo.js") });
176 var compiledSourceCode = createUISouceCode("compiled.js");
177 panel._uiSourceCodeAdded({ data: compiledSourceCode });
179 InspectorTest.assertEquals(2, panel._filesSelectElement.length);
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] }});
186 InspectorTest.assertEquals(3, panel._filesSelectElement.length);
187 showSourceFrame(panel, "source2.js");
188 showSourceFrame(panel, "source1.js");
190 // Unplug compiler source mapping.
191 panel._uiSourceCodeReplaced({ data: { oldUISourceCodeList: [source1SourceCode, source2SourceCode], uiSourceCodeList: [compiledSourceCode] }});
192 InspectorTest.assertEquals(2, panel._filesSelectElement.length);
204 <body onload="runTest()">
205 <p>Tests that scripts panel UI elements work as intended.</p>