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

Side by Side Diff: chrome/test/data/webui/test_api.js

Issue 7553009: Add some browser tests for net-internals (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Use g_browser.receive as function name when appropriate (Really, this time). Created 9 years, 4 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
OLDNEW
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 Library providing basic test framework functionality. 6 * @fileoverview Library providing basic test framework functionality.
7 **/ 7 **/
8 8
9 /** 9 /**
10 * Namespace for |Test|. 10 * Namespace for |Test|.
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 errors.push(e); 476 errors.push(e);
477 } 477 }
478 }; 478 };
479 expectFunc.isExpect = true; 479 expectFunc.isExpect = true;
480 expectFunc.expectName = assertFunc.name.replace(/^assert/, 'expect'); 480 expectFunc.expectName = assertFunc.name.replace(/^assert/, 'expect');
481 return expectFunc; 481 return expectFunc;
482 } 482 }
483 483
484 /** 484 /**
485 * This is the starting point for tests run by WebUIBrowserTest. It clears 485 * This is the starting point for tests run by WebUIBrowserTest. It clears
486 * |errors|, runs the test surrounded by an expect to catch Errors. If 486 * |errors|, runs the test surrounded by an expect to catch Errors. If
Sheridan Rawlins 2011/08/03 18:29:57 This doesn't clear |errors| anymore.
mmenke 2011/08/03 19:30:12 Wasn't sure if I should leave that in or not, as c
487 * |errors| is non-empty, it reports a failure and a message by joining 487 * |errors| is non-empty, it reports a failure and a message by joining
488 * |errors|. 488 * |errors|.
489 * @param {string} testFunction The function name to call. 489 * @param {string} testFunction The function name to call.
490 * @param {Array} testArguments The arguments to call |testFunction| with. 490 * @param {Array} testArguments The arguments to call |testFunction| with.
491 * @return {Array.<boolean, string>} [test-succeeded, message-if-failed] 491 * @return {Array.<boolean, string>} [test-succeeded, message-if-failed]
492 * @see errors 492 * @see errors
493 * @see createExpect 493 * @see createExpect
Sheridan Rawlins 2011/08/03 18:29:57 @see runTestFunction
mmenke 2011/08/03 19:30:12 Done.
494 **/ 494 **/
495 function runTest(testFunction, testArguments) { 495 function runTest(testFunction, testArguments) {
496 errors.splice(0, errors.length);
497 // Avoid eval() if at all possible, since it will not work on pages 496 // Avoid eval() if at all possible, since it will not work on pages
498 // that have enabled content-security-policy. 497 // that have enabled content-security-policy.
499 var testBody = this[testFunction]; // global object -- not a method. 498 var testBody = this[testFunction]; // global object -- not a method.
500 if (typeof testBody === "undefined") 499 if (typeof testBody === "undefined")
501 testBody = eval(testFunction); 500 testBody = eval(testFunction);
502 if (testBody != RUN_TEST_F) { 501 if (testBody != RUN_TEST_F) {
503 var testName = 502 var testName =
504 testFunction.name ? testFunction.name : testBody.toString(); 503 testFunction.name ? testFunction.name : testBody.toString();
505 console.log('Running test ' + testName); 504 console.log('Running test ' + testName);
506 } 505 }
506 return runTestFunction(testFunction, testBody, testArguments);
507 }
508
509 /**
510 * This is the guts of WebUIBrowserTest. It clears |errors|, runs the
511 * test surrounded by an expect to catch Errors. If |errors| is
512 * non-empty, it reports a failure and a message by joining |errors|.
513 * Consumers can use this to use assert/expect functions asynchronously,
514 * but are then responsible for reporting errors to the browser themselves.
515 * @param {string} testFunction The function name to report on failure.
516 * @param {Function} testBody The function to call.
517 * @param {Array} testArguments The arguments to call |testBody| with.
518 * @return {Array.<boolean, string>} [test-succeeded, message-if-failed]
519 * @see errors
520 * @see createExpect
521 **/
522 function runTestFunction(testFunction, testBody, testArguments) {
523 errors.splice(0, errors.length);
507 createExpect(testBody).apply(null, testArguments); 524 createExpect(testBody).apply(null, testArguments);
508 525
509 var result = [true]; 526 var result = [true];
510 if (errors.length) { 527 if (errors.length) {
511 var message = ''; 528 var message = '';
512 for (var i = 0; i < errors.length; ++i) { 529 for (var i = 0; i < errors.length; ++i) {
513 message += 'Failed: ' + testFunction + '(' + 530 message += 'Failed: ' + testFunction + '(' +
514 testArguments.map(JSON.stringify) + 531 testArguments.map(JSON.stringify) +
515 ')\n' + errors[i].stack; 532 ')\n' + errors[i].stack;
516 } 533 }
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 window.expectGT = createExpect(assertGT); 729 window.expectGT = createExpect(assertGT);
713 window.expectEquals = createExpect(assertEquals); 730 window.expectEquals = createExpect(assertEquals);
714 window.expectLE = createExpect(assertLE); 731 window.expectLE = createExpect(assertLE);
715 window.expectLT = createExpect(assertLT); 732 window.expectLT = createExpect(assertLT);
716 window.expectNotEquals = createExpect(assertNotEquals); 733 window.expectNotEquals = createExpect(assertNotEquals);
717 window.expectNotReached = createExpect(assertNotReached); 734 window.expectNotReached = createExpect(assertNotReached);
718 window.preloadJavascriptLibraries = preloadJavascriptLibraries; 735 window.preloadJavascriptLibraries = preloadJavascriptLibraries;
719 window.registerMessageCallback = registerMessageCallback; 736 window.registerMessageCallback = registerMessageCallback;
720 window.registerMockMessageCallbacks = registerMockMessageCallbacks; 737 window.registerMockMessageCallbacks = registerMockMessageCallbacks;
721 window.runTest = runTest; 738 window.runTest = runTest;
739 window.runTestFunction = runTestFunction;
722 window.SaveArgumentsMatcher = SaveArgumentsMatcher; 740 window.SaveArgumentsMatcher = SaveArgumentsMatcher;
723 window.TEST = TEST; 741 window.TEST = TEST;
724 window.TEST_F = TEST_F; 742 window.TEST_F = TEST_F;
725 window.GEN = GEN; 743 window.GEN = GEN;
726 744
727 // Import the Mock4JS helpers. 745 // Import the Mock4JS helpers.
728 Mock4JS.addMockSupport(window); 746 Mock4JS.addMockSupport(window);
729 })(); 747 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698