Commit 38f4426e authored by miguelg@chromium.org's avatar miguelg@chromium.org

Rename hasPermission to permissionState.

As per https://github.com/w3c/push-api/issues/136
BUG=479246

Review URL: https://codereview.chromium.org/1083193006

git-svn-id: svn://svn.chromium.org/blink/trunk@194410 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 6097f44e
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
assert_own_property(PushManager.prototype, 'subscribe'); assert_own_property(PushManager.prototype, 'subscribe');
assert_own_property(PushManager.prototype, 'getSubscription'); assert_own_property(PushManager.prototype, 'getSubscription');
assert_own_property(PushManager.prototype, 'hasPermission'); assert_own_property(PushManager.prototype, 'permissionState');
}, 'PushManager should be exposed and have the expected interface in a Document.'); }, 'PushManager should be exposed and have the expected interface in a Document.');
...@@ -34,4 +34,4 @@ ...@@ -34,4 +34,4 @@
}, 'PushSubscription should be exposed and have the expected interface in a Document.'); }, 'PushSubscription should be exposed and have the expected interface in a Document.');
</script> </script>
</body> </body>
</html> </html>
\ No newline at end of file
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>Push API: hasPermission resolves with default when no permission is set</title> <title>Push API: permissionState resolves with default when no permission is set</title>
<link rel="manifest" href="resources/push_manifest.json"> <link rel="manifest" href="resources/push_manifest.json">
<script src="../resources/testharness.js"></script> <script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script> <script src="../resources/testharnessreport.js"></script>
...@@ -18,14 +18,14 @@ async_test(function(test) { ...@@ -18,14 +18,14 @@ async_test(function(test) {
service_worker_unregister_and_register(test, workerUrl, workerScope) service_worker_unregister_and_register(test, workerUrl, workerScope)
.then(function(serviceWorkerRegistration) { .then(function(serviceWorkerRegistration) {
// If running manually, clear permissions before running this test. // If running manually, clear permissions before running this test.
return serviceWorkerRegistration.pushManager.hasPermission(); return serviceWorkerRegistration.pushManager.permissionState();
}) })
.then(function(permissionStatus) { .then(function(permissionStatus) {
assert_equals(permissionStatus, 'default'); assert_equals(permissionStatus, 'default');
return service_worker_unregister_and_done(test, workerScope); return service_worker_unregister_and_done(test, workerScope);
}) })
.catch(unreached_rejection(test)); .catch(unreached_rejection(test));
}, 'Push API: hasPermission resolves with default when permission is not set'); }, 'Push API: permissionState() resolves with default when permission is not set');
</script> </script>
</body> </body>
</html> </html>
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<html> <html>
<head> <head>
<title> <title>
hasPermission when called in service worker resolves with default when no permission is set Push API: permissionState when called in service worker resolves with default when no permission is set
</title> </title>
<link rel="manifest" href="resources/push_manifest.json"> <link rel="manifest" href="resources/push_manifest.json">
<script src="../resources/testharness.js"></script> <script src="../resources/testharness.js"></script>
...@@ -21,21 +21,21 @@ async_test(function(test) { ...@@ -21,21 +21,21 @@ async_test(function(test) {
var scope = 'resources/scope/' + location.pathname; var scope = 'resources/scope/' + location.pathname;
getActiveServiceWorkerWithMessagePort(test, script, scope).then(function(workerInfo) { getActiveServiceWorkerWithMessagePort(test, script, scope).then(function(workerInfo) {
workerInfo.port.postMessage({command: 'hasPermission'}); workerInfo.port.postMessage({command: 'permissionState'});
workerInfo.port.addEventListener('message', function(event) { workerInfo.port.addEventListener('message', function(event) {
if (typeof event.data != 'object' || !event.data.command) if (typeof event.data != 'object' || !event.data.command)
assert_unreached('Invalid message from the service worker'); assert_unreached('Invalid message from the service worker');
assert_equals(event.data.command, 'hasPermission'); assert_equals(event.data.command, 'permissionState');
assert_true(event.data.success, assert_true(event.data.success,
'hasPermission should succeed. Error message: ' + event.data.errorMessage); 'permissionState should succeed. Error message: ' + event.data.errorMessage);
assert_equals(event.data.permission, 'default'); assert_equals(event.data.permission, 'default');
test.done(); test.done();
}); });
}).catch(unreached_rejection(test)); }).catch(unreached_rejection(test));
}, 'hasPermission when called in service worker resolves with default when no permission is set'); }, 'permissionState when called in service worker resolves with default when no permission is set');
</script> </script>
</body> </body>
</html> </html>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>Push API: hasPermission resolves with denied when permission is denied</title> <title>Push API: permissionState resolves with denied when permission is denied</title>
<link rel="manifest" href="resources/push_manifest.json"> <link rel="manifest" href="resources/push_manifest.json">
<script src="../resources/testharness.js"></script> <script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script> <script src="../resources/testharnessreport.js"></script>
...@@ -17,14 +17,14 @@ async_test(function(test) { ...@@ -17,14 +17,14 @@ async_test(function(test) {
// If running manually, deny permission when prompted. // If running manually, deny permission when prompted.
if (window.testRunner) if (window.testRunner)
testRunner.setPermission('push-messaging', 'denied', location.origin, location.origin); testRunner.setPermission('push-messaging', 'denied', location.origin, location.origin);
return serviceWorkerRegistration.pushManager.hasPermission(); return serviceWorkerRegistration.pushManager.permissionState();
}) })
.then(function(permissionStatus) { .then(function(permissionStatus) {
assert_equals(permissionStatus, 'denied'); assert_equals(permissionStatus, 'denied');
return service_worker_unregister_and_done(test, workerScope); return service_worker_unregister_and_done(test, workerScope);
}) })
.catch(unreached_rejection(test)); .catch(unreached_rejection(test));
}, 'Push API: hasPermission resolves with denied when permission is denied'); }, 'Push API: permissionState resolves with denied when permission is denied');
</script> </script>
</body> </body>
</html> </html>
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<html> <html>
<head> <head>
<title> <title>
hasPermission when called in service worker resolves with denied when permission is denied Push API: permissionState when called in service worker resolves with denied when permission is denied
</title> </title>
<link rel="manifest" href="resources/push_manifest.json"> <link rel="manifest" href="resources/push_manifest.json">
<script src="../resources/testharness.js"></script> <script src="../resources/testharness.js"></script>
...@@ -21,21 +21,21 @@ async_test(function(test) { ...@@ -21,21 +21,21 @@ async_test(function(test) {
var scope = 'resources/scope/' + location.pathname; var scope = 'resources/scope/' + location.pathname;
getActiveServiceWorkerWithMessagePort(test, script, scope).then(function(workerInfo) { getActiveServiceWorkerWithMessagePort(test, script, scope).then(function(workerInfo) {
workerInfo.port.postMessage({command: 'hasPermission'}); workerInfo.port.postMessage({command: 'permissionState'});
workerInfo.port.addEventListener('message', function(event) { workerInfo.port.addEventListener('message', function(event) {
if (typeof event.data != 'object' || !event.data.command) if (typeof event.data != 'object' || !event.data.command)
assert_unreached('Invalid message from the service worker'); assert_unreached('Invalid message from the service worker');
assert_equals(event.data.command, 'hasPermission'); assert_equals(event.data.command, 'permissionState');
assert_true(event.data.success, assert_true(event.data.success,
'hasPermission should succeed. Error message: ' + event.data.errorMessage); 'permissionState should succeed. Error message: ' + event.data.errorMessage);
assert_equals(event.data.permission, 'denied'); assert_equals(event.data.permission, 'denied');
test.done(); test.done();
}); });
}).catch(unreached_rejection(test)); }).catch(unreached_rejection(test));
}, 'hasPermission when called in service worker resolves with denied when permission is denied'); }, 'permissionState when called in service worker resolves with denied when permission is denied');
</script> </script>
</body> </body>
</html> </html>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<title>Push API: hasPermission resolves with granted when permission is granted</title> <title>Push API: permissionState resolves with granted when permission is granted</title>
<link rel="manifest" href="resources/push_manifest.json"> <link rel="manifest" href="resources/push_manifest.json">
<script src="../resources/testharness.js"></script> <script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script> <script src="../resources/testharnessreport.js"></script>
...@@ -17,14 +17,14 @@ async_test(function(test) { ...@@ -17,14 +17,14 @@ async_test(function(test) {
// If running manually, grant permission when prompted. // If running manually, grant permission when prompted.
if (window.testRunner) if (window.testRunner)
testRunner.setPermission('push-messaging', 'granted', location.origin, location.origin); testRunner.setPermission('push-messaging', 'granted', location.origin, location.origin);
return serviceWorkerRegistration.pushManager.hasPermission(); return serviceWorkerRegistration.pushManager.permissionState();
}) })
.then(function(permissionStatus) { .then(function(permissionStatus) {
assert_equals(permissionStatus, 'granted'); assert_equals(permissionStatus, 'granted');
return service_worker_unregister_and_done(test, workerScope); return service_worker_unregister_and_done(test, workerScope);
}) })
.catch(unreached_rejection(test)); .catch(unreached_rejection(test));
}, 'Push API: hasPermission resolves with granted when permission is granted'); }, 'Push API: permissionState resolves with granted when permission is granted');
</script> </script>
</body> </body>
</html> </html>
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
<html> <html>
<head> <head>
<title> <title>
hasPermission when called in service worker resolves with granted when permission is granted permissionState when called in service worker resolves with granted when permission is granted
</title> </title>
<link rel="manifest" href="resources/push_manifest.json"> <link rel="manifest" href="resources/push_manifest.json">
<script src="../resources/testharness.js"></script> <script src="../resources/testharness.js"></script>
...@@ -21,21 +21,21 @@ async_test(function(test) { ...@@ -21,21 +21,21 @@ async_test(function(test) {
var scope = 'resources/scope/' + location.pathname; var scope = 'resources/scope/' + location.pathname;
getActiveServiceWorkerWithMessagePort(test, script, scope).then(function(workerInfo) { getActiveServiceWorkerWithMessagePort(test, script, scope).then(function(workerInfo) {
workerInfo.port.postMessage({command: 'hasPermission'}); workerInfo.port.postMessage({command: 'permissionState'});
workerInfo.port.addEventListener('message', function(event) { workerInfo.port.addEventListener('message', function(event) {
if (typeof event.data != 'object' || !event.data.command) if (typeof event.data != 'object' || !event.data.command)
assert_unreached('Invalid message from the service worker'); assert_unreached('Invalid message from the service worker');
assert_equals(event.data.command, 'hasPermission'); assert_equals(event.data.command, 'permissionState');
assert_true(event.data.success, assert_true(event.data.success,
'hasPermission should succeed. Error message: ' + event.data.errorMessage); 'permissionState should succeed. Error message: ' + event.data.errorMessage);
assert_equals(event.data.permission, 'granted'); assert_equals(event.data.permission, 'granted');
test.done(); test.done();
}); });
}).catch(unreached_rejection(test)); }).catch(unreached_rejection(test));
}, 'hasPermission when called in service worker resolves with granted when permission is granted'); }, 'permissionState when called in service worker resolves with granted when permission is granted');
</script> </script>
</body> </body>
</html> </html>
...@@ -15,8 +15,8 @@ self.addEventListener('message', function(workerEvent) { ...@@ -15,8 +15,8 @@ self.addEventListener('message', function(workerEvent) {
return; return;
switch (event.data.command) { switch (event.data.command) {
case 'hasPermission': case 'permissionState':
self.registration.pushManager.hasPermission().then(function(permissionStatus) { self.registration.pushManager.permissionState().then(function(permissionStatus) {
port.postMessage({ command: event.data.command, port.postMessage({ command: event.data.command,
success: true, success: true,
permission: permissionStatus }); permission: permissionStatus });
......
...@@ -19,7 +19,7 @@ test(function() { ...@@ -19,7 +19,7 @@ test(function() {
assert_inherits(registration.pushManager, 'subscribe'); assert_inherits(registration.pushManager, 'subscribe');
assert_inherits(registration.pushManager, 'getSubscription'); assert_inherits(registration.pushManager, 'getSubscription');
assert_inherits(registration.pushManager, 'hasPermission'); assert_inherits(registration.pushManager, 'permissionState');
}, 'PushManager should be exposed and have the expected interface.'); }, 'PushManager should be exposed and have the expected interface.');
......
...@@ -3693,6 +3693,7 @@ interface PushManager ...@@ -3693,6 +3693,7 @@ interface PushManager
method constructor method constructor
method getSubscription method getSubscription
method hasPermission method hasPermission
method permissionState
method subscribe method subscribe
interface PushSubscription interface PushSubscription
getter endpoint getter endpoint
......
...@@ -75,7 +75,7 @@ ScriptPromise PushManager::getSubscription(ScriptState* scriptState) ...@@ -75,7 +75,7 @@ ScriptPromise PushManager::getSubscription(ScriptState* scriptState)
return promise; return promise;
} }
ScriptPromise PushManager::hasPermission(ScriptState* scriptState) ScriptPromise PushManager::permissionState(ScriptState* scriptState)
{ {
if (scriptState->executionContext()->isDocument()) { if (scriptState->executionContext()->isDocument()) {
Document* document = toDocument(scriptState->executionContext()); Document* document = toDocument(scriptState->executionContext());
...@@ -90,6 +90,11 @@ ScriptPromise PushManager::hasPermission(ScriptState* scriptState) ...@@ -90,6 +90,11 @@ ScriptPromise PushManager::hasPermission(ScriptState* scriptState)
return promise; return promise;
} }
ScriptPromise PushManager::hasPermission(ScriptState* scriptState)
{
return permissionState(scriptState);
}
DEFINE_TRACE(PushManager) DEFINE_TRACE(PushManager)
{ {
visitor->trace(m_registration); visitor->trace(m_registration);
......
...@@ -24,6 +24,7 @@ public: ...@@ -24,6 +24,7 @@ public:
ScriptPromise subscribe(ScriptState*); ScriptPromise subscribe(ScriptState*);
ScriptPromise getSubscription(ScriptState*); ScriptPromise getSubscription(ScriptState*);
ScriptPromise permissionState(ScriptState*);
ScriptPromise hasPermission(ScriptState*); ScriptPromise hasPermission(ScriptState*);
DECLARE_TRACE(); DECLARE_TRACE();
......
...@@ -11,5 +11,8 @@ ...@@ -11,5 +11,8 @@
] interface PushManager { ] interface PushManager {
[CallWith=ScriptState] Promise<PushSubscription> subscribe(); [CallWith=ScriptState] Promise<PushSubscription> subscribe();
[CallWith=ScriptState] Promise<PushSubscription?> getSubscription(); [CallWith=ScriptState] Promise<PushSubscription?> getSubscription();
[RuntimeEnabled=PushMessagingHasPermission,CallWith=ScriptState] Promise permissionState();
// temporarily enabled as well for three sided patch
[RuntimeEnabled=PushMessagingHasPermission,CallWith=ScriptState] Promise hasPermission(); [RuntimeEnabled=PushMessagingHasPermission,CallWith=ScriptState] Promise hasPermission();
}; };
...@@ -121,8 +121,7 @@ PseudoClassesInMatchingCriteriaInAuthorShadowTrees status=test ...@@ -121,8 +121,7 @@ PseudoClassesInMatchingCriteriaInAuthorShadowTrees status=test
PushMessaging status=stable PushMessaging status=stable
// Push messaging payloads are blocked on the Push API supporting encryption. // Push messaging payloads are blocked on the Push API supporting encryption.
PushMessagingData status=test PushMessagingData status=test
// PushManager.hasPermission() is currently disabled, expecting Permissions API // PushManager.permissionState() is currently disabled.
// to fulfill the same role.
PushMessagingHasPermission status=test PushMessagingHasPermission status=test
QuotaPromise status=experimental QuotaPromise status=experimental
ReducedReferrerGranularity ReducedReferrerGranularity
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment