Index: third_party/WebKit/LayoutTests/usb/usb.html |
diff --git a/third_party/WebKit/LayoutTests/usb/usb.html b/third_party/WebKit/LayoutTests/usb/usb.html |
index 4f2f30da4a6fa98497bb7432a6f06c8ad111ba79..82bc0f5af3e447ef55ec6951685715093044c2ab 100644 |
--- a/third_party/WebKit/LayoutTests/usb/usb.html |
+++ b/third_party/WebKit/LayoutTests/usb/usb.html |
@@ -1,9 +1,9 @@ |
<!DOCTYPE html> |
<script src="../resources/testharness.js"></script> |
<script src="../resources/testharnessreport.js"></script> |
-<script src="../resources/mojo-helpers.js"></script> |
<script src="resources/fake-devices.js"></script> |
<script src="resources/usb-helpers.js"></script> |
+<script src="resources/webusb-test.js"></script> |
<script> |
'use strict'; |
@@ -20,17 +20,17 @@ function connectionEventPromise(eventType) { |
}); |
} |
-usb_test(usb => { |
- usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
+usb_test(() => { |
+ navigator.usb.test.addFakeDevice(fakeDeviceInit); |
return navigator.usb.getDevices().then(devices => { |
assert_equals(devices.length, 1); |
- usb.assertDeviceInfoEquals(devices[0], usb.fakeDevices[0]); |
+ assertDeviceInfoEquals(devices[0], fakeDeviceInit); |
}); |
}, 'getDevices returns devices exposed by the DeviceManager service'); |
-usb_test(usb => { |
- usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
+usb_test(() => { |
+ navigator.usb.test.addFakeDevice(fakeDeviceInit); |
return navigator.usb.getDevices().then(devicesFirstTime => { |
assert_equals(devicesFirstTime.length, 1); |
@@ -40,7 +40,7 @@ usb_test(usb => { |
}); |
}, 'getDevices returns the same objects for each USB device'); |
-usb_test(usb => { |
+usb_test(() => { |
return navigator.usb.requestDevice({ filters: [] }) |
.then(device => { |
assert_unreachable('requestDevice should reject without a user gesture'); |
@@ -50,8 +50,7 @@ usb_test(usb => { |
}); |
}, 'requestDevice rejects when called without a user gesture'); |
-usb_test(usb => { |
- usb.mockChooserService.setChosenDevice(null); |
+usb_test(() => { |
return callWithKeyDown(() => navigator.usb.requestDevice({ filters: [] }) |
.then(device => { |
assert_unreachable('requestDevice should reject when no device selected'); |
@@ -62,19 +61,21 @@ usb_test(usb => { |
); |
}, 'requestDevice rejects when no device is chosen'); |
-usb_test(usb => { |
- usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
- usb.mockChooserService.setChosenDevice(usb.fakeDevices[0]); |
+usb_test(() => { |
+ let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit); |
+ navigator.usb.test.chosenDevice = guid; |
+ |
return callWithKeyDown(() => navigator.usb.requestDevice({ filters: [] }) |
.then(device => { |
- usb.assertDeviceInfoEquals(device, usb.fakeDevices[0]); |
+ assertDeviceInfoEquals(device, fakeDeviceInit); |
}) |
); |
}, 'requestDevice returns the device chosen by the user'); |
-usb_test(usb => { |
- usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
- usb.mockChooserService.setChosenDevice(usb.fakeDevices[0]); |
+usb_test(() => { |
+ let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit); |
+ navigator.usb.test.chosenDevice = guid; |
+ |
return callWithKeyDown(() => navigator.usb.requestDevice({ filters: [] }) |
.then(device => navigator.usb.getDevices().then(devices => { |
assert_equals(devices.length, 1); |
@@ -83,51 +84,40 @@ usb_test(usb => { |
); |
}, 'getDevices returns the same object as requestDevice'); |
-usb_test(usb => { |
+usb_test(() => { |
const expectedFilters = [ |
{ vendorId: 1234, classCode: 0xFF, serialNumber: "123ABC" }, |
{ vendorId: 5678, productId: 0xF00F } |
]; |
- usb.mockChooserService.setChosenDevice(null); |
+ |
return callWithKeyDown(() => navigator.usb.requestDevice({ filters: expectedFilters }) |
.then(device => { |
assert_unreachable('requestDevice should reject because no device selected'); |
}) |
.catch(error => { |
assert_equals(error.code, DOMException.NOT_FOUND_ERR); |
- let actualFilters = usb.mockChooserService.getLastFilters(); |
+ let actualFilters = navigator.usb.test.lastFilters; |
assert_equals(actualFilters.length, expectedFilters.length); |
- assert_true(actualFilters[0].has_vendor_id); |
- assert_equals(actualFilters[0].vendor_id, expectedFilters[0].vendorId); |
- assert_false(actualFilters[0].has_product_id); |
- assert_true(actualFilters[0].has_class_code, expectedFilters[0].classCode); |
- assert_false(actualFilters[0].has_subclass_code); |
- assert_false(actualFilters[0].has_protocol_code); |
- assert_equals(actualFilters[0].serial_number, expectedFilters[0].serialNumber); |
- assert_true(actualFilters[1].has_vendor_id); |
- assert_equals(actualFilters[1].vendor_id, expectedFilters[1].vendorId); |
- assert_true(actualFilters[1].has_product_id); |
- assert_equals(actualFilters[1].product_id, expectedFilters[1].productId); |
- assert_false(actualFilters[1].has_class_code); |
- assert_false(actualFilters[1].has_subclass_code); |
- assert_false(actualFilters[1].has_protocol_code); |
- assert_equals(actualFilters[1].serial_number, null); |
+ for (var i = 0; i < actualFilters.length; ++i) |
+ assert_object_equals(actualFilters[i], expectedFilters[i]); |
}) |
); |
}, 'filters are sent correctly'); |
-usb_test(usb => { |
+usb_test(() => { |
let promise = connectionEventPromise('connect'); |
- usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
+ navigator.usb.test.addFakeDevice(fakeDeviceInit); |
+ |
return promise.then(device => { |
- usb.assertDeviceInfoEquals(device, usb.fakeDevices[0]); |
+ assertDeviceInfoEquals(device, fakeDeviceInit); |
return device.open().then(() => device.close()); |
}); |
}, 'onconnect event is trigged by adding a device'); |
usb_test(usb => { |
let promise = connectionEventPromise('connect'); |
- usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
+ navigator.usb.test.addFakeDevice(fakeDeviceInit); |
+ |
return promise |
.then(device => navigator.usb.getDevices().then(devices => { |
assert_equals(devices.length, 1); |
@@ -137,12 +127,13 @@ usb_test(usb => { |
usb_test(usb => { |
let deviceAdded = connectionEventPromise('connect'); |
- usb.mockDeviceManager.addMockDevice(usb.fakeDevices[0]); |
+ let guid = navigator.usb.test.addFakeDevice(fakeDeviceInit); |
+ |
return deviceAdded.then(device => { |
let deviceRemoved = connectionEventPromise('disconnect'); |
- usb.mockDeviceManager.removeMockDevice(usb.fakeDevices[0]); |
+ navigator.usb.test.removeFakeDevice(guid); |
return deviceRemoved.then(removedDevice => { |
- usb.assertDeviceInfoEquals(removedDevice, usb.fakeDevices[0]); |
+ assertDeviceInfoEquals(removedDevice, fakeDeviceInit); |
assert_equals(removedDevice, device); |
return removedDevice.open().then(() => { |
assert_unreachable('should not be able to open a disconnected device'); |