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

Side by Side Diff: content/browser/message_port_provider_browsertest.cc

Issue 2375133002: Move MessagePort implementation from android_webview to content (Closed)
Patch Set: rsesek nits and git cl format Created 4 years, 2 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 | « content/browser/message_port_provider.cc ('k') | content/common/BUILD.gn » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/macros.h" 6 #include "base/macros.h"
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "base/synchronization/waitable_event.h" 8 #include "base/synchronization/waitable_event.h"
9 #include "content/browser/message_port_service.h" 9 #include "content/browser/message_port_service.h"
10 #include "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 const std::vector<int> ports; 80 const std::vector<int> ports;
81 content::TitleWatcher title_watcher(shell()->web_contents(), message); 81 content::TitleWatcher title_watcher(shell()->web_contents(), message);
82 MessagePortProvider::PostMessageToFrame(shell()->web_contents(), 82 MessagePortProvider::PostMessageToFrame(shell()->web_contents(),
83 source_origin, 83 source_origin,
84 target_origin, 84 target_origin,
85 message, 85 message,
86 ports); 86 ports);
87 EXPECT_EQ(message, title_watcher.WaitAndGetTitle()); 87 EXPECT_EQ(message, title_watcher.WaitAndGetTitle());
88 } 88 }
89 89
90 namespace {
91
92 void VerifyCreateChannelOnIOThread(base::WaitableEvent* event) {
93
94 const base::char16 MESSAGE1[] = { 0x1000, 0 };
95 const base::char16 MESSAGE2[] = { 0x1001, 0 };
96
97 MockMessagePortDelegate delegate;
98 int port1;
99 int port2;
100
101 MessagePortProvider::CreateMessageChannel(&delegate, &port1, &port2);
102 MessagePortService* service = MessagePortService::GetInstance();
103 // Send a message to port1 transferring no ports.
104 std::vector<int> sent_ports;
105 service->PostMessage(port1, base::string16(MESSAGE1), sent_ports);
106 // Verify that message is received
107 const MockMessagePortDelegate::Messages& received =
108 delegate.getReceivedMessages();
109 EXPECT_EQ(received.size(), 1u);
110 // Verify that message sent to port1 is received by entangled port, which is
111 // port2.
112 EXPECT_EQ(received[0].route_id, port2);
113 EXPECT_EQ(received[0].data, MESSAGE1);
114 EXPECT_EQ(received[0].sent_ports.size(), 0u);
115
116 // Create a new channel, and transfer one of its ports to port2, making sure
117 // the transferred port is received.
118 int port3;
119 int port4;
120 MessagePortProvider::CreateMessageChannel(&delegate, &port3, &port4);
121 sent_ports.push_back(port3);
122 service->PostMessage(port1, base::string16(MESSAGE2), sent_ports);
123 EXPECT_EQ(received.size(), 2u);
124 EXPECT_EQ(received[1].route_id, port2);
125 EXPECT_EQ(received[1].data, MESSAGE2);
126 EXPECT_EQ(received[1].sent_ports.size(), 1u);
127 EXPECT_EQ(received[1].sent_ports[0], port3);
128
129 event->Signal();
130 }
131
132 } // namespace
133
134 // Verify that a message channel can be created and used for exchanging
135 // messages.
136 IN_PROC_BROWSER_TEST_F(MessagePortProviderBrowserTest, CreateChannel) {
137 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::MANUAL,
138 base::WaitableEvent::InitialState::NOT_SIGNALED);
139 BrowserThread::PostTask(
140 BrowserThread::IO, FROM_HERE,
141 base::Bind(&VerifyCreateChannelOnIOThread, &event));
142 event.Wait();
143 }
144
145 } // namespace content 90 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/message_port_provider.cc ('k') | content/common/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698