Re: [sensors] Introduce WebDriver extension API

Probably defining following 4 methods to WPT's testdriver.js respectively corresponding to extension commands defined in this spec. 
```
test_driver.create_sensor(sensorType, configurations)    //no return value
test_driver.get_sensor(sensorType)    //return serialized mock sensor properties
test_driver.update_sensor_reading(sensorType, readingValues)  //no return value
test_driver.delete_sensor(sensorType)   //no return value
```

Then override them in Chromium's testdriver-vendor.js with [mock mojo interface](https://chromium.googlesource.com/chromium/src.git/+/master/third_party/WebKit/LayoutTests/http/tests/resources/sensor-helpers.js), 

1. override `test_driver.create_sensor(sensorType, configurations)`:
```
  window.test_driver_internal.create_sensor = function(sensorType, configurations) {
    return new Promise(function(resolve, reject) {
      if (window.chrome) {
        let sensorProvider = sensorMocks();
        sensorProvider.initialize(configurations.sensorType); 
        if(configurations.connected == false) 
          sensorProvider.setGetSensorShouldFail(true);
        if(configurations.maxSamplingFrequency != null)
          sensorProvider.setMaximumSupportedFrequency(configurations.maxSamplingFrequency);
        ...
        resolve();
      } else {
        reject(new Error("error"));
      }
    });
  };
``` 
2. override `test_driver.get_sensor(sensorType)`:
```
  let mockSensor = sensorProvider.getCreatedSensor(sensorType);
  let samplingFrequency= mockSensor.getSamplingFrequency();
  let ...
  let serializedSensor =  {RequestedSamplingFrequency: samplingFrequency, maxSamplingFrequency: ....};
  return new Promise(resolve(serializedSensor));
```
3. override `test_driver.update_sensor_reading(sensorType, readingValues)`:
```
  let mockSensor = sensorProvider.getCreatedSensor(sensorType),
  mockSensor.setUpdateSensorReadingFunction(updateReading(readingValues));
```
4. override `test_driver.delete_sensor(sensorType)`:
`  sensorProvider.reset(sensorType);`

Here comes up with a problem, that "create mock sensor" command(`test_driver.create_sensor(sensorType, configurations)`) do not return a mock sensor instance, while in Chromium's testdriver-vendor.js it definitely needs returning a `sensorProvider` instance, then pass it to rest methods. Is that possible to restore it in somewhere as a global variable? Do you have any good idea?

-- 
GitHub Notification of comment by Honry
Please view or discuss this issue at https://github.com/w3c/sensors/pull/369#issuecomment-421281618 using your GitHub account

Received on Friday, 14 September 2018 08:58:36 UTC