Index: LayoutTests/resources/permissions-helper.js |
diff --git a/LayoutTests/resources/permissions-helper.js b/LayoutTests/resources/permissions-helper.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2f8bda3a6482972077e081a7aebb294168be8c6f |
--- /dev/null |
+++ b/LayoutTests/resources/permissions-helper.js |
@@ -0,0 +1,36 @@ |
+function permissionNameToPermissionObject(permissionName) { |
mlamouri (slow - plz ping)
2015/08/21 17:15:23
It would be good if we could make sure this is not
Lalit Maganti
2015/08/21 18:30:19
Done.
|
+ switch (permissionName) { |
+ case "midi": |
+ return {name: "midi"} |
+ case "midi-sysex": |
+ return {name: "midi", sysex: true} |
+ case "push-messaging": |
+ return {name: "push", userVisibleOnly: true} |
+ case "notifications": |
+ return {name: "midi"} |
mlamouri (slow - plz ping)
2015/08/21 17:15:23
midi?
Lalit Maganti
2015/08/21 18:30:19
Done.
|
+ case "geolocation": |
+ return {name: "geolocation", sysex: true} |
mlamouri (slow - plz ping)
2015/08/21 17:15:23
sysex?
Lalit Maganti
2015/08/21 18:30:19
Done.
|
+ case "protected-media-identifier": |
+ default: |
+ // We can't deal with these two yet. |
mlamouri (slow - plz ping)
2015/08/21 17:15:23
These 'two'?
Lalit Maganti
2015/08/21 18:30:19
Done.
|
+ return {name: "midi"} |
mlamouri (slow - plz ping)
2015/08/21 17:15:23
Can you actually throw in that case?
Lalit Maganti
2015/08/21 18:30:19
Done.
|
+ } |
+} |
+ |
+function setPermission(testRunner, permissionName, newState) { |
mlamouri (slow - plz ping)
2015/08/21 17:15:23
Can we use testRunner directly instead of taking i
Lalit Maganti
2015/08/21 18:30:19
Done.
|
+ return new Promise(function(resolver, reject) { |
+ navigator.permissions.query(permissionNameToPermissionObject(permissionName)).then(function(result) { |
+ if (result.state == newState) { |
+ resolver() |
+ return; |
+ } |
+ |
+ result.onchange = function() { |
+ result.onchange = null; |
+ resolver(); |
+ }; |
+ |
+ testRunner.setPermission(permissionName, newState, location.origin, location.origin); |
+ }); |
+ }); |
+} |