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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/AudioContext/audiocontext-suspend-resume.html

Issue 2895963003: Apply layout-test-tidy to LayoutTests/webaudio (Closed)
Patch Set: Created 3 years, 7 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 <!doctype html> 1 <!DOCTYPE html>
2 <html> 2 <html>
3 <head> 3 <head>
4 <title>Test AudioContext.suspend() and AudioContext.resume()</title> 4 <title>
5 <script src="../../resources/testharness.js"></script> 5 Test AudioContext.suspend() and AudioContext.resume()
6 <script src="../../resources/testharnessreport.js"></script> 6 </title>
7 <script src="../resources/audit-util.js"></script> 7 <script src="../../resources/testharness.js"></script>
8 <script src="../resources/audit.js"></script> 8 <script src="../../resources/testharnessreport.js"></script>
9 </head> 9 <script src="../resources/audit-util.js"></script>
10 <script src="../resources/audit.js"></script>
11 </head>
12 <body>
13 <script id="layout-test-code">
14 let offlineContext;
15 let osc;
16 let p1;
17 let p2;
18 let p3;
10 19
11 <body> 20 let sampleRate = 44100;
12 <script> 21 let durationInSeconds = 1;
13 let offlineContext;
14 let osc;
15 let p1;
16 let p2;
17 let p3;
18 22
19 let sampleRate = 44100; 23 let audit = Audit.createTaskRunner();
20 let durationInSeconds = 1;
21 24
22 let audit = Audit.createTaskRunner(); 25 // Task: test suspend().
26 audit.define(
27 {
28 label: 'test-suspend',
29 description: 'Test suspend() for offline context'
30 },
31 function(task, should) {
32 // Test suspend/resume. Ideally this test is best with a online
33 // AudioContext, but content shell doesn't really have a working
34 // online AudioContext. Hence, use an OfflineAudioContext. Not all
35 // possible scenarios can be easily checked with an offline context
36 // instead of an online context.
23 37
24 // Task: test suspend(). 38 // Create an audio context with an oscillator.
25 audit.define({ 39 should(
26 label: 'test-suspend', 40 () => {
27 description: "Test suspend() for offline context" 41 offlineContext = new OfflineAudioContext(
28 }, function (task, should) { 42 1, durationInSeconds * sampleRate, sampleRate);
29 // Test suspend/resume. Ideally this test is best with a online 43 },
30 // AudioContext, but content shell doesn't really have a working online 44 'offlineContext = new OfflineAudioContext(1, ' +
31 // AudioContext. Hence, use an OfflineAudioContext. Not all possible 45 (durationInSeconds * sampleRate) + ', ' + sampleRate + ')')
32 // scenarios can be easily checked with an offline context instead of an 46 .notThrow();
33 // online context. 47 osc = offlineContext.createOscillator();
48 osc.connect(offlineContext.destination);
34 49
35 // Create an audio context with an oscillator. 50 // Verify the state.
36 should(() => { 51 should(offlineContext.state, 'offlineContext.state')
37 offlineContext = new OfflineAudioContext(1, durationInSeconds * 52 .beEqualTo('suspended');
38 sampleRate, sampleRate);
39 },
40 "offlineContext = new OfflineAudioContext(1, " + (
41 durationInSeconds *
42 sampleRate) + ", " + sampleRate + ")"
43 )
44 .notThrow();
45 osc = offlineContext.createOscillator();
46 osc.connect(offlineContext.destination);
47 53
48 // Verify the state. 54 // Multiple calls to suspend() should not be a problem. But we can't
49 should(offlineContext.state, "offlineContext.state") 55 // test that on an offline context. Thus, check that suspend() on
50 .beEqualTo("suspended"); 56 // an OfflineAudioContext rejects the promise.
57 should(
58 () => p1 = offlineContext.suspend(),
59 'p1 = offlineContext.suspend()')
60 .notThrow();
61 should(p1 instanceof Promise, 'p1 instanceof Promise').beTrue();
51 62
52 // Multiple calls to suspend() should not be a problem. But we can't test 63 should(p1, 'p1').beRejected().then(task.done.bind(task));
53 // that on an offline context. Thus, check that suspend() on an 64 });
54 // OfflineAudioContext rejects the promise.
55 should(() => p1 = offlineContext.suspend(),
56 "p1 = offlineContext.suspend()")
57 .notThrow();
58 should(p1 instanceof Promise, "p1 instanceof Promise")
59 .beTrue();
60
61 should(p1, "p1")
62 .beRejected()
63 .then(task.done.bind(task));
64 });
65 65
66 66
67 // Task: test resume(). 67 // Task: test resume().
68 audit.define({ 68 audit.define(
69 label: 'test-resume', 69 {
70 description: "Test resume() for offline context" 70 label: 'test-resume',
71 }, function (task, should) { 71 description: 'Test resume() for offline context'
72 // Multiple calls to resume should not be a problem. But we can't test 72 },
73 // that on an offline context. Thus, check that resume() on an 73 function(task, should) {
74 // OfflineAudioContext rejects the promise. 74 // Multiple calls to resume should not be a problem. But we can't
75 should(() => p2 = offlineContext.resume(), 75 // test that on an offline context. Thus, check that resume() on an
76 "p2 = offlineContext.resume()") 76 // OfflineAudioContext rejects the promise.
77 .notThrow(); 77 should(
78 should(p2 instanceof Promise, "p2 instanceof Promise") 78 () => p2 = offlineContext.resume(),
79 .beTrue(); 79 'p2 = offlineContext.resume()')
80 .notThrow();
81 should(p2 instanceof Promise, 'p2 instanceof Promise').beTrue();
80 82
81 // Resume doesn't actually resume an offline context 83 // Resume doesn't actually resume an offline context
82 should(offlineContext.state, "After resume, offlineContext.state") 84 should(offlineContext.state, 'After resume, offlineContext.state')
83 .beEqualTo("suspended"); 85 .beEqualTo('suspended');
84 should(p2, "p2") 86 should(p2, 'p2').beRejected().then(task.done.bind(task));
85 .beRejected() 87 });
86 .then(task.done.bind(task));
87 });
88 88
89 // Task: test the state after context closed. 89 // Task: test the state after context closed.
90 audit.define({ 90 audit.define(
91 label: 'test-after-close', 91 {
92 description: "Test state after context closed" 92 label: 'test-after-close',
93 }, function (task, should) { 93 description: 'Test state after context closed'
94 // Render the offline context. 94 },
95 osc.start(); 95 function(task, should) {
96 // Render the offline context.
97 osc.start();
96 98
97 // Test suspend/resume in tested promise pattern. We don't care about the 99 // Test suspend/resume in tested promise pattern. We don't care
98 // actual result of the offline rendering. 100 // about the actual result of the offline rendering.
99 should(() => p3 = offlineContext.startRendering(), 101 should(
100 "p3 = offlineContext.startRendering()") 102 () => p3 = offlineContext.startRendering(),
101 .notThrow(); 103 'p3 = offlineContext.startRendering()')
104 .notThrow();
102 105
103 p3.then(() => { 106 p3.then(() => {
104 should(offlineContext.state, "After close, offlineContext.state") 107 should(offlineContext.state, 'After close, offlineContext.state')
105 .beEqualTo("closed"); 108 .beEqualTo('closed');
106 109
107 // suspend() should be rejected on a closed context. 110 // suspend() should be rejected on a closed context.
108 should(offlineContext.suspend(), "offlineContext.suspend()") 111 should(offlineContext.suspend(), 'offlineContext.suspend()')
109 .beRejected() 112 .beRejected()
110 .then(() => { 113 .then(() => {
111 // resume() should be rejected on closed context. 114 // resume() should be rejected on closed context.
112 should(offlineContext.resume(), 115 should(offlineContext.resume(), 'offlineContext.resume()')
113 "offlineContext.resume()") 116 .beRejected()
114 .beRejected() 117 .then(task.done.bind(task));
115 .then(task.done.bind(task)); 118 })
116 }) 119 });
117 }); 120 });
118 });
119 121
120 audit.define({ 122 audit.define(
121 label: 'resume-running-context', 123 {
122 description: 'Test resuming a running context' 124 label: 'resume-running-context',
123 }, (task, should) => { 125 description: 'Test resuming a running context'
124 let context; 126 },
125 should(() => context = new AudioContext(), 127 (task, should) => {
126 'Create online context') 128 let context;
127 .notThrow(); 129 should(() => context = new AudioContext(), 'Create online context')
130 .notThrow();
128 131
129 should(context.state, 'context.state') 132 should(context.state, 'context.state').beEqualTo('running');
130 .beEqualTo('running'); 133 should(context.resume(), 'context.resume')
131 should(context.resume(), 'context.resume') 134 .beResolved()
132 .beResolved() 135 .then(() => {
133 .then(() => { 136 should(context.state, 'context.state after resume')
134 should(context.state, 'context.state after resume') 137 .beEqualTo('running');
135 .beEqualTo('running'); 138 })
136 }) 139 .then(() => task.done());
137 .then(() => task.done()); 140 });
138 });
139 141
140 audit.run(); 142 audit.run();
141 </script> 143 </script>
142 </body> 144 </body>
143 </html> 145 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698