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

Unified Diff: chrome/test/data/extensions/api_test/messaging/externally_connectable/sites/assertions.js

Issue 23057005: In extension messaging, use the sender frame's URL as the sender URL rather (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add test, rebase Created 7 years, 4 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
« no previous file with comments | « chrome/renderer/extensions/runtime_custom_bindings.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
+}());
« no previous file with comments | « chrome/renderer/extensions/runtime_custom_bindings.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698