forked from web-platform-tests/wpt-actions-test
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bluetooth: Migrate server connection tests
This change migrates the server/(dis)connect tests and the same object test. This change also modifies bluetooth-helpers.js to use the correct path for health-thermometer-iframe.html for migrated tests and tests that have not yet been migrated. BUG=509038 Change-Id: I0485dd173898983841cea25a8ff3bdde198f9206 Reviewed-on: https://chromium-review.googlesource.com/836689 Commit-Queue: Ovidio Henriquez <[email protected]> Reviewed-by: Conley Owens <[email protected]> Reviewed-by: Vincent Scheib <[email protected]> Cr-Commit-Position: refs/heads/master@{#528054}
- Loading branch information
1 parent
657ac6f
commit ec972dc
Showing
10 changed files
with
254 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<!DOCTYPE html> | ||
<script> | ||
let device; | ||
|
||
function requestDeviceWithOptionsAndConnect(options) { | ||
return navigator.bluetooth.requestDevice(options) | ||
.then(device => device.gatt.connect()); | ||
} | ||
|
||
window.onmessage = messageEvent => { | ||
switch (messageEvent.data.type) { | ||
case 'RequestAndConnect': | ||
requestDeviceWithOptionsAndConnect(messageEvent.data.options) | ||
.then(gatt => { | ||
device = gatt.device; | ||
parent.postMessage('Connected', '*'); | ||
}).catch(err => { | ||
parent.postMessage(`FAIL: ${err}`, '*'); | ||
}); | ||
break; | ||
case 'DiscoverServices': | ||
requestDeviceWithOptionsAndConnect(messageEvent.data.options) | ||
.then(gatt => gatt.getPrimaryServices()) | ||
.then(() => parent.postMessage('DiscoveryComplete', '*')) | ||
.catch(err => { | ||
parent.postMessage(`FAIL: ${err}`, '*'); | ||
}); | ||
break; | ||
default: | ||
parent.postMessage(`FAIL: Bad message type: ${messageEvent.data.type}`, | ||
'*'); | ||
} | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<!DOCTYPE html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/resources/testdriver.js"></script> | ||
<script src="/resources/testdriver-vendor.js"></script> | ||
<script src="/bluetooth/resources/bluetooth-helpers.js"></script> | ||
<script> | ||
'use strict'; | ||
bluetooth_test(() => { | ||
return getDiscoveredHealthThermometerDevice() | ||
.then(({device, fake_peripheral}) => { | ||
return fake_peripheral.setNextGATTConnectionResponse({code: HCI_SUCCESS}) | ||
.then(() => device.gatt.connect()) | ||
.then(gatt => assert_true(gatt.connected)); | ||
}); | ||
}, 'Device will connect'); | ||
</script> |
22 changes: 22 additions & 0 deletions
22
bluetooth/server/connect/garbage-collection-ran-during-success.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/resources/testdriver.js"></script> | ||
<script src="/resources/testdriver-vendor.js"></script> | ||
<script src="/bluetooth/resources/bluetooth-helpers.js"></script> | ||
<script> | ||
'use strict'; | ||
bluetooth_test(() => { | ||
return getDiscoveredHealthThermometerDevice() | ||
.then(({device, fake_peripheral}) => { | ||
return fake_peripheral.setNextGATTConnectionResponse({code: HCI_SUCCESS}) | ||
.then(() => { | ||
// Don't return the promise and let |device| go out of scope | ||
// so that it gets garbage collected. | ||
device.gatt.connect(); | ||
}); | ||
}) | ||
.then(runGarbageCollection) | ||
}, 'Garbage Collection ran during a connect call that succeeds. ' + | ||
'Should not crash.'); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/resources/testdriver.js"></script> | ||
<script src="/resources/testdriver-vendor.js"></script> | ||
<script src="/bluetooth/resources/bluetooth-helpers.js"></script> | ||
<script> | ||
'use strict'; | ||
bluetooth_test(() => { | ||
return getDiscoveredHealthThermometerDevice() | ||
.then(({device, fake_peripheral}) => { | ||
return fake_peripheral | ||
.setNextGATTConnectionResponse({code: HCI_SUCCESS}) | ||
.then(() => device.gatt.connect()) | ||
.then(gatt1 => { | ||
// No second response is necessary because an ATT Bearer | ||
// already exists from the first connection. | ||
// See https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-connect | ||
// step 5.1. | ||
return device.gatt.connect().then(gatt2 => [gatt1, gatt2]); | ||
}); | ||
}) | ||
.then(([gatt1, gatt2]) => assert_equals(gatt1, gatt2)); | ||
}, 'Multiple connects should return the same gatt object.'); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<!DOCTYPE html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/resources/testdriver.js"></script> | ||
<script src="/resources/testdriver-vendor.js"></script> | ||
<script src="/bluetooth/resources/bluetooth-helpers.js"></script> | ||
<script> | ||
'use strict'; | ||
bluetooth_test(() => { | ||
return getDiscoveredHealthThermometerDevice() | ||
.then(({device, fake_peripheral}) => { | ||
return fake_peripheral.setNextGATTConnectionResponse({code: HCI_SUCCESS}) | ||
.then(() => device.gatt.connect()); | ||
}) | ||
.then(gatt => { | ||
assert_equals(gatt.device, gatt.device); | ||
}); | ||
}, "[SameObject] test for BluetoothRemoteGATTServer's device."); | ||
</script> |
29 changes: 29 additions & 0 deletions
29
bluetooth/server/disconnect/connect-disconnect-twice.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!DOCTYPE html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/resources/testdriver.js"></script> | ||
<script src="/resources/testdriver-vendor.js"></script> | ||
<script src="/bluetooth/resources/bluetooth-helpers.js"></script> | ||
<script> | ||
'use strict'; | ||
const test_desc = 'Connect + Disconnect twice still results in ' + | ||
'\'connected\' being false.'; | ||
let device, fake_peripheral; | ||
|
||
// TODO(569716): Test that the disconnect signal was sent to the device. | ||
bluetooth_test(() => getDiscoveredHealthThermometerDevice() | ||
.then(_ => ({device, fake_peripheral} = _)) | ||
.then(() => fake_peripheral.setNextGATTConnectionResponse({ | ||
code: HCI_SUCCESS, | ||
})) | ||
.then(() => device.gatt.connect() | ||
.then(gattServer => { | ||
gattServer.disconnect(); | ||
assert_false(gattServer.connected); | ||
}) | ||
.then(() => device.gatt.connect()) | ||
.then(gattServer => { | ||
gattServer.disconnect(); | ||
assert_false(gattServer.connected); | ||
})), test_desc); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!DOCTYPE html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/resources/testdriver.js"></script> | ||
<script src="/resources/testdriver-vendor.js"></script> | ||
<script src="/bluetooth/resources/bluetooth-helpers.js"></script> | ||
<body> | ||
<script> | ||
'use strict'; | ||
const test_desc = 'Detach frame then garbage collect. We shouldn\'t crash.'; | ||
let iframe = document.createElement('iframe'); | ||
|
||
bluetooth_test(() => setUpConnectableHealthThermometerDevice() | ||
// 1. Load the iframe. | ||
.then(() => new Promise(resolve => { | ||
iframe.src = '/bluetooth/resources/health-thermometer-iframe.html'; | ||
document.body.appendChild(iframe); | ||
iframe.addEventListener('load', resolve); | ||
})) | ||
// 2. Connect device, detach the iframe, and run garbage collection. | ||
.then(() => new Promise(resolve => { | ||
callWithTrustedClick(() => { | ||
iframe.contentWindow.postMessage({ | ||
type: 'RequestAndConnect', | ||
options: {filters: [{services: ['health_thermometer']}]} | ||
}, '*'); | ||
}); | ||
|
||
window.onmessage = messageEvent => { | ||
assert_equals(messageEvent.data, 'Connected'); | ||
iframe.remove(); | ||
runGarbageCollection().then(resolve); | ||
} | ||
})), test_desc) | ||
</script> | ||
</body> |
26 changes: 26 additions & 0 deletions
26
bluetooth/server/disconnect/disconnect-twice-in-a-row.https.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/resources/testdriver.js"></script> | ||
<script src="/resources/testdriver-vendor.js"></script> | ||
<script src="/bluetooth/resources/bluetooth-helpers.js"></script> | ||
<script> | ||
'use strict'; | ||
const test_desc = 'Calling disconnect twice in a row still results in ' + | ||
'\'connected\' being false.'; | ||
let device, fake_peripheral; | ||
|
||
// TODO(569716): Test that the disconnect signal was sent to the device. | ||
bluetooth_test(() => getDiscoveredHealthThermometerDevice() | ||
.then(_ => ({device, fake_peripheral} = _)) | ||
.then(() => fake_peripheral.setNextGATTConnectionResponse({ | ||
code: HCI_SUCCESS, | ||
})) | ||
.then(() => device.gatt.connect()) | ||
.then(gattServer => { | ||
gattServer.disconnect(); | ||
assert_false(gattServer.connected); | ||
gattServer.disconnect(); | ||
assert_false(gattServer.connected); | ||
}), test_desc); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<!DOCTYPE html> | ||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
<script src="/resources/testdriver.js"></script> | ||
<script src="/resources/testdriver-vendor.js"></script> | ||
<script src="/bluetooth/resources/bluetooth-helpers.js"></script> | ||
<body> | ||
<script> | ||
'use strict'; | ||
const test_desc = 'Garbage collect then detach frame. We shouldn\'t crash.'; | ||
let iframe = document.createElement('iframe'); | ||
|
||
bluetooth_test(() => setUpConnectableHealthThermometerDevice() | ||
// 1. Load the iframe. | ||
.then((f) => new Promise(resolve => { | ||
iframe.src = '/bluetooth/resources/health-thermometer-iframe.html'; | ||
document.body.appendChild(iframe); | ||
iframe.addEventListener('load', resolve); | ||
})) | ||
// 2. Connect device, run garbage collection, and detach iframe. | ||
.then(() => new Promise(resolve => { | ||
callWithTrustedClick(() => { | ||
iframe.contentWindow.postMessage({ | ||
type: 'RequestAndConnect', | ||
options: {filters: [{services: ['health_thermometer']}]} | ||
}, '*'); | ||
}); | ||
|
||
window.onmessage = messageEvent => { | ||
assert_equals(messageEvent.data, 'Connected'); | ||
runGarbageCollection().then(() => { | ||
iframe.remove(); | ||
resolve(); | ||
}); | ||
} | ||
})), test_desc) | ||
</script> | ||
</body> |