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

Unified Diff: chrome/test/data/extensions/api_test/messaging/interstitial_component/contentscript.js

Issue 1629013002: Allow a main interstitial frame to act as an ExtensionMessagePort opener (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@extension-message-port-onDisconnect-580882
Patch Set: Remove trailing space Created 4 years, 11 months 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: chrome/test/data/extensions/api_test/messaging/interstitial_component/contentscript.js
diff --git a/chrome/test/data/extensions/api_test/messaging/interstitial_component/contentscript.js b/chrome/test/data/extensions/api_test/messaging/interstitial_component/contentscript.js
new file mode 100644
index 0000000000000000000000000000000000000000..81d2b26f630dbc809250a3cef3a496f94066dab0
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/messaging/interstitial_component/contentscript.js
@@ -0,0 +1,53 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+var testPort = chrome.runtime.connect({
+ name: 'port from interstitial'
+});
+
+var currentTest;
+testPort.onMessage.addListener(function(msg) {
+ console.assert(!currentTest, 'Should only run one test at a time');
+ currentTest = msg;
+
+ if (msg === 'testSendMessage') {
+ testSendMessage();
+ } else if (msg === 'testDisconnectByBackground') {
+ testDisconnectByBackground();
+ } else if (msg === 'testDisconnectByInterstitial') {
+ testDisconnectByInterstitial();
+ } else {
+ done('Unexpected test: ' + msg);
+ }
+});
+
+function done(test) {
+ console.assert(test === currentTest, 'test name should match current test');
+ currentTest = null;
+ testPort.postMessage(test);
+}
+
+function testSendMessage() {
+ chrome.runtime.sendMessage('First from interstitial', function(msg) {
+ chrome.runtime.sendMessage('interstitial received: ' + msg);
+ done('testSendMessage');
+ });
+}
+
+function testDisconnectByBackground() {
+ var port = chrome.runtime.connect({
+ name: 'disconnect by background'
+ });
+ port.onDisconnect.addListener(function() {
+ done('testDisconnectByBackground');
+ });
+}
+
+function testDisconnectByInterstitial() {
+ var port = chrome.runtime.connect({
+ name: 'disconnect by interstitial'
+ });
+ port.disconnect();
+ done('testDisconnectByInterstitial');
+}

Powered by Google App Engine
This is Rietveld 408576698