Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: webkit/glue/devtools/js/tests.js

Issue 149256: DevTools: test that a breakpoint can be set (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/debugger/devtools_sanity_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 22 matching lines...) Expand all
33 } else { 33 } else {
34 throw message; 34 throw message;
35 } 35 }
36 }; 36 };
37 37
38 38
39 /** 39 /**
40 * Equals assertion tests that expected == actual. 40 * Equals assertion tests that expected == actual.
41 * @param {Object} expected Expected object. 41 * @param {Object} expected Expected object.
42 * @param {Object} actual Actual object. 42 * @param {Object} actual Actual object.
43 * @param {string} opt_message User message to print if the test fails.
43 */ 44 */
44 TestSuite.prototype.assertEquals = function(expected, actual) { 45 TestSuite.prototype.assertEquals = function(expected, actual, opt_message) {
45 if (expected != actual) { 46 if (expected != actual) {
46 this.fail('Expected: "' + expected + '", but was "' + actual + '"'); 47 var message = 'Expected: "' + expected + '", but was "' + actual + '"';
48 if (opt_message) {
49 message = opt_message + '(' + message + ')';
50 }
51 this.fail(message);
47 } 52 }
48 }; 53 };
49 54
50 55
51 /** 56 /**
52 * True assertion tests that value == true. 57 * True assertion tests that value == true.
53 * @param {Object} expected Expected object.
54 * @param {Object} value Actual object. 58 * @param {Object} value Actual object.
59 * @param {string} opt_message User message to print if the test fails.
55 */ 60 */
56 TestSuite.prototype.assertTrue = function(value) { 61 TestSuite.prototype.assertTrue = function(value, opt_message) {
57 this.assertEquals(true, value); 62 this.assertEquals(true, value, opt_message);
58 }; 63 };
59 64
60 65
61 /** 66 /**
62 * Contains assertion tests that string contains substring. 67 * Contains assertion tests that string contains substring.
63 * @param {string} string Outer. 68 * @param {string} string Outer.
64 * @param {string} substring Inner. 69 * @param {string} substring Inner.
65 */ 70 */
66 TestSuite.prototype.assertContains = function(string, substring) { 71 TestSuite.prototype.assertContains = function(string, substring) {
67 if (string.indexOf(substring) == -1) { 72 if (string.indexOf(substring) == -1) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 */ 140 */
136 TestSuite.prototype.showPanel = function(panelName) { 141 TestSuite.prototype.showPanel = function(panelName) {
137 // Open Scripts panel. 142 // Open Scripts panel.
138 var toolbar = document.getElementById('toolbar'); 143 var toolbar = document.getElementById('toolbar');
139 var button = toolbar.getElementsByClassName(panelName)[0]; 144 var button = toolbar.getElementsByClassName(panelName)[0];
140 button.click(); 145 button.click();
141 this.assertEquals(WebInspector.panels[panelName], 146 this.assertEquals(WebInspector.panels[panelName],
142 WebInspector.currentPanel); 147 WebInspector.currentPanel);
143 }; 148 };
144 149
150
151 /**
152 * Overrides the method with specified name until it's called first time.
153 * @param {Object} receiver An object whose method to override.
154 * @param {string} methodName Name of the method to override.
155 * @param {Function} override A function that should be called right after the
156 * overriden method returns.
157 * @param {boolean} opt_sticky Whether restore original method after first run
158 * or not.
159 */
160 TestSuite.prototype.addSniffer = function(receiver, methodName, override,
161 opt_sticky) {
162 var orig = receiver[methodName];
163 if (typeof orig != 'function') {
164 this.fail('Cannot find method to override: ' + methodName);
165 }
166 var test = this;
167 receiver[methodName] = function(var_args) {
168 try {
169 var result = orig.apply(this, arguments);
170 } finally {
171 if (!opt_sticky) {
172 receiver[methodName] = orig;
173 }
174 }
175 // In case of exception the override won't be called.
176 try {
177 override.apply(this, arguments);
178 } catch (e) {
179 test.fail('Exception in overriden method "' + methodName + '": ' + e);
180 }
181 return result;
182 };
183 };
184
185
145 // UI Tests 186 // UI Tests
146 187
147 188
148 /** 189 /**
149 * Tests that the real injected host is present in the context. 190 * Tests that the real injected host is present in the context.
150 */ 191 */
151 TestSuite.prototype.testHostIsPresent = function() { 192 TestSuite.prototype.testHostIsPresent = function() {
152 var domAgent = devtools.tools.getDomAgent(); 193 var domAgent = devtools.tools.getDomAgent();
153 var doc = domAgent.getDocument(); 194 var doc = domAgent.getDocument();
154 this.assertTrue(typeof DevToolsHost == 'object' && !DevToolsHost.isStub); 195 this.assertTrue(typeof DevToolsHost == 'object' && !DevToolsHost.isStub);
(...skipping 26 matching lines...) Expand all
181 }; 222 };
182 223
183 224
184 /** 225 /**
185 * Tests that resources tab is enabled when corresponding item is selected. 226 * Tests that resources tab is enabled when corresponding item is selected.
186 */ 227 */
187 TestSuite.prototype.testEnableResourcesTab = function() { 228 TestSuite.prototype.testEnableResourcesTab = function() {
188 this.showPanel('resources'); 229 this.showPanel('resources');
189 230
190 var test = this; 231 var test = this;
191 var oldAddResource = WebInspector.addResource; 232 this.addSniffer(WebInspector, 'addResource',
192 WebInspector.addResource = function(identifier, payload) { 233 function(identifier, payload) {
193 WebInspector.addResource = oldAddResource; 234 test.assertEquals('simple_page.html', payload.lastPathComponent);
194 oldAddResource.call(this, identifier, payload); 235 WebInspector.panels.resources.refresh();
195 test.assertEquals('simple_page.html', payload.lastPathComponent); 236 WebInspector.resources[identifier]._resourcesTreeElement.select();
196 WebInspector.panels.resources.refresh();
197 WebInspector.resources[identifier]._resourcesTreeElement.select();
198 237
199 test.releaseControl(); 238 test.releaseControl();
200 }; 239 });
201 240
202 // Following call should lead to reload that we capture in the 241 // Following call should lead to reload that we capture in the
203 // addResource override. 242 // addResource override.
204 WebInspector.panels.resources._enableResourceTracking(); 243 WebInspector.panels.resources._enableResourceTracking();
205 244
206 // We now have some time to report results to controller. 245 // We now have some time to report results to controller.
207 this.takeControl(); 246 this.takeControl();
208 }; 247 };
209 248
210 249
211 /** 250 /**
212 * Tests resource headers. 251 * Tests resource headers.
213 */ 252 */
214 TestSuite.prototype.testResourceHeaders = function() { 253 TestSuite.prototype.testResourceHeaders = function() {
215 this.showPanel('resources'); 254 this.showPanel('resources');
216 255
217 var test = this; 256 var test = this;
218 var oldAddResource = WebInspector.addResource;
219 var oldUpdateResource = WebInspector.updateResource;
220 257
221 var requestOk = false; 258 var requestOk = false;
222 var responseOk = false; 259 var responseOk = false;
223 var timingOk = false; 260 var timingOk = false;
224 261
225 WebInspector.addResource = function(identifier, payload) { 262 this.addSniffer(WebInspector, 'addResource',
226 oldAddResource.call(this, identifier, payload); 263 function(identifier, payload) {
227 var resource = this.resources[identifier]; 264 var resource = this.resources[identifier];
228 if (resource.mainResource) { 265 if (resource.mainResource) {
229 // We are only interested in secondary resources in this test. 266 // We are only interested in secondary resources in this test.
230 return; 267 return;
231 } 268 }
232 269
233 var requestHeaders = JSON.stringify(resource.requestHeaders); 270 var requestHeaders = JSON.stringify(resource.requestHeaders);
234 test.assertContains(requestHeaders, 'Accept'); 271 test.assertContains(requestHeaders, 'Accept');
235 requestOk = true; 272 requestOk = true;
236 }; 273 }, true);
237 274
238 WebInspector.updateResource = function(identifier, payload) { 275 this.addSniffer(WebInspector, 'updateResource',
239 oldUpdateResource.call(this, identifier, payload); 276 function(identifier, payload) {
240 var resource = this.resources[identifier]; 277 var resource = this.resources[identifier];
241 if (resource.mainResource) { 278 if (resource.mainResource) {
242 // We are only interested in secondary resources in this test. 279 // We are only interested in secondary resources in this test.
243 return; 280 return;
244 } 281 }
245 282
246 if (payload.didResponseChange) { 283 if (payload.didResponseChange) {
247 var responseHeaders = JSON.stringify(resource.responseHeaders); 284 var responseHeaders = JSON.stringify(resource.responseHeaders);
248 test.assertContains(responseHeaders, 'Content-type'); 285 test.assertContains(responseHeaders, 'Content-type');
249 test.assertContains(responseHeaders, 'Content-Length'); 286 test.assertContains(responseHeaders, 'Content-Length');
250 test.assertTrue(typeof resource.responseReceivedTime != 'undefnied'); 287 test.assertTrue(typeof resource.responseReceivedTime != 'undefnied');
251 responseOk = true; 288 responseOk = true;
252 } 289 }
253 290
254 if (payload.didTimingChange) { 291 if (payload.didTimingChange) {
255 test.assertTrue(typeof resource.startTime != 'undefnied'); 292 test.assertTrue(typeof resource.startTime != 'undefnied');
256 timingOk = true; 293 timingOk = true;
257 } 294 }
258 295
259 if (payload.didCompletionChange) { 296 if (payload.didCompletionChange) {
260 test.assertTrue(requestOk); 297 test.assertTrue(requestOk);
261 test.assertTrue(responseOk); 298 test.assertTrue(responseOk);
262 test.assertTrue(timingOk); 299 test.assertTrue(timingOk);
263 test.assertTrue(typeof resource.endTime != 'undefnied'); 300 test.assertTrue(typeof resource.endTime != 'undefnied');
264 test.releaseControl(); 301 test.releaseControl();
265 } 302 }
266 }; 303 }, true);
267 304
268 WebInspector.panels.resources._enableResourceTracking(); 305 WebInspector.panels.resources._enableResourceTracking();
269 this.takeControl(); 306 this.takeControl();
270 }; 307 };
271 308
272 309
273 /** 310 /**
274 * Test that profiler works. 311 * Test that profiler works.
275 */ 312 */
276 TestSuite.prototype.testProfilerTab = function() { 313 TestSuite.prototype.testProfilerTab = function() {
277 this.showPanel('profiles'); 314 this.showPanel('profiles');
278 315
279 var test = this; 316 var test = this;
280 var oldAddProfile = WebInspector.addProfile; 317 this.addSniffer(WebInspector, 'addProfile',
281 WebInspector.addProfile = function(profile) { 318 function(profile) {
282 WebInspector.addProfile = oldAddProfile; 319 var panel = WebInspector.panels.profiles;
283 oldAddProfile.call(this, profile); 320 panel.showProfile(profile);
321 var node = panel.visibleView.profileDataGridTree.children[0];
322 // Iterate over displayed functions and search for a function
323 // that is called 'fib' or 'eternal_fib'. If found, it will mean
324 // that we actually have profiled page's code.
325 while (node) {
326 if (node.functionName.indexOf("fib") != -1) {
327 test.releaseControl();
328 }
329 node = node.traverseNextNode(true, null, true);
330 }
284 331
285 var panel = WebInspector.panels.profiles; 332 test.fail();
286 panel.showProfile(profile); 333 });
287 var node = panel.visibleView.profileDataGridTree.children[0];
288 // Iterate over displayed functions and search for a function
289 // that is called 'fib' or 'eternal_fib'. If found, it will mean
290 // that we actually have profiled page's code.
291 while (node) {
292 if (node.functionName.indexOf("fib") != -1) {
293 test.releaseControl();
294 }
295 node = node.traverseNextNode(true, null, true);
296 }
297
298 test.fail();
299 };
300 334
301 InspectorController.startProfiling(); 335 InspectorController.startProfiling();
302 window.setTimeout('InspectorController.stopProfiling();', 1000); 336 window.setTimeout('InspectorController.stopProfiling();', 1000);
303 this.takeControl(); 337 this.takeControl();
304 }; 338 };
305 339
306 340
307 /** 341 /**
308 * Tests that scripts tab can be open and populated with inspected scripts. 342 * Tests that scripts tab can be open and populated with inspected scripts.
309 */ 343 */
310 TestSuite.prototype.testShowScriptsTab = function() { 344 TestSuite.prototype.testShowScriptsTab = function() {
311 var parsedDebuggerTestPageHtml = false; 345 var parsedDebuggerTestPageHtml = false;
312 var parsedDebuggerTestJs = false; 346 var parsedDebuggerTestJs = false;
313 347
314 // Intercept parsedScriptSource calls to check that all expected scripts are 348 // Intercept parsedScriptSource calls to check that all expected scripts are
315 // added to the debugger. 349 // added to the debugger.
316 var test = this; 350 var test = this;
317 var originalParsedScriptSource = WebInspector.parsedScriptSource; 351 this.addSniffer(WebInspector, 'parsedScriptSource',
318 WebInspector.parsedScriptSource = function(sourceID, sourceURL, source, 352 function(sourceID, sourceURL, source, startingLine) {
319 startingLine) { 353 if (sourceURL.search(/debugger_test_page.html$/) != -1) {
320 if (sourceURL.search(/debugger_test_page.html$/) != -1) { 354 if (parsedDebuggerTestPageHtml) {
321 if (parsedDebuggerTestPageHtml) { 355 test.fail('Unexpected parse event: ' + sourceURL);
322 test.fail('Unexpected parse event: ' + sourceURL); 356 }
323 } 357 parsedDebuggerTestPageHtml = true;
324 parsedDebuggerTestPageHtml = true; 358 } else if (sourceURL.search(/debugger_test.js$/) != -1) {
325 } else if (sourceURL.search(/debugger_test.js$/) != -1) { 359 if (parsedDebuggerTestJs) {
326 if (parsedDebuggerTestJs) { 360 test.fail('Unexpected parse event: ' + sourceURL);
327 test.fail('Unexpected parse event: ' + sourceURL); 361 }
328 } 362 parsedDebuggerTestJs = true;
329 parsedDebuggerTestJs = true; 363 } else {
330 } else { 364 test.fail('Unexpected script URL: ' + sourceURL);
331 test.fail('Unexpected script URL: ' + sourceURL); 365 }
332 }
333 originalParsedScriptSource.apply(this, arguments);
334 366
335 if (!WebInspector.panels.scripts.visibleView) { 367 if (!WebInspector.panels.scripts.visibleView) {
336 test.fail('No visible script view: ' + sourceURL); 368 test.fail('No visible script view: ' + sourceURL);
337 } 369 }
338 370
339 if (parsedDebuggerTestJs && parsedDebuggerTestPageHtml) { 371 if (parsedDebuggerTestJs && parsedDebuggerTestPageHtml) {
340 test.releaseControl(); 372 test.releaseControl();
341 } 373 }
342 }; 374 }, true /* sticky */);
343 375
344 this.showPanel('scripts'); 376 this.showPanel('scripts');
345 377
346 // Wait until all scripts are added to the debugger. 378 // Wait until all scripts are added to the debugger.
347 this.takeControl(); 379 this.takeControl();
348 }; 380 };
349 381
350 382
351 /** 383 /**
384 * Tests that a breakpoint can be set.
385 */
386 TestSuite.prototype.testSetBreakpoint = function() {
387 var parsedDebuggerTestPageHtml = false;
388 var parsedDebuggerTestJs = false;
389
390 this.showPanel('scripts');
391
392 var scriptUrl = null;
393 var breakpointLine = 12;
394
395 var test = this;
396 var orig = devtools.DebuggerAgent.prototype.handleScriptsResponse_;
397 this.addSniffer(devtools.DebuggerAgent.prototype, 'handleScriptsResponse_',
398 function(msg) {
399 var scriptSelect = document.getElementById('scripts-files');
400 var scriptResource =
401 scriptSelect.options[scriptSelect.selectedIndex].representedObject;
402
403 test.assertTrue(scriptResource instanceof WebInspector.Resource);
404 test.assertTrue(!!scriptResource.url);
405 test.assertTrue(
406 scriptResource.url.search(/debugger_test_page.html$/) != -1,
407 'Main HTML resource should be selected.');
408
409 // Store for access from setbreakpoint handler.
410 scriptUrl = scriptResource.url;
411
412 var scriptsPanel = WebInspector.panels.scripts;
413
414 var view = scriptsPanel.visibleView;
415 test.assertTrue(view instanceof WebInspector.SourceView);
416
417 if (!view.sourceFrame._isContentLoaded()) {
418 test.addSniffer(view, '_sourceFrameSetupFinished', function(event) {
419 view._addBreakpoint(breakpointLine);
420 // Force v8 execution.
421 devtools.tools.evaluateJavaScript('javascript:void(0)');
422 });
423 } else {
424 view._addBreakpoint(breakpointLine);
425 // Force v8 execution.
426 devtools.tools.evaluateJavaScript('javascript:void(0)');
427 }
428 });
429
430 this.addSniffer(
431 devtools.DebuggerAgent.prototype,
432 'handleSetBreakpointResponse_',
433 function(msg) {
434 var bps = this.urlToBreakpoints_[scriptUrl];
435 test.assertTrue(!!bps, 'No breakpoints for line ' + breakpointLine);
436 var line = devtools.DebuggerAgent.webkitToV8LineNumber_(breakpointLine);
437 test.assertTrue(!!bps[line].getV8Id(),
438 'Breakpoint id was not assigned.');
439 test.releaseControl();
440 });
441
442 this.takeControl();
443 };
444
445
446 /**
352 * Key event with given key identifier. 447 * Key event with given key identifier.
353 */ 448 */
354 TestSuite.KeyEvent = function(key) { 449 TestSuite.KeyEvent = function(key) {
355 this.keyIdentifier = key; 450 this.keyIdentifier = key;
356 }; 451 };
357 TestSuite.KeyEvent.prototype.preventDefault = function() {}; 452 TestSuite.KeyEvent.prototype.preventDefault = function() {};
358 TestSuite.KeyEvent.prototype.stopPropagation = function() {}; 453 TestSuite.KeyEvent.prototype.stopPropagation = function() {};
359 454
360 455
361 /** 456 /**
362 * Tests console eval. 457 * Tests console eval.
363 */ 458 */
364 TestSuite.prototype.testConsoleEval = function() { 459 TestSuite.prototype.testConsoleEval = function() {
365 WebInspector.console.visible = true; 460 WebInspector.console.visible = true;
366 WebInspector.console.prompt.text = '123'; 461 WebInspector.console.prompt.text = '123';
367 WebInspector.console.promptElement.handleKeyEvent( 462 WebInspector.console.promptElement.handleKeyEvent(
368 new TestSuite.KeyEvent('Enter')); 463 new TestSuite.KeyEvent('Enter'));
369 464
370 var test = this; 465 var test = this;
371 var originalConsoleAddMessage = WebInspector.Console.prototype.addMessage; 466 this.addSniffer(WebInspector.Console.prototype, 'addMessage',
372 WebInspector.Console.prototype.addMessage = function(commandResult) { 467 function(commandResult) {
373 originalConsoleAddMessage.call(this, commandResult); 468 test.assertEquals('123', commandResult.toMessageElement().textContent);
374 WebInspector.Console.prototype.addMessage = originalConsoleAddMessage; 469 test.releaseControl();
375 test.assertEquals('123', commandResult.toMessageElement().textContent); 470 });
376 test.releaseControl();
377 };
378 471
379 this.takeControl(); 472 this.takeControl();
380 }; 473 };
381 474
382 475
383 /** 476 /**
384 * Tests console log. 477 * Tests console log.
385 */ 478 */
386 TestSuite.prototype.testConsoleLog = function() { 479 TestSuite.prototype.testConsoleLog = function() {
387 WebInspector.console.visible = true; 480 WebInspector.console.visible = true;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 /** 517 /**
425 * Tests eval of global objects. 518 * Tests eval of global objects.
426 */ 519 */
427 TestSuite.prototype.testEvalGlobal = function() { 520 TestSuite.prototype.testEvalGlobal = function() {
428 WebInspector.console.visible = true; 521 WebInspector.console.visible = true;
429 WebInspector.console.prompt.text = 'foo'; 522 WebInspector.console.prompt.text = 'foo';
430 WebInspector.console.promptElement.handleKeyEvent( 523 WebInspector.console.promptElement.handleKeyEvent(
431 new TestSuite.KeyEvent('Enter')); 524 new TestSuite.KeyEvent('Enter'));
432 525
433 var test = this; 526 var test = this;
434 var originalConsoleAddMessage = WebInspector.Console.prototype.addMessage; 527 this.addSniffer(WebInspector.Console.prototype, 'addMessage',
435 WebInspector.Console.prototype.addMessage = function(commandResult) { 528 function(commandResult) {
436 originalConsoleAddMessage.call(this, commandResult); 529 test.assertEquals('fooValue',
437 test.assertEquals('fooValue', commandResult.toMessageElement().textContent); 530 commandResult.toMessageElement().textContent);
438 test.releaseControl(); 531 test.releaseControl();
439 }; 532 });
440 533
441 this.takeControl(); 534 this.takeControl();
442 }; 535 };
443 536
444 537
445 /** 538 /**
446 * Tests eval on call frame. 539 * Tests eval on call frame.
447 */ 540 */
448 TestSuite.prototype.testEvalCallFrame = function() { 541 TestSuite.prototype.testEvalCallFrame = function() {
449 }; 542 };
(...skipping 22 matching lines...) Expand all
472 /** 565 /**
473 * Run specified test on a fresh instance of the test suite. 566 * Run specified test on a fresh instance of the test suite.
474 * @param {string} name Name of a test method from TestSuite class. 567 * @param {string} name Name of a test method from TestSuite class.
475 */ 568 */
476 uiTests.runTest = function(name) { 569 uiTests.runTest = function(name) {
477 new TestSuite().runTest(name); 570 new TestSuite().runTest(name);
478 }; 571 };
479 572
480 573
481 } 574 }
OLDNEW
« no previous file with comments | « chrome/browser/debugger/devtools_sanity_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698