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

Side by Side Diff: chrome/browser/resources/chromeos/chromevox/testing/assert_additions.js

Issue 484063003: Port braille related tests from ChromeVox upstream. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@lkcr
Patch Set: Rename a fake class. Created 6 years, 3 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 * Asserts that a given argument's value is undefined. 6 * Asserts that a given argument's value is undefined.
7 * @param {object} a The argument to check. 7 * @param {object} a The argument to check.
8 */ 8 */
9 function assertUndefined(a) { 9 function assertUndefined(a) {
10 if (a !== undefined) { 10 if (a !== undefined) {
11 throw new Error('Assertion failed: expected undefined'); 11 throw new Error('Assertion failed: expected undefined');
12 } 12 }
13 } 13 }
14 14
15 /** 15 /**
16 * Asserts that the argument is neither null nor undefined.
17 * @param {object} obj The argument to check.
18 * @param {string=} opt_message Error message if the condition is not met.
19 */
20 function assertNotNullNorUndefined(obj, opt_message) {
21 if (obj === undefined || obj === null) {
22 throw new Error('Can\'t be null or undefined: ' + (opt_message || '') +
23 '\n' + 'Actual: ' + a);
24 }
25 }
26
27 /**
16 * Asserts that a given function call throws an exception. 28 * Asserts that a given function call throws an exception.
17 * @param {string} msg Message to print if exception not thrown. 29 * @param {string} msg Message to print if exception not thrown.
18 * @param {Function} fn The function to call. 30 * @param {Function} fn The function to call.
19 * @param {string} error The name of the exception we expect {@code fn} to 31 * @param {string} error The name of the exception we expect {@code fn} to
20 * throw. 32 * throw.
21 */ 33 */
22 function assertException(msg, fn, error) { 34 function assertException(msg, fn, error) {
23 try { 35 try {
24 fn(); 36 fn();
25 } catch (e) { 37 } catch (e) {
(...skipping 23 matching lines...) Expand all
49 } 61 }
50 } 62 }
51 if (!same) { 63 if (!same) {
52 throw new Error('Expected ' + JSON.stringify(array1) + 64 throw new Error('Expected ' + JSON.stringify(array1) +
53 ', got ' + JSON.stringify(array2)); 65 ', got ' + JSON.stringify(array2));
54 } 66 }
55 } 67 }
56 68
57 /** 69 /**
58 * Asserts that two objects have the same JSON serialization. 70 * Asserts that two objects have the same JSON serialization.
59 * @param {Object} obj1 The expected object. 71 * @param {Object} expected The expected object.
60 * @param {Object} obj2 The actual object. 72 * @param {Object} actual The actual object.
73 * @param {string=} opt_message Message used for errors.
61 */ 74 */
62 function assertEqualsJSON(obj1, obj2) { 75 function assertEqualsJSON(expected, actual, opt_message) {
63 if (!eqJSON(obj1, obj2)) { 76 if (JSON.stringify(actual) !== JSON.stringify(expected)) {
64 throw new Error('Expected ' + JSON.stringify(obj1) + 77 throw new Error((opt_message ? opt_message + '\n' : '') +
65 ', got ' + JSON.stringify(obj2)); 78 'Expected ' + JSON.stringify(expected) + '\n' +
79 'Got ' + JSON.stringify(actual));
66 } 80 }
67 } 81 }
68 82
69 assertSame = assertEquals; 83 assertSame = assertEquals;
70 assertNotSame = assertNotEquals; 84 assertNotSame = assertNotEquals;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698