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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 for (var name in this) { | 72 for (var name in this) { |
73 if (name.substring(0, 4) == 'test' && | 73 if (name.substring(0, 4) == 'test' && |
74 typeof this[name] == 'function') { | 74 typeof this[name] == 'function') { |
75 this.runTest(name); | 75 this.runTest(name); |
76 } | 76 } |
77 } | 77 } |
78 }; | 78 }; |
79 | 79 |
80 | 80 |
81 /** | 81 /** |
82 * Async tests use this one to report that they are completed. | |
83 */ | |
84 TestSuite.prototype.reportOk = function() { | |
85 window.domAutomationController.send('[OK]'); | |
86 }; | |
87 | |
88 | |
89 /** | |
90 * Manual controller for async tests. | 82 * Manual controller for async tests. |
91 * @constructor. | 83 * @constructor. |
92 */ | 84 */ |
93 TestSuite.Controller = function() { | 85 TestSuite.Controller = function() { |
94 this.controlTaken_ = false; | 86 this.controlTaken_ = false; |
95 this.timerId_ = -1; | 87 this.timerId_ = -1; |
96 }; | 88 }; |
97 | 89 |
98 | 90 |
99 /** | 91 /** |
100 * Takes control over execution. | 92 * Takes control over execution. |
101 */ | 93 */ |
102 TestSuite.Controller.prototype.takeControl = function() { | 94 TestSuite.Controller.prototype.takeControl = function() { |
103 this.controlTaken_ = true; | 95 this.controlTaken_ = true; |
104 // Set up guard timer. | 96 // Set up guard timer. |
105 var self = this; | 97 var self = this; |
106 this.timerId_ = setTimeout(function() { | 98 this.timerId_ = setTimeout(function() { |
107 self.reportFailure('Timeout exceeded: 20 sec'); | 99 self.reportFailure_('Timeout exceeded: 20 sec'); |
108 }, 20000); | 100 }, 20000); |
109 }; | 101 }; |
110 | 102 |
111 | 103 |
112 /** | 104 /** |
| 105 * Releases control over execution. |
| 106 */ |
| 107 TestSuite.Controller.prototype.releaseControl = function() { |
| 108 this.controlTaken_ = false; |
| 109 if (this.timerId_ != -1) { |
| 110 this.timerId_ = -1; |
| 111 clearTimeout(this.timerId_); |
| 112 } |
| 113 this.reportOk_(); |
| 114 }; |
| 115 |
| 116 |
| 117 /** |
113 * Async tests use this one to report that they are completed. | 118 * Async tests use this one to report that they are completed. |
114 */ | 119 */ |
115 TestSuite.Controller.prototype.reportOk = function() { | 120 TestSuite.Controller.prototype.reportOk_ = function() { |
116 if (this.timerId_ != -1) { | |
117 this.timerId_ = -1; | |
118 clearTimeout(this.timerId_); | |
119 } | |
120 window.domAutomationController.send('[OK]'); | 121 window.domAutomationController.send('[OK]'); |
121 }; | 122 }; |
122 | 123 |
123 | 124 |
124 /** | 125 /** |
125 * Async tests use this one to report failures. | 126 * Async tests use this one to report failures. |
126 */ | 127 */ |
127 TestSuite.Controller.prototype.reportFailure = function(error) { | 128 TestSuite.Controller.prototype.reportFailure_ = function(error) { |
128 if (this.timerId_ != -1) { | 129 if (this.timerId_ != -1) { |
129 this.timerId_ = -1; | 130 this.timerId_ = -1; |
130 clearTimeout(this.timerId_); | 131 clearTimeout(this.timerId_); |
131 } | 132 } |
132 window.domAutomationController.send('[FAILED] ' + error); | 133 window.domAutomationController.send('[FAILED] ' + error); |
133 }; | 134 }; |
134 | 135 |
135 | 136 |
136 /** | 137 /** |
137 * Runs all global functions starting with 'test' as unit tests. | 138 * Runs all global functions starting with 'test' as unit tests. |
138 */ | 139 */ |
139 TestSuite.prototype.runTest = function(testName) { | 140 TestSuite.prototype.runTest = function(testName) { |
140 var controller = new TestSuite.Controller(); | 141 var controller = new TestSuite.Controller(); |
141 try { | 142 try { |
142 this[testName](controller); | 143 this[testName](controller); |
143 if (!controller.controlTaken_) { | 144 if (!controller.controlTaken_) { |
144 controller.reportOk(); | 145 controller.reportOk_(); |
145 } | 146 } |
146 } catch (e) { | 147 } catch (e) { |
147 controller.reportFailure(e); | 148 controller.reportFailure_(e); |
148 } | 149 } |
149 }; | 150 }; |
150 | 151 |
151 | 152 |
152 /** | 153 /** |
153 * @param {string} panelName Name of the panel to show. | 154 * @param {string} panelName Name of the panel to show. |
154 */ | 155 */ |
155 TestSuite.prototype.showPanel = function(panelName) { | 156 TestSuite.prototype.showPanel = function(panelName) { |
156 // Open Scripts panel. | 157 // Open Scripts panel. |
157 var toolbar = document.getElementById('toolbar'); | 158 var toolbar = document.getElementById('toolbar'); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 | 209 |
209 var test = this; | 210 var test = this; |
210 var oldAddResource = WebInspector.addResource; | 211 var oldAddResource = WebInspector.addResource; |
211 WebInspector.addResource = function(identifier, payload) { | 212 WebInspector.addResource = function(identifier, payload) { |
212 WebInspector.addResource = oldAddResource; | 213 WebInspector.addResource = oldAddResource; |
213 oldAddResource.call(this, identifier, payload); | 214 oldAddResource.call(this, identifier, payload); |
214 test.assertEquals('simple_page.html', payload.lastPathComponent); | 215 test.assertEquals('simple_page.html', payload.lastPathComponent); |
215 WebInspector.panels.resources.refresh(); | 216 WebInspector.panels.resources.refresh(); |
216 WebInspector.resources[identifier]._resourcesTreeElement.select(); | 217 WebInspector.resources[identifier]._resourcesTreeElement.select(); |
217 | 218 |
218 controller.reportOk(); | 219 controller.releaseControl(); |
219 }; | 220 }; |
220 | 221 |
221 // Following call should lead to reload that we capture in the | 222 // Following call should lead to reload that we capture in the |
222 // addResource override. | 223 // addResource override. |
223 WebInspector.panels.resources._enableResourceTracking(); | 224 WebInspector.panels.resources._enableResourceTracking(); |
224 | 225 |
225 // We now have some time to report results to controller. | 226 // We now have some time to report results to controller. |
226 controller.takeControl(); | 227 controller.takeControl(); |
227 }; | 228 }; |
228 | 229 |
229 | 230 |
230 /** | 231 /** |
| 232 * Tests resource headers. |
| 233 */ |
| 234 TestSuite.prototype.testResourceHeaders = function(controller) { |
| 235 this.showPanel('resources'); |
| 236 |
| 237 var test = this; |
| 238 var oldAddResource = WebInspector.addResource; |
| 239 var oldUpdateResource = WebInspector.updateResource; |
| 240 |
| 241 var requestOk = false; |
| 242 var responseOk = false; |
| 243 var timingOk = false; |
| 244 |
| 245 WebInspector.addResource = function(identifier, payload) { |
| 246 oldAddResource.call(this, identifier, payload); |
| 247 var resource = this.resources[identifier]; |
| 248 if (resource.mainResource) { |
| 249 // We are only interested in secondary resources in this test. |
| 250 return; |
| 251 } |
| 252 |
| 253 var requestHeaders = JSON.stringify(resource.requestHeaders); |
| 254 test.assertContains(requestHeaders, 'Accept'); |
| 255 requestOk = true; |
| 256 }; |
| 257 |
| 258 WebInspector.updateResource = function(identifier, payload) { |
| 259 oldUpdateResource.call(this, identifier, payload); |
| 260 var resource = this.resources[identifier]; |
| 261 if (resource.mainResource) { |
| 262 // We are only interested in secondary resources in this test. |
| 263 return; |
| 264 } |
| 265 |
| 266 if (payload.didResponseChange) { |
| 267 var responseHeaders = JSON.stringify(resource.responseHeaders); |
| 268 test.assertContains(responseHeaders, 'Content-type'); |
| 269 test.assertContains(responseHeaders, 'Content-Length'); |
| 270 test.assertTrue(typeof resource.responseReceivedTime != 'undefnied'); |
| 271 responseOk = true; |
| 272 } |
| 273 |
| 274 if (payload.didTimingChange) { |
| 275 test.assertTrue(typeof resource.startTime != 'undefnied'); |
| 276 timingOk = true; |
| 277 } |
| 278 |
| 279 if (payload.didCompletionChange) { |
| 280 test.assertTrue(requestOk); |
| 281 test.assertTrue(responseOk); |
| 282 test.assertTrue(timingOk); |
| 283 test.assertTrue(typeof resource.endTime != 'undefnied'); |
| 284 controller.releaseControl(); |
| 285 } |
| 286 }; |
| 287 |
| 288 WebInspector.panels.resources._enableResourceTracking(); |
| 289 controller.takeControl(); |
| 290 }; |
| 291 |
| 292 |
| 293 /** |
231 * Test that profiler works. | 294 * Test that profiler works. |
232 */ | 295 */ |
233 TestSuite.prototype.testProfilerTab = function(controller) { | 296 TestSuite.prototype.testProfilerTab = function(controller) { |
234 this.showPanel('profiles'); | 297 this.showPanel('profiles'); |
235 | 298 |
| 299 var test = this; |
236 var oldAddProfile = WebInspector.addProfile; | 300 var oldAddProfile = WebInspector.addProfile; |
237 WebInspector.addProfile = function(profile) { | 301 WebInspector.addProfile = function(profile) { |
238 WebInspector.addProfile = oldAddProfile; | 302 WebInspector.addProfile = oldAddProfile; |
239 oldAddProfile.call(this, profile); | 303 oldAddProfile.call(this, profile); |
240 | 304 |
241 var panel = WebInspector.panels.profiles; | 305 var panel = WebInspector.panels.profiles; |
242 panel.showProfile(profile); | 306 panel.showProfile(profile); |
243 var node = panel.visibleView.profileDataGridTree.children[0]; | 307 var node = panel.visibleView.profileDataGridTree.children[0]; |
244 // Iterate over displayed functions and search for a function | 308 // Iterate over displayed functions and search for a function |
245 // that is called 'fib' or 'eternal_fib'. If found, it will mean | 309 // that is called 'fib' or 'eternal_fib'. If found, it will mean |
246 // that we actually have profiled page's code. | 310 // that we actually have profiled page's code. |
247 while (node) { | 311 while (node) { |
248 if (node.functionName.indexOf("fib") != -1) { | 312 if (node.functionName.indexOf("fib") != -1) { |
249 controller.reportOk(); | 313 controller.releaseControl(); |
250 } | 314 } |
251 node = node.traverseNextNode(true, null, true); | 315 node = node.traverseNextNode(true, null, true); |
252 } | 316 } |
253 | 317 |
254 controller.reportFailure(); | 318 test.fail(); |
255 }; | 319 }; |
256 | 320 |
257 InspectorController.startProfiling(); | 321 InspectorController.startProfiling(); |
258 window.setTimeout('InspectorController.stopProfiling();', 1000); | 322 window.setTimeout('InspectorController.stopProfiling();', 1000); |
259 controller.takeControl(); | 323 controller.takeControl(); |
260 }; | 324 }; |
261 | 325 |
262 | 326 |
263 /** | 327 /** |
264 * Tests that scripts tab can be open and populated with inspected scripts. | 328 * Tests that scripts tab can be open and populated with inspected scripts. |
265 */ | 329 */ |
266 TestSuite.prototype.testShowScriptsTab = function(controller) { | 330 TestSuite.prototype.testShowScriptsTab = function(controller) { |
267 var parsedDebuggerTestPageHtml = false; | 331 var parsedDebuggerTestPageHtml = false; |
268 var parsedDebuggerTestJs = false; | 332 var parsedDebuggerTestJs = false; |
269 | 333 |
270 // Intercept parsedScriptSource calls to check that all expected scripts are | 334 // Intercept parsedScriptSource calls to check that all expected scripts are |
271 // added to the debugger. | 335 // added to the debugger. |
272 var self = this; | 336 var test = this; |
273 var originalParsedScriptSource = WebInspector.parsedScriptSource; | 337 var originalParsedScriptSource = WebInspector.parsedScriptSource; |
274 WebInspector.parsedScriptSource = function(sourceID, sourceURL, source, | 338 WebInspector.parsedScriptSource = function(sourceID, sourceURL, source, |
275 startingLine) { | 339 startingLine) { |
276 if (sourceURL.search(/debugger_test_page.html$/) != -1) { | 340 if (sourceURL.search(/debugger_test_page.html$/) != -1) { |
277 if (parsedDebuggerTestPageHtml) { | 341 if (parsedDebuggerTestPageHtml) { |
278 controller.reportFailure('Unexpected parse event: ' + sourceURL); | 342 test.fail('Unexpected parse event: ' + sourceURL); |
279 return; | |
280 } | 343 } |
281 parsedDebuggerTestPageHtml = true; | 344 parsedDebuggerTestPageHtml = true; |
282 } else if (sourceURL.search(/debugger_test.js$/) != -1) { | 345 } else if (sourceURL.search(/debugger_test.js$/) != -1) { |
283 if (parsedDebuggerTestJs) { | 346 if (parsedDebuggerTestJs) { |
284 controller.reportFailure('Unexpected parse event: ' + sourceURL); | 347 test.fail('Unexpected parse event: ' + sourceURL); |
285 return; | |
286 } | 348 } |
287 parsedDebuggerTestJs = true; | 349 parsedDebuggerTestJs = true; |
288 } else { | 350 } else { |
289 controller.reportFailure('Unexpected script URL: ' + sourceURL); | 351 test.fail('Unexpected script URL: ' + sourceURL); |
290 } | 352 } |
291 originalParsedScriptSource.apply(this, arguments); | 353 originalParsedScriptSource.apply(this, arguments); |
292 | 354 |
293 if (!WebInspector.panels.scripts.visibleView) { | 355 if (!WebInspector.panels.scripts.visibleView) { |
294 controller.reportFailure('No visible script view: ' + sourceURL); | 356 test.fail('No visible script view: ' + sourceURL); |
295 return; | |
296 } | 357 } |
297 | 358 |
298 if (parsedDebuggerTestJs && parsedDebuggerTestPageHtml) { | 359 if (parsedDebuggerTestJs && parsedDebuggerTestPageHtml) { |
299 controller.reportOk(); | 360 controller.releaseControl(); |
300 } | 361 } |
301 controller.reportOk(); | |
302 }; | 362 }; |
303 | 363 |
304 this.showPanel('scripts'); | 364 this.showPanel('scripts'); |
305 | 365 |
306 // Wait until all scripts are added to the debugger. | 366 // Wait until all scripts are added to the debugger. |
307 controller.takeControl(); | 367 controller.takeControl(); |
308 }; | 368 }; |
309 | 369 |
310 | 370 |
311 TestSuite.ConsoleEnter = { | |
312 keyIdentifier : 'Enter', | |
313 preventDefault : function() {}, | |
314 stopPropagation : function() {} | |
315 }; | |
316 | |
317 | |
318 /** | 371 /** |
| 372 * Key event with given key identifier. |
| 373 */ |
| 374 TestSuite.KeyEvent = function(key) { |
| 375 this.keyIdentifier = key; |
| 376 }; |
| 377 TestSuite.KeyEvent.prototype.preventDefault = function() {}; |
| 378 TestSuite.KeyEvent.prototype.stopPropagation = function() {}; |
| 379 |
| 380 |
| 381 /** |
319 * Tests console eval. | 382 * Tests console eval. |
320 */ | 383 */ |
321 TestSuite.prototype.testConsoleEval = function(controller) { | 384 TestSuite.prototype.testConsoleEval = function(controller) { |
322 var test = this; | 385 var test = this; |
323 var originalConsoleAddMessage = WebInspector.Console.prototype.addMessage; | 386 var originalConsoleAddMessage = WebInspector.Console.prototype.addMessage; |
324 WebInspector.Console.prototype.addMessage = function(commandResult) { | 387 WebInspector.Console.prototype.addMessage = function(commandResult) { |
325 originalConsoleAddMessage.call(this, commandResult); | 388 originalConsoleAddMessage.call(this, commandResult); |
326 WebInspector.Console.prototype.addMessage = originalConsoleAddMessage; | 389 WebInspector.Console.prototype.addMessage = originalConsoleAddMessage; |
327 test.assertEquals('123', commandResult.toMessageElement().textContent); | 390 test.assertEquals('123', commandResult.toMessageElement().textContent); |
328 controller.reportOk(); | 391 controller.releaseControl(); |
329 }; | 392 }; |
330 | 393 |
331 WebInspector.console.visible = true; | 394 WebInspector.console.visible = true; |
332 WebInspector.console.prompt.text = '123'; | 395 WebInspector.console.prompt.text = '123'; |
333 WebInspector.console.promptElement.handleKeyEvent(TestSuite.ConsoleEnter); | 396 WebInspector.console.promptElement.handleKeyEvent( |
| 397 new TestSuite.KeyEvent('Enter')); |
334 | 398 |
335 controller.takeControl(); | 399 controller.takeControl(); |
336 }; | 400 }; |
337 | 401 |
338 | 402 |
339 /** | 403 /** |
340 * Tests console log. | 404 * Tests console log. |
341 */ | 405 */ |
342 TestSuite.prototype.testConsoleLog = function(controller) { | 406 TestSuite.prototype.testConsoleLog = function(controller) { |
343 WebInspector.console.visible = true; | 407 WebInspector.console.visible = true; |
(...skipping 26 matching lines...) Expand all Loading... |
370 assertNext('19', 'Object Object'); | 434 assertNext('19', 'Object Object'); |
371 assertNext('22', 'repeated', 'log', 5); | 435 assertNext('22', 'repeated', 'log', 5); |
372 assertNext('26', 'count: 1'); | 436 assertNext('26', 'count: 1'); |
373 assertNext('26', 'count: 2'); | 437 assertNext('26', 'count: 2'); |
374 assertNext('29', 'group', 'group-title'); | 438 assertNext('29', 'group', 'group-title'); |
375 index++; | 439 index++; |
376 assertNext('33', 'timer:', 'log', '', true); | 440 assertNext('33', 'timer:', 'log', '', true); |
377 }; | 441 }; |
378 | 442 |
379 | 443 |
| 444 /** |
| 445 * Tests eval of global objects. |
| 446 */ |
| 447 TestSuite.prototype.testEvalGlobal = function(controller) { |
| 448 var test = this; |
| 449 var originalConsoleAddMessage = WebInspector.Console.prototype.addMessage; |
| 450 WebInspector.Console.prototype.addMessage = function(commandResult) { |
| 451 originalConsoleAddMessage.call(this, commandResult); |
| 452 WebInspector.Console.prototype.addMessage = originalConsoleAddMessage; |
| 453 test.assertEquals('fooValue', commandResult.toMessageElement().textContent); |
| 454 controller.releaseControl(); |
| 455 }; |
| 456 |
| 457 WebInspector.console.visible = true; |
| 458 WebInspector.console.prompt.text = 'foo'; |
| 459 WebInspector.console.promptElement.handleKeyEvent( |
| 460 new TestSuite.KeyEvent('Enter')); |
| 461 |
| 462 controller.takeControl(); |
| 463 }; |
| 464 |
| 465 |
| 466 /** |
| 467 * Tests eval on call frame. |
| 468 */ |
| 469 TestSuite.prototype.testEvalCallFrame = function(controller) { |
| 470 }; |
| 471 |
| 472 |
380 var uiTests = new TestSuite(); | 473 var uiTests = new TestSuite(); |
381 } | 474 } |
OLD | NEW |