Index: chrome/test/data/extensions/api_test/bindings/external_message_listener/background.js |
diff --git a/chrome/test/data/extensions/api_test/bindings/external_message_listener/background.js b/chrome/test/data/extensions/api_test/bindings/external_message_listener/background.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b5dce1a7af70ffca58036d0f7f64c5721e83245f |
--- /dev/null |
+++ b/chrome/test/data/extensions/api_test/bindings/external_message_listener/background.js |
@@ -0,0 +1,32 @@ |
+// 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 messagesReceived = []; |
+ |
+// Have we received the real message from the sender extension? |
+var receivedRealSenderMessage = false; |
+ |
+// Has the c++ code in the browser test asked us for the total count of messages |
+// we've received? |
+var sendCountAfterSenderMessage = false; |
+ |
+function getMessageCountAfterReceivingRealSenderMessage() { |
+ if (receivedRealSenderMessage) { |
+ window.domAutomationController.send(messagesReceived.length); |
+ } else { |
+ sendCountAfterSenderMessage = true; |
+ } |
+} |
+ |
+chrome.runtime.onMessageExternal.addListener(function(msg, sender, respond) { |
+ messagesReceived.push({msg:msg, sender:sender}); |
+ if (msg == 'from_sender') { |
+ receivedRealSenderMessage = true; |
+ if (sendCountAfterSenderMessage) { |
+ window.domAutomationController.send(messagesReceived.length); |
+ } |
+ } |
+}); |
+ |
+chrome.test.sendMessage('receiver_ready'); |