| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/time/time.h" | 7 #include "base/time/time.h" |
| 8 #include "content/browser/devtools/devtools_manager.h" | 8 #include "content/browser/devtools/devtools_manager.h" |
| 9 #include "content/browser/devtools/embedded_worker_devtools_manager.h" | 9 #include "content/browser/devtools/embedded_worker_devtools_manager.h" |
| 10 #include "content/browser/devtools/render_view_devtools_agent_host.h" | 10 #include "content/browser/devtools/render_view_devtools_agent_host.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 } | 41 } |
| 42 | 42 |
| 43 void Close() { | 43 void Close() { |
| 44 EXPECT_FALSE(closed_); | 44 EXPECT_FALSE(closed_); |
| 45 close_counter++; | 45 close_counter++; |
| 46 agent_host_->DetachClient(); | 46 agent_host_->DetachClient(); |
| 47 closed_ = true; | 47 closed_ = true; |
| 48 } | 48 } |
| 49 | 49 |
| 50 virtual void AgentHostClosed( | 50 virtual void AgentHostClosed( |
| 51 DevToolsAgentHost* agent_host, bool replaced) OVERRIDE { | 51 DevToolsAgentHost* agent_host, bool replaced) override { |
| 52 FAIL(); | 52 FAIL(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 virtual void DispatchProtocolMessage( | 55 virtual void DispatchProtocolMessage( |
| 56 DevToolsAgentHost* agent_host, const std::string& message) OVERRIDE { | 56 DevToolsAgentHost* agent_host, const std::string& message) override { |
| 57 last_sent_message = &message; | 57 last_sent_message = &message; |
| 58 } | 58 } |
| 59 | 59 |
| 60 void InspectAgentHost(DevToolsAgentHost* agent_host) { | 60 void InspectAgentHost(DevToolsAgentHost* agent_host) { |
| 61 agent_host_ = agent_host; | 61 agent_host_ = agent_host; |
| 62 agent_host_->AttachClient(this); | 62 agent_host_->AttachClient(this); |
| 63 } | 63 } |
| 64 | 64 |
| 65 DevToolsAgentHost* agent_host() { return agent_host_.get(); } | 65 DevToolsAgentHost* agent_host() { return agent_host_.get(); } |
| 66 | 66 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 80 }; | 80 }; |
| 81 | 81 |
| 82 int TestDevToolsClientHost::close_counter = 0; | 82 int TestDevToolsClientHost::close_counter = 0; |
| 83 | 83 |
| 84 | 84 |
| 85 class TestWebContentsDelegate : public WebContentsDelegate { | 85 class TestWebContentsDelegate : public WebContentsDelegate { |
| 86 public: | 86 public: |
| 87 TestWebContentsDelegate() : renderer_unresponsive_received_(false) {} | 87 TestWebContentsDelegate() : renderer_unresponsive_received_(false) {} |
| 88 | 88 |
| 89 // Notification that the contents is hung. | 89 // Notification that the contents is hung. |
| 90 virtual void RendererUnresponsive(WebContents* source) OVERRIDE { | 90 virtual void RendererUnresponsive(WebContents* source) override { |
| 91 renderer_unresponsive_received_ = true; | 91 renderer_unresponsive_received_ = true; |
| 92 } | 92 } |
| 93 | 93 |
| 94 bool renderer_unresponsive_received() const { | 94 bool renderer_unresponsive_received() const { |
| 95 return renderer_unresponsive_received_; | 95 return renderer_unresponsive_received_; |
| 96 } | 96 } |
| 97 | 97 |
| 98 private: | 98 private: |
| 99 bool renderer_unresponsive_received_; | 99 bool renderer_unresponsive_received_; |
| 100 }; | 100 }; |
| 101 | 101 |
| 102 class TestTarget : public DevToolsTarget { | 102 class TestTarget : public DevToolsTarget { |
| 103 public: | 103 public: |
| 104 explicit TestTarget(scoped_refptr<DevToolsAgentHost> agent_host) | 104 explicit TestTarget(scoped_refptr<DevToolsAgentHost> agent_host) |
| 105 : agent_host_(agent_host) {} | 105 : agent_host_(agent_host) {} |
| 106 virtual ~TestTarget() {} | 106 virtual ~TestTarget() {} |
| 107 | 107 |
| 108 virtual std::string GetId() const OVERRIDE { return agent_host_->GetId(); } | 108 virtual std::string GetId() const override { return agent_host_->GetId(); } |
| 109 virtual std::string GetParentId() const OVERRIDE { return std::string(); } | 109 virtual std::string GetParentId() const override { return std::string(); } |
| 110 virtual std::string GetType() const OVERRIDE { return std::string(); } | 110 virtual std::string GetType() const override { return std::string(); } |
| 111 virtual std::string GetTitle() const OVERRIDE { | 111 virtual std::string GetTitle() const override { |
| 112 return agent_host_->GetTitle(); | 112 return agent_host_->GetTitle(); |
| 113 } | 113 } |
| 114 virtual std::string GetDescription() const OVERRIDE { return std::string(); } | 114 virtual std::string GetDescription() const override { return std::string(); } |
| 115 virtual GURL GetURL() const OVERRIDE { return agent_host_->GetURL(); } | 115 virtual GURL GetURL() const override { return agent_host_->GetURL(); } |
| 116 virtual GURL GetFaviconURL() const OVERRIDE { return GURL(); } | 116 virtual GURL GetFaviconURL() const override { return GURL(); } |
| 117 virtual base::TimeTicks GetLastActivityTime() const OVERRIDE { | 117 virtual base::TimeTicks GetLastActivityTime() const override { |
| 118 return base::TimeTicks(); | 118 return base::TimeTicks(); |
| 119 } | 119 } |
| 120 virtual bool IsAttached() const OVERRIDE { return agent_host_->IsAttached(); } | 120 virtual bool IsAttached() const override { return agent_host_->IsAttached(); } |
| 121 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const OVERRIDE { | 121 virtual scoped_refptr<DevToolsAgentHost> GetAgentHost() const override { |
| 122 return agent_host_; | 122 return agent_host_; |
| 123 } | 123 } |
| 124 virtual bool Activate() const OVERRIDE { return agent_host_->Activate(); } | 124 virtual bool Activate() const override { return agent_host_->Activate(); } |
| 125 virtual bool Close() const OVERRIDE { return agent_host_->Close(); } | 125 virtual bool Close() const override { return agent_host_->Close(); } |
| 126 | 126 |
| 127 private: | 127 private: |
| 128 scoped_refptr<DevToolsAgentHost> agent_host_; | 128 scoped_refptr<DevToolsAgentHost> agent_host_; |
| 129 }; | 129 }; |
| 130 | 130 |
| 131 class TestDevToolsManagerDelegate : public DevToolsManagerDelegate { | 131 class TestDevToolsManagerDelegate : public DevToolsManagerDelegate { |
| 132 public: | 132 public: |
| 133 virtual ~TestDevToolsManagerDelegate() {} | 133 virtual ~TestDevToolsManagerDelegate() {} |
| 134 | 134 |
| 135 virtual void Inspect(BrowserContext* browser_context, | 135 virtual void Inspect(BrowserContext* browser_context, |
| 136 DevToolsAgentHost* agent_host) OVERRIDE {} | 136 DevToolsAgentHost* agent_host) override {} |
| 137 | 137 |
| 138 virtual void DevToolsAgentStateChanged(DevToolsAgentHost* agent_host, | 138 virtual void DevToolsAgentStateChanged(DevToolsAgentHost* agent_host, |
| 139 bool attached) OVERRIDE {} | 139 bool attached) override {} |
| 140 | 140 |
| 141 virtual base::DictionaryValue* HandleCommand( | 141 virtual base::DictionaryValue* HandleCommand( |
| 142 DevToolsAgentHost* agent_host, | 142 DevToolsAgentHost* agent_host, |
| 143 base::DictionaryValue* command) OVERRIDE { return NULL; } | 143 base::DictionaryValue* command) override { return NULL; } |
| 144 | 144 |
| 145 virtual scoped_ptr<DevToolsTarget> CreateNewTarget(const GURL& url) OVERRIDE { | 145 virtual scoped_ptr<DevToolsTarget> CreateNewTarget(const GURL& url) override { |
| 146 return scoped_ptr<DevToolsTarget>(); | 146 return scoped_ptr<DevToolsTarget>(); |
| 147 } | 147 } |
| 148 | 148 |
| 149 virtual void EnumerateTargets(TargetCallback callback) OVERRIDE { | 149 virtual void EnumerateTargets(TargetCallback callback) override { |
| 150 TargetList result; | 150 TargetList result; |
| 151 DevToolsAgentHost::List agents = DevToolsAgentHost::GetOrCreateAll(); | 151 DevToolsAgentHost::List agents = DevToolsAgentHost::GetOrCreateAll(); |
| 152 for (DevToolsAgentHost::List::iterator it = agents.begin(); | 152 for (DevToolsAgentHost::List::iterator it = agents.begin(); |
| 153 it != agents.end(); ++it) { | 153 it != agents.end(); ++it) { |
| 154 if ((*it)->GetType() == DevToolsAgentHost::TYPE_WEB_CONTENTS) | 154 if ((*it)->GetType() == DevToolsAgentHost::TYPE_WEB_CONTENTS) |
| 155 result.insert(result.begin(), new TestTarget(*it)); | 155 result.insert(result.begin(), new TestTarget(*it)); |
| 156 else | 156 else |
| 157 result.push_back(new TestTarget(*it)); | 157 result.push_back(new TestTarget(*it)); |
| 158 } | 158 } |
| 159 callback.Run(result); | 159 callback.Run(result); |
| 160 } | 160 } |
| 161 | 161 |
| 162 virtual std::string GetPageThumbnailData(const GURL& url) OVERRIDE { | 162 virtual std::string GetPageThumbnailData(const GURL& url) override { |
| 163 return std::string(); | 163 return std::string(); |
| 164 } | 164 } |
| 165 }; | 165 }; |
| 166 | 166 |
| 167 class ContentBrowserClientWithDevTools : public TestContentBrowserClient { | 167 class ContentBrowserClientWithDevTools : public TestContentBrowserClient { |
| 168 public: | 168 public: |
| 169 virtual ~ContentBrowserClientWithDevTools() {} | 169 virtual ~ContentBrowserClientWithDevTools() {} |
| 170 virtual content::DevToolsManagerDelegate* | 170 virtual content::DevToolsManagerDelegate* |
| 171 GetDevToolsManagerDelegate() OVERRIDE { | 171 GetDevToolsManagerDelegate() override { |
| 172 return new TestDevToolsManagerDelegate(); | 172 return new TestDevToolsManagerDelegate(); |
| 173 } | 173 } |
| 174 }; | 174 }; |
| 175 | 175 |
| 176 class TestDevToolsManagerObserver : public DevToolsManager::Observer { | 176 class TestDevToolsManagerObserver : public DevToolsManager::Observer { |
| 177 public: | 177 public: |
| 178 TestDevToolsManagerObserver() | 178 TestDevToolsManagerObserver() |
| 179 : updates_count_(0) {} | 179 : updates_count_(0) {} |
| 180 virtual ~TestDevToolsManagerObserver() {} | 180 virtual ~TestDevToolsManagerObserver() {} |
| 181 | 181 |
| 182 int updates_count() { return updates_count_; } | 182 int updates_count() { return updates_count_; } |
| 183 const std::vector<scoped_refptr<DevToolsAgentHost>> hosts() { | 183 const std::vector<scoped_refptr<DevToolsAgentHost>> hosts() { |
| 184 return hosts_; | 184 return hosts_; |
| 185 } | 185 } |
| 186 | 186 |
| 187 virtual void TargetListChanged(const TargetList& targets) OVERRIDE { | 187 virtual void TargetListChanged(const TargetList& targets) override { |
| 188 updates_count_++; | 188 updates_count_++; |
| 189 hosts_.clear(); | 189 hosts_.clear(); |
| 190 for (TargetList::const_iterator it = targets.begin(); | 190 for (TargetList::const_iterator it = targets.begin(); |
| 191 it != targets.end(); ++it) { | 191 it != targets.end(); ++it) { |
| 192 hosts_.push_back((*it)->GetAgentHost()); | 192 hosts_.push_back((*it)->GetAgentHost()); |
| 193 } | 193 } |
| 194 } | 194 } |
| 195 | 195 |
| 196 private: | 196 private: |
| 197 int updates_count_; | 197 int updates_count_; |
| 198 std::vector<scoped_refptr<DevToolsAgentHost>> hosts_; | 198 std::vector<scoped_refptr<DevToolsAgentHost>> hosts_; |
| 199 }; | 199 }; |
| 200 | 200 |
| 201 } // namespace | 201 } // namespace |
| 202 | 202 |
| 203 class DevToolsManagerTest : public RenderViewHostImplTestHarness { | 203 class DevToolsManagerTest : public RenderViewHostImplTestHarness { |
| 204 public: | 204 public: |
| 205 DevToolsManagerTest() | 205 DevToolsManagerTest() |
| 206 : old_browser_client_(NULL) {} | 206 : old_browser_client_(NULL) {} |
| 207 | 207 |
| 208 protected: | 208 protected: |
| 209 virtual void SetUp() OVERRIDE { | 209 virtual void SetUp() override { |
| 210 RenderViewHostImplTestHarness::SetUp(); | 210 RenderViewHostImplTestHarness::SetUp(); |
| 211 TestDevToolsClientHost::ResetCounters(); | 211 TestDevToolsClientHost::ResetCounters(); |
| 212 old_browser_client_ = SetBrowserClientForTesting(&browser_client_); | 212 old_browser_client_ = SetBrowserClientForTesting(&browser_client_); |
| 213 } | 213 } |
| 214 | 214 |
| 215 virtual void TearDown() OVERRIDE { | 215 virtual void TearDown() override { |
| 216 SetBrowserClientForTesting(old_browser_client_); | 216 SetBrowserClientForTesting(old_browser_client_); |
| 217 RenderViewHostImplTestHarness::TearDown(); | 217 RenderViewHostImplTestHarness::TearDown(); |
| 218 } | 218 } |
| 219 | 219 |
| 220 ContentBrowserClientWithDevTools browser_client_; | 220 ContentBrowserClientWithDevTools browser_client_; |
| 221 ContentBrowserClient* old_browser_client_; | 221 ContentBrowserClient* old_browser_client_; |
| 222 }; | 222 }; |
| 223 | 223 |
| 224 TEST_F(DevToolsManagerTest, OpenAndManuallyCloseDevToolsClientHost) { | 224 TEST_F(DevToolsManagerTest, OpenAndManuallyCloseDevToolsClientHost) { |
| 225 scoped_refptr<DevToolsAgentHost> agent( | 225 scoped_refptr<DevToolsAgentHost> agent( |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 void recordEvent(const std::string& name) { | 312 void recordEvent(const std::string& name) { |
| 313 if (event_counter_.find(name) == event_counter_.end()) | 313 if (event_counter_.find(name) == event_counter_.end()) |
| 314 event_counter_[name] = 0; | 314 event_counter_[name] = 0; |
| 315 event_counter_[name] = event_counter_[name] + 1; | 315 event_counter_[name] = event_counter_[name] + 1; |
| 316 } | 316 } |
| 317 | 317 |
| 318 void expectEvent(int count, const std::string& name) { | 318 void expectEvent(int count, const std::string& name) { |
| 319 EXPECT_EQ(count, event_counter_[name]); | 319 EXPECT_EQ(count, event_counter_[name]); |
| 320 } | 320 } |
| 321 | 321 |
| 322 virtual void Attach(DevToolsExternalAgentProxy* proxy) OVERRIDE { | 322 virtual void Attach(DevToolsExternalAgentProxy* proxy) override { |
| 323 recordEvent("Attach"); | 323 recordEvent("Attach"); |
| 324 }; | 324 }; |
| 325 | 325 |
| 326 virtual void Detach() OVERRIDE { | 326 virtual void Detach() override { |
| 327 recordEvent("Detach"); | 327 recordEvent("Detach"); |
| 328 }; | 328 }; |
| 329 | 329 |
| 330 virtual void SendMessageToBackend(const std::string& message) OVERRIDE { | 330 virtual void SendMessageToBackend(const std::string& message) override { |
| 331 recordEvent(std::string("SendMessageToBackend.") + message); | 331 recordEvent(std::string("SendMessageToBackend.") + message); |
| 332 }; | 332 }; |
| 333 | 333 |
| 334 public : | 334 public : |
| 335 virtual ~TestExternalAgentDelegate() { | 335 virtual ~TestExternalAgentDelegate() { |
| 336 expectEvent(1, "Attach"); | 336 expectEvent(1, "Attach"); |
| 337 expectEvent(1, "Detach"); | 337 expectEvent(1, "Detach"); |
| 338 expectEvent(0, "SendMessageToBackend.message0"); | 338 expectEvent(0, "SendMessageToBackend.message0"); |
| 339 expectEvent(1, "SendMessageToBackend.message1"); | 339 expectEvent(1, "SendMessageToBackend.message1"); |
| 340 expectEvent(2, "SendMessageToBackend.message2"); | 340 expectEvent(2, "SendMessageToBackend.message2"); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 457 EXPECT_TRUE(scheduler.IsEmpty()); | 457 EXPECT_TRUE(scheduler.IsEmpty()); |
| 458 EXPECT_EQ(4, observer->updates_count()); | 458 EXPECT_EQ(4, observer->updates_count()); |
| 459 | 459 |
| 460 manager->RemoveObserver(observer.get()); | 460 manager->RemoveObserver(observer.get()); |
| 461 | 461 |
| 462 EXPECT_TRUE(scheduler.IsEmpty()); | 462 EXPECT_TRUE(scheduler.IsEmpty()); |
| 463 manager->SetSchedulerForTest(DevToolsManager::Scheduler()); | 463 manager->SetSchedulerForTest(DevToolsManager::Scheduler()); |
| 464 } | 464 } |
| 465 | 465 |
| 466 } // namespace content | 466 } // namespace content |
| OLD | NEW |