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( | 8 test(() => assert_throws( |
9 new RangeError(), | 9 new RangeError(), |
10 () => new sensorType({frequency: -60})), | 10 () => new sensorType({frequency: -60})), |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 }, reject); | 90 }, reject); |
91 sensorObject.onactivate = wrapper.callback; | 91 sensorObject.onactivate = wrapper.callback; |
92 sensorObject.onerror = reject; | 92 sensorObject.onerror = reject; |
93 }); | 93 }); |
94 }) | 94 }) |
95 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); | 95 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); |
96 return testPromise; | 96 return testPromise; |
97 }, 'Test that frequency is capped to the maximum supported from frequency.'); | 97 }, 'Test that frequency is capped to the maximum supported from frequency.'); |
98 | 98 |
99 sensor_test(sensor => { | 99 sensor_test(sensor => { |
100 let sensorObject = new sensorType({frequency: 60}); | 100 let sensorObject = new sensorType({frequency: 60}); |
101 sensorObject.start(); | 101 assert_equals(sensorObject.state, 'unconnected'); |
102 let testPromise = sensor.mockSensorProvider.getCreatedSensor() | 102 sensorObject.start(); |
| 103 assert_equals(sensorObject.state, 'activating'); |
| 104 let testPromise = sensor.mockSensorProvider.getCreatedSensor() |
103 .then((mockSensor) => { | 105 .then((mockSensor) => { |
104 return new Promise((resolve, reject) => { | 106 return new Promise((resolve, reject) => { |
105 let wrapper = new CallbackWrapper(() => { | 107 let wrapper = new CallbackWrapper(() => { |
106 assert_equals(sensorObject.state, 'activated'); | 108 assert_equals(sensorObject.state, 'activated'); |
107 sensorObject.stop(); | 109 sensorObject.stop(); |
108 assert_equals(sensorObject.state, 'idle'); | 110 assert_equals(sensorObject.state, 'idle'); |
109 resolve(mockSensor); | 111 resolve(mockSensor); |
110 }, reject); | 112 }, reject); |
111 sensorObject.onactivate = wrapper.callback; | 113 sensorObject.onactivate = wrapper.callback; |
112 sensorObject.onerror = reject; | 114 sensorObject.onerror = reject; |
113 }); | 115 }); |
114 }) | 116 }) |
115 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); | 117 .then(mockSensor => { return mockSensor.removeConfigurationCalled(); }); |
116 return testPromise; | 118 return testPromise; |
117 }, 'Test that sensor can be successfully created if sensor is supported.'); | 119 }, 'Test that sensor can be successfully created and its states are correct.')
; |
118 | 120 |
119 sensor_test(sensor => { | 121 sensor_test(sensor => { |
120 let sensorObject = new sensorType(); | 122 let sensorObject = new sensorType(); |
121 sensorObject.start(); | 123 sensorObject.start(); |
122 let testPromise = sensor.mockSensorProvider.getCreatedSensor() | 124 let testPromise = sensor.mockSensorProvider.getCreatedSensor() |
123 .then((mockSensor) => { | 125 .then((mockSensor) => { |
124 return new Promise((resolve, reject) => { | 126 return new Promise((resolve, reject) => { |
125 let wrapper = new CallbackWrapper(() => { | 127 let wrapper = new CallbackWrapper(() => { |
126 assert_equals(sensorObject.state, 'activated'); | 128 assert_equals(sensorObject.state, 'activated'); |
127 sensorObject.stop(); | 129 sensorObject.stop(); |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 | 327 |
326 sensor_test(sensor => { | 328 sensor_test(sensor => { |
327 return checkFrequencyHintWorks(sensor); | 329 return checkFrequencyHintWorks(sensor); |
328 }, 'Test that frequency hint works (onchange reporting).'); | 330 }, 'Test that frequency hint works (onchange reporting).'); |
329 | 331 |
330 sensor_test(sensor => { | 332 sensor_test(sensor => { |
331 sensor.mockSensorProvider.setContinuousReportingMode(); | 333 sensor.mockSensorProvider.setContinuousReportingMode(); |
332 return checkFrequencyHintWorks(sensor); | 334 return checkFrequencyHintWorks(sensor); |
333 }, 'Test that frequency hint works (continuous reporting).'); | 335 }, 'Test that frequency hint works (continuous reporting).'); |
334 } | 336 } |
OLD | NEW |