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

Side by Side Diff: chrome/browser/extensions/extension_messages_unittest.cc

Issue 179027: Make a bunch of backlogged breaking changes to the extensions (Closed)
Patch Set: Put chrome.self back Created 11 years, 3 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/common/extensions/docs/static/background_pages.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/extension_message_service.h" 5 #include "chrome/browser/extensions/extension_message_service.h"
6 #include "chrome/common/render_messages.h" 6 #include "chrome/common/render_messages.h"
7 #include "chrome/renderer/extensions/event_bindings.h" 7 #include "chrome/renderer/extensions/event_bindings.h"
8 #include "chrome/renderer/extensions/renderer_extension_bindings.h" 8 #include "chrome/renderer/extensions/renderer_extension_bindings.h"
9 #include "chrome/test/render_view_test.h" 9 #include "chrome/test/render_view_test.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 ViewHostMsg_RunJavaScriptMessage::SendParam alert_param; 81 ViewHostMsg_RunJavaScriptMessage::SendParam alert_param;
82 ASSERT_TRUE(IPC::ReadParam(alert_msg, &iter, &alert_param)); 82 ASSERT_TRUE(IPC::ReadParam(alert_msg, &iter, &alert_param));
83 EXPECT_EQ(L"content got: 42", alert_param.a); 83 EXPECT_EQ(L"content got: 42", alert_param.a);
84 } 84 }
85 85
86 // Tests that the bindings for handling a new channel connection and channel 86 // Tests that the bindings for handling a new channel connection and channel
87 // closing all works. 87 // closing all works.
88 TEST_F(RenderViewTest, ExtensionMessagesOnConnect) { 88 TEST_F(RenderViewTest, ExtensionMessagesOnConnect) {
89 LoadHTML("<body></body>"); 89 LoadHTML("<body></body>");
90 ExecuteJavaScript( 90 ExecuteJavaScript(
91 "chrome.self.onConnect.addListener(function (port) {" 91 "chrome.extension.onConnect.addListener(function (port) {"
92 " port.test = 24;" 92 " port.test = 24;"
93 " port.onMessage.addListener(doOnMessage);" 93 " port.onMessage.addListener(doOnMessage);"
94 " port.onDisconnect.addListener(doOnDisconnect);" 94 " port.onDisconnect.addListener(doOnDisconnect);"
95 " port.postMessage({message: 'onconnect from ' + port.tab.url + " 95 " port.postMessage({message: 'onconnect from ' + port.tab.url + "
96 " ' name ' + port.name});" 96 " ' name ' + port.name});"
97 "});" 97 "});"
98 "function doOnMessage(msg, port) {" 98 "function doOnMessage(msg, port) {"
99 " alert('got: ' + msg.val);" 99 " alert('got: ' + msg.val);"
100 "}" 100 "}"
101 "function doOnDisconnect(port) {" 101 "function doOnDisconnect(port) {"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 iter = IPC::SyncMessage::GetDataIterator(alert_msg); 146 iter = IPC::SyncMessage::GetDataIterator(alert_msg);
147 ASSERT_TRUE(IPC::ReadParam(alert_msg, &iter, &alert_param)); 147 ASSERT_TRUE(IPC::ReadParam(alert_msg, &iter, &alert_param));
148 EXPECT_EQ(L"disconnected: 24", alert_param.a); 148 EXPECT_EQ(L"disconnected: 24", alert_param.a);
149 } 149 }
150 150
151 // Tests that we don't send the disconnect message until all ports have 151 // Tests that we don't send the disconnect message until all ports have
152 // disconnected. 152 // disconnected.
153 TEST_F(RenderViewTest, ExtensionMessagesDisconnect) { 153 TEST_F(RenderViewTest, ExtensionMessagesDisconnect) {
154 LoadHTML("<body></body>"); 154 LoadHTML("<body></body>");
155 ExecuteJavaScript( 155 ExecuteJavaScript(
156 "chrome.self.onConnect.addListener(function (port) {" 156 "chrome.extension.onConnect.addListener(function (port) {"
157 " port.onMessage.addListener(function(msg, p) {" 157 " port.onMessage.addListener(function(msg, p) {"
158 " if (msg.disconnect) port.disconnect();" 158 " if (msg.disconnect) port.disconnect();"
159 " });" 159 " });"
160 "});" 160 "});"
161 "var iframe1 = document.createElement('iframe');" 161 "var iframe1 = document.createElement('iframe');"
162 "var iframe2 = document.createElement('iframe');" 162 "var iframe2 = document.createElement('iframe');"
163 "var src = 'javascript:" 163 "var src = 'javascript:"
164 " chrome.self.onConnect.addListener(function(port) {" 164 " chrome.extension.onConnect.addListener(function(port) {"
165 " port.postMessage(\"onconnect\");" 165 " port.postMessage(\"onconnect\");"
166 " port.onMessage.addListener(function(p) { alert(\"NOTREACHED\"); });" 166 " port.onMessage.addListener(function(p) { alert(\"NOTREACHED\"); });"
167 " port.disconnect();" 167 " port.disconnect();"
168 " });';" 168 " });';"
169 "iframe1.src = src;" 169 "iframe1.src = src;"
170 "iframe2.src = src;" 170 "iframe2.src = src;"
171 "document.body.appendChild(iframe1);" 171 "document.body.appendChild(iframe1);"
172 "document.body.appendChild(iframe2);"); 172 "document.body.appendChild(iframe2);");
173 173
174 render_thread_.sink().ClearMessages(); 174 render_thread_.sink().ClearMessages();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 // Disconnect the port in the top frame. 209 // Disconnect the port in the top frame.
210 render_thread_.sink().ClearMessages(); 210 render_thread_.sink().ClearMessages();
211 DispatchOnMessage("{\"disconnect\": true}", kPortId); 211 DispatchOnMessage("{\"disconnect\": true}", kPortId);
212 212
213 // Now we should have a disconnect message. 213 // Now we should have a disconnect message.
214 disconnect_msg = 214 disconnect_msg =
215 render_thread_.sink().GetUniqueMessageMatching( 215 render_thread_.sink().GetUniqueMessageMatching(
216 ViewHostMsg_ExtensionCloseChannel::ID); 216 ViewHostMsg_ExtensionCloseChannel::ID);
217 ASSERT_TRUE(disconnect_msg); 217 ASSERT_TRUE(disconnect_msg);
218 } 218 }
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/docs/static/background_pages.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698