Chromium Code Reviews| 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 : thread_bundle_(content::TestBrowserThreadBundle::REAL_DB_THREAD), |
| 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) { | 35 host_desktop_type_(chrome::HOST_DESKTOP_TYPE_NATIVE) { |
| 41 db_thread_.Start(); | 36 //TODO(ajwong): REal Db huh? |
|
jam
2013/07/11 16:28:44
is this temporary?
awong
2013/07/11 21:04:15
Oops. Removed the REAL_DB_THREAD. I think I cleane
| |
| 42 } | 37 } |
| 43 | 38 |
| 44 BrowserWithTestWindowTest::~BrowserWithTestWindowTest() { | 39 BrowserWithTestWindowTest::~BrowserWithTestWindowTest() { |
| 45 db_thread_.Stop(); | |
| 46 } | 40 } |
| 47 | 41 |
| 48 void BrowserWithTestWindowTest::SetHostDesktopType( | 42 void BrowserWithTestWindowTest::SetHostDesktopType( |
| 49 chrome::HostDesktopType host_desktop_type) { | 43 chrome::HostDesktopType host_desktop_type) { |
| 50 DCHECK(!window_); | 44 DCHECK(!window_); |
| 51 host_desktop_type_ = host_desktop_type; | 45 host_desktop_type_ = host_desktop_type; |
| 52 } | 46 } |
| 53 | 47 |
| 54 void BrowserWithTestWindowTest::SetUp() { | 48 void BrowserWithTestWindowTest::SetUp() { |
| 55 testing::Test::SetUp(); | 49 testing::Test::SetUp(); |
| 56 #if defined(OS_CHROMEOS) | 50 #if defined(OS_CHROMEOS) |
| 57 // TODO(jamescook): Windows Ash support. This will require refactoring | 51 // TODO(jamescook): Windows Ash support. This will require refactoring |
| 58 // AshTestHelper and AuraTestHelper so they can be used at the same time, | 52 // AshTestHelper and AuraTestHelper so they can be used at the same time, |
| 59 // perhaps by AshTestHelper owning an AuraTestHelper. | 53 // perhaps by AshTestHelper owning an AuraTestHelper. |
| 60 ash_test_helper_.reset(new ash::test::AshTestHelper(&ui_loop_)); | 54 ash_test_helper_.reset(new ash::test::AshTestHelper( |
| 55 base::MessageLoopForUI::current())); | |
| 61 ash_test_helper_->SetUp(); | 56 ash_test_helper_->SetUp(); |
| 62 #elif defined(USE_AURA) | 57 #elif defined(USE_AURA) |
| 63 aura_test_helper_.reset(new aura::test::AuraTestHelper(&ui_loop_)); | 58 aura_test_helper_.reset(new aura::test::AuraTestHelper( |
| 59 base::MessageLoopForUI::current())); | |
| 64 aura_test_helper_->SetUp(); | 60 aura_test_helper_->SetUp(); |
| 65 #endif // USE_AURA | 61 #endif // USE_AURA |
| 66 | 62 |
| 67 // Subclasses can provide their own Profile. | 63 // Subclasses can provide their own Profile. |
| 68 profile_.reset(CreateProfile()); | 64 profile_.reset(CreateProfile()); |
| 69 // Subclasses can provide their own test BrowserWindow. If they return NULL | 65 // Subclasses can provide their own test BrowserWindow. If they return NULL |
| 70 // then Browser will create the a production BrowserWindow and the subclass | 66 // then Browser will create the a production BrowserWindow and the subclass |
| 71 // is responsible for cleaning it up (usually by NativeWidget destruction). | 67 // is responsible for cleaning it up (usually by NativeWidget destruction). |
| 72 window_.reset(CreateBrowserWindow()); | 68 window_.reset(CreateBrowserWindow()); |
| 73 | 69 |
| 74 Browser::CreateParams params(profile(), host_desktop_type_); | 70 Browser::CreateParams params(profile(), host_desktop_type_); |
| 75 params.window = window_.get(); | 71 params.window = window_.get(); |
| 76 browser_.reset(new Browser(params)); | 72 browser_.reset(new Browser(params)); |
| 77 } | 73 } |
| 78 | 74 |
| 79 void BrowserWithTestWindowTest::TearDown() { | 75 void BrowserWithTestWindowTest::TearDown() { |
| 80 // Some tests end up posting tasks to the DB thread that must be completed | 76 // 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. | 77 // before the profile can be destroyed and the test safely shut down. |
| 82 base::WaitableEvent done(false, false); | 78 base::RunLoop().RunUntilIdle(); |
| 83 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, | |
| 84 base::Bind(&base::WaitableEvent::Signal, base::Unretained(&done))); | |
| 85 done.Wait(); | |
| 86 | 79 |
| 87 // Reset the profile here because some profile keyed services (like the | 80 // Reset the profile here because some profile keyed services (like the |
| 88 // audio service) depend on test stubs that the helpers below will remove. | 81 // audio service) depend on test stubs that the helpers below will remove. |
| 89 DestroyBrowserAndProfile(); | 82 DestroyBrowserAndProfile(); |
| 90 | 83 |
| 91 #if defined(OS_CHROMEOS) | 84 #if defined(OS_CHROMEOS) |
| 92 ash_test_helper_->TearDown(); | 85 ash_test_helper_->TearDown(); |
| 93 #elif defined(USE_AURA) | 86 #elif defined(USE_AURA) |
| 94 aura_test_helper_->TearDown(); | 87 aura_test_helper_->TearDown(); |
| 95 #endif | 88 #endif |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 profile_.reset(NULL); | 183 profile_.reset(NULL); |
| 191 } | 184 } |
| 192 | 185 |
| 193 TestingProfile* BrowserWithTestWindowTest::CreateProfile() { | 186 TestingProfile* BrowserWithTestWindowTest::CreateProfile() { |
| 194 return new TestingProfile(); | 187 return new TestingProfile(); |
| 195 } | 188 } |
| 196 | 189 |
| 197 BrowserWindow* BrowserWithTestWindowTest::CreateBrowserWindow() { | 190 BrowserWindow* BrowserWithTestWindowTest::CreateBrowserWindow() { |
| 198 return new TestBrowserWindow(); | 191 return new TestBrowserWindow(); |
| 199 } | 192 } |
| OLD | NEW |