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

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: Fix comments 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 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 } catch (e) { 475 } catch (e) {
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. If an error
486 * |errors|, runs the test surrounded by an expect to catch Errors. If 486 * occurs, it reports a failure and a message created by joining individual
487 * |errors| is non-empty, it reports a failure and a message by joining 487 * error messages.
488 * |errors|.
489 * @param {string} testFunction The function name to call. 488 * @param {string} testFunction The function name to call.
490 * @param {Array} testArguments The arguments to call |testFunction| with. 489 * @param {Array} testArguments The arguments to call |testFunction| with.
491 * @return {Array.<boolean, string>} [test-succeeded, message-if-failed] 490 * @return {Array.<boolean, string>} [test-succeeded, message-if-failed]
492 * @see errors 491 * @see errors
493 * @see createExpect 492 * @see runTestFunction
494 **/ 493 **/
495 function runTest(testFunction, testArguments) { 494 function runTest(testFunction, testArguments) {
496 errors.splice(0, errors.length);
497 // Avoid eval() if at all possible, since it will not work on pages 495 // Avoid eval() if at all possible, since it will not work on pages
498 // that have enabled content-security-policy. 496 // that have enabled content-security-policy.
499 var testBody = this[testFunction]; // global object -- not a method. 497 var testBody = this[testFunction]; // global object -- not a method.
500 if (typeof testBody === "undefined") 498 if (typeof testBody === "undefined")
501 testBody = eval(testFunction); 499 testBody = eval(testFunction);
502 if (testBody != RUN_TEST_F) { 500 if (testBody != RUN_TEST_F) {
503 var testName = 501 var testName =
504 testFunction.name ? testFunction.name : testBody.toString(); 502 testFunction.name ? testFunction.name : testBody.toString();
505 console.log('Running test ' + testName); 503 console.log('Running test ' + testName);
506 } 504 }
505 return runTestFunction(testFunction, testBody, testArguments);
506 }
507
508 /**
509 * This is the guts of WebUIBrowserTest. It clears |errors|, runs the
510 * test surrounded by an expect to catch Errors. If |errors| is
511 * non-empty, it reports a failure and a message by joining |errors|.
512 * Consumers can use this to use assert/expect functions asynchronously,
513 * but are then responsible for reporting errors to the browser themselves.
514 * @param {string} testFunction The function name to report on failure.
515 * @param {Function} testBody The function to call.
516 * @param {Array} testArguments The arguments to call |testBody| with.
517 * @return {Array.<boolean, string>} [test-succeeded, message-if-failed]
518 * @see errors
519 * @see createExpect
520 **/
521 function runTestFunction(testFunction, testBody, testArguments) {
522 errors.splice(0, errors.length);
507 createExpect(testBody).apply(null, testArguments); 523 createExpect(testBody).apply(null, testArguments);
508 524
509 var result = [true]; 525 var result = [true];
510 if (errors.length) { 526 if (errors.length) {
511 var message = ''; 527 var message = '';
512 for (var i = 0; i < errors.length; ++i) { 528 for (var i = 0; i < errors.length; ++i) {
513 message += 'Failed: ' + testFunction + '(' + 529 message += 'Failed: ' + testFunction + '(' +
514 testArguments.map(JSON.stringify) + 530 testArguments.map(JSON.stringify) +
515 ')\n' + errors[i].stack; 531 ')\n' + errors[i].stack;
516 } 532 }
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 window.expectGT = createExpect(assertGT); 728 window.expectGT = createExpect(assertGT);
713 window.expectEquals = createExpect(assertEquals); 729 window.expectEquals = createExpect(assertEquals);
714 window.expectLE = createExpect(assertLE); 730 window.expectLE = createExpect(assertLE);
715 window.expectLT = createExpect(assertLT); 731 window.expectLT = createExpect(assertLT);
716 window.expectNotEquals = createExpect(assertNotEquals); 732 window.expectNotEquals = createExpect(assertNotEquals);
717 window.expectNotReached = createExpect(assertNotReached); 733 window.expectNotReached = createExpect(assertNotReached);
718 window.preloadJavascriptLibraries = preloadJavascriptLibraries; 734 window.preloadJavascriptLibraries = preloadJavascriptLibraries;
719 window.registerMessageCallback = registerMessageCallback; 735 window.registerMessageCallback = registerMessageCallback;
720 window.registerMockMessageCallbacks = registerMockMessageCallbacks; 736 window.registerMockMessageCallbacks = registerMockMessageCallbacks;
721 window.runTest = runTest; 737 window.runTest = runTest;
738 window.runTestFunction = runTestFunction;
722 window.SaveArgumentsMatcher = SaveArgumentsMatcher; 739 window.SaveArgumentsMatcher = SaveArgumentsMatcher;
723 window.TEST = TEST; 740 window.TEST = TEST;
724 window.TEST_F = TEST_F; 741 window.TEST_F = TEST_F;
725 window.GEN = GEN; 742 window.GEN = GEN;
726 743
727 // Import the Mock4JS helpers. 744 // Import the Mock4JS helpers.
728 Mock4JS.addMockSupport(window); 745 Mock4JS.addMockSupport(window);
729 })(); 746 })();
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698