OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <title>audit.js: handling failures</title> | 4 <title> |
5 <script src="../../resources/testharness.js"></script> | 5 audit.js: handling failures |
6 <script src="../../resources/testharnessreport.js"></script> | 6 </title> |
7 <script src="../resources/audit.js"></script> | 7 <script src="../../resources/testharness.js"></script> |
8 </head> | 8 <script src="../../resources/testharnessreport.js"></script> |
9 <body> | 9 <script src="../resources/audit.js"></script> |
10 <script> | 10 </head> |
11 // The task runner will print out a console message to ensure the text file | 11 <body> |
12 // comparison. | 12 <script id="layout-test-code"> |
13 var audit = Audit.createTaskRunner({ requireResultFile: true }); | 13 // The task runner will print out a console message to ensure the text |
| 14 // file comparison. |
| 15 let audit = Audit.createTaskRunner({requireResultFile: true}); |
14 | 16 |
15 | 17 |
16 // These assertions are supposed to be failed. The WPT (testharness) fails | 18 // These assertions are supposed to be failed. The WPT (testharness) fails |
17 // because the assertions are failing, but the existence of expected test | 19 // because the assertions are failing, but the existence of expected test |
18 // result makes this test pass as long as the actual and the expected match. | 20 // result makes this test pass as long as the actual and the expected |
19 // See the expected result file to see the logging message from Audit. | 21 // match. See the expected result file to see the logging message from |
| 22 // Audit. |
20 | 23 |
21 | 24 |
22 // Basic assertions. | 25 // Basic assertions. |
23 audit.define({ | 26 audit.define( |
24 label: 'basic-failure', | 27 { |
25 description: 'Testing basic assertion failures.' | 28 label: 'basic-failure', |
26 }, function (task, should) { | 29 description: 'Testing basic assertion failures.' |
27 should(function () { var foo = bar; }, 'Setting foo to bar').notThrow(); | 30 }, |
28 should(function () { var foo = 0; }).throw('ReferenceError'); | 31 function(task, should) { |
29 should(3 > 5, '3 < 5').beTrue(); | 32 should(function() { |
30 should(true).beFalse(); | 33 let foo = bar; |
31 should(1, 'The number of channels').beEqualTo(2); | 34 }, 'Setting foo to bar').notThrow(); |
32 should(1).notBeEqualTo(1); | 35 should(function() { |
33 should(typeof 3.141592, 'typeof 3.141592').beEqualTo('string'); | 36 let foo = 0; |
34 should(1).beGreaterThan(2); | 37 }).throw('ReferenceError'); |
35 should(1).beGreaterThanOrEqualTo(2); | 38 should(3 > 5, '3 < 5').beTrue(); |
36 should(2).beLessThan(1); | 39 should(true).beFalse(); |
37 should(2).beLessThanOrEqualTo(1); | 40 should(1, 'The number of channels').beEqualTo(2); |
38 should(should(1).beEqualTo(2), 'should(1).beEqualTo(2)').beTrue(); | 41 should(1).notBeEqualTo(1); |
39 should(false, 'The message is').message('truthful!', 'false!'); | 42 should(typeof 3.141592, 'typeof 3.141592').beEqualTo('string'); |
| 43 should(1).beGreaterThan(2); |
| 44 should(1).beGreaterThanOrEqualTo(2); |
| 45 should(2).beLessThan(1); |
| 46 should(2).beLessThanOrEqualTo(1); |
| 47 should(should(1).beEqualTo(2), 'should(1).beEqualTo(2)').beTrue(); |
| 48 should(false, 'The message is').message('truthful!', 'false!'); |
40 | 49 |
41 let oac = new OfflineAudioContext(1, 128, 44100); | 50 let oac = new OfflineAudioContext(1, 128, 44100); |
42 Promise.all([ | 51 Promise |
43 should(oac.decodeAudioData(), 'Decoding audio data with no argument'
) | 52 .all([ |
44 .beResolved(), | 53 should( |
45 should(oac.startRendering(), 'Start OAC rendering').beRejected(), | 54 oac.decodeAudioData(), |
46 should(oac.suspend(), 'Suspending OAC with no argument') | 55 'Decoding audio data with no argument') |
47 .beRejectedWith('IndexSizeError') | 56 .beResolved(), |
48 ]).then(task.done.bind(task)); | 57 should(oac.startRendering(), 'Start OAC rendering') |
49 } | 58 .beRejected(), |
50 ); | 59 should(oac.suspend(), 'Suspending OAC with no argument') |
| 60 .beRejectedWith('IndexSizeError') |
| 61 ]) |
| 62 .then(task.done.bind(task)); |
| 63 }); |
51 | 64 |
52 | 65 |
53 // Numerical assertions. | 66 // Numerical assertions. |
54 audit.define({ | 67 audit.define( |
55 label: 'numerical-failures', | 68 { |
56 description: 'Testing numerical assertion failures.' | 69 label: 'numerical-failures', |
57 }, function (task, should) { | 70 description: 'Testing numerical assertion failures.' |
58 should(0).beCloseTo(0.1, { threshold: 0 }); | 71 }, |
59 should(59, 'The measured decibel').beCloseTo(62, { threshold: 0.01 }); | 72 function(task, should) { |
60 should([1, 8, 11, 18, 6, 5, 5, 5, 123, 49]).beConstantValueOf(5); | 73 should(0).beCloseTo(0.1, {threshold: 0}); |
61 should([0, 0, 0]).notBeConstantValueOf(0); | 74 should(59, 'The measured decibel').beCloseTo(62, {threshold: 0.01}); |
62 should([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]) | 75 should([1, 8, 11, 18, 6, 5, 5, 5, 123, 49]).beConstantValueOf(5); |
63 .beEqualToArray([0, 0, 0, 0, 0, 0, 0, 0, 0, 0]); | 76 should([0, 0, 0]).notBeConstantValueOf(0); |
64 should([1, 1, 1, 1, 2, 2, 3, 3, 3]).containValues([1, 3, 2]); | 77 should([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]).beEqualToArray([ |
65 should([0.5, 0.5, 0.55, 0.5, 0.45, 0.5]).notGlitch(0.04); | 78 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 |
66 should([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.9]) | 79 ]); |
67 .beCloseToArray([0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1], { | 80 should([1, 1, 1, 1, 2, 2, 3, 3, 3]).containValues([1, 3, 2]); |
| 81 should([0.5, 0.5, 0.55, 0.5, 0.45, 0.5]).notGlitch(0.04); |
| 82 should([ |
| 83 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.9 |
| 84 ]).beCloseToArray([0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1], { |
68 absoluteThreshold: 0.02 | 85 absoluteThreshold: 0.02 |
69 }); | 86 }); |
70 should([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.9]) | 87 should([ |
71 .beCloseToArray([0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1], { | 88 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.9 |
| 89 ]).beCloseToArray([0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1], { |
72 relativeThreshold: 0.1 | 90 relativeThreshold: 0.1 |
73 }); | 91 }); |
74 should([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.9]) | 92 should([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.9]) |
75 .beCloseToArray([0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1], { | 93 .beCloseToArray( |
76 absoluteThreshold: 0.02, | 94 [0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1], |
77 relativeThreshold: 0.1 | 95 {absoluteThreshold: 0.02, relativeThreshold: 0.1}); |
| 96 |
| 97 // Tests extra info |
| 98 should([ |
| 99 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 |
| 100 ]).beCloseToArray([2, 3, 4, 5, 6, 7, 800, 900, 1000, 1100, 1200], { |
| 101 absoluteThreshold: 0 |
78 }); | 102 }); |
| 103 task.done(); |
| 104 }); |
79 | 105 |
80 // Tests extra info | 106 // Testing the failure handling of Audit.loadFileFromUrl(). |
81 should([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]) | 107 audit.define( |
82 .beCloseToArray([2, 3, 4, 5, 6, 7, 800, 900, 1000, 1100, 1200], { | 108 { |
83 absoluteThreshold: 0 | 109 label: 'load-file-in-should', |
84 }); | 110 description: |
85 task.done(); | 111 'Testing the failure handling of Audit.loadFileFromUrl().' |
86 }); | 112 }, |
| 113 (task, should) => { |
| 114 let url = 'non-existent-audio-file.wav'; |
| 115 let promise = |
| 116 should( |
| 117 Audit.loadFileFromUrl(url), |
| 118 'Loading non-existent file within should().beResolved()') |
| 119 .beResolved(); |
| 120 promise.then(() => {task.done()}); |
| 121 }); |
87 | 122 |
88 // Testing the failure handling of Audit.loadFileFromUrl(). | 123 // With no argument, this executes all tasks in the order defined. |
89 audit.define({ | 124 audit.run(); |
90 label: 'load-file-in-should', | 125 </script> |
91 description: 'Testing the failure handling of Audit.loadFileFromUrl().' | 126 </body> |
92 }, (task, should) => { | |
93 let url = 'non-existent-audio-file.wav'; | |
94 let promise = should( | |
95 Audit.loadFileFromUrl(url), | |
96 'Loading non-existent file within should().beResolved()') | |
97 .beResolved(); | |
98 promise.then(() => { task.done() }); | |
99 } | |
100 ); | |
101 | |
102 // With no argument, this executes all tasks in the order defined. | |
103 audit.run(); | |
104 </script> | |
105 </body> | |
106 </html> | 127 </html> |
OLD | NEW |