| 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" |
| 11 #include "chrome/browser/profiles/profile_destroyer.h" | 11 #include "chrome/browser/profiles/profile_destroyer.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/browser_navigator.h" | 13 #include "chrome/browser/ui/browser_navigator.h" |
| 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 14 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 15 #include "chrome/common/render_messages.h" | 15 #include "chrome/common/render_messages.h" |
| 16 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
| 17 #include "content/public/browser/navigation_controller.h" | 17 #include "content/public/browser/navigation_controller.h" |
| 18 #include "content/public/browser/navigation_entry.h" | 18 #include "content/public/browser/navigation_entry.h" |
| 19 #include "content/public/browser/web_contents.h" | 19 #include "content/public/browser/web_contents.h" |
| 20 #include "content/public/test/test_renderer_host.h" | 20 #include "content/public/test/test_renderer_host.h" |
| 21 #include "ui/base/page_transition_types.h" | 21 #include "ui/base/page_transition_types.h" |
| 22 | 22 |
| 23 #if defined(USE_AURA) | 23 #if defined(OS_CHROMEOS) |
| 24 #include "ui/aura/test/aura_test_helper.h" | |
| 25 #include "ui/compositor/compositor.h" | |
| 26 #include "ui/compositor/test/context_factories_for_test.h" | |
| 27 #include "ui/wm/core/default_activation_client.h" | |
| 28 #endif | |
| 29 | |
| 30 #if defined(USE_ASH) | |
| 31 #include "ash/test/ash_test_helper.h" | 24 #include "ash/test/ash_test_helper.h" |
| 32 #include "ash/test/ash_test_views_delegate.h" | 25 #elif defined(TOOLKIT_VIEWS) |
| 26 #include "ui/views/test/scoped_views_test_helper.h" |
| 33 #endif | 27 #endif |
| 34 | 28 |
| 35 #if defined(TOOLKIT_VIEWS) | 29 #if defined(TOOLKIT_VIEWS) |
| 36 #include "chrome/browser/ui/views/chrome_constrained_window_views_client.h" | 30 #include "chrome/browser/ui/views/chrome_constrained_window_views_client.h" |
| 37 #include "components/constrained_window/constrained_window_views.h" | 31 #include "components/constrained_window/constrained_window_views.h" |
| 38 #include "ui/views/test/test_views_delegate.h" | |
| 39 #endif | 32 #endif |
| 40 | 33 |
| 41 using content::NavigationController; | 34 using content::NavigationController; |
| 42 using content::RenderFrameHost; | 35 using content::RenderFrameHost; |
| 43 using content::RenderFrameHostTester; | 36 using content::RenderFrameHostTester; |
| 44 using content::WebContents; | 37 using content::WebContents; |
| 45 | 38 |
| 46 BrowserWithTestWindowTest::BrowserWithTestWindowTest() | 39 BrowserWithTestWindowTest::BrowserWithTestWindowTest() |
| 47 : browser_type_(Browser::TYPE_TABBED), | 40 : browser_type_(Browser::TYPE_TABBED), |
| 48 host_desktop_type_(chrome::HOST_DESKTOP_TYPE_NATIVE), | 41 host_desktop_type_(chrome::HOST_DESKTOP_TYPE_NATIVE), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 59 } | 52 } |
| 60 | 53 |
| 61 BrowserWithTestWindowTest::~BrowserWithTestWindowTest() { | 54 BrowserWithTestWindowTest::~BrowserWithTestWindowTest() { |
| 62 } | 55 } |
| 63 | 56 |
| 64 void BrowserWithTestWindowTest::SetUp() { | 57 void BrowserWithTestWindowTest::SetUp() { |
| 65 testing::Test::SetUp(); | 58 testing::Test::SetUp(); |
| 66 #if defined(OS_CHROMEOS) | 59 #if defined(OS_CHROMEOS) |
| 67 // TODO(jamescook): Windows Ash support. This will require refactoring | 60 // TODO(jamescook): Windows Ash support. This will require refactoring |
| 68 // AshTestHelper and AuraTestHelper so they can be used at the same time, | 61 // AshTestHelper and AuraTestHelper so they can be used at the same time, |
| 69 // perhaps by AshTestHelper owning an AuraTestHelper. Also, need to cleanup | 62 // perhaps by AshTestHelper owning an AuraTestHelper. |
| 70 // CreateViewsDelegate() below when cleanup done. | |
| 71 ash_test_helper_.reset(new ash::test::AshTestHelper( | 63 ash_test_helper_.reset(new ash::test::AshTestHelper( |
| 72 base::MessageLoopForUI::current())); | 64 base::MessageLoopForUI::current())); |
| 73 ash_test_helper_->SetUp(true); | 65 ash_test_helper_->SetUp(true); |
| 74 #elif defined(USE_AURA) | 66 #elif defined(TOOLKIT_VIEWS) |
| 75 // The ContextFactory must exist before any Compositors are created. | 67 views_test_helper_.reset(new views::ScopedViewsTestHelper()); |
| 76 bool enable_pixel_output = false; | 68 #endif |
| 77 ui::ContextFactory* context_factory = | |
| 78 ui::InitializeContextFactoryForTests(enable_pixel_output); | |
| 79 | |
| 80 aura_test_helper_.reset(new aura::test::AuraTestHelper( | |
| 81 base::MessageLoopForUI::current())); | |
| 82 aura_test_helper_->SetUp(context_factory); | |
| 83 new wm::DefaultActivationClient(aura_test_helper_->root_window()); | |
| 84 #endif // USE_AURA | |
| 85 | |
| 86 #if defined(TOOLKIT_VIEWS) | 69 #if defined(TOOLKIT_VIEWS) |
| 87 #if !defined(OS_CHROMEOS) | |
| 88 views_delegate_.reset(CreateViewsDelegate()); | |
| 89 #endif // !OS_CHROMEOS | |
| 90 SetConstrainedWindowViewsClient(CreateChromeConstrainedWindowViewsClient()); | 70 SetConstrainedWindowViewsClient(CreateChromeConstrainedWindowViewsClient()); |
| 91 #endif // TOOLKIT_VIEWS | 71 #endif |
| 92 | 72 |
| 93 // Subclasses can provide their own Profile. | 73 // Subclasses can provide their own Profile. |
| 94 profile_ = CreateProfile(); | 74 profile_ = CreateProfile(); |
| 95 // Subclasses can provide their own test BrowserWindow. If they return NULL | 75 // Subclasses can provide their own test BrowserWindow. If they return NULL |
| 96 // then Browser will create the a production BrowserWindow and the subclass | 76 // then Browser will create the a production BrowserWindow and the subclass |
| 97 // is responsible for cleaning it up (usually by NativeWidget destruction). | 77 // is responsible for cleaning it up (usually by NativeWidget destruction). |
| 98 window_.reset(CreateBrowserWindow()); | 78 window_.reset(CreateBrowserWindow()); |
| 99 | 79 |
| 100 browser_.reset(CreateBrowser(profile(), browser_type_, hosted_app_, | 80 browser_.reset(CreateBrowser(profile(), browser_type_, hosted_app_, |
| 101 host_desktop_type_, window_.get())); | 81 host_desktop_type_, window_.get())); |
| 102 } | 82 } |
| 103 | 83 |
| 104 void BrowserWithTestWindowTest::TearDown() { | 84 void BrowserWithTestWindowTest::TearDown() { |
| 105 // Some tests end up posting tasks to the DB thread that must be completed | 85 // Some tests end up posting tasks to the DB thread that must be completed |
| 106 // before the profile can be destroyed and the test safely shut down. | 86 // before the profile can be destroyed and the test safely shut down. |
| 107 base::RunLoop().RunUntilIdle(); | 87 base::RunLoop().RunUntilIdle(); |
| 108 | 88 |
| 109 // Reset the profile here because some profile keyed services (like the | 89 // Reset the profile here because some profile keyed services (like the |
| 110 // audio service) depend on test stubs that the helpers below will remove. | 90 // audio service) depend on test stubs that the helpers below will remove. |
| 111 DestroyBrowserAndProfile(); | 91 DestroyBrowserAndProfile(); |
| 112 | 92 |
| 93 #if defined(TOOLKIT_VIEWS) |
| 94 constrained_window::SetConstrainedWindowViewsClient(nullptr); |
| 95 #endif |
| 96 |
| 113 #if defined(OS_CHROMEOS) | 97 #if defined(OS_CHROMEOS) |
| 114 ash_test_helper_->TearDown(); | 98 ash_test_helper_->TearDown(); |
| 115 #elif defined(USE_AURA) | 99 #elif defined(TOOLKIT_VIEWS) |
| 116 aura_test_helper_->TearDown(); | 100 views_test_helper_.reset(); |
| 117 ui::TerminateContextFactoryForTests(); | |
| 118 #endif | 101 #endif |
| 102 |
| 119 testing::Test::TearDown(); | 103 testing::Test::TearDown(); |
| 120 | 104 |
| 121 // A Task is leaked if we don't destroy everything, then run the message | 105 // A Task is leaked if we don't destroy everything, then run the message |
| 122 // loop. | 106 // loop. |
| 123 base::ThreadTaskRunnerHandle::Get()->PostTask( | 107 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 124 FROM_HERE, base::MessageLoop::QuitClosure()); | 108 FROM_HERE, base::MessageLoop::QuitClosure()); |
| 125 base::MessageLoop::current()->Run(); | 109 base::MessageLoop::current()->Run(); |
| 110 } |
| 126 | 111 |
| 127 #if defined(TOOLKIT_VIEWS) | 112 gfx::NativeWindow BrowserWithTestWindowTest::GetContext() { |
| 128 constrained_window::SetConstrainedWindowViewsClient(nullptr); | 113 #if defined(OS_CHROMEOS) |
| 129 views_delegate_.reset(NULL); | 114 return ash_test_helper_->CurrentContext(); |
| 115 #elif defined(TOOLKIT_VIEWS) |
| 116 return views_test_helper_->GetContext(); |
| 117 #else |
| 118 return nullptr; |
| 130 #endif | 119 #endif |
| 131 } | 120 } |
| 132 | 121 |
| 133 void BrowserWithTestWindowTest::AddTab(Browser* browser, const GURL& url) { | 122 void BrowserWithTestWindowTest::AddTab(Browser* browser, const GURL& url) { |
| 134 chrome::NavigateParams params(browser, url, ui::PAGE_TRANSITION_TYPED); | 123 chrome::NavigateParams params(browser, url, ui::PAGE_TRANSITION_TYPED); |
| 135 params.tabstrip_index = 0; | 124 params.tabstrip_index = 0; |
| 136 params.disposition = NEW_FOREGROUND_TAB; | 125 params.disposition = NEW_FOREGROUND_TAB; |
| 137 chrome::Navigate(¶ms); | 126 chrome::Navigate(¶ms); |
| 138 CommitPendingLoad(¶ms.target_contents->GetController()); | 127 CommitPendingLoad(¶ms.target_contents->GetController()); |
| 139 } | 128 } |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 true /* trusted_source */, | 237 true /* trusted_source */, |
| 249 gfx::Rect(), | 238 gfx::Rect(), |
| 250 profile, | 239 profile, |
| 251 host_desktop_type); | 240 host_desktop_type); |
| 252 } else { | 241 } else { |
| 253 params.type = browser_type; | 242 params.type = browser_type; |
| 254 } | 243 } |
| 255 params.window = browser_window; | 244 params.window = browser_window; |
| 256 return new Browser(params); | 245 return new Browser(params); |
| 257 } | 246 } |
| 258 | |
| 259 #if !defined(OS_CHROMEOS) && defined(TOOLKIT_VIEWS) | |
| 260 views::ViewsDelegate* BrowserWithTestWindowTest::CreateViewsDelegate() { | |
| 261 #if defined(USE_ASH) | |
| 262 return new ash::test::AshTestViewsDelegate; | |
| 263 #else | |
| 264 return new views::TestViewsDelegate; | |
| 265 #endif | |
| 266 } | |
| 267 #endif | |
| OLD | NEW |