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

Side by Side Diff: third_party/WebKit/LayoutTests/sensor/resources/sensor-helpers.js

Issue 2471103002: [sensors] Close mock sensor stubs after test is finished (Closed)
Patch Set: Fix for comment from Mikhail Created 4 years, 1 month 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 'use strict'; 1 'use strict';
2 2
3 function sensor_mocks(mojo) { 3 function sensor_mocks(mojo) {
4 return define('Generic Sensor API mocks', [ 4 return define('Generic Sensor API mocks', [
5 'mojo/public/js/core', 5 'mojo/public/js/core',
6 'mojo/public/js/bindings', 6 'mojo/public/js/bindings',
7 'mojo/public/js/connection', 7 'mojo/public/js/connection',
8 'device/generic_sensor/public/interfaces/sensor_provider.mojom', 8 'device/generic_sensor/public/interfaces/sensor_provider.mojom',
9 'device/generic_sensor/public/interfaces/sensor.mojom', 9 'device/generic_sensor/public/interfaces/sensor.mojom',
10 ], (core, bindings, connection, sensor_provider, sensor) => { 10 ], (core, bindings, connection, sensor_provider, sensor) => {
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 this.resume_called_(this); 105 this.resume_called_(this);
106 } 106 }
107 } 107 }
108 108
109 // Mock functions 109 // Mock functions
110 110
111 // Resets mock Sensor state. 111 // Resets mock Sensor state.
112 reset() { 112 reset() {
113 if (this.sensor_reading_timer_id_) { 113 if (this.sensor_reading_timer_id_) {
114 window.clearTimeout(this.sensor_reading_timer_id_); 114 window.clearTimeout(this.sensor_reading_timer_id_);
115 this.sensor_reading_timer_id_ = null;
115 } 116 }
116 117
117 this.start_should_fail_ = false; 118 this.start_should_fail_ = false;
118 this.sensor_reading_timer_id_ = null; 119 this.update_reading_function_ = null;
119 this.active_sensor_configurations_ = []; 120 this.active_sensor_configurations_ = [];
120 this.suspend_called_ = null; 121 this.suspend_called_ = null;
121 this.resume_called_ = null; 122 this.resume_called_ = null;
122 this.add_configuration_called_ = null; 123 this.add_configuration_called_ = null;
123 this.remove_configuration_called_ = null; 124 this.remove_configuration_called_ = null;
124 this.resetBuffer(); 125 this.resetBuffer();
126 core.unmapBuffer(this.buffer_array_);
127 this.buffer_array_ = null;
128 bindings.StubBindings(this.stub_).close();
125 } 129 }
126 130
127 // Zeroes shared buffer. 131 // Zeroes shared buffer.
128 resetBuffer() { 132 resetBuffer() {
129 for (let i = 0; i < this.buffer_.length; ++i) { 133 for (let i = 0; i < this.buffer_.length; ++i) {
130 this.buffer_[i] = 0; 134 this.buffer_[i] = 0;
131 } 135 }
132 } 136 }
133 137
134 // Sets callback that is used to deliver sensor reading updates. 138 // Sets callback that is used to deliver sensor reading updates.
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 pipe, sensor_provider.SensorProvider); 254 pipe, sensor_provider.SensorProvider);
251 bindings.StubBindings(this.stub_).delegate = this; 255 bindings.StubBindings(this.stub_).delegate = this;
252 } 256 }
253 257
254 // Mock functions 258 // Mock functions
255 259
256 // Resets state of mock SensorProvider between test runs. 260 // Resets state of mock SensorProvider between test runs.
257 reset() { 261 reset() {
258 if (this.active_sensor_ != null) { 262 if (this.active_sensor_ != null) {
259 this.active_sensor_.reset(); 263 this.active_sensor_.reset();
264 this.active_sensor_ = null;
260 } 265 }
261 266
262 this.get_sensor_should_fail_ = false; 267 this.get_sensor_should_fail_ = false;
263 this.resolve_func_ = null; 268 this.resolve_func_ = null;
264 } 269 }
265 270
266 // Sets flag that forces mock SensorProvider to fail when getSensor() is 271 // Sets flag that forces mock SensorProvider to fail when getSensor() is
267 // invoked. 272 // invoked.
268 setGetSensorShouldFail(should_fail) { 273 setGetSensorShouldFail(should_fail) {
269 this.get_sensor_should_fail_ = should_fail; 274 this.get_sensor_should_fail_ = should_fail;
(...skipping 24 matching lines...) Expand all
294 }); 299 });
295 300
296 return Promise.resolve({ 301 return Promise.resolve({
297 mockSensorProvider: mockSensorProvider, 302 mockSensorProvider: mockSensorProvider,
298 }); 303 });
299 }); 304 });
300 } 305 }
301 306
302 function sensor_test(func, name, properties) { 307 function sensor_test(func, name, properties) {
303 mojo_test(mojo => sensor_mocks(mojo).then(sensor => { 308 mojo_test(mojo => sensor_mocks(mojo).then(sensor => {
304 let result = Promise.resolve(func(sensor)); 309 // Clean up and reset mock sensor stubs asynchronously, so that the blink
305 let cleanUp = () => { sensor.mockSensorProvider.reset(); }; 310 // side closes its proxies and notifies JS sensor objects before new test is
306 return result.then(cleanUp, cleanUp); 311 // started.
312 let onSuccess = () => {
313 sensor.mockSensorProvider.reset();
314 return new Promise((resolve, reject) => { setTimeout(resolve, 0); });
315 };
316
317 let onFailure = () => {
318 sensor.mockSensorProvider.reset();
319 return new Promise((resolve, reject) => { setTimeout(reject, 0); });
320 };
321
322 return Promise.resolve(func(sensor)).then(onSuccess, onFailure);
307 }), name, properties); 323 }), name, properties);
308 } 324 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698