OLD | NEW |
1 'use strict'; | 1 'use strict'; |
2 | 2 |
3 // Run a set of tests for a given |sensorType|. |updateReading| is | 3 // Run a set of tests for a given |sensorType|. |updateReading| is |
4 // a called by the test to provide the mock values for sensor. |verifyReading| | 4 // a called by the test to provide the mock values for sensor. |verifyReading| |
5 // is called so that the value read in JavaScript are the values expected (the o
nes | 5 // is called so that the value read in JavaScript are the values expected (the o
nes |
6 // sent by |updateReading|). | 6 // sent by |updateReading|). |
7 function runGenericSensorTests(sensorType, updateReading, verifyReading) { | 7 function runGenericSensorTests(sensorType, updateReading, verifyReading) { |
8 test(() => assert_throws( | |
9 new RangeError(), | |
10 () => new sensorType({frequency: -60})), | |
11 'Test that negative frequency causes exception from constructor.'); | |
12 | |
13 sensor_test(sensor => { | 8 sensor_test(sensor => { |
14 sensor.mockSensorProvider.setGetSensorShouldFail(true); | 9 sensor.mockSensorProvider.setGetSensorShouldFail(true); |
15 let sensorObject = new sensorType; | 10 let sensorObject = new sensorType; |
16 sensorObject.start(); | 11 sensorObject.start(); |
17 return new Promise((resolve, reject) => { | 12 return new Promise((resolve, reject) => { |
18 let wrapper = new CallbackWrapper(event => { | 13 let wrapper = new CallbackWrapper(event => { |
19 assert_equals(sensorObject.state, 'errored'); | 14 assert_equals(sensorObject.state, 'errored'); |
20 assert_equals(event.error.name, 'NotReadableError'); | 15 assert_equals(event.error.name, 'NotReadableError'); |
21 sensorObject.onerror = null; | 16 sensorObject.onerror = null; |
22 resolve(); | 17 resolve(); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 }, reject); | 85 }, reject); |
91 sensorObject.onactivate = wrapper.callback; | 86 sensorObject.onactivate = wrapper.callback; |
92 sensorObject.onerror = reject; | 87 sensorObject.onerror = reject; |
93 }); | 88 }); |
94 }) | 89 }) |
95 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); | 90 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); |
96 return testPromise; | 91 return testPromise; |
97 }, 'Test that frequency is capped to the maximum supported from frequency.'); | 92 }, 'Test that frequency is capped to the maximum supported from frequency.'); |
98 | 93 |
99 sensor_test(sensor => { | 94 sensor_test(sensor => { |
| 95 let minSupportedFrequency = 2; |
| 96 sensor.mockSensorProvider.setMinimumSupportedFrequency(minSupportedFrequency
); |
| 97 let sensorObject = new sensorType({frequency: -1}); |
| 98 sensorObject.start(); |
| 99 let testPromise = sensor.mockSensorProvider.getCreatedSensor() |
| 100 .then(mockSensor => { return mockSensor.addConfigurationCalled(); }) |
| 101 .then(mockSensor => { |
| 102 return new Promise((resolve, reject) => { |
| 103 let wrapper = new CallbackWrapper(() => { |
| 104 let configuration = mockSensor.active_sensor_configurations_[0]; |
| 105 assert_equals(configuration.frequency, minSupportedFrequency); |
| 106 sensorObject.stop(); |
| 107 assert_equals(sensorObject.state, 'idle'); |
| 108 resolve(mockSensor); |
| 109 }, reject); |
| 110 sensorObject.onactivate = wrapper.callback; |
| 111 sensorObject.onerror = reject; |
| 112 }); |
| 113 }) |
| 114 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); |
| 115 return testPromise; |
| 116 }, 'Test that frequency is limited to the minimum supported from frequency.'); |
| 117 |
| 118 sensor_test(sensor => { |
100 let sensorObject = new sensorType({frequency: 60}); | 119 let sensorObject = new sensorType({frequency: 60}); |
101 assert_equals(sensorObject.state, 'unconnected'); | 120 assert_equals(sensorObject.state, 'unconnected'); |
102 sensorObject.start(); | 121 sensorObject.start(); |
103 assert_equals(sensorObject.state, 'activating'); | 122 assert_equals(sensorObject.state, 'activating'); |
104 let testPromise = sensor.mockSensorProvider.getCreatedSensor() | 123 let testPromise = sensor.mockSensorProvider.getCreatedSensor() |
105 .then((mockSensor) => { | 124 .then((mockSensor) => { |
106 return new Promise((resolve, reject) => { | 125 return new Promise((resolve, reject) => { |
107 let wrapper = new CallbackWrapper(() => { | 126 let wrapper = new CallbackWrapper(() => { |
108 assert_equals(sensorObject.state, 'activated'); | 127 assert_equals(sensorObject.state, 'activated'); |
109 sensorObject.stop(); | 128 sensorObject.stop(); |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 | 346 |
328 sensor_test(sensor => { | 347 sensor_test(sensor => { |
329 return checkFrequencyHintWorks(sensor); | 348 return checkFrequencyHintWorks(sensor); |
330 }, 'Test that frequency hint works (onchange reporting).'); | 349 }, 'Test that frequency hint works (onchange reporting).'); |
331 | 350 |
332 sensor_test(sensor => { | 351 sensor_test(sensor => { |
333 sensor.mockSensorProvider.setContinuousReportingMode(); | 352 sensor.mockSensorProvider.setContinuousReportingMode(); |
334 return checkFrequencyHintWorks(sensor); | 353 return checkFrequencyHintWorks(sensor); |
335 }, 'Test that frequency hint works (continuous reporting).'); | 354 }, 'Test that frequency hint works (continuous reporting).'); |
336 } | 355 } |
OLD | NEW |