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

Side by Side Diff: chrome/browser/devtools/devtools_sanity_browsertest.cc

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again Created 7 years, 6 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 | Annotate | Revision Log
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/bind.h" 5 #include "base/bind.h"
6 #include "base/cancelable_callback.h" 6 #include "base/cancelable_callback.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/ref_counted.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 public: 63 public:
64 explicit BrowserClosedObserver(Browser* browser) { 64 explicit BrowserClosedObserver(Browser* browser) {
65 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSED, 65 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_CLOSED,
66 content::Source<Browser>(browser)); 66 content::Source<Browser>(browser));
67 content::RunMessageLoop(); 67 content::RunMessageLoop();
68 } 68 }
69 69
70 virtual void Observe(int type, 70 virtual void Observe(int type,
71 const content::NotificationSource& source, 71 const content::NotificationSource& source,
72 const content::NotificationDetails& details) OVERRIDE { 72 const content::NotificationDetails& details) OVERRIDE {
73 MessageLoopForUI::current()->Quit(); 73 base::MessageLoopForUI::current()->Quit();
74 } 74 }
75 75
76 private: 76 private:
77 content::NotificationRegistrar registrar_; 77 content::NotificationRegistrar registrar_;
78 DISALLOW_COPY_AND_ASSIGN(BrowserClosedObserver); 78 DISALLOW_COPY_AND_ASSIGN(BrowserClosedObserver);
79 }; 79 };
80 80
81 // The delay waited in some cases where we don't have a notifications for an 81 // The delay waited in some cases where we don't have a notifications for an
82 // action we take. 82 // action we take.
83 const int kActionDelayMs = 500; 83 const int kActionDelayMs = 500;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 if (browser) 164 if (browser)
165 BrowserClosedObserver close_observer(browser); 165 BrowserClosedObserver close_observer(browser);
166 } 166 }
167 167
168 DevToolsWindow* window_; 168 DevToolsWindow* window_;
169 RenderViewHost* inspected_rvh_; 169 RenderViewHost* inspected_rvh_;
170 }; 170 };
171 171
172 void TimeoutCallback(const std::string& timeout_message) { 172 void TimeoutCallback(const std::string& timeout_message) {
173 FAIL() << timeout_message; 173 FAIL() << timeout_message;
174 MessageLoop::current()->Quit(); 174 base::MessageLoop::current()->Quit();
175 } 175 }
176 176
177 // Base class for DevTools tests that test devtools functionality for 177 // Base class for DevTools tests that test devtools functionality for
178 // extensions and content scripts. 178 // extensions and content scripts.
179 class DevToolsExtensionTest : public DevToolsSanityTest, 179 class DevToolsExtensionTest : public DevToolsSanityTest,
180 public content::NotificationObserver { 180 public content::NotificationObserver {
181 public: 181 public:
182 DevToolsExtensionTest() : DevToolsSanityTest() { 182 DevToolsExtensionTest() : DevToolsSanityTest() {
183 PathService::Get(chrome::DIR_TEST_DATA, &test_extensions_dir_); 183 PathService::Get(chrome::DIR_TEST_DATA, &test_extensions_dir_);
184 test_extensions_dir_ = test_extensions_dir_.AppendASCII("devtools"); 184 test_extensions_dir_ = test_extensions_dir_.AppendASCII("devtools");
(...skipping 11 matching lines...) Expand all
196 bool LoadExtensionFromPath(const base::FilePath& path) { 196 bool LoadExtensionFromPath(const base::FilePath& path) {
197 ExtensionService* service = extensions::ExtensionSystem::Get( 197 ExtensionService* service = extensions::ExtensionSystem::Get(
198 browser()->profile())->extension_service(); 198 browser()->profile())->extension_service();
199 size_t num_before = service->extensions()->size(); 199 size_t num_before = service->extensions()->size();
200 { 200 {
201 content::NotificationRegistrar registrar; 201 content::NotificationRegistrar registrar;
202 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED, 202 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_LOADED,
203 content::NotificationService::AllSources()); 203 content::NotificationService::AllSources());
204 base::CancelableClosure timeout( 204 base::CancelableClosure timeout(
205 base::Bind(&TimeoutCallback, "Extension load timed out.")); 205 base::Bind(&TimeoutCallback, "Extension load timed out."));
206 MessageLoop::current()->PostDelayedTask( 206 base::MessageLoop::current()->PostDelayedTask(
207 FROM_HERE, timeout.callback(), base::TimeDelta::FromSeconds(4)); 207 FROM_HERE, timeout.callback(), base::TimeDelta::FromSeconds(4));
208 extensions::UnpackedInstaller::Create(service)->Load(path); 208 extensions::UnpackedInstaller::Create(service)->Load(path);
209 content::RunMessageLoop(); 209 content::RunMessageLoop();
210 timeout.Cancel(); 210 timeout.Cancel();
211 } 211 }
212 size_t num_after = service->extensions()->size(); 212 size_t num_after = service->extensions()->size();
213 if (num_after != (num_before + 1)) 213 if (num_after != (num_before + 1))
214 return false; 214 return false;
215 215
216 return WaitForExtensionViewsToLoad(); 216 return WaitForExtensionViewsToLoad();
217 } 217 }
218 218
219 bool WaitForExtensionViewsToLoad() { 219 bool WaitForExtensionViewsToLoad() {
220 // Wait for all the extension render views that exist to finish loading. 220 // Wait for all the extension render views that exist to finish loading.
221 // NOTE: This assumes that the extension views list is not changing while 221 // NOTE: This assumes that the extension views list is not changing while
222 // this method is running. 222 // this method is running.
223 223
224 content::NotificationRegistrar registrar; 224 content::NotificationRegistrar registrar;
225 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING, 225 registrar.Add(this, chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
226 content::NotificationService::AllSources()); 226 content::NotificationService::AllSources());
227 base::CancelableClosure timeout( 227 base::CancelableClosure timeout(
228 base::Bind(&TimeoutCallback, "Extension host load timed out.")); 228 base::Bind(&TimeoutCallback, "Extension host load timed out."));
229 MessageLoop::current()->PostDelayedTask( 229 base::MessageLoop::current()->PostDelayedTask(
230 FROM_HERE, timeout.callback(), base::TimeDelta::FromSeconds(4)); 230 FROM_HERE, timeout.callback(), base::TimeDelta::FromSeconds(4));
231 231
232 ExtensionProcessManager* manager = 232 ExtensionProcessManager* manager =
233 extensions::ExtensionSystem::Get(browser()->profile())-> 233 extensions::ExtensionSystem::Get(browser()->profile())->
234 process_manager(); 234 process_manager();
235 ExtensionProcessManager::ViewSet all_views = manager->GetAllViews(); 235 ExtensionProcessManager::ViewSet all_views = manager->GetAllViews();
236 for (ExtensionProcessManager::ViewSet::const_iterator iter = 236 for (ExtensionProcessManager::ViewSet::const_iterator iter =
237 all_views.begin(); 237 all_views.begin();
238 iter != all_views.end();) { 238 iter != all_views.end();) {
239 if (!(*iter)->IsLoading()) 239 if (!(*iter)->IsLoading())
240 ++iter; 240 ++iter;
241 else 241 else
242 content::RunMessageLoop(); 242 content::RunMessageLoop();
243 } 243 }
244 244
245 timeout.Cancel(); 245 timeout.Cancel();
246 return true; 246 return true;
247 } 247 }
248 248
249 virtual void Observe(int type, 249 virtual void Observe(int type,
250 const content::NotificationSource& source, 250 const content::NotificationSource& source,
251 const content::NotificationDetails& details) OVERRIDE { 251 const content::NotificationDetails& details) OVERRIDE {
252 switch (type) { 252 switch (type) {
253 case chrome::NOTIFICATION_EXTENSION_LOADED: 253 case chrome::NOTIFICATION_EXTENSION_LOADED:
254 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING: 254 case chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING:
255 MessageLoopForUI::current()->Quit(); 255 base::MessageLoopForUI::current()->Quit();
256 break; 256 break;
257 default: 257 default:
258 NOTREACHED(); 258 NOTREACHED();
259 break; 259 break;
260 } 260 }
261 } 261 }
262 262
263 base::FilePath test_extensions_dir_; 263 base::FilePath test_extensions_dir_;
264 }; 264 };
265 265
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 297
298 virtual void WorkerCreated ( 298 virtual void WorkerCreated (
299 const GURL& url, 299 const GURL& url,
300 const string16& name, 300 const string16& name,
301 int process_id, 301 int process_id,
302 int route_id) OVERRIDE { 302 int route_id) OVERRIDE {
303 worker_data_->worker_process_id = process_id; 303 worker_data_->worker_process_id = process_id;
304 worker_data_->worker_route_id = route_id; 304 worker_data_->worker_route_id = route_id;
305 WorkerService::GetInstance()->RemoveObserver(this); 305 WorkerService::GetInstance()->RemoveObserver(this);
306 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 306 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
307 MessageLoop::QuitClosure()); 307 base::MessageLoop::QuitClosure());
308 delete this; 308 delete this;
309 } 309 }
310 scoped_refptr<WorkerData> worker_data_; 310 scoped_refptr<WorkerData> worker_data_;
311 }; 311 };
312 312
313 class WorkerTerminationObserver : public WorkerServiceObserver { 313 class WorkerTerminationObserver : public WorkerServiceObserver {
314 public: 314 public:
315 explicit WorkerTerminationObserver(WorkerData* worker_data) 315 explicit WorkerTerminationObserver(WorkerData* worker_data)
316 : worker_data_(worker_data) { 316 : worker_data_(worker_data) {
317 } 317 }
318 318
319 private: 319 private:
320 virtual ~WorkerTerminationObserver() {} 320 virtual ~WorkerTerminationObserver() {}
321 321
322 virtual void WorkerDestroyed(int process_id, int route_id) OVERRIDE { 322 virtual void WorkerDestroyed(int process_id, int route_id) OVERRIDE {
323 ASSERT_EQ(worker_data_->worker_process_id, process_id); 323 ASSERT_EQ(worker_data_->worker_process_id, process_id);
324 ASSERT_EQ(worker_data_->worker_route_id, route_id); 324 ASSERT_EQ(worker_data_->worker_route_id, route_id);
325 WorkerService::GetInstance()->RemoveObserver(this); 325 WorkerService::GetInstance()->RemoveObserver(this);
326 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 326 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
327 MessageLoop::QuitClosure()); 327 base::MessageLoop::QuitClosure());
328 delete this; 328 delete this;
329 } 329 }
330 scoped_refptr<WorkerData> worker_data_; 330 scoped_refptr<WorkerData> worker_data_;
331 }; 331 };
332 332
333 void RunTest(const char* test_name, const char* test_page) { 333 void RunTest(const char* test_name, const char* test_page) {
334 ASSERT_TRUE(test_server()->Start()); 334 ASSERT_TRUE(test_server()->Start());
335 GURL url = test_server()->GetURL(test_page); 335 GURL url = test_server()->GetURL(test_page);
336 ui_test_utils::NavigateToURL(browser(), url); 336 ui_test_utils::NavigateToURL(browser(), url);
337 337
(...skipping 21 matching lines...) Expand all
359 } 359 }
360 360
361 static void WaitForFirstSharedWorkerOnIOThread( 361 static void WaitForFirstSharedWorkerOnIOThread(
362 scoped_refptr<WorkerData> worker_data) { 362 scoped_refptr<WorkerData> worker_data) {
363 std::vector<WorkerService::WorkerInfo> worker_info = 363 std::vector<WorkerService::WorkerInfo> worker_info =
364 WorkerService::GetInstance()->GetWorkers(); 364 WorkerService::GetInstance()->GetWorkers();
365 if (!worker_info.empty()) { 365 if (!worker_info.empty()) {
366 worker_data->worker_process_id = worker_info[0].process_id; 366 worker_data->worker_process_id = worker_info[0].process_id;
367 worker_data->worker_route_id = worker_info[0].route_id; 367 worker_data->worker_route_id = worker_info[0].route_id;
368 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 368 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
369 MessageLoop::QuitClosure()); 369 base::MessageLoop::QuitClosure());
370 return; 370 return;
371 } 371 }
372 372
373 WorkerService::GetInstance()->AddObserver( 373 WorkerService::GetInstance()->AddObserver(
374 new WorkerCreationObserver(worker_data.get())); 374 new WorkerCreationObserver(worker_data.get()));
375 } 375 }
376 376
377 static scoped_refptr<WorkerData> WaitForFirstSharedWorker() { 377 static scoped_refptr<WorkerData> WaitForFirstSharedWorker() {
378 scoped_refptr<WorkerData> worker_data(new WorkerData()); 378 scoped_refptr<WorkerData> worker_data(new WorkerData());
379 BrowserThread::PostTask( 379 BrowserThread::PostTask(
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); 642 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_);
643 test_data_dir_ = test_data_dir_.AppendASCII("devtools"); 643 test_data_dir_ = test_data_dir_.AppendASCII("devtools");
644 } 644 }
645 }; 645 };
646 646
647 IN_PROC_BROWSER_TEST_F(RemoteDebuggingTest, RemoteDebugger) { 647 IN_PROC_BROWSER_TEST_F(RemoteDebuggingTest, RemoteDebugger) {
648 ASSERT_TRUE(RunExtensionTest("target_list")) << message_; 648 ASSERT_TRUE(RunExtensionTest("target_list")) << message_;
649 } 649 }
650 650
651 } // namespace 651 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/devtools/devtools_adb_bridge.cc ('k') | chrome/browser/download/chrome_download_manager_delegate_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698