summaryrefslogtreecommitdiffstats
path: root/chrome/test/data/extensions/good
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-24 00:04:33 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-24 00:04:33 +0000
commit8569eafc863900c15ba3df7da5b05ac8ec145ec5 (patch)
tree13b680d773e8197182be85917625d5e4c0fb1a3c /chrome/test/data/extensions/good
parent1669e4d96e503460e2888320c5dc6d3217234599 (diff)
downloadchromium_src-8569eafc863900c15ba3df7da5b05ac8ec145ec5.zip
chromium_src-8569eafc863900c15ba3df7da5b05ac8ec145ec5.tar.gz
chromium_src-8569eafc863900c15ba3df7da5b05ac8ec145ec5.tar.bz2
Another try at enabling the content script messaging test.
Also fixes some issues that that test exposes. My previous attempt (http://src.chromium.org/viewvc/chrome?view=rev&revision=21324) was reverted. TEST=no BUG=no Review URL: http://codereview.chromium.org/160048 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21483 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/data/extensions/good')
-rw-r--r--chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/background.html38
-rw-r--r--chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/manifest.json2
-rw-r--r--chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/page.js37
-rw-r--r--chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/toolstrip.html46
4 files changed, 71 insertions, 52 deletions
diff --git a/chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/background.html b/chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/background.html
deleted file mode 100644
index d68d4d6..0000000
--- a/chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/background.html
+++ /dev/null
@@ -1,38 +0,0 @@
-<script>
-chrome.extension.onConnect.addListener(function(port) {
- port.onMessage.addListener(function(msg) {
- if (msg.testPostMessageFromTab) {
- port.postMessage({success: true});
- }
- // Ignore other messages since they are from us.
- });
-});
-
-// Tests that postMessage to the tab and its response works.
-function testPostMessage() {
- var port = chrome.extension.connect();
- port.postMessage({testPostMessage: true});
- port.onMessage.addListener(function(msg) {
- window.domAutomationController.send(msg.success);
- port.disconnect();
- });
-}
-
-// Tests that we get the disconnect event when the tab disconnect.
-function testDisconnect() {
- var port = chrome.extension.connect();
- port.postMessage({testDisconnect: true});
- port.onDisconnect.addListener(function() {
- window.domAutomationController.send(true);
- });
-}
-
-// Tests that we get the disconnect event when the tab context closes.
-function testDisconnectOnClose() {
- var port = chrome.extension.connect();
- port.postMessage({testDisconnectOnClose: true});
- port.onDisconnect.addListener(function() {
- window.domAutomationController.send(true);
- });
-}
-</script>
diff --git a/chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/manifest.json b/chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/manifest.json
index b1a24a9..6cb06ff 100644
--- a/chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/manifest.json
+++ b/chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/manifest.json
@@ -2,7 +2,7 @@
"key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDRS2GUBOUAO5VZ2CMRId/eRR8/e9V42nUvY5XG+0sZ+JDHEjIQdq8qQy7HqdqEpCXKPMSPuMiC2t2HE9/hpL89SblNn3mwYPtSJGQdZvAzuv6SB0oA6jZ66V7+h/k0noGD3Tcu+Ko/vfkt5wCx2uHVK29k5JR/vGr0klaoVezGlwIDAQAB",
"version": "1.0",
"name": "My extension 3",
- "background_page": "background.html",
+ "toolstrips": ["toolstrip.html"],
"content_scripts": [
{
"matches": ["file://*"],
diff --git a/chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/page.js b/chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/page.js
index 7adb0c5..cee9476 100644
--- a/chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/page.js
+++ b/chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/page.js
@@ -3,20 +3,24 @@ if (typeof(contentWindow) != 'undefined') {
win = contentWindow;
}
-chrome.extension.onConnect.addListener(function(port) {
- console.log('connected');
- port.onMessage.addListener(function(msg) {
- console.log('got ' + msg);
- if (msg.testPostMessage) {
- port.postMessage({success: true});
- } else if (msg.testDisconnect) {
- port.disconnect();
- } else if (msg.testDisconnectOnClose) {
- win.location = "about:blank";
- }
- // Ignore other messages since they are from us.
+win.onload = function() {
+ // Do this in an onload handler because I'm not sure if chrome.extension
+ // is available before then.
+ chrome.extension.onConnect.addListener(function(port) {
+ console.log('connected');
+ port.onMessage.addListener(function(msg) {
+ console.log('got ' + msg);
+ if (msg.testPostMessage) {
+ port.postMessage({success: true});
+ } else if (msg.testDisconnect) {
+ port.disconnect();
+ } else if (msg.testDisconnectOnClose) {
+ win.location = "about:blank";
+ }
+ // Ignore other messages since they are from us.
+ });
});
-});
+}
// Tests that postMessage to the extension and its response works.
win.testPostMessageFromTab = function() {
@@ -29,3 +33,10 @@ win.testPostMessageFromTab = function() {
});
console.log('posted message');
}
+
+// Workaround two bugs: shutdown crash if we hook 'unload', and content script
+// GC if we don't register any event handlers.
+// http://code.google.com/p/chromium/issues/detail?id=17410
+// http://code.google.com/p/chromium/issues/detail?id=17582
+function foo() {}
+win.addEventListener('error', foo);
diff --git a/chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/toolstrip.html b/chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/toolstrip.html
new file mode 100644
index 0000000..aae7daa
--- /dev/null
+++ b/chrome/test/data/extensions/good/Extensions/bjafgdebaacbbbecmhlhpofkepfkgcpa/1.0/toolstrip.html
@@ -0,0 +1,46 @@
+<script>
+window.onload = function() {
+ chrome.extension.onConnect.addListener(function(port) {
+ port.onMessage.addListener(function(msg) {
+ if (msg.testPostMessageFromTab) {
+ port.postMessage({success: true});
+ }
+ // Ignore other messages since they are from us.
+ });
+ });
+};
+
+// Tests that postMessage to the tab and its response works.
+function testPostMessage() {
+ chrome.tabs.getSelected(null, function(tab) {
+ var port = chrome.tabs.connect(tab.id);
+ port.postMessage({testPostMessage: true});
+ port.onMessage.addListener(function(msg) {
+ window.domAutomationController.send(msg.success);
+ port.disconnect();
+ });
+ });
+}
+
+// Tests that we get the disconnect event when the tab disconnect.
+function testDisconnect() {
+ chrome.tabs.getSelected(null, function(tab) {
+ var port = chrome.tabs.connect(tab.id);
+ port.postMessage({testDisconnect: true});
+ port.onDisconnect.addListener(function() {
+ window.domAutomationController.send(true);
+ });
+ });
+}
+
+// Tests that we get the disconnect event when the tab context closes.
+function testDisconnectOnClose() {
+ chrome.tabs.getSelected(null, function(tab) {
+ var port = chrome.tabs.connect(tab.id);
+ port.postMessage({testDisconnectOnClose: true});
+ port.onDisconnect.addListener(function() {
+ window.domAutomationController.send(true);
+ });
+ });
+}
+</script>