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 "chrome/test/base/browser_with_test_window_test.h" | 5 #include "chrome/test/base/browser_with_test_window_test.h" |
6 | 6 |
7 #include "base/synchronization/waitable_event.h" | 7 #include "base/run_loop.h" |
8 #include "chrome/browser/profiles/profile_destroyer.h" | 8 #include "chrome/browser/profiles/profile_destroyer.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_navigator.h" | 10 #include "chrome/browser/ui/browser_navigator.h" |
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
12 #include "chrome/common/render_messages.h" | 12 #include "chrome/common/render_messages.h" |
13 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
14 #include "content/public/browser/navigation_controller.h" | 14 #include "content/public/browser/navigation_controller.h" |
15 #include "content/public/browser/navigation_entry.h" | 15 #include "content/public/browser/navigation_entry.h" |
16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
17 #include "content/public/common/page_transition_types.h" | 17 #include "content/public/common/page_transition_types.h" |
18 #include "content/public/test/test_renderer_host.h" | 18 #include "content/public/test/test_renderer_host.h" |
19 | 19 |
20 #if defined(USE_AURA) | 20 #if defined(USE_AURA) |
21 #include "ui/aura/test/aura_test_helper.h" | 21 #include "ui/aura/test/aura_test_helper.h" |
22 #endif | 22 #endif |
23 | 23 |
24 #if defined(USE_ASH) | 24 #if defined(USE_ASH) |
25 #include "ash/test/ash_test_helper.h" | 25 #include "ash/test/ash_test_helper.h" |
26 #endif | 26 #endif |
27 | 27 |
28 using content::BrowserThread; | |
29 using content::NavigationController; | 28 using content::NavigationController; |
30 using content::RenderViewHost; | 29 using content::RenderViewHost; |
31 using content::RenderViewHostTester; | 30 using content::RenderViewHostTester; |
32 using content::WebContents; | 31 using content::WebContents; |
33 | 32 |
34 BrowserWithTestWindowTest::BrowserWithTestWindowTest() | 33 BrowserWithTestWindowTest::BrowserWithTestWindowTest() |
35 : ui_thread_(BrowserThread::UI, message_loop()), | 34 : host_desktop_type_(chrome::HOST_DESKTOP_TYPE_NATIVE) { |
36 db_thread_(BrowserThread::DB), | |
37 file_thread_(BrowserThread::FILE, message_loop()), | |
38 file_user_blocking_thread_( | |
39 BrowserThread::FILE_USER_BLOCKING, message_loop()), | |
40 host_desktop_type_(chrome::HOST_DESKTOP_TYPE_NATIVE) { | |
41 db_thread_.Start(); | |
42 } | 35 } |
43 | 36 |
44 BrowserWithTestWindowTest::~BrowserWithTestWindowTest() { | 37 BrowserWithTestWindowTest::~BrowserWithTestWindowTest() { |
45 db_thread_.Stop(); | |
46 } | 38 } |
47 | 39 |
48 void BrowserWithTestWindowTest::SetHostDesktopType( | 40 void BrowserWithTestWindowTest::SetHostDesktopType( |
49 chrome::HostDesktopType host_desktop_type) { | 41 chrome::HostDesktopType host_desktop_type) { |
50 DCHECK(!window_); | 42 DCHECK(!window_); |
51 host_desktop_type_ = host_desktop_type; | 43 host_desktop_type_ = host_desktop_type; |
52 } | 44 } |
53 | 45 |
54 void BrowserWithTestWindowTest::SetUp() { | 46 void BrowserWithTestWindowTest::SetUp() { |
55 testing::Test::SetUp(); | 47 testing::Test::SetUp(); |
56 #if defined(OS_CHROMEOS) | 48 #if defined(OS_CHROMEOS) |
57 // TODO(jamescook): Windows Ash support. This will require refactoring | 49 // TODO(jamescook): Windows Ash support. This will require refactoring |
58 // AshTestHelper and AuraTestHelper so they can be used at the same time, | 50 // AshTestHelper and AuraTestHelper so they can be used at the same time, |
59 // perhaps by AshTestHelper owning an AuraTestHelper. | 51 // perhaps by AshTestHelper owning an AuraTestHelper. |
60 ash_test_helper_.reset(new ash::test::AshTestHelper(&ui_loop_)); | 52 ash_test_helper_.reset(new ash::test::AshTestHelper( |
| 53 base::MessageLoopForUI::current())); |
61 ash_test_helper_->SetUp(); | 54 ash_test_helper_->SetUp(); |
62 #elif defined(USE_AURA) | 55 #elif defined(USE_AURA) |
63 aura_test_helper_.reset(new aura::test::AuraTestHelper(&ui_loop_)); | 56 aura_test_helper_.reset(new aura::test::AuraTestHelper( |
| 57 base::MessageLoopForUI::current())); |
64 aura_test_helper_->SetUp(); | 58 aura_test_helper_->SetUp(); |
65 #endif // USE_AURA | 59 #endif // USE_AURA |
66 | 60 |
67 // Subclasses can provide their own Profile. | 61 // Subclasses can provide their own Profile. |
68 profile_.reset(CreateProfile()); | 62 profile_.reset(CreateProfile()); |
69 // Subclasses can provide their own test BrowserWindow. If they return NULL | 63 // Subclasses can provide their own test BrowserWindow. If they return NULL |
70 // then Browser will create the a production BrowserWindow and the subclass | 64 // then Browser will create the a production BrowserWindow and the subclass |
71 // is responsible for cleaning it up (usually by NativeWidget destruction). | 65 // is responsible for cleaning it up (usually by NativeWidget destruction). |
72 window_.reset(CreateBrowserWindow()); | 66 window_.reset(CreateBrowserWindow()); |
73 | 67 |
74 Browser::CreateParams params(profile(), host_desktop_type_); | 68 Browser::CreateParams params(profile(), host_desktop_type_); |
75 params.window = window_.get(); | 69 params.window = window_.get(); |
76 browser_.reset(new Browser(params)); | 70 browser_.reset(new Browser(params)); |
77 } | 71 } |
78 | 72 |
79 void BrowserWithTestWindowTest::TearDown() { | 73 void BrowserWithTestWindowTest::TearDown() { |
80 // Some tests end up posting tasks to the DB thread that must be completed | 74 // Some tests end up posting tasks to the DB thread that must be completed |
81 // before the profile can be destroyed and the test safely shut down. | 75 // before the profile can be destroyed and the test safely shut down. |
82 base::WaitableEvent done(false, false); | 76 base::RunLoop().RunUntilIdle(); |
83 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | |
84 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); | |
85 done.Wait(); | |
86 | 77 |
87 // Reset the profile here because some profile keyed services (like the | 78 // Reset the profile here because some profile keyed services (like the |
88 // audio service) depend on test stubs that the helpers below will remove. | 79 // audio service) depend on test stubs that the helpers below will remove. |
89 DestroyBrowserAndProfile(); | 80 DestroyBrowserAndProfile(); |
90 | 81 |
91 #if defined(OS_CHROMEOS) | 82 #if defined(OS_CHROMEOS) |
92 ash_test_helper_->TearDown(); | 83 ash_test_helper_->TearDown(); |
93 #elif defined(USE_AURA) | 84 #elif defined(USE_AURA) |
94 aura_test_helper_->TearDown(); | 85 aura_test_helper_->TearDown(); |
95 #endif | 86 #endif |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 profile_.reset(NULL); | 182 profile_.reset(NULL); |
192 } | 183 } |
193 | 184 |
194 TestingProfile* BrowserWithTestWindowTest::CreateProfile() { | 185 TestingProfile* BrowserWithTestWindowTest::CreateProfile() { |
195 return new TestingProfile(); | 186 return new TestingProfile(); |
196 } | 187 } |
197 | 188 |
198 BrowserWindow* BrowserWithTestWindowTest::CreateBrowserWindow() { | 189 BrowserWindow* BrowserWithTestWindowTest::CreateBrowserWindow() { |
199 return new TestBrowserWindow(); | 190 return new TestBrowserWindow(); |
200 } | 191 } |
OLD | NEW |