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

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

Issue 152003: Fix some issues with extension messaging: (Closed)
Patch Set: Created 11 years, 5 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
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 16 matching lines...) Expand all
27 static void DispatchOnMessage(const std::string& message, int source_port_id) { 27 static void DispatchOnMessage(const std::string& message, int source_port_id) {
28 ListValue args; 28 ListValue args;
29 args.Set(0, Value::CreateStringValue(message)); 29 args.Set(0, Value::CreateStringValue(message));
30 args.Set(1, Value::CreateIntegerValue(source_port_id)); 30 args.Set(1, Value::CreateIntegerValue(source_port_id));
31 RendererExtensionBindings::Invoke( 31 RendererExtensionBindings::Invoke(
32 ExtensionMessageService::kDispatchOnMessage, args); 32 ExtensionMessageService::kDispatchOnMessage, args);
33 } 33 }
34 34
35 // Tests that the bindings for opening a channel to an extension and sending 35 // Tests that the bindings for opening a channel to an extension and sending
36 // and receiving messages through that channel all works. 36 // and receiving messages through that channel all works.
37 TEST_F(RenderViewTest, DISABLED_ExtensionMessagesOpenChannel) { 37 TEST_F(RenderViewTest, ExtensionMessagesOpenChannel) {
38 render_thread_.sink().ClearMessages(); 38 render_thread_.sink().ClearMessages();
39 LoadHTML("<body></body>"); 39 LoadHTML("<body></body>");
40 ExecuteJavaScript( 40 ExecuteJavaScript(
41 "var e = new chrome.Extension('foobar');" 41 "var e = new chrome.Extension('foobar');"
42 "var port = e.connect();" 42 "var port = e.connect();"
43 "port.onMessage.addListener(doOnMessage);" 43 "port.onMessage.addListener(doOnMessage);"
44 "port.postMessage({message: 'content ready'});" 44 "port.postMessage({message: 'content ready'});"
45 "function doOnMessage(msg, port) {" 45 "function doOnMessage(msg, port) {"
46 " alert('content got: ' + msg.val);" 46 " alert('content got: ' + msg.val);"
47 "}"); 47 "}");
(...skipping 23 matching lines...) Expand all
71 ViewHostMsg_RunJavaScriptMessage::ID); 71 ViewHostMsg_RunJavaScriptMessage::ID);
72 ASSERT_TRUE(alert_msg); 72 ASSERT_TRUE(alert_msg);
73 void* iter = IPC::SyncMessage::GetDataIterator(alert_msg); 73 void* iter = IPC::SyncMessage::GetDataIterator(alert_msg);
74 ViewHostMsg_RunJavaScriptMessage::SendParam alert_param; 74 ViewHostMsg_RunJavaScriptMessage::SendParam alert_param;
75 ASSERT_TRUE(IPC::ReadParam(alert_msg, &iter, &alert_param)); 75 ASSERT_TRUE(IPC::ReadParam(alert_msg, &iter, &alert_param));
76 EXPECT_EQ(L"content got: 42", alert_param.a); 76 EXPECT_EQ(L"content got: 42", alert_param.a);
77 } 77 }
78 78
79 // Tests that the bindings for handling a new channel connection and channel 79 // Tests that the bindings for handling a new channel connection and channel
80 // closing all works. 80 // closing all works.
81 TEST_F(RenderViewTest, DISABLED_ExtensionMessagesOnConnect) { 81 TEST_F(RenderViewTest, ExtensionMessagesOnConnect) {
82 LoadHTML("<body></body>"); 82 LoadHTML("<body></body>");
83 ExecuteJavaScript( 83 ExecuteJavaScript(
84 "chrome.self.onConnect.addListener(function (port) {" 84 "chrome.self.onConnect.addListener(function (port) {"
85 " port.test = 24;" 85 " port.test = 24;"
86 " port.onMessage.addListener(doOnMessage);" 86 " port.onMessage.addListener(doOnMessage);"
87 " port.onDisconnect.addListener(doOnDisconnect);" 87 " port.onDisconnect.addListener(doOnDisconnect);"
88 " port.postMessage({message: 'onconnect from ' + port.tab.url});" 88 " port.postMessage({message: 'onconnect from ' + port.tab.url});"
89 "});" 89 "});"
90 "function doOnMessage(msg, port) {" 90 "function doOnMessage(msg, port) {"
91 " alert('got: ' + msg.val);" 91 " alert('got: ' + msg.val);"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 129
130 // Verify that we got it. 130 // Verify that we got it.
131 alert_msg = 131 alert_msg =
132 render_thread_.sink().GetUniqueMessageMatching( 132 render_thread_.sink().GetUniqueMessageMatching(
133 ViewHostMsg_RunJavaScriptMessage::ID); 133 ViewHostMsg_RunJavaScriptMessage::ID);
134 ASSERT_TRUE(alert_msg); 134 ASSERT_TRUE(alert_msg);
135 iter = IPC::SyncMessage::GetDataIterator(alert_msg); 135 iter = IPC::SyncMessage::GetDataIterator(alert_msg);
136 ASSERT_TRUE(IPC::ReadParam(alert_msg, &iter, &alert_param)); 136 ASSERT_TRUE(IPC::ReadParam(alert_msg, &iter, &alert_param));
137 EXPECT_EQ(L"disconnected: 24", alert_param.a); 137 EXPECT_EQ(L"disconnected: 24", alert_param.a);
138 } 138 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_message_service.cc ('k') | chrome/renderer/extensions/event_bindings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698