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