OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 * @fileoverview The way these tests work is as follows: | 6 * @fileoverview The way these tests work is as follows: |
7 * C++ in net_internals_ui_browsertest.cc does any necessary setup, and then | 7 * C++ in net_internals_ui_browsertest.cc does any necessary setup, and then |
8 * calls the entry point for a test with RunJavascriptTest. The called | 8 * calls the entry point for a test with RunJavascriptTest. The called |
9 * function can then use the assert/expect functions defined in test_api.js. | 9 * function can then use the assert/expect functions defined in test_api.js. |
10 * All callbacks from the browser are wrapped in such a way that they can | 10 * All callbacks from the browser are wrapped in such a way that they can |
(...skipping 17 matching lines...) Expand all Loading... | |
28 /** | 28 /** |
29 * Map of tab handle names to location hashes. | 29 * Map of tab handle names to location hashes. |
30 * @type {object.<string, string>} | 30 * @type {object.<string, string>} |
31 */ | 31 */ |
32 var hashToTabHandleIdMap = { | 32 var hashToTabHandleIdMap = { |
33 capture: CaptureView.TAB_HANDLE_ID, | 33 capture: CaptureView.TAB_HANDLE_ID, |
34 export: ExportView.TAB_HANDLE_ID, | 34 export: ExportView.TAB_HANDLE_ID, |
35 import: ImportView.TAB_HANDLE_ID, | 35 import: ImportView.TAB_HANDLE_ID, |
36 proxy: ProxyView.TAB_HANDLE_ID, | 36 proxy: ProxyView.TAB_HANDLE_ID, |
37 events: EventsView.TAB_HANDLE_ID, | 37 events: EventsView.TAB_HANDLE_ID, |
38 timeline: TimelineView.TAB_HANDLE_ID, | |
38 dns: DnsView.TAB_HANDLE_ID, | 39 dns: DnsView.TAB_HANDLE_ID, |
39 sockets: SocketsView.TAB_HANDLE_ID, | 40 sockets: SocketsView.TAB_HANDLE_ID, |
40 spdy: SpdyView.TAB_HANDLE_ID, | 41 spdy: SpdyView.TAB_HANDLE_ID, |
41 httpCache: HttpCacheView.TAB_HANDLE_ID, | 42 httpCache: HttpCacheView.TAB_HANDLE_ID, |
42 httpThrottling: HttpThrottlingView.TAB_HANDLE_ID, | 43 httpThrottling: HttpThrottlingView.TAB_HANDLE_ID, |
43 serviceProviders: ServiceProvidersView.TAB_HANDLE_ID, | 44 serviceProviders: ServiceProvidersView.TAB_HANDLE_ID, |
44 tests: TestView.TAB_HANDLE_ID, | 45 tests: TestView.TAB_HANDLE_ID, |
45 hsts: HSTSView.TAB_HANDLE_ID, | 46 hsts: HSTSView.TAB_HANDLE_ID, |
46 logs: LogsView.TAB_HANDLE_ID, | 47 logs: LogsView.TAB_HANDLE_ID, |
47 prerender: PrerenderView.TAB_HANDLE_ID | 48 prerender: PrerenderView.TAB_HANDLE_ID |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
311 * Adds a Task to the end of the queue. Each Task may only be added once | 312 * Adds a Task to the end of the queue. Each Task may only be added once |
312 * to a single queue. | 313 * to a single queue. |
313 * @param {Task}: task The Task to add. | 314 * @param {Task}: task The Task to add. |
314 */ | 315 */ |
315 addTask: function(task) { | 316 addTask: function(task) { |
316 this.tasks_.push(task); | 317 this.tasks_.push(task); |
317 task.setTaskQueue_(this); | 318 task.setTaskQueue_(this); |
318 }, | 319 }, |
319 | 320 |
320 /** | 321 /** |
322 * Adds a Task to the end of the queue. The task will call the provided | |
323 * function, and then complete. | |
324 * @param {function}: taskFunction The function the task will call. | |
325 */ | |
326 addFunctionTask: function(taskFunction) { | |
327 this.addTask(new CallFunctionTask(taskFunction)); | |
328 }, | |
329 | |
330 /** | |
321 * Starts running the Tasks in the queue. Once called, may not be called | 331 * Starts running the Tasks in the queue. Once called, may not be called |
322 * again. | 332 * again. |
323 */ | 333 */ |
324 run: function() { | 334 run: function() { |
325 assertFalse(this.isRunning_); | 335 assertFalse(this.isRunning_); |
326 this.isRunning_ = true; | 336 this.isRunning_ = true; |
327 this.runNextTask_(); | 337 this.runNextTask_(); |
328 }, | 338 }, |
329 | 339 |
330 /** | 340 /** |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
384 * task. Runs the next task, if any. | 394 * task. Runs the next task, if any. |
385 */ | 395 */ |
386 onTaskDone: function() { | 396 onTaskDone: function() { |
387 assertFalse(this.isDone_); | 397 assertFalse(this.isDone_); |
388 this.isDone_ = true; | 398 this.isDone_ = true; |
389 this.taskQueue_.runNextTask_(); | 399 this.taskQueue_.runNextTask_(); |
390 } | 400 } |
391 }; | 401 }; |
392 | 402 |
393 /** | 403 /** |
404 * A Task that can be added to a TaskQueue. A Task is started with a call to | |
405 * the start function, and must call its own onTaskDone when complete. | |
406 * @constructor | |
407 */ | |
408 function CallFunctionTask(taskFunction) { | |
409 Task.call(this); | |
410 assertEquals('function', typeof taskFunction); | |
411 this.taskFunction_ = taskFunction; | |
412 }; | |
eroman
2011/11/16 04:03:46
nit: no need for semicolon.
mmenke
2011/11/16 18:39:35
Done.
| |
413 | |
414 CallFunctionTask.prototype = { | |
415 __proto__: Task.prototype, | |
416 | |
417 /** | |
418 * Runs the function and then completes. | |
419 */ | |
420 start: function() { | |
421 this.taskFunction_(); | |
422 this.onTaskDone(); | |
423 } | |
424 }; | |
425 | |
426 /** | |
394 * Returns true if a node does not have a 'display' property of 'none'. | 427 * Returns true if a node does not have a 'display' property of 'none'. |
395 * @param {node}: node The node to check. | 428 * @param {node}: node The node to check. |
396 */ | 429 */ |
397 function isDisplayed(node) { | 430 function isDisplayed(node) { |
398 var style = getComputedStyle(node); | 431 var style = getComputedStyle(node); |
399 return style.getPropertyValue('display') != 'none'; | 432 return style.getPropertyValue('display') != 'none'; |
400 } | 433 } |
401 | 434 |
435 /** | |
436 * Creates a new NetLog source. Note that the id may conflict with events | |
437 * received from the browser. | |
438 * @param {int}: type The source type. | |
439 * @param {int}: id The source id. | |
440 * @constructor | |
441 */ | |
442 function Source(type, id) { | |
443 assertNotEquals(getKeyWithValue(LogSourceType, type), '?'); | |
444 assertGE(id, 0); | |
445 this.type = type; | |
446 this.id = id; | |
447 } | |
448 | |
449 /** | |
450 * Creates a new NetLog event. | |
451 * @param {Source}: source The source associated with the event. | |
452 * @param {int}: type The event id. | |
453 * @param {int}: time When the event occurred. | |
454 * @param {int}: phase The event phase. | |
455 * @param {object}: params The event parameters. May be null. | |
456 * @constructor | |
457 */ | |
458 function Event(source, type, time, phase, params) { | |
459 assertNotEquals(getKeyWithValue(LogEventType, type), '?'); | |
460 assertNotEquals(getKeyWithValue(LogEventPhase, phase), '?'); | |
461 | |
462 this.source = source; | |
463 this.phase = phase; | |
464 this.type = type; | |
465 this.time = "" + time; | |
466 this.phase = phase; | |
467 if (params) | |
468 this.params = params; | |
469 } | |
470 | |
471 /** | |
472 * Creates a new NetLog begin event. Parameters are the same as Event, | |
473 * except there's no |phase| argument. | |
474 * @see Event | |
475 */ | |
476 function CreateBeginEvent(source, type, time, params) { | |
477 return new Event(source, type, time, LogEventPhase.PHASE_BEGIN, params); | |
478 } | |
479 | |
480 /** | |
481 * Creates a new NetLog end event. Parameters are the same as Event, | |
482 * except there's no |phase| argument. | |
483 * @see Event | |
484 */ | |
485 function CreateEndEvent(source, type, time, params) { | |
486 return new Event(source, type, time, LogEventPhase.PHASE_END, params); | |
487 } | |
488 | |
489 /** | |
490 * Creates a new NetLog end event matching the given begin event. | |
491 * @param {Event}: beginEvent The begin event. Returned event will have the | |
492 * same source and type. | |
493 * @param {int}: time When the event occurred. | |
494 * @param {object}: params The event parameters. May be null. | |
495 * @see Event | |
496 */ | |
497 function CreateMatchingEndEvent(beginEvent, time, params) { | |
498 return CreateEndEvent(beginEvent.source, beginEvent.type, time, params); | |
499 } | |
500 | |
402 // Exported functions. | 501 // Exported functions. |
403 return { | 502 return { |
404 test: test, | 503 test: test, |
405 checkStyledTableRows: checkStyledTableRows, | 504 checkStyledTableRows: checkStyledTableRows, |
406 checkTabHandleVisibility: checkTabHandleVisibility, | 505 checkTabHandleVisibility: checkTabHandleVisibility, |
407 getStyledTableText: getStyledTableText, | 506 getStyledTableText: getStyledTableText, |
408 isDisplayed: isDisplayed, | 507 isDisplayed: isDisplayed, |
409 runTest: runTest, | 508 runTest: runTest, |
410 switchToView: switchToView, | 509 switchToView: switchToView, |
510 TaskQueue: TaskQueue, | |
411 Task: Task, | 511 Task: Task, |
412 TaskQueue: TaskQueue | 512 Source: Source, |
513 Event: Event, | |
514 CreateBeginEvent: CreateBeginEvent, | |
515 CreateEndEvent: CreateEndEvent, | |
516 CreateMatchingEndEvent: CreateMatchingEndEvent | |
413 }; | 517 }; |
414 })(); | 518 })(); |
415 | 519 |
416 netInternalsTest.test('netInternalsDone', function() { | 520 netInternalsTest.test('netInternalsDone', function() { |
417 testDone(); | 521 testDone(); |
418 }); | 522 }); |
419 | 523 |
420 netInternalsTest.test('netInternalsExpectFail', function() { | 524 netInternalsTest.test('netInternalsExpectFail', function() { |
421 expectNotReached(); | 525 expectNotReached(); |
422 }); | 526 }); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
474 HostResolverInfoObserver.prototype.onHostResolverInfoChanged = function() { | 578 HostResolverInfoObserver.prototype.onHostResolverInfoChanged = function() { |
475 assertNotReached(); | 579 assertNotReached(); |
476 }; | 580 }; |
477 | 581 |
478 // Create the observer and add it to |g_browser|. | 582 // Create the observer and add it to |g_browser|. |
479 g_browser.addHostResolverInfoObserver(new HostResolverInfoObserver()); | 583 g_browser.addHostResolverInfoObserver(new HostResolverInfoObserver()); |
480 | 584 |
481 // Needed to trigger an update. | 585 // Needed to trigger an update. |
482 netInternalsTest.switchToView('dns'); | 586 netInternalsTest.switchToView('dns'); |
483 }); | 587 }); |
OLD | NEW |