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

Side by Side Diff: chrome/browser/debugger/devtools_sanity_unittest.cc

Issue 9150017: Add a Content API around BrowserChildProcessHost, similar to what was done with ChildProcessHost.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix?! Created 8 years, 11 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"
11 #include "base/stringprintf.h" 11 #include "base/stringprintf.h"
12 #include "base/test/test_timeouts.h" 12 #include "base/test/test_timeouts.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "chrome/browser/debugger/devtools_window.h" 14 #include "chrome/browser/debugger/devtools_window.h"
15 #include "chrome/browser/extensions/extension_host.h" 15 #include "chrome/browser/extensions/extension_host.h"
16 #include "chrome/browser/extensions/extension_service.h" 16 #include "chrome/browser/extensions/extension_service.h"
17 #include "chrome/browser/extensions/unpacked_installer.h" 17 #include "chrome/browser/extensions/unpacked_installer.h"
18 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 20 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
21 #include "chrome/common/chrome_notification_types.h" 21 #include "chrome/common/chrome_notification_types.h"
22 #include "chrome/common/chrome_paths.h" 22 #include "chrome/common/chrome_paths.h"
23 #include "chrome/common/chrome_switches.h" 23 #include "chrome/common/chrome_switches.h"
24 #include "chrome/test/base/in_process_browser_test.h" 24 #include "chrome/test/base/in_process_browser_test.h"
25 #include "chrome/test/base/ui_test_utils.h" 25 #include "chrome/test/base/ui_test_utils.h"
26 #include "content/browser/renderer_host/render_view_host.h" 26 #include "content/browser/renderer_host/render_view_host.h"
27 #include "content/browser/worker_host/worker_process_host.h" 27 #include "content/browser/worker_host/worker_process_host.h"
28 #include "content/public/browser/browser_child_process_host_iterator.h"
29 #include "content/public/browser/child_process_data.h"
28 #include "content/public/browser/content_browser_client.h" 30 #include "content/public/browser/content_browser_client.h"
29 #include "content/public/browser/devtools_agent_host_registry.h" 31 #include "content/public/browser/devtools_agent_host_registry.h"
30 #include "content/public/browser/devtools_client_host.h" 32 #include "content/public/browser/devtools_client_host.h"
31 #include "content/public/browser/devtools_manager.h" 33 #include "content/public/browser/devtools_manager.h"
32 #include "content/public/browser/notification_registrar.h" 34 #include "content/public/browser/notification_registrar.h"
33 #include "content/public/browser/notification_service.h" 35 #include "content/public/browser/notification_service.h"
34 #include "content/public/browser/render_view_host_delegate.h" 36 #include "content/public/browser/render_view_host_delegate.h"
35 #include "content/public/browser/web_contents.h" 37 #include "content/public/browser/web_contents.h"
36 #include "content/public/browser/worker_service.h" 38 #include "content/public/browser/worker_service.h"
37 #include "content/public/browser/worker_service_observer.h" 39 #include "content/public/browser/worker_service_observer.h"
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 explicit WorkerCreationObserver(WorkerData* worker_data) 287 explicit WorkerCreationObserver(WorkerData* worker_data)
286 : worker_data_(worker_data) { 288 : worker_data_(worker_data) {
287 } 289 }
288 290
289 private: 291 private:
290 virtual ~WorkerCreationObserver() {} 292 virtual ~WorkerCreationObserver() {}
291 293
292 virtual void WorkerCreated ( 294 virtual void WorkerCreated (
293 WorkerProcessHost* process, 295 WorkerProcessHost* process,
294 const WorkerProcessHost::WorkerInstance& instance) OVERRIDE { 296 const WorkerProcessHost::WorkerInstance& instance) OVERRIDE {
295 worker_data_->worker_process_id = process->data().id; 297 worker_data_->worker_process_id = process->GetData().id;
296 worker_data_->worker_route_id = instance.worker_route_id(); 298 worker_data_->worker_route_id = instance.worker_route_id();
297 WorkerService::GetInstance()->RemoveObserver(this); 299 WorkerService::GetInstance()->RemoveObserver(this);
298 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 300 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
299 MessageLoop::QuitClosure()); 301 MessageLoop::QuitClosure());
300 delete this; 302 delete this;
301 } 303 }
302 virtual void WorkerDestroyed( 304 virtual void WorkerDestroyed(
303 WorkerProcessHost*, 305 WorkerProcessHost*,
304 int worker_route_id) OVERRIDE {} 306 int worker_route_id) OVERRIDE {}
305 virtual void WorkerContextStarted( 307 virtual void WorkerContextStarted(
(...skipping 10 matching lines...) Expand all
316 318
317 private: 319 private:
318 virtual ~WorkerTerminationObserver() {} 320 virtual ~WorkerTerminationObserver() {}
319 321
320 virtual void WorkerCreated ( 322 virtual void WorkerCreated (
321 WorkerProcessHost* process, 323 WorkerProcessHost* process,
322 const WorkerProcessHost::WorkerInstance& instance) OVERRIDE {} 324 const WorkerProcessHost::WorkerInstance& instance) OVERRIDE {}
323 virtual void WorkerDestroyed( 325 virtual void WorkerDestroyed(
324 WorkerProcessHost* process, 326 WorkerProcessHost* process,
325 int worker_route_id) OVERRIDE { 327 int worker_route_id) OVERRIDE {
326 ASSERT_EQ(worker_data_->worker_process_id, process->data().id); 328 ASSERT_EQ(worker_data_->worker_process_id, process->GetData().id);
327 ASSERT_EQ(worker_data_->worker_route_id, worker_route_id); 329 ASSERT_EQ(worker_data_->worker_route_id, worker_route_id);
328 WorkerService::GetInstance()->RemoveObserver(this); 330 WorkerService::GetInstance()->RemoveObserver(this);
329 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 331 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
330 MessageLoop::QuitClosure()); 332 MessageLoop::QuitClosure());
331 delete this; 333 delete this;
332 } 334 }
333 virtual void WorkerContextStarted( 335 virtual void WorkerContextStarted(
334 WorkerProcessHost*, 336 WorkerProcessHost*,
335 int worker_route_id) OVERRIDE {} 337 int worker_route_id) OVERRIDE {}
336 scoped_refptr<WorkerData> worker_data_; 338 scoped_refptr<WorkerData> worker_data_;
337 }; 339 };
338 340
339 void RunTest(const char* test_name, const char* test_page) { 341 void RunTest(const char* test_name, const char* test_page) {
340 ASSERT_TRUE(test_server()->Start()); 342 ASSERT_TRUE(test_server()->Start());
341 GURL url = test_server()->GetURL(test_page); 343 GURL url = test_server()->GetURL(test_page);
342 ui_test_utils::NavigateToURL(browser(), url); 344 ui_test_utils::NavigateToURL(browser(), url);
343 345
344 scoped_refptr<WorkerData> worker_data = WaitForFirstSharedWorker(); 346 scoped_refptr<WorkerData> worker_data = WaitForFirstSharedWorker();
345 OpenDevToolsWindowForSharedWorker(worker_data.get()); 347 OpenDevToolsWindowForSharedWorker(worker_data.get());
346 RunTestFunction(window_, test_name); 348 RunTestFunction(window_, test_name);
347 CloseDevToolsWindow(); 349 CloseDevToolsWindow();
348 } 350 }
349 351
350 static void TerminateWorkerOnIOThread( 352 static void TerminateWorkerOnIOThread(
351 scoped_refptr<WorkerData> worker_data) { 353 scoped_refptr<WorkerData> worker_data) {
352 for (BrowserChildProcessHost::Iterator iter(content::PROCESS_TYPE_WORKER); 354 for (WorkerProcessHostIterator iter; !iter.Done(); ++iter) {
353 !iter.Done(); ++iter) { 355 if (iter.GetData().id == worker_data->worker_process_id) {
354 if (iter->data().id == worker_data->worker_process_id) { 356 iter->TerminateWorker(worker_data->worker_route_id);
355 WorkerProcessHost* host = static_cast<WorkerProcessHost*>(*iter);
356 host->TerminateWorker(worker_data->worker_route_id);
357 WorkerService::GetInstance()->AddObserver( 357 WorkerService::GetInstance()->AddObserver(
358 new WorkerTerminationObserver(worker_data)); 358 new WorkerTerminationObserver(worker_data));
359 return; 359 return;
360 } 360 }
361 } 361 }
362 FAIL() << "Failed to terminate worker.\n"; 362 FAIL() << "Failed to terminate worker.\n";
363 } 363 }
364 364
365 static void TerminateWorker(scoped_refptr<WorkerData> worker_data) { 365 static void TerminateWorker(scoped_refptr<WorkerData> worker_data) {
366 BrowserThread::PostTask( 366 BrowserThread::PostTask(
367 BrowserThread::IO, FROM_HERE, 367 BrowserThread::IO, FROM_HERE,
368 base::Bind(&TerminateWorkerOnIOThread, worker_data)); 368 base::Bind(&TerminateWorkerOnIOThread, worker_data));
369 ui_test_utils::RunMessageLoop(); 369 ui_test_utils::RunMessageLoop();
370 } 370 }
371 371
372 static void WaitForFirstSharedWorkerOnIOThread( 372 static void WaitForFirstSharedWorkerOnIOThread(
373 scoped_refptr<WorkerData> worker_data) { 373 scoped_refptr<WorkerData> worker_data) {
374 BrowserChildProcessHost::Iterator iter(content::PROCESS_TYPE_WORKER); 374 for (WorkerProcessHostIterator iter; !iter.Done(); ++iter) {
375 for (; !iter.Done(); ++iter) { 375 const WorkerProcessHost::Instances& instances = iter->instances();
376 WorkerProcessHost* worker = static_cast<WorkerProcessHost*>(*iter);
377 const WorkerProcessHost::Instances& instances = worker->instances();
378 for (WorkerProcessHost::Instances::const_iterator i = instances.begin(); 376 for (WorkerProcessHost::Instances::const_iterator i = instances.begin();
379 i != instances.end(); ++i) { 377 i != instances.end(); ++i) {
380 378
381 worker_data->worker_process_id = worker->data().id; 379 worker_data->worker_process_id = iter.GetData().id;
382 worker_data->worker_route_id = i->worker_route_id(); 380 worker_data->worker_route_id = i->worker_route_id();
383 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 381 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
384 MessageLoop::QuitClosure()); 382 MessageLoop::QuitClosure());
385 return; 383 return;
386 } 384 }
387 } 385 }
388 386
389 WorkerService::GetInstance()->AddObserver( 387 WorkerService::GetInstance()->AddObserver(
390 new WorkerCreationObserver(worker_data.get())); 388 new WorkerCreationObserver(worker_data.get()));
391 } 389 }
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 593
596 // Reload page to restart the worker. 594 // Reload page to restart the worker.
597 ui_test_utils::NavigateToURL(browser(), url); 595 ui_test_utils::NavigateToURL(browser(), url);
598 596
599 // Wait until worker script is paused on the debugger statement. 597 // Wait until worker script is paused on the debugger statement.
600 RunTestFunction(window_, "testPauseInSharedWorkerInitialization"); 598 RunTestFunction(window_, "testPauseInSharedWorkerInitialization");
601 CloseDevToolsWindow(); 599 CloseDevToolsWindow();
602 } 600 }
603 601
604 } // namespace 602 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/browser_process_impl.cc ('k') | chrome/browser/extensions/extension_tabs_module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698