Index: LayoutTests/http/tests/permissions/resources/helpers.js |
diff --git a/LayoutTests/http/tests/permissions/resources/helpers.js b/LayoutTests/http/tests/permissions/resources/helpers.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a14f4766883f3cadf0b855f66f35ecc488e97d58 |
--- /dev/null |
+++ b/LayoutTests/http/tests/permissions/resources/helpers.js |
@@ -0,0 +1,47 @@ |
+// Any copyright is dedicated to the Public Domain. |
+// http://creativecommons.org/publicdomain/zero/1.0/ |
Peter Beverloo
2014/12/01 11:30:34
Please don't add this copyright header. (Nor in th
mlamouri (slow - plz ping)
2014/12/01 12:36:00
This is unfortunate.
|
+ |
+// This file is using testharness.js coding style. |
+ |
+function get_script_href() |
+{ |
+ var filename = window.location.href.substr(window.location.href.lastIndexOf('/') + 1); |
+ return 'resources/' + filename.replace('.html', '.js'); |
+} |
+ |
+function get_current_scope() |
+{ |
+ if ('document' in self) { |
+ return 'Window'; |
Peter Beverloo
2014/12/01 11:30:34
indentation
mlamouri (slow - plz ping)
2014/12/01 12:36:00
Fixed.
|
+ } |
+ if ('DedicatedWorkerGlobalScope' in self && |
+ self instanceof DedicatedWorkerGlobalScope) { |
+ return 'DedicatedWorker'; |
Peter Beverloo
2014/12/01 11:30:34
indentation
mlamouri (slow - plz ping)
2014/12/01 12:36:00
Fixed.
|
+ } |
+ if ('SharedWorkerGlobalScope' in self && |
+ self instanceof SharedWorkerGlobalScope) { |
+ return 'SharedWorker'; |
+ } |
+ if ('ServiceWorkerGlobalScope' in self && |
+ self instanceof ServiceWorkerGlobalScope) { |
+ return 'ServiceWorker'; |
+ } |
+ |
+ throw new Error('unknown scope'); |
+} |
+ |
+if (get_current_scope() == 'Window') { |
+ window.addEventListener('load', function() { |
+ var script_href = get_script_href(); |
+ |
+ // Run the tests on the Window scope. |
+ var script_element = document.createElement('script'); |
+ script_element.src = script_href; |
+ document.body.appendChild(script_element); |
+ |
+ // Run the tests on {Dedicated,Shared,Shared}Worker. |
+ fetch_tests_from_worker(new Worker(script_href)); |
+ fetch_tests_from_worker(new SharedWorker(script_href)); |
+ window.service_worker_test(script_href); |
+ }); |
+} |