Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 | 5 |
| 6 /** | 6 /** |
| 7 * @fileoverview This file contains small testing framework along with the | 7 * @fileoverview This file contains small testing framework along with the |
| 8 * test suite for the frontend. These tests are a part of the continues build | 8 * test suite for the frontend. These tests are a part of the continues build |
| 9 * and are executed by the devtools_sanity_unittest.cc as a part of the | 9 * and are executed by the devtools_sanity_unittest.cc as a part of the |
| 10 * Interactive UI Test suite. | 10 * Interactive UI Test suite. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 * True assertion tests that value == true. | 46 * True assertion tests that value == true. |
| 47 * @param {Object} expected Expected object. | 47 * @param {Object} expected Expected object. |
| 48 * @param {Object} value Actual object. | 48 * @param {Object} value Actual object. |
| 49 */ | 49 */ |
| 50 TestSuite.prototype.assertTrue = function(value) { | 50 TestSuite.prototype.assertTrue = function(value) { |
| 51 this.assertEquals(true, value); | 51 this.assertEquals(true, value); |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 | 54 |
| 55 /** | 55 /** |
| 56 * Contains assertion tests that string contains substring. | |
| 57 * @param {string} string Outer. | |
| 58 * @param {string} substring Inner. | |
| 59 */ | |
| 60 TestSuite.prototype.assertContains = function(string, substring) { | |
| 61 if (string.indexOf(substring) == -1) { | |
| 62 this.fail('Expected to: "' + string + '" to contain "' + substring + '"'); | |
| 63 } | |
| 64 }; | |
| 65 | |
| 66 | |
| 67 /** | |
| 56 * Runs all global functions starting with 'test' as unit tests. | 68 * Runs all global functions starting with 'test' as unit tests. |
| 57 */ | 69 */ |
| 58 TestSuite.prototype.runAllTests = function() { | 70 TestSuite.prototype.runAllTests = function() { |
| 59 // For debugging purposes. | 71 // For debugging purposes. |
| 60 for (var name in this) { | 72 for (var name in this) { |
| 61 if (name.substring(0, 4) == 'test' && | 73 if (name.substring(0, 4) == 'test' && |
| 62 typeof this[name] == 'function') { | 74 typeof this[name] == 'function') { |
| 63 this.runTest(name); | 75 this.runTest(name); |
| 64 } | 76 } |
| 65 } | 77 } |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 this[testName](controller); | 142 this[testName](controller); |
| 131 if (!controller.controlTaken_) { | 143 if (!controller.controlTaken_) { |
| 132 controller.reportOk(); | 144 controller.reportOk(); |
| 133 } | 145 } |
| 134 } catch (e) { | 146 } catch (e) { |
| 135 controller.reportFailure(e); | 147 controller.reportFailure(e); |
| 136 } | 148 } |
| 137 }; | 149 }; |
| 138 | 150 |
| 139 | 151 |
| 152 /** | |
| 153 * @param {string} panelName Name of the panel to show. | |
| 154 */ | |
| 155 TestSuite.prototype.showPanel = function(panelName) { | |
| 156 // Open Scripts panel. | |
| 157 var toolbar = document.getElementById('toolbar'); | |
| 158 var button = toolbar.getElementsByClassName(panelName)[0]; | |
| 159 button.click(); | |
| 160 this.assertEquals(WebInspector.panels[panelName], | |
| 161 WebInspector.currentPanel); | |
| 162 }; | |
| 163 | |
| 140 // UI Tests | 164 // UI Tests |
| 141 | 165 |
| 142 | 166 |
| 143 /** | 167 /** |
| 144 * Tests that the real injected host is present in the context. | 168 * Tests that the real injected host is present in the context. |
| 145 */ | 169 */ |
| 146 TestSuite.prototype.testHostIsPresent = function() { | 170 TestSuite.prototype.testHostIsPresent = function() { |
| 147 var domAgent = devtools.tools.getDomAgent(); | 171 var domAgent = devtools.tools.getDomAgent(); |
| 148 var doc = domAgent.getDocument(); | 172 var doc = domAgent.getDocument(); |
| 149 this.assertTrue(typeof DevToolsHost == 'object' && !DevToolsHost.isStub); | 173 this.assertTrue(typeof DevToolsHost == 'object' && !DevToolsHost.isStub); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 173 tokens.push(resources[id].lastPathComponent); | 197 tokens.push(resources[id].lastPathComponent); |
| 174 } | 198 } |
| 175 this.assertEquals('simple_page.html', tokens.join(',')); | 199 this.assertEquals('simple_page.html', tokens.join(',')); |
| 176 }; | 200 }; |
| 177 | 201 |
| 178 | 202 |
| 179 /** | 203 /** |
| 180 * Tests that resources tab is enabled when corresponding item is selected. | 204 * Tests that resources tab is enabled when corresponding item is selected. |
| 181 */ | 205 */ |
| 182 TestSuite.prototype.testEnableResourcesTab = function(controller) { | 206 TestSuite.prototype.testEnableResourcesTab = function(controller) { |
| 183 WebInspector.panels.elements.hide(); | 207 this.showPanel('resources'); |
| 184 WebInspector.panels.resources.show(); | |
| 185 | 208 |
| 186 var test = this; | 209 var test = this; |
| 187 var oldAddResource = WebInspector.addResource; | 210 var oldAddResource = WebInspector.addResource; |
| 188 WebInspector.addResource = function(identifier, payload) { | 211 WebInspector.addResource = function(identifier, payload) { |
| 189 WebInspector.addResource = oldAddResource; | 212 WebInspector.addResource = oldAddResource; |
| 190 oldAddResource.call(this, identifier, payload); | 213 oldAddResource.call(this, identifier, payload); |
| 191 test.assertEquals('simple_page.html', payload.lastPathComponent); | 214 test.assertEquals('simple_page.html', payload.lastPathComponent); |
| 192 WebInspector.panels.resources.refresh(); | 215 WebInspector.panels.resources.refresh(); |
| 193 WebInspector.resources[identifier]._resourcesTreeElement.select(); | 216 WebInspector.resources[identifier]._resourcesTreeElement.select(); |
| 194 | 217 |
| 195 controller.reportOk(); | 218 controller.reportOk(); |
| 196 }; | 219 }; |
| 197 | 220 |
| 198 // Following call should lead to reload that we capture in the | 221 // Following call should lead to reload that we capture in the |
| 199 // addResource override. | 222 // addResource override. |
| 200 WebInspector.panels.resources._enableResourceTracking(); | 223 WebInspector.panels.resources._enableResourceTracking(); |
| 201 | 224 |
| 202 // We now have some time to report results to controller. | 225 // We now have some time to report results to controller. |
| 203 controller.takeControl(); | 226 controller.takeControl(); |
| 204 }; | 227 }; |
| 205 | 228 |
| 206 | 229 |
| 207 /** | 230 /** |
| 208 * Test that profiler works. | 231 * Test that profiler works. |
| 209 */ | 232 */ |
| 210 TestSuite.prototype.testProfilerTab = function(controller) { | 233 TestSuite.prototype.testProfilerTab = function(controller) { |
| 211 var panel = WebInspector.panels.profiles; | 234 this.showPanel('profiles'); |
| 212 WebInspector.panels.elements.hide(); | |
| 213 panel.show(); | |
| 214 | 235 |
| 215 var oldAddProfile = WebInspector.addProfile; | 236 var oldAddProfile = WebInspector.addProfile; |
| 216 WebInspector.addProfile = function(profile) { | 237 WebInspector.addProfile = function(profile) { |
| 217 WebInspector.addProfile = oldAddProfile; | 238 WebInspector.addProfile = oldAddProfile; |
| 218 oldAddProfile.call(this, profile); | 239 oldAddProfile.call(this, profile); |
| 219 | 240 |
| 241 var panel = WebInspector.panels.profiles; | |
| 220 panel.showProfile(profile); | 242 panel.showProfile(profile); |
| 221 var node = panel.visibleView.profileDataGridTree.children[0]; | 243 var node = panel.visibleView.profileDataGridTree.children[0]; |
| 222 // Iterate over displayed functions and search for a function | 244 // Iterate over displayed functions and search for a function |
| 223 // that is called 'fib' or 'eternal_fib'. If found, it will mean | 245 // that is called 'fib' or 'eternal_fib'. If found, it will mean |
| 224 // that we actually have profiled page's code. | 246 // that we actually have profiled page's code. |
| 225 while (node) { | 247 while (node) { |
| 226 if (node.functionName.indexOf("fib") != -1) { | 248 if (node.functionName.indexOf("fib") != -1) { |
| 227 controller.reportOk(); | 249 controller.reportOk(); |
| 228 } | 250 } |
| 229 node = node.traverseNextNode(true, null, true); | 251 node = node.traverseNextNode(true, null, true); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 originalParsedScriptSource.apply(this, arguments); | 291 originalParsedScriptSource.apply(this, arguments); |
| 270 | 292 |
| 271 if (!WebInspector.panels.scripts.visibleView) { | 293 if (!WebInspector.panels.scripts.visibleView) { |
| 272 controller.reportFailure('No visible script view: ' + sourceURL); | 294 controller.reportFailure('No visible script view: ' + sourceURL); |
| 273 return; | 295 return; |
| 274 } | 296 } |
| 275 | 297 |
| 276 if (parsedDebuggerTestJs && parsedDebuggerTestPageHtml) { | 298 if (parsedDebuggerTestJs && parsedDebuggerTestPageHtml) { |
| 277 controller.reportOk(); | 299 controller.reportOk(); |
| 278 } | 300 } |
| 301 controller.reportOk(); | |
|
yurys
2009/07/03 11:07:05
remove this?
| |
| 279 }; | 302 }; |
| 280 | 303 |
| 281 // Open Scripts panel. | 304 this.showPanel('scripts'); |
| 282 var toolbar = document.getElementById('toolbar'); | |
| 283 var scriptsButton = toolbar.getElementsByClassName('scripts')[0]; | |
| 284 scriptsButton.click(); | |
| 285 | |
| 286 this.assertEquals(WebInspector.panels.scripts, WebInspector.currentPanel); | |
| 287 | 305 |
| 288 // Wait until all scripts are added to the debugger. | 306 // Wait until all scripts are added to the debugger. |
| 289 controller.takeControl(); | 307 controller.takeControl(); |
| 290 }; | 308 }; |
| 291 | 309 |
| 292 | 310 |
| 293 var uiTests = new TestSuite(); | 311 TestSuite.ConsoleEnter = { |
|
yurys
2009/07/03 11:07:05
ConsoleEnterEvent would sound better
| |
| 312 keyIdentifier : 'Enter', | |
| 313 preventDefault : function() {}, | |
| 314 stopPropagation : function() {} | |
| 315 }; | |
| 294 | 316 |
| 295 | 317 |
| 318 /** | |
| 319 * Tests console eval. | |
| 320 */ | |
| 321 TestSuite.prototype.testConsoleEval = function(controller) { | |
| 322 var test = this; | |
| 323 var originalConsoleAddMessage = WebInspector.Console.prototype.addMessage; | |
| 324 WebInspector.Console.prototype.addMessage = function(commandResult) { | |
| 325 originalConsoleAddMessage.call(this, commandResult); | |
| 326 WebInspector.Console.prototype.addMessage = originalConsoleAddMessage; | |
| 327 test.assertEquals('123', commandResult.toMessageElement().textContent); | |
| 328 controller.reportOk(); | |
| 329 }; | |
| 330 | |
| 331 WebInspector.console.visible = true; | |
| 332 WebInspector.console.prompt.text = '123'; | |
| 333 WebInspector.console.promptElement.handleKeyEvent(TestSuite.ConsoleEnter); | |
| 334 | |
| 335 controller.takeControl(); | |
| 336 }; | |
| 337 | |
| 338 | |
| 339 /** | |
| 340 * Tests console log. | |
| 341 */ | |
| 342 TestSuite.prototype.testConsoleLog = function(controller) { | |
| 343 WebInspector.console.visible = true; | |
| 344 var messages = WebInspector.console.messages; | |
| 345 var index = 0; | |
| 346 | |
| 347 var test = this; | |
| 348 var assertNext = function(line, message, opt_level, opt_count, opt_substr) { | |
| 349 var elem = messages[index++].toMessageElement(); | |
| 350 var clazz = elem.getAttribute('class'); | |
| 351 var expectation = (opt_count || '') + 'console_test_page.html:' + | |
| 352 line + message; | |
| 353 if (opt_substr) { | |
| 354 test.assertContains(elem.textContent, expectation); | |
| 355 } else { | |
| 356 test.assertEquals(expectation, elem.textContent); | |
| 357 } | |
| 358 if (opt_level) { | |
| 359 test.assertContains(clazz, 'console-' + opt_level + '-level'); | |
| 360 } | |
| 361 }; | |
| 362 | |
| 363 assertNext('5', 'log', 'log'); | |
| 364 assertNext('7', 'debug', 'log'); | |
| 365 assertNext('9', 'info', 'log'); | |
| 366 assertNext('11', 'warn', 'warning'); | |
| 367 assertNext('13', 'error', 'error'); | |
| 368 assertNext('15', 'Message format number 1, 2 and 3.5'); | |
| 369 assertNext('17', 'Message format for string'); | |
| 370 assertNext('19', 'Object Object'); | |
| 371 assertNext('22', 'repeated', 'log', 5); | |
| 372 assertNext('26', 'count: 1'); | |
| 373 assertNext('26', 'count: 2'); | |
| 374 assertNext('29', 'group', 'group-title'); | |
| 375 index++; | |
| 376 assertNext('33', 'timer:', 'log', '', true); | |
| 377 }; | |
| 378 | |
| 379 | |
| 380 var uiTests = new TestSuite(); | |
| 296 } | 381 } |
| OLD | NEW |