| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/browser/ui/views/frame/browser_view.h" | 5 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 | 8 |
| 9 #include "chrome/app/chrome_command_ids.h" | 9 #include "chrome/app/chrome_command_ids.h" |
| 10 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 10 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
| 11 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 11 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
| 12 #include "chrome/browser/predictors/predictor_database.h" |
| 12 #include "chrome/browser/search_engines/template_url_service.h" | 13 #include "chrome/browser/search_engines/template_url_service.h" |
| 13 #include "chrome/browser/search_engines/template_url_service_factory.h" | 14 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 14 #include "chrome/browser/ui/browser_commands.h" | 15 #include "chrome/browser/ui/browser_commands.h" |
| 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 16 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" | 17 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" |
| 17 #include "chrome/browser/ui/views/frame/browser_view_layout.h" | 18 #include "chrome/browser/ui/views/frame/browser_view_layout.h" |
| 18 #include "chrome/browser/ui/views/frame/top_container_view.h" | 19 #include "chrome/browser/ui/views/frame/top_container_view.h" |
| 19 #include "chrome/browser/ui/views/infobars/infobar_container_view.h" | 20 #include "chrome/browser/ui/views/infobars/infobar_container_view.h" |
| 20 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 21 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
| 21 #include "chrome/browser/ui/views/toolbar_view.h" | 22 #include "chrome/browser/ui/views/toolbar_view.h" |
| 22 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
| 23 #include "chrome/test/base/browser_with_test_window_test.h" | 24 #include "chrome/test/base/browser_with_test_window_test.h" |
| 24 #include "chrome/test/base/scoped_testing_local_state.h" | 25 #include "chrome/test/base/scoped_testing_local_state.h" |
| 25 #include "chrome/test/base/testing_browser_process.h" | 26 #include "chrome/test/base/testing_browser_process.h" |
| 27 #include "chrome/test/base/testing_io_thread_state.h" |
| 28 #include "content/public/test/test_utils.h" |
| 26 #include "grit/theme_resources.h" | 29 #include "grit/theme_resources.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 28 #include "ui/views/controls/single_split_view.h" | 31 #include "ui/views/controls/single_split_view.h" |
| 29 #include "ui/views/controls/webview/webview.h" | 32 #include "ui/views/controls/webview/webview.h" |
| 30 | 33 |
| 31 #if defined(OS_CHROMEOS) | 34 #if defined(OS_CHROMEOS) |
| 32 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" | 35 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" |
| 33 #include "chrome/browser/chromeos/input_method/mock_input_method_manager.h" | 36 #include "chrome/browser/chromeos/input_method/mock_input_method_manager.h" |
| 34 #endif | 37 #endif |
| 35 | 38 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 virtual void TearDown() OVERRIDE; | 76 virtual void TearDown() OVERRIDE; |
| 74 virtual TestingProfile* CreateProfile() OVERRIDE; | 77 virtual TestingProfile* CreateProfile() OVERRIDE; |
| 75 virtual BrowserWindow* CreateBrowserWindow() OVERRIDE; | 78 virtual BrowserWindow* CreateBrowserWindow() OVERRIDE; |
| 76 | 79 |
| 77 void Init(); | 80 void Init(); |
| 78 BrowserView* browser_view() { return browser_view_; } | 81 BrowserView* browser_view() { return browser_view_; } |
| 79 | 82 |
| 80 private: | 83 private: |
| 81 BrowserView* browser_view_; // Not owned. | 84 BrowserView* browser_view_; // Not owned. |
| 82 scoped_ptr<ScopedTestingLocalState> local_state_; | 85 scoped_ptr<ScopedTestingLocalState> local_state_; |
| 86 scoped_ptr<predictors::PredictorDatabase> predictor_db_; |
| 87 scoped_ptr<chrome::TestingIOThreadState> testing_io_thread_state_; |
| 83 DISALLOW_COPY_AND_ASSIGN(BrowserViewTest); | 88 DISALLOW_COPY_AND_ASSIGN(BrowserViewTest); |
| 84 }; | 89 }; |
| 85 | 90 |
| 86 BrowserViewTest::BrowserViewTest() | 91 BrowserViewTest::BrowserViewTest() |
| 87 : browser_view_(NULL) { | 92 : browser_view_(NULL) { |
| 88 } | 93 } |
| 89 | 94 |
| 90 void BrowserViewTest::SetUp() { | 95 void BrowserViewTest::SetUp() { |
| 91 Init(); | 96 Init(); |
| 92 // Memory ownership is tricky here. BrowserView has taken ownership of | 97 // Memory ownership is tricky here. BrowserView has taken ownership of |
| 93 // |browser|, so BrowserWithTestWindowTest cannot continue to own it. | 98 // |browser|, so BrowserWithTestWindowTest cannot continue to own it. |
| 94 ASSERT_TRUE(release_browser()); | 99 ASSERT_TRUE(release_browser()); |
| 95 } | 100 } |
| 96 | 101 |
| 97 void BrowserViewTest::TearDown() { | 102 void BrowserViewTest::TearDown() { |
| 98 // Clean up any tabs we opened, otherwise Browser crashes in destruction. | 103 // Clean up any tabs we opened, otherwise Browser crashes in destruction. |
| 99 browser_view_->browser()->tab_strip_model()->CloseAllTabs(); | 104 browser_view_->browser()->tab_strip_model()->CloseAllTabs(); |
| 100 // Ensure the Browser is reset before BrowserWithTestWindowTest cleans up | 105 // Ensure the Browser is reset before BrowserWithTestWindowTest cleans up |
| 101 // the Profile. | 106 // the Profile. |
| 102 browser_view_->GetWidget()->CloseNow(); | 107 browser_view_->GetWidget()->CloseNow(); |
| 103 browser_view_ = NULL; | 108 browser_view_ = NULL; |
| 109 content::RunAllPendingInMessageLoop(content::BrowserThread::DB); |
| 104 BrowserWithTestWindowTest::TearDown(); | 110 BrowserWithTestWindowTest::TearDown(); |
| 111 testing_io_thread_state_.reset(); |
| 112 predictor_db_.reset(); |
| 105 #if defined(OS_CHROMEOS) | 113 #if defined(OS_CHROMEOS) |
| 106 chromeos::input_method::Shutdown(); | 114 chromeos::input_method::Shutdown(); |
| 107 #endif | 115 #endif |
| 108 local_state_.reset(NULL); | 116 local_state_.reset(NULL); |
| 109 } | 117 } |
| 110 | 118 |
| 111 TestingProfile* BrowserViewTest::CreateProfile() { | 119 TestingProfile* BrowserViewTest::CreateProfile() { |
| 112 TestingProfile* profile = BrowserWithTestWindowTest::CreateProfile(); | 120 TestingProfile* profile = BrowserWithTestWindowTest::CreateProfile(); |
| 113 // TemplateURLService is normally NULL during testing. Instant extended | 121 // TemplateURLService is normally NULL during testing. Instant extended |
| 114 // needs this service so set a custom factory function. | 122 // needs this service so set a custom factory function. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 127 return NULL; | 135 return NULL; |
| 128 } | 136 } |
| 129 | 137 |
| 130 void BrowserViewTest::Init() { | 138 void BrowserViewTest::Init() { |
| 131 local_state_.reset( | 139 local_state_.reset( |
| 132 new ScopedTestingLocalState(TestingBrowserProcess::GetGlobal())); | 140 new ScopedTestingLocalState(TestingBrowserProcess::GetGlobal())); |
| 133 #if defined(OS_CHROMEOS) | 141 #if defined(OS_CHROMEOS) |
| 134 chromeos::input_method::InitializeForTesting( | 142 chromeos::input_method::InitializeForTesting( |
| 135 new chromeos::input_method::MockInputMethodManager); | 143 new chromeos::input_method::MockInputMethodManager); |
| 136 #endif | 144 #endif |
| 145 testing_io_thread_state_.reset(new chrome::TestingIOThreadState()); |
| 137 BrowserWithTestWindowTest::SetUp(); | 146 BrowserWithTestWindowTest::SetUp(); |
| 147 predictor_db_.reset(new predictors::PredictorDatabase(GetProfile())); |
| 138 browser_view_ = static_cast<BrowserView*>(browser()->window()); | 148 browser_view_ = static_cast<BrowserView*>(browser()->window()); |
| 139 } | 149 } |
| 140 | 150 |
| 141 // Test basic construction and initialization. | 151 // Test basic construction and initialization. |
| 142 TEST_F(BrowserViewTest, BrowserView) { | 152 TEST_F(BrowserViewTest, BrowserView) { |
| 143 // The window is owned by the native widget, not the test class. | 153 // The window is owned by the native widget, not the test class. |
| 144 EXPECT_FALSE(window()); | 154 EXPECT_FALSE(window()); |
| 145 // |browser_view_| owns the Browser, not the test class. | 155 // |browser_view_| owns the Browser, not the test class. |
| 146 EXPECT_FALSE(browser()); | 156 EXPECT_FALSE(browser()); |
| 147 EXPECT_TRUE(browser_view()->browser()); | 157 EXPECT_TRUE(browser_view()->browser()); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 virtual gfx::Rect GetRestoredBounds() const OVERRIDE { | 292 virtual gfx::Rect GetRestoredBounds() const OVERRIDE { |
| 283 return gfx::Rect(); | 293 return gfx::Rect(); |
| 284 } | 294 } |
| 285 virtual bool IsMaximized() const OVERRIDE { | 295 virtual bool IsMaximized() const OVERRIDE { |
| 286 return false; | 296 return false; |
| 287 } | 297 } |
| 288 }; | 298 }; |
| 289 | 299 |
| 290 BrowserViewIncognitoSwitcherTest() | 300 BrowserViewIncognitoSwitcherTest() |
| 291 : browser_view_(NULL) {} | 301 : browser_view_(NULL) {} |
| 292 virtual ~BrowserViewIncognitoSwitcherTest() {} | |
| 293 | 302 |
| 294 virtual void SetUp() OVERRIDE { | 303 virtual void SetUp() OVERRIDE { |
| 295 Init(); | 304 Init(); |
| 296 browser_view_->Init(browser()); | 305 browser_view_->Init(browser()); |
| 297 (new BrowserFrame(browser_view_))->InitBrowserFrame(); | 306 (new BrowserFrame(browser_view_))->InitBrowserFrame(); |
| 298 browser_view_->SetBounds(gfx::Rect(10, 10, 500, 500)); | 307 browser_view_->SetBounds(gfx::Rect(10, 10, 500, 500)); |
| 299 browser_view_->Show(); | 308 browser_view_->Show(); |
| 300 // Memory ownership is tricky here. BrowserView has taken ownership of | 309 // Memory ownership is tricky here. BrowserView has taken ownership of |
| 301 // |browser|, so BrowserWithTestWindowTest cannot continue to own it. | 310 // |browser|, so BrowserWithTestWindowTest cannot continue to own it. |
| 302 ASSERT_TRUE(release_browser()); | 311 ASSERT_TRUE(release_browser()); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 // Test initial state. | 353 // Test initial state. |
| 345 EXPECT_TRUE(browser_view()->IsTabStripVisible()); | 354 EXPECT_TRUE(browser_view()->IsTabStripVisible()); |
| 346 // Validate whether the window switcher button is the target for the position | 355 // Validate whether the window switcher button is the target for the position |
| 347 // passed in. | 356 // passed in. |
| 348 gfx::Point switcher_point(browser_view()->window_switcher_button()->x() + 2, | 357 gfx::Point switcher_point(browser_view()->window_switcher_button()->x() + 2, |
| 349 browser_view()->window_switcher_button()->y()); | 358 browser_view()->window_switcher_button()->y()); |
| 350 EXPECT_EQ(browser_view()->GetEventHandlerForPoint(switcher_point), | 359 EXPECT_EQ(browser_view()->GetEventHandlerForPoint(switcher_point), |
| 351 browser_view()->window_switcher_button()); | 360 browser_view()->window_switcher_button()); |
| 352 } | 361 } |
| 353 #endif | 362 #endif |
| OLD | NEW |