blob: 351f123a7d9d796420a4ddee07552c76f6f1c908 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<title>Stringifying a PushSubscription object includes all object members</title>
<link rel="manifest" href="resources/push_manifest.json">
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<script src="../serviceworker/resources/test-helpers.js"></script>
</head>
<body>
<script>
// Converts an ArrayBuffer to a base64url encoded string.
function ArrayBufferToBase64UrlEncodedString(buffer) {
var base64 = btoa(String.fromCharCode.apply(null, new Uint8Array(buffer)));
return base64.replace(/\//g, '_').replace(/\+/g, '-');
}
async_test(function(test) {
var workerUrl = 'resources/empty_worker.js';
var workerScope = 'resources/scope/' + location.pathname;
var swRegistration;
service_worker_unregister_and_register(test, workerUrl, workerScope)
.then(function(serviceWorkerRegistration) {
swRegistration = serviceWorkerRegistration;
return wait_for_state(test, swRegistration.installing, 'activated');
})
.then(function() {
// If running manually, grant permission when prompted.
if (window.testRunner)
testRunner.setPermission('push-messaging', 'granted', location.origin, location.origin);
return swRegistration.pushManager.subscribe();
})
.then(function(pushSubscription) {
var reflectedObject = JSON.parse(JSON.stringify(pushSubscription));
assert_own_property(reflectedObject, 'endpoint');
assert_equals(reflectedObject.endpoint, pushSubscription.endpoint);
assert_own_property(reflectedObject, 'expirationTime');
assert_equals(reflectedObject.expirationTime, null);
assert_own_property(reflectedObject, 'keys');
assert_own_property(reflectedObject.keys, 'p256dh');
assert_own_property(reflectedObject.keys, 'auth');
var key = ArrayBufferToBase64UrlEncodedString(pushSubscription.getKey('p256dh')),
auth = ArrayBufferToBase64UrlEncodedString(pushSubscription.getKey('auth'));
assert_equals(reflectedObject.keys.p256dh, key);
assert_equals(reflectedObject.keys.auth, auth);
return service_worker_unregister_and_done(test, workerScope);
})
.catch(unreached_rejection(test));
}, 'Stringifying a PushSubscription object includes all object members');
</script>
</body>
</html>