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/location.h" | 7 #include "base/location.h" |
| 8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 31 #include "chrome/browser/ui/views/chrome_constrained_window_views_client.h" | 31 #include "chrome/browser/ui/views/chrome_constrained_window_views_client.h" |
| 32 #include "components/constrained_window/constrained_window_views.h" | 32 #include "components/constrained_window/constrained_window_views.h" |
| 33 #endif | 33 #endif |
| 34 | 34 |
| 35 using content::NavigationController; | 35 using content::NavigationController; |
| 36 using content::RenderFrameHost; | 36 using content::RenderFrameHost; |
| 37 using content::RenderFrameHostTester; | 37 using content::RenderFrameHostTester; |
| 38 using content::WebContents; | 38 using content::WebContents; |
| 39 | 39 |
| 40 BrowserWithTestWindowTest::BrowserWithTestWindowTest() | 40 BrowserWithTestWindowTest::BrowserWithTestWindowTest() |
| 41 : browser_type_(Browser::TYPE_TABBED), | 41 : browser_type_(Browser::TYPE_TABBED), hosted_app_(false) {} |
|
sky
2016/02/16 02:59:04
nit: use delegating constructors.
scottmg
2016/02/17 05:33:33
Done.
| |
| 42 host_desktop_type_(chrome::HOST_DESKTOP_TYPE_NATIVE), | |
| 43 hosted_app_(false) { | |
| 44 } | |
| 45 | 42 |
| 46 BrowserWithTestWindowTest::BrowserWithTestWindowTest( | 43 BrowserWithTestWindowTest::BrowserWithTestWindowTest(Browser::Type browser_type, |
| 47 Browser::Type browser_type, | 44 bool hosted_app) |
| 48 chrome::HostDesktopType host_desktop_type, | 45 : browser_type_(browser_type), hosted_app_(hosted_app) {} |
| 49 bool hosted_app) | |
| 50 : browser_type_(browser_type), | |
| 51 host_desktop_type_(host_desktop_type), | |
| 52 hosted_app_(hosted_app) { | |
| 53 } | |
| 54 | 46 |
| 55 BrowserWithTestWindowTest::~BrowserWithTestWindowTest() { | 47 BrowserWithTestWindowTest::~BrowserWithTestWindowTest() { |
| 56 } | 48 } |
| 57 | 49 |
| 58 void BrowserWithTestWindowTest::SetUp() { | 50 void BrowserWithTestWindowTest::SetUp() { |
| 59 testing::Test::SetUp(); | 51 testing::Test::SetUp(); |
| 60 #if defined(OS_CHROMEOS) | 52 #if defined(OS_CHROMEOS) |
| 61 // TODO(jamescook): Windows Ash support. This will require refactoring | 53 // TODO(jamescook): Windows Ash support. This will require refactoring |
| 62 // AshTestHelper and AuraTestHelper so they can be used at the same time, | 54 // AshTestHelper and AuraTestHelper so they can be used at the same time, |
| 63 // perhaps by AshTestHelper owning an AuraTestHelper. | 55 // perhaps by AshTestHelper owning an AuraTestHelper. |
| 64 ash_test_helper_.reset(new ash::test::AshTestHelper( | 56 ash_test_helper_.reset(new ash::test::AshTestHelper( |
| 65 base::MessageLoopForUI::current())); | 57 base::MessageLoopForUI::current())); |
| 66 ash_test_helper_->SetUp(true); | 58 ash_test_helper_->SetUp(true); |
| 67 #elif defined(TOOLKIT_VIEWS) | 59 #elif defined(TOOLKIT_VIEWS) |
| 68 views_test_helper_.reset(new views::ScopedViewsTestHelper()); | 60 views_test_helper_.reset(new views::ScopedViewsTestHelper()); |
| 69 #endif | 61 #endif |
| 70 #if defined(TOOLKIT_VIEWS) | 62 #if defined(TOOLKIT_VIEWS) |
| 71 SetConstrainedWindowViewsClient(CreateChromeConstrainedWindowViewsClient()); | 63 SetConstrainedWindowViewsClient(CreateChromeConstrainedWindowViewsClient()); |
| 72 #endif | 64 #endif |
| 73 | 65 |
| 74 // Subclasses can provide their own Profile. | 66 // Subclasses can provide their own Profile. |
| 75 profile_ = CreateProfile(); | 67 profile_ = CreateProfile(); |
| 76 // Subclasses can provide their own test BrowserWindow. If they return NULL | 68 // Subclasses can provide their own test BrowserWindow. If they return NULL |
| 77 // then Browser will create the a production BrowserWindow and the subclass | 69 // then Browser will create the a production BrowserWindow and the subclass |
| 78 // is responsible for cleaning it up (usually by NativeWidget destruction). | 70 // is responsible for cleaning it up (usually by NativeWidget destruction). |
| 79 window_.reset(CreateBrowserWindow()); | 71 window_.reset(CreateBrowserWindow()); |
| 80 | 72 |
| 81 browser_.reset(CreateBrowser(profile(), browser_type_, hosted_app_, | 73 browser_.reset( |
| 82 host_desktop_type_, window_.get())); | 74 CreateBrowser(profile(), browser_type_, hosted_app_, window_.get())); |
| 83 } | 75 } |
| 84 | 76 |
| 85 void BrowserWithTestWindowTest::TearDown() { | 77 void BrowserWithTestWindowTest::TearDown() { |
| 86 // Some tests end up posting tasks to the DB thread that must be completed | 78 // Some tests end up posting tasks to the DB thread that must be completed |
| 87 // before the profile can be destroyed and the test safely shut down. | 79 // before the profile can be destroyed and the test safely shut down. |
| 88 base::RunLoop().RunUntilIdle(); | 80 base::RunLoop().RunUntilIdle(); |
| 89 | 81 |
| 90 // Reset the profile here because some profile keyed services (like the | 82 // Reset the profile here because some profile keyed services (like the |
| 91 // audio service) depend on test stubs that the helpers below will remove. | 83 // audio service) depend on test stubs that the helpers below will remove. |
| 92 DestroyBrowserAndProfile(); | 84 DestroyBrowserAndProfile(); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 223 } | 215 } |
| 224 | 216 |
| 225 BrowserWindow* BrowserWithTestWindowTest::CreateBrowserWindow() { | 217 BrowserWindow* BrowserWithTestWindowTest::CreateBrowserWindow() { |
| 226 return new TestBrowserWindow(); | 218 return new TestBrowserWindow(); |
| 227 } | 219 } |
| 228 | 220 |
| 229 Browser* BrowserWithTestWindowTest::CreateBrowser( | 221 Browser* BrowserWithTestWindowTest::CreateBrowser( |
| 230 Profile* profile, | 222 Profile* profile, |
| 231 Browser::Type browser_type, | 223 Browser::Type browser_type, |
| 232 bool hosted_app, | 224 bool hosted_app, |
| 233 chrome::HostDesktopType host_desktop_type, | |
| 234 BrowserWindow* browser_window) { | 225 BrowserWindow* browser_window) { |
| 235 Browser::CreateParams params(profile); | 226 Browser::CreateParams params(profile); |
| 236 if (hosted_app) { | 227 if (hosted_app) { |
| 237 params = Browser::CreateParams::CreateForApp( | 228 params = Browser::CreateParams::CreateForApp( |
| 238 "Test", true /* trusted_source */, gfx::Rect(), profile); | 229 "Test", true /* trusted_source */, gfx::Rect(), profile); |
| 239 } else { | 230 } else { |
| 240 params.type = browser_type; | 231 params.type = browser_type; |
| 241 } | 232 } |
| 242 params.window = browser_window; | 233 params.window = browser_window; |
| 243 return new Browser(params); | 234 return new Browser(params); |
| 244 } | 235 } |
| OLD | NEW |