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'); |
+} |