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

Side by Side Diff: third_party/WebKit/LayoutTests/external/wpt/webusb/usb-manual.https.html

Issue 2789723003: Migrate WebUSB LayoutTests into external/wpt (Closed)
Patch Set: Add README.md and more comments explaining the polyfill Created 3 years, 6 months 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 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <script src="../resources/testharness.js"></script> 2 <script src="/resources/testharness.js"></script>
3 <script src="../resources/testharnessreport.js"></script> 3 <script src="/resources/testharnessreport.js"></script>
4 <script src="resources/fake-devices.js"></script> 4 <script src="resources/fake-devices.js"></script>
5 <script src="resources/usb-helpers.js"></script> 5 <script src="resources/usb-helpers.js"></script>
6 <script src="resources/webusb-test.js"></script>
7 <script> 6 <script>
8 'use strict'; 7 'use strict';
9 8
10 usb_test(() => { 9 usb_test(() => {
11 return getFakeDevice().then(({ device }) => { 10 return getFakeDevice().then(({ device }) => {
12 return navigator.usb.getDevices().then(devices => { 11 return navigator.usb.getDevices().then(devices => {
13 assert_equals(devices.length, 1); 12 assert_equals(devices.length, 1);
14 assert_equals(device, devices[0]); 13 assert_equals(device, devices[0]);
15 assertDeviceInfoEquals(devices[0], fakeDeviceInit); 14 assertDeviceInfoEquals(devices[0], fakeDeviceInit);
16 }); 15 });
(...skipping 15 matching lines...) Expand all
32 return navigator.usb.requestDevice({ filters: [] }) 31 return navigator.usb.requestDevice({ filters: [] })
33 .then(device => { 32 .then(device => {
34 assert_unreachable('requestDevice should reject without a user gesture'); 33 assert_unreachable('requestDevice should reject without a user gesture');
35 }) 34 })
36 .catch(error => { 35 .catch(error => {
37 assert_equals(error.code, DOMException.SECURITY_ERR); 36 assert_equals(error.code, DOMException.SECURITY_ERR);
38 }); 37 });
39 }, 'requestDevice rejects when called without a user gesture'); 38 }, 'requestDevice rejects when called without a user gesture');
40 39
41 usb_test(() => { 40 usb_test(() => {
42 return callWithKeyDown(() => navigator.usb.requestDevice({ filters: [] }) 41 return callWithTrustedClick(() => navigator.usb.requestDevice({ filters: [] })
43 .then(device => { 42 .then(device => {
44 assert_unreachable('requestDevice should reject when no device selected'); 43 assert_unreachable('requestDevice should reject when no device selected');
45 }) 44 })
46 .catch(error => { 45 .catch(error => {
47 assert_equals(error.code, DOMException.NOT_FOUND_ERR); 46 assert_equals(error.code, DOMException.NOT_FOUND_ERR);
48 }) 47 })
49 ); 48 );
50 }, 'requestDevice rejects when no device is chosen'); 49 }, 'requestDevice rejects when no device is chosen');
51 50
52 usb_test(() => { 51 usb_test(() => {
53 return getFakeDevice().then(({ device, fakeDevice }) => { 52 return getFakeDevice().then(({ device, fakeDevice }) => {
54 navigator.usb.test.chosenDevice = fakeDevice; 53 navigator.usb.test.chosenDevice = fakeDevice;
55 return callWithKeyDown(() => { 54 return callWithTrustedClick(() => {
56 return navigator.usb.requestDevice({ filters: [] }).then(chosenDevice => { 55 return navigator.usb.requestDevice({ filters: [] }).then(chosenDevice => {
57 assert_equals(chosenDevice, device); 56 assert_equals(chosenDevice, device);
58 }); 57 });
59 }); 58 });
60 }); 59 });
61 }, 'requestDevice returns the device chosen by the user'); 60 }, 'requestDevice returns the device chosen by the user');
62 61
63 usb_test(() => { 62 usb_test(() => {
64 return getFakeDevice().then(({ device, fakeDevice }) => { 63 return getFakeDevice().then(({ device, fakeDevice }) => {
65 navigator.usb.test.chosenDevice = fakeDevice; 64 navigator.usb.test.chosenDevice = fakeDevice;
66 return callWithKeyDown(() => { 65 return callWithTrustedClick(() => {
67 return navigator.usb.requestDevice({ filters: [] }).then(chosenDevice => { 66 return navigator.usb.requestDevice({ filters: [] }).then(chosenDevice => {
68 assert_equals(chosenDevice, device); 67 assert_equals(chosenDevice, device);
69 return navigator.usb.getDevices().then(devices => { 68 return navigator.usb.getDevices().then(devices => {
70 assert_equals(devices.length, 1); 69 assert_equals(devices.length, 1);
71 assert_equals(devices[0], chosenDevice); 70 assert_equals(devices[0], chosenDevice);
72 }); 71 });
73 }); 72 });
74 }); 73 });
75 }); 74 });
76 }, 'getDevices returns the same object as requestDevice'); 75 }, 'getDevices returns the same object as requestDevice');
77 76
78 usb_test(() => { 77 usb_test(() => {
79 const expectedFilters = [ 78 const expectedFilters = [
80 { vendorId: 1234, classCode: 0xFF, serialNumber: "123ABC" }, 79 { vendorId: 1234, classCode: 0xFF, serialNumber: "123ABC" },
81 { vendorId: 5678, productId: 0xF00F } 80 { vendorId: 5678, productId: 0xF00F }
82 ]; 81 ];
83 82
84 return callWithKeyDown(() => navigator.usb.requestDevice({ filters: expectedFi lters }) 83 return callWithTrustedClick(() => {
85 .then(device => { 84 return navigator.usb.requestDevice({ filters: expectedFilters })
86 assert_unreachable('requestDevice should reject because no device selected '); 85 .then(device => {
87 }) 86 assert_unreachable('requestDevice should reject because no device select ed');
88 .catch(error => { 87 })
89 assert_equals(error.code, DOMException.NOT_FOUND_ERR); 88 .catch(error => {
90 let actualFilters = navigator.usb.test.lastFilters; 89 assert_equals(error.code, DOMException.NOT_FOUND_ERR);
91 assert_equals(actualFilters.length, expectedFilters.length); 90 let actualFilters = navigator.usb.test.lastFilters;
92 for (var i = 0; i < actualFilters.length; ++i) 91 assert_equals(actualFilters.length, expectedFilters.length);
93 assert_object_equals(actualFilters[i], expectedFilters[i]); 92 for (var i = 0; i < actualFilters.length; ++i)
94 }) 93 assert_object_equals(actualFilters[i], expectedFilters[i]);
95 ); 94 });
95 });
96 }, 'filters are sent correctly'); 96 }, 'filters are sent correctly');
97 97
98 usb_test(() => { 98 usb_test(() => {
99 return getFakeDevice().then(({ device }) => { 99 return getFakeDevice().then(({ device }) => {
100 assertDeviceInfoEquals(device, fakeDeviceInit); 100 assertDeviceInfoEquals(device, fakeDeviceInit);
101 return device.open().then(() => device.close()); 101 return device.open().then(() => device.close());
102 }); 102 });
103 }, 'onconnect event is trigged by adding a device'); 103 }, 'onconnect event is trigged by adding a device');
104 104
105 usb_test(usb => { 105 usb_test(usb => {
106 return getFakeDevice().then(({ device, fakeDevice }) => { 106 return getFakeDevice().then(({ device, fakeDevice }) => {
107 return waitForDisconnect(fakeDevice).then(removedDevice => { 107 return waitForDisconnect(fakeDevice).then(removedDevice => {
108 assertDeviceInfoEquals(removedDevice, fakeDeviceInit); 108 assertDeviceInfoEquals(removedDevice, fakeDeviceInit);
109 assert_equals(removedDevice, device); 109 assert_equals(removedDevice, device);
110 return removedDevice.open().then(() => { 110 return removedDevice.open().then(() => {
111 assert_unreachable('should not be able to open a disconnected device'); 111 assert_unreachable('should not be able to open a disconnected device');
112 }, error => { 112 }, error => {
113 assert_equals(error.code, DOMException.NOT_FOUND_ERR); 113 assert_equals(error.code, DOMException.NOT_FOUND_ERR);
114 }); 114 });
115 }); 115 });
116 }); 116 });
117 }, 'ondisconnect event is triggered by removing a device'); 117 }, 'ondisconnect event is triggered by removing a device');
118 </script> 118 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698