Index: chrome/test/data/extensions/api_test/messaging/externally_connectable/sites/assertions.js |
diff --git a/chrome/test/data/extensions/api_test/messaging/externally_connectable/sites/assertions.js b/chrome/test/data/extensions/api_test/messaging/externally_connectable/sites/assertions.js |
index 3f58051c84416c83914362310b8e353433974cc0..d2090d888c863facc42b3864bf4831c54e8d7c15 100644 |
--- a/chrome/test/data/extensions/api_test/messaging/externally_connectable/sites/assertions.js |
+++ b/chrome/test/data/extensions/api_test/messaging/externally_connectable/sites/assertions.js |
@@ -2,7 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-window.assertions = (function() { |
+(function() { |
// We are going to kill all of the builtins, so hold onto the ones we need. |
var defineGetter = Object.prototype.__defineGetter__; |
@@ -75,6 +75,20 @@ var results = { |
// Make the messages sent vaguely complex, but unambiguously JSON-ifiable. |
var message = [{'a': {'b': 10}}, 20, 'c\x10\x11']; |
+// Our tab's location. Normally this would be our document's location but if |
+// we're an iframe it will be the location of the parent - in which case, |
+// expect to be told. |
+var tabLocationHref = null; |
+ |
+if (parent == window) { |
+ tabLocationHref = document.location.href; |
+} else { |
+ window.addEventListener('message', function listener(event) { |
+ window.removeEventListener(listener); |
+ tabLocationHref = event.data; |
+ }); |
+} |
+ |
function checkLastError(reply) { |
if (!chrome.runtime.lastError) |
return true; |
@@ -97,8 +111,8 @@ function checkResponse(response, reply) { |
console.warn('Expected a tab, got none'); |
incorrectSender = true; |
} |
- if (response.sender.tab.url != document.location.href) { |
- console.warn('Expected tab url ' + document.location.href + ' got ' + |
+ if (response.sender.tab.url != tabLocationHref) { |
+ console.warn('Expected tab url ' + tabLocationHref + ' got ' + |
response.sender.tab.url); |
incorrectSender = true; |
} |
@@ -130,7 +144,22 @@ function sendToBrowser(msg) { |
domAutomationController.send(msg); |
} |
-return { |
+window.actions = { |
+ appendIframe: function(src) { |
+ var iframe = document.createElement('iframe'); |
+ // When iframe has loaded, notify it of our tab location (probably |
+ // document.location) to use in its assertions, then continue. |
+ iframe.addEventListener('load', function listener() { |
+ iframe.removeEventListener('load', listener); |
+ iframe.contentWindow.postMessage(tabLocationHref, '*'); |
+ sendToBrowser(true); |
+ }); |
+ iframe.src = src; |
+ document.body.appendChild(iframe); |
+ } |
+}; |
+ |
+window.assertions = { |
canConnectAndSendMessages: function(extensionId) { |
if (!chrome.runtime) { |
sendToBrowser(results.NAMESPACE_NOT_DEFINED); |
@@ -189,4 +218,4 @@ return { |
} |
}; |
-}()); // window.assertions |
+}()); |