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