OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/browser/devtools/devtools_manager.h" | 5 #include "content/browser/devtools/devtools_manager.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/guid.h" | 9 #include "base/guid.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 contents()->TestDidNavigate(contents()->GetMainFrame(), 1, pending_id, false, | 204 contents()->TestDidNavigate(contents()->GetMainFrame(), 1, pending_id, false, |
205 url, ui::PAGE_TRANSITION_TYPED); | 205 url, ui::PAGE_TRANSITION_TYPED); |
206 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); | 206 EXPECT_FALSE(contents()->CrossProcessNavigationPending()); |
207 EXPECT_EQ(client_host.agent_host(), | 207 EXPECT_EQ(client_host.agent_host(), |
208 DevToolsAgentHost::GetOrCreateFor(web_contents()).get()); | 208 DevToolsAgentHost::GetOrCreateFor(web_contents()).get()); |
209 client_host.Close(); | 209 client_host.Close(); |
210 } | 210 } |
211 | 211 |
212 class TestExternalAgentDelegate: public DevToolsExternalAgentProxyDelegate { | 212 class TestExternalAgentDelegate: public DevToolsExternalAgentProxyDelegate { |
213 public: | 213 public: |
214 TestExternalAgentDelegate() : id_(base::GenerateGUID()) { | 214 TestExternalAgentDelegate() { |
215 } | 215 } |
216 ~TestExternalAgentDelegate() override { | 216 ~TestExternalAgentDelegate() override { |
217 expectEvent(1, "Attach"); | 217 expectEvent(1, "Attach"); |
218 expectEvent(1, "Detach"); | 218 expectEvent(1, "Detach"); |
219 expectEvent(0, "SendMessageToBackend.message0"); | 219 expectEvent(0, "SendMessageToBackend.message0"); |
220 expectEvent(1, "SendMessageToBackend.message1"); | 220 expectEvent(1, "SendMessageToBackend.message1"); |
221 expectEvent(2, "SendMessageToBackend.message2"); | 221 expectEvent(2, "SendMessageToBackend.message2"); |
222 } | 222 } |
223 | 223 |
224 private: | 224 private: |
225 std::string id_; | |
226 std::map<std::string,int> event_counter_; | 225 std::map<std::string,int> event_counter_; |
227 | 226 |
228 void recordEvent(const std::string& name) { | 227 void recordEvent(const std::string& name) { |
229 if (event_counter_.find(name) == event_counter_.end()) | 228 if (event_counter_.find(name) == event_counter_.end()) |
230 event_counter_[name] = 0; | 229 event_counter_[name] = 0; |
231 event_counter_[name] = event_counter_[name] + 1; | 230 event_counter_[name] = event_counter_[name] + 1; |
232 } | 231 } |
233 | 232 |
234 void expectEvent(int count, const std::string& name) { | 233 void expectEvent(int count, const std::string& name) { |
235 EXPECT_EQ(count, event_counter_[name]); | 234 EXPECT_EQ(count, event_counter_[name]); |
236 } | 235 } |
237 | 236 |
238 void Attach(DevToolsExternalAgentProxy* proxy) override { | 237 void Attach(DevToolsExternalAgentProxy* proxy) override { |
239 recordEvent("Attach"); | 238 recordEvent("Attach"); |
240 }; | 239 }; |
241 | 240 |
242 void Detach() override { recordEvent("Detach"); }; | 241 void Detach() override { recordEvent("Detach"); }; |
243 | 242 |
244 std::string GetId() override { return id_; } | |
245 std::string GetType() override { return ""; } | 243 std::string GetType() override { return ""; } |
246 std::string GetTitle() override { return ""; } | 244 std::string GetTitle() override { return ""; } |
247 std::string GetDescription() override { return ""; } | 245 std::string GetDescription() override { return ""; } |
248 GURL GetURL() override { return GURL(); } | 246 GURL GetURL() override { return GURL(); } |
249 GURL GetFaviconURL() override { return GURL(); } | 247 GURL GetFaviconURL() override { return GURL(); } |
250 | 248 |
251 bool Activate() override { return false; }; | 249 bool Activate() override { return false; }; |
252 bool Inspect() override { return false; }; | 250 bool Inspect() override { return false; }; |
253 void Reload() override { }; | 251 void Reload() override { }; |
254 bool Close() override { return false; }; | 252 bool Close() override { return false; }; |
255 | 253 |
256 void SendMessageToBackend(const std::string& message) override { | 254 void SendMessageToBackend(const std::string& message) override { |
257 recordEvent(std::string("SendMessageToBackend.") + message); | 255 recordEvent(std::string("SendMessageToBackend.") + message); |
258 }; | 256 }; |
259 | 257 |
260 }; | 258 }; |
261 | 259 |
262 TEST_F(DevToolsManagerTest, TestExternalProxy) { | 260 TEST_F(DevToolsManagerTest, TestExternalProxy) { |
263 TestExternalAgentDelegate* delegate = new TestExternalAgentDelegate(); | 261 std::unique_ptr<TestExternalAgentDelegate> delegate( |
| 262 new TestExternalAgentDelegate()); |
264 | 263 |
265 scoped_refptr<DevToolsAgentHost> agent_host = | 264 scoped_refptr<DevToolsAgentHost> agent_host = |
266 DevToolsAgentHost::Create(delegate); | 265 DevToolsAgentHost::Forward(base::GenerateGUID(), std::move(delegate)); |
267 EXPECT_EQ(agent_host, DevToolsAgentHost::GetForId(agent_host->GetId())); | 266 EXPECT_EQ(agent_host, DevToolsAgentHost::GetForId(agent_host->GetId())); |
268 | 267 |
269 TestDevToolsClientHost client_host; | 268 TestDevToolsClientHost client_host; |
270 client_host.InspectAgentHost(agent_host.get()); | 269 client_host.InspectAgentHost(agent_host.get()); |
271 agent_host->DispatchProtocolMessage(&client_host, "message1"); | 270 agent_host->DispatchProtocolMessage(&client_host, "message1"); |
272 agent_host->DispatchProtocolMessage(&client_host, "message2"); | 271 agent_host->DispatchProtocolMessage(&client_host, "message2"); |
273 agent_host->DispatchProtocolMessage(&client_host, "message2"); | 272 agent_host->DispatchProtocolMessage(&client_host, "message2"); |
274 | 273 |
275 client_host.Close(); | 274 client_host.Close(); |
276 } | 275 } |
277 | 276 |
278 } // namespace content | 277 } // namespace content |
OLD | NEW |