Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Unified Diff: content/test/data/background_sync/background_sync_test_helpers.js

Issue 1471763003: [BackgroundSync] Only allow SyncManager.register to occur from main frame (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@split
Patch Set: Address comments from PS6 Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/test/data/background_sync/background_sync_test_helpers.js
diff --git a/content/test/data/background_sync/background_sync_test_helpers.js b/content/test/data/background_sync/background_sync_test_helpers.js
index 79005264a28e3ca1ec9244c54e3f8368621da34e..7d118752a510297c88b4a1d742a24ce9740aca6f 100644
--- a/content/test/data/background_sync/background_sync_test_helpers.js
+++ b/content/test/data/background_sync/background_sync_test_helpers.js
@@ -115,6 +115,62 @@ function rejectDelayedOneShot() {
.catch(sendErrorToTest);
}
+function createFrame(url) {
+ return new Promise(function(resolve) {
+ var frame = document.createElement('iframe');
+ frame.src = url;
+ frame.onload = function() { resolve(frame); };
+ document.body.appendChild(frame);
+ });
+}
+
+function registerOneShotFromLocalFrame(frame_url) {
+ var frameWindow;
+ return createFrame(frame_url)
+ .then(function(frame) {
+ frameWindow = frame.contentWindow;
+ return frameWindow.navigator.serviceWorker.register('service_worker.js');
+ })
+ .then(function() {
+ return frameWindow.navigator.serviceWorker.ready;
+ })
+ .then(function(frame_registration) {
+ return frame_registration.sync.register('foo');
+ })
+ .then(function() {
+ sendResultToTest('error - iframe registered sync');
+ }, function(e) {
+ if (e.name != 'AbortError' || e.message !== 'Registration failed - not ' +
+ 'called from a main frame.') {
+ sendErrorToTest(e);
+ return;
+ }
+ sendResultToTest('ok - iframe failed to register sync');
+ });
+}
+
+function receiveMessage() {
+ return new Promise(function(resolve) {
+ window.addEventListener('message', function(message) {
+ resolve(message.data);
+ });
+ });
+}
+
+function registerOneShotFromCrossOriginServiceWorker(cross_frame_url) {
+ return createFrame(cross_frame_url)
+ .then(function(frame) {
+ return receiveMessage();
+ })
+ .then(function(message) {
+ console.log(message);
+ if (message !== 'registration failed') {
+ sendResultToTest('failed - ' + message);
+ return;
+ }
+ sendResultToTest('ok - worker failed to register sync');
+ });
+}
// Queue storing asynchronous results received from the Service Worker. Results
// are sent to the test when requested.
« no previous file with comments | « content/browser/service_worker/service_worker_context_wrapper.cc ('k') | content/test/data/background_sync/empty.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698