| 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 // Library providing basic test framework functionality. | 5 // Library providing basic test framework functionality. |
| 6 | 6 |
| 7 (function() { | 7 (function() { |
| 8 // Indicates a pass to the C++ backend. | 8 // Indicates a pass to the C++ backend. |
| 9 function pass() { | 9 function pass() { |
| 10 chrome.send('Pass', []); | 10 chrome.send('Pass', []); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 function assertTrue(test, message) { | 32 function assertTrue(test, message) { |
| 33 assertBool(test, true, message); | 33 assertBool(test, true, message); |
| 34 } | 34 } |
| 35 | 35 |
| 36 function assertFalse(test, message) { | 36 function assertFalse(test, message) { |
| 37 assertBool(test, false, message); | 37 assertBool(test, false, message); |
| 38 } | 38 } |
| 39 | 39 |
| 40 function assertEquals(expected, actual, message) { | 40 function assertEquals(expected, actual, message) { |
| 41 if (expected != actual) { | 41 if (expected !== actual) { |
| 42 throw new Error('Test Error. Actual: ' + actual + '\nExpected: ' + | 42 throw new Error('Test Error in ' + testName(currentTest) + |
| 43 expected + '\n' + message); | 43 '\nActual: ' + actual + '\nExpected: ' + expected + |
| 44 '\n' + message); |
| 44 } | 45 } |
| 45 if (typeof expected != typeof actual) { | 46 if (typeof expected != typeof actual) { |
| 46 throw new Error('Test Error' + | 47 throw new Error('Test Error in ' + testName(currentTest) + |
| 47 ' (type mismatch)\nActual Type: ' + typeof actual + | 48 ' (type mismatch)\nActual Type: ' + typeof actual + |
| 48 '\nExpected Type:' + typeof expected + '\n' + message); | 49 '\nExpected Type:' + typeof expected + '\n' + message); |
| 49 } | 50 } |
| 50 } | 51 } |
| 51 | 52 |
| 52 function assertNotReached(message) { | 53 function assertNotReached(message) { |
| 53 throw new Error(message); | 54 throw new Error(message); |
| 54 } | 55 } |
| 55 | 56 |
| 56 function runTest(currentTest) { | 57 function runTest(currentTest) { |
| 57 try { | 58 try { |
| 58 console.log('Running test ' + currentTest.name); | 59 console.log('Running test ' + currentTest.name); |
| 59 currentTest.call(); | 60 currentTest.call(); |
| 60 } catch (e) { | 61 } catch (e) { |
| 61 console.log( | 62 console.error( |
| 62 'Failed: ' + currentTest.name + '\nwith exception: ' + e.message); | 63 'Failed: ' + currentTest.name + '\nwith exception: ' + e.message); |
| 63 | 64 |
| 64 fail(e.message); | 65 fail(e.message); |
| 65 return; | 66 return; |
| 66 } | 67 } |
| 67 | 68 |
| 68 | 69 |
| 69 // All tests passed. | 70 // All tests passed. |
| 70 pass(''); | 71 pass(''); |
| 71 } | 72 } |
| 72 | 73 |
| 73 // Exports. | 74 // Exports. |
| 74 window.assertTrue = assertTrue; | 75 window.assertTrue = assertTrue; |
| 75 window.assertFalse = assertFalse; | 76 window.assertFalse = assertFalse; |
| 76 window.assertEquals = assertEquals; | 77 window.assertEquals = assertEquals; |
| 77 window.assertNotReached = assertNotReached; | 78 window.assertNotReached = assertNotReached; |
| 78 window.runTest = runTest; | 79 window.runTest = runTest; |
| 79 })(); | 80 })(); |
| OLD | NEW |