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

Side by Side Diff: content/browser/devtools/devtools_manager_unittest.cc

Issue 1114503002: [DevTools] Cleanup DevToolsTarget and DevToolsManagerDelegate after moving to devtools_discovery. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@devtools-discovery-chrome
Patch Set: Created 5 years, 7 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
OLDNEW
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/shared_worker_devtools_manager.h" 9 #include "content/browser/devtools/shared_worker_devtools_manager.h"
10 #include "content/browser/shared_worker/shared_worker_instance.h" 10 #include "content/browser/shared_worker/shared_worker_instance.h"
11 #include "content/browser/shared_worker/worker_storage_partition.h" 11 #include "content/browser/shared_worker/worker_storage_partition.h"
12 #include "content/common/view_messages.h" 12 #include "content/common/view_messages.h"
13 #include "content/public/browser/browser_context.h" 13 #include "content/public/browser/browser_context.h"
14 #include "content/public/browser/content_browser_client.h" 14 #include "content/public/browser/content_browser_client.h"
15 #include "content/public/browser/devtools_agent_host.h" 15 #include "content/public/browser/devtools_agent_host.h"
16 #include "content/public/browser/devtools_external_agent_proxy.h" 16 #include "content/public/browser/devtools_external_agent_proxy.h"
17 #include "content/public/browser/devtools_external_agent_proxy_delegate.h" 17 #include "content/public/browser/devtools_external_agent_proxy_delegate.h"
18 #include "content/public/browser/devtools_target.h"
19 #include "content/public/browser/web_contents_delegate.h" 18 #include "content/public/browser/web_contents_delegate.h"
20 #include "content/public/test/test_utils.h" 19 #include "content/public/test/test_utils.h"
21 #include "content/test/test_content_browser_client.h" 20 #include "content/test/test_content_browser_client.h"
22 #include "content/test/test_render_view_host.h" 21 #include "content/test/test_render_view_host.h"
23 #include "content/test/test_web_contents.h" 22 #include "content/test/test_web_contents.h"
24 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
25 24
26 using base::TimeDelta; 25 using base::TimeDelta;
27 26
28 namespace content { 27 namespace content {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 87 }
89 88
90 bool renderer_unresponsive_received() const { 89 bool renderer_unresponsive_received() const {
91 return renderer_unresponsive_received_; 90 return renderer_unresponsive_received_;
92 } 91 }
93 92
94 private: 93 private:
95 bool renderer_unresponsive_received_; 94 bool renderer_unresponsive_received_;
96 }; 95 };
97 96
98 class TestTarget : public DevToolsTarget {
99 public:
100 explicit TestTarget(scoped_refptr<DevToolsAgentHost> agent_host)
101 : agent_host_(agent_host) {}
102 ~TestTarget() override {}
103
104 std::string GetId() const override { return agent_host_->GetId(); }
105 std::string GetParentId() const override { return std::string(); }
106 std::string GetType() const override { return std::string(); }
107 std::string GetTitle() const override { return agent_host_->GetTitle(); }
108 std::string GetDescription() const override { return std::string(); }
109 GURL GetURL() const override { return agent_host_->GetURL(); }
110 GURL GetFaviconURL() const override { return GURL(); }
111 base::TimeTicks GetLastActivityTime() const override {
112 return base::TimeTicks();
113 }
114 bool IsAttached() const override { return agent_host_->IsAttached(); }
115 scoped_refptr<DevToolsAgentHost> GetAgentHost() const override {
116 return agent_host_;
117 }
118 bool Activate() const override { return agent_host_->Activate(); }
119 bool Close() const override { return agent_host_->Close(); }
120
121 private:
122 scoped_refptr<DevToolsAgentHost> agent_host_;
123 };
124
125 class TestDevToolsManagerDelegate : public DevToolsManagerDelegate {
126 public:
127 ~TestDevToolsManagerDelegate() override {}
128
129 void Inspect(BrowserContext* browser_context,
130 DevToolsAgentHost* agent_host) override {}
131
132 void DevToolsAgentStateChanged(DevToolsAgentHost* agent_host,
133 bool attached) override {}
134
135 base::DictionaryValue* HandleCommand(
136 DevToolsAgentHost* agent_host,
137 base::DictionaryValue* command) override {
138 return NULL;
139 }
140
141 scoped_ptr<DevToolsTarget> CreateNewTarget(const GURL& url) override {
142 return scoped_ptr<DevToolsTarget>();
143 }
144
145 void EnumerateTargets(TargetCallback callback) override {
146 TargetList result;
147 DevToolsAgentHost::List agents = DevToolsAgentHost::GetOrCreateAll();
148 for (DevToolsAgentHost::List::iterator it = agents.begin();
149 it != agents.end(); ++it) {
150 if ((*it)->GetType() == DevToolsAgentHost::TYPE_WEB_CONTENTS)
151 result.insert(result.begin(), new TestTarget(*it));
152 else
153 result.push_back(new TestTarget(*it));
154 }
155 callback.Run(result);
156 }
157
158 std::string GetPageThumbnailData(const GURL& url) override {
159 return std::string();
160 }
161 };
162
163 class ContentBrowserClientWithDevTools : public TestContentBrowserClient {
164 public:
165 ~ContentBrowserClientWithDevTools() override {}
166 content::DevToolsManagerDelegate* GetDevToolsManagerDelegate() override {
167 return new TestDevToolsManagerDelegate();
168 }
169 };
170
171 } // namespace 97 } // namespace
172 98
173 class DevToolsManagerTest : public RenderViewHostImplTestHarness { 99 class DevToolsManagerTest : public RenderViewHostImplTestHarness {
174 public: 100 public:
175 DevToolsManagerTest() 101 DevToolsManagerTest() {}
176 : old_browser_client_(NULL) {}
177 102
178 protected: 103 protected:
179 void SetUp() override { 104 void SetUp() override {
180 RenderViewHostImplTestHarness::SetUp(); 105 RenderViewHostImplTestHarness::SetUp();
181 TestDevToolsClientHost::ResetCounters(); 106 TestDevToolsClientHost::ResetCounters();
182 old_browser_client_ = SetBrowserClientForTesting(&browser_client_);
183 } 107 }
184
185 void TearDown() override {
186 SetBrowserClientForTesting(old_browser_client_);
187 RenderViewHostImplTestHarness::TearDown();
188 }
189
190 ContentBrowserClientWithDevTools browser_client_;
191 ContentBrowserClient* old_browser_client_;
192 }; 108 };
193 109
194 TEST_F(DevToolsManagerTest, OpenAndManuallyCloseDevToolsClientHost) { 110 TEST_F(DevToolsManagerTest, OpenAndManuallyCloseDevToolsClientHost) {
195 scoped_refptr<DevToolsAgentHost> agent( 111 scoped_refptr<DevToolsAgentHost> agent(
196 DevToolsAgentHost::GetOrCreateFor(web_contents())); 112 DevToolsAgentHost::GetOrCreateFor(web_contents()));
197 EXPECT_FALSE(agent->IsAttached()); 113 EXPECT_FALSE(agent->IsAttached());
198 114
199 TestDevToolsClientHost client_host; 115 TestDevToolsClientHost client_host;
200 client_host.InspectAgentHost(agent.get()); 116 client_host.InspectAgentHost(agent.get());
201 // Test that the connection is established. 117 // Test that the connection is established.
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 TestDevToolsClientHost client_host; 242 TestDevToolsClientHost client_host;
327 client_host.InspectAgentHost(agent_host.get()); 243 client_host.InspectAgentHost(agent_host.get());
328 agent_host->DispatchProtocolMessage("message1"); 244 agent_host->DispatchProtocolMessage("message1");
329 agent_host->DispatchProtocolMessage("message2"); 245 agent_host->DispatchProtocolMessage("message2");
330 agent_host->DispatchProtocolMessage("message2"); 246 agent_host->DispatchProtocolMessage("message2");
331 247
332 client_host.Close(); 248 client_host.Close();
333 } 249 }
334 250
335 } // namespace content 251 } // namespace content
OLDNEW
« no previous file with comments | « components/devtools_http_handler/devtools_http_handler_unittest.cc ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698