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