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

Side by Side Diff: third_party/WebKit/LayoutTests/bluetooth/writeValue.html

Issue 1844153002: bluetooth: Split writeValue tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bluetooth-testrunner-mojo
Patch Set: Merge Created 4 years, 8 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
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/bluetooth/writeValue-blacklist.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <script src="../resources/testharness.js"></script>
3 <script src="../resources/testharnessreport.js"></script>
4 <script src="resources/bluetooth-helpers.js"></script>
5 <script>
6 'use strict';
7
8 test(t => { assert_exists(window, 'testRunner'); t.done(); },
9 'window.testRunner is required for the following tests.');
10
11 promise_test(() => {
12 return setBluetoothFakeAdapter('HeartRateAdapter')
13 .then(() => requestDeviceWithKeyDown({
14 filters: [{services: ['heart_rate']}],
15 optionalServices: ['generic_access']}))
16 .then(device => device.gatt.connect())
17 .then(gattServer => gattServer.getPrimaryService('generic_access'))
18 .then(service => service.getCharacteristic('gap.device_name'))
19 .then(characteristic => {
20 return setBluetoothFakeAdapter('EmptyAdapter')
21 .then(() => assert_promise_rejects_with_message(
22 characteristic.writeValue(new ArrayBuffer(1 /* length */)),
23 new DOMException(
24 'Bluetooth Device is no longer in range.', 'NetworkError'),
25 'Device went out of range.'));
26 });
27 }, 'Device goes out of range. Reject with NetworkError.');
28
29 promise_test(() => {
30 return setBluetoothFakeAdapter('HeartRateAdapter')
31 .then(() => requestDeviceWithKeyDown({
32 filters: [{services: ['heart_rate']}],
33 optionalServices: ['generic_access']}))
34 .then(device => device.gatt.connect())
35 .then(gattServer => gattServer.getPrimaryService('generic_access'))
36 .then(service => service.getCharacteristic('gap.device_name'))
37 .then(characteristic => {
38 return setBluetoothFakeAdapter('MissingServiceHeartRateAdapter')
39 .then(() => assert_promise_rejects_with_message(
40 characteristic.writeValue(new ArrayBuffer(1 /* length */)),
41 new DOMException('GATT Service no longer exists.',
42 'InvalidStateError'),
43 'Service got removed.'));
44 });
45 }, 'Service gets removed. Reject with InvalidStateError.');
46
47 promise_test(() => {
48 return setBluetoothFakeAdapter('HeartRateAdapter')
49 .then(() => requestDeviceWithKeyDown({
50 filters: [{services: ['heart_rate']}],
51 optionalServices: ['generic_access']}))
52 .then(device => device.gatt.connect())
53 .then(gattServer => gattServer.getPrimaryService('generic_access'))
54 .then(service => service.getCharacteristic('gap.device_name'))
55 .then(characteristic => {
56 return setBluetoothFakeAdapter('MissingCharacteristicHeartRateAdapter')
57 .then(() => assert_promise_rejects_with_message(
58 characteristic.writeValue(new ArrayBuffer(1 /* length */)),
59 new DOMException(
60 'GATT Characteristic no longer exists.', 'InvalidStateError'),
61 'Characteristic got removed.'));
62 });
63 }, 'Characteristic gets removed. Reject with InvalidStateError.');
64
65 gatt_errors_tests.forEach(testSpec => {
66 promise_test(() => {
67 return setBluetoothFakeAdapter('FailingGATTOperationsAdapter')
68 .then(() => requestDeviceWithKeyDown({
69 filters: [{services: [errorUUID(0xA0)]}]}))
70 .then(device => device.gatt.connect())
71 .then(gattServer => gattServer.getPrimaryService(errorUUID(0xA0)))
72 .then(service => service.getCharacteristic(testSpec.uuid))
73 .then(characteristic => {
74 return assert_promise_rejects_with_message(
75 characteristic.writeValue(new Uint8Array([1])),
76 testSpec.error,
77 'Trying to write to a characteristic failed.');
78 });
79 }, testSpec.testName);
80 });
81
82 promise_test(() => {
83 return setBluetoothFakeAdapter('HeartRateAdapter')
84 .then(() => requestDeviceWithKeyDown({
85 filters: [{services: ['heart_rate']}],
86 optionalServices: ['generic_access']}))
87 .then(device => device.gatt.connect())
88 .then(gattServer => gattServer.getPrimaryService('generic_access'))
89 .then(service => service.getCharacteristic('gap.device_name'))
90 .then(characteristic => {
91 return assert_promise_rejects_with_message(
92 characteristic.writeValue(new Uint8Array(513 /* length */)),
93 new DOMException(
94 'Value can\'t exceed 512 bytes.', 'InvalidModificationError'),
95 'Value passed was too long.');
96 });
97 }, 'Trying to write more than 512 bytes should return an error.');
98
99 promise_test(() => {
100 return setBluetoothFakeAdapter('HeartRateAdapter')
101 .then(() => requestDeviceWithKeyDown({
102 filters: [{services: ['heart_rate']}],
103 optionalServices: ['generic_access']}))
104 .then(device => device.gatt.connect())
105 .then(gattServer => gattServer.getPrimaryService('generic_access'))
106 .then(service => service.getCharacteristic('gap.device_name'))
107 .then(characteristic => Promise.all(
108 [characteristic.writeValue(new Uint8Array(1 /* length */)),
109 characteristic.writeValue(new ArrayBuffer(1 /* length */)),
110 characteristic.writeValue(new DataView(new ArrayBuffer(1 /* length */)))] ));
111 }, 'A regular write request to a writable characteristic should succeed.');
112
113 promise_test(() => {
114 return setBluetoothFakeAdapter('HeartRateAdapter')
115 .then(() => requestDeviceWithKeyDown({
116 filters: [{services: ['heart_rate']}],
117 optionalServices: ['generic_access']}))
118 .then(device => device.gatt.connect())
119 .then(gattServer => gattServer.getPrimaryService('generic_access'))
120 .then(service => service.getCharacteristic('gap.device_name'))
121 .then(characteristic => {
122 assert_equals(characteristic.value, null);
123 let textEncoder = new TextEncoder();
124 let newValue = textEncoder.encode('foo');
125 return characteristic.writeValue(newValue).then(() => {
126 assert_array_equals(characteristic.value.buffer, newValue.buffer);
127 });
128 });
129 }, 'A regular write request to a writable characteristic should update value.');
130 </script>
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/bluetooth/writeValue-blacklist.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698