OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/compiler_specific.h" | 5 #include "base/compiler_specific.h" |
6 #include "base/string_number_conversions.h" | 6 #include "base/string_number_conversions.h" |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
9 #include "chrome/browser/automation/ui_controls.h" | 9 #include "chrome/browser/automation/ui_controls.h" |
10 #include "chrome/browser/bookmarks/bookmark_model.h" | 10 #include "chrome/browser/bookmarks/bookmark_model.h" |
11 #include "chrome/browser/bookmarks/bookmark_utils.h" | 11 #include "chrome/browser/bookmarks/bookmark_utils.h" |
12 #include "chrome/browser/prefs/pref_service.h" | 12 #include "chrome/browser/prefs/pref_service.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" | 15 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" |
15 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
17 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
18 #include "chrome/test/base/testing_profile.h" | 19 #include "chrome/test/base/testing_profile.h" |
19 #include "chrome/test/base/view_event_test_base.h" | 20 #include "chrome/test/base/view_event_test_base.h" |
| 21 #include "chrome/test/testing_browser_process.h" |
20 #include "content/browser/tab_contents/page_navigator.h" | 22 #include "content/browser/tab_contents/page_navigator.h" |
21 #include "content/common/notification_service.h" | 23 #include "content/common/notification_service.h" |
22 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
23 #include "ui/base/accessibility/accessibility_types.h" | 25 #include "ui/base/accessibility/accessibility_types.h" |
24 #include "ui/base/clipboard/clipboard.h" | 26 #include "ui/base/clipboard/clipboard.h" |
25 #include "ui/base/keycodes/keyboard_codes.h" | 27 #include "ui/base/keycodes/keyboard_codes.h" |
26 #include "views/controls/button/menu_button.h" | 28 #include "views/controls/button/menu_button.h" |
27 #include "views/controls/button/text_button.h" | 29 #include "views/controls/button/text_button.h" |
28 #include "views/controls/menu/menu_controller.h" | 30 #include "views/controls/menu/menu_controller.h" |
29 #include "views/controls/menu/menu_item_view.h" | 31 #include "views/controls/menu/menu_item_view.h" |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 } | 175 } |
174 | 176 |
175 virtual void SetUp() { | 177 virtual void SetUp() { |
176 BookmarkBarView::testing_ = true; | 178 BookmarkBarView::testing_ = true; |
177 | 179 |
178 profile_.reset(new TestingProfile()); | 180 profile_.reset(new TestingProfile()); |
179 profile_->CreateBookmarkModel(true); | 181 profile_->CreateBookmarkModel(true); |
180 profile_->BlockUntilBookmarkModelLoaded(); | 182 profile_->BlockUntilBookmarkModelLoaded(); |
181 profile_->GetPrefs()->SetBoolean(prefs::kShowBookmarkBar, true); | 183 profile_->GetPrefs()->SetBoolean(prefs::kShowBookmarkBar, true); |
182 | 184 |
| 185 browser_.reset(new Browser(Browser::TYPE_TABBED, profile_.get())); |
| 186 |
183 model_ = profile_->GetBookmarkModel(); | 187 model_ = profile_->GetBookmarkModel(); |
184 model_->ClearStore(); | 188 model_->ClearStore(); |
185 | 189 |
186 bb_view_ = new BookmarkBarView(profile_.get(), NULL); | 190 bb_view_.reset(new BookmarkBarView(browser_.get())); |
187 bb_view_->SetPageNavigator(&navigator_); | 191 bb_view_->SetPageNavigator(&navigator_); |
188 | 192 |
189 AddTestData(CreateBigMenu()); | 193 AddTestData(CreateBigMenu()); |
190 | 194 |
191 // Calculate the preferred size so that one button doesn't fit, which | 195 // Calculate the preferred size so that one button doesn't fit, which |
192 // triggers the overflow button to appear. | 196 // triggers the overflow button to appear. |
193 // | 197 // |
194 // BookmarkBarView::Layout does nothing if the parent is NULL and | 198 // BookmarkBarView::Layout does nothing if the parent is NULL and |
195 // GetPreferredSize hard codes a width of 1. For that reason we add the | 199 // GetPreferredSize hard codes a width of 1. For that reason we add the |
196 // BookmarkBarView to a dumby view as the parent. | 200 // BookmarkBarView to a dumby view as the parent. |
197 // | 201 // |
198 // This code looks a bit hacky, but I've written it so that it shouldn't | 202 // This code looks a bit hacky, but I've written it so that it shouldn't |
199 // be dependant upon any of the layout code in BookmarkBarView. Instead | 203 // be dependant upon any of the layout code in BookmarkBarView. Instead |
200 // we brute force search for a size that triggers the overflow button. | 204 // we brute force search for a size that triggers the overflow button. |
201 views::View tmp_parent; | 205 views::View tmp_parent; |
202 | 206 |
203 tmp_parent.AddChildView(bb_view_); | 207 tmp_parent.AddChildView(bb_view_.get()); |
204 | 208 |
205 bb_view_pref_ = bb_view_->GetPreferredSize(); | 209 bb_view_pref_ = bb_view_->GetPreferredSize(); |
206 bb_view_pref_.set_width(1000); | 210 bb_view_pref_.set_width(1000); |
207 views::TextButton* button = GetBookmarkButton(4); | 211 views::TextButton* button = GetBookmarkButton(4); |
208 while (button->IsVisible()) { | 212 while (button->IsVisible()) { |
209 bb_view_pref_.set_width(bb_view_pref_.width() - 25); | 213 bb_view_pref_.set_width(bb_view_pref_.width() - 25); |
210 bb_view_->SetBounds(0, 0, bb_view_pref_.width(), bb_view_pref_.height()); | 214 bb_view_->SetBounds(0, 0, bb_view_pref_.width(), bb_view_pref_.height()); |
211 bb_view_->Layout(); | 215 bb_view_->Layout(); |
212 } | 216 } |
213 | 217 |
214 tmp_parent.RemoveChildView(bb_view_); | 218 tmp_parent.RemoveChildView(bb_view_.get()); |
215 | 219 |
216 ViewEventTestBase::SetUp(); | 220 ViewEventTestBase::SetUp(); |
217 } | 221 } |
218 | 222 |
219 virtual void TearDown() { | 223 virtual void TearDown() { |
| 224 // Destroy everything, then run the message loop to ensure we delete all |
| 225 // Tasks and fully shut down. |
| 226 browser_->CloseAllTabs(); |
| 227 bb_view_.reset(); |
| 228 browser_.reset(); |
| 229 profile_.reset(); |
| 230 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask); |
| 231 MessageLoop::current()->Run(); |
| 232 |
220 ViewEventTestBase::TearDown(); | 233 ViewEventTestBase::TearDown(); |
221 BookmarkBarView::testing_ = false; | 234 BookmarkBarView::testing_ = false; |
222 views::ViewsDelegate::views_delegate = NULL; | 235 views::ViewsDelegate::views_delegate = NULL; |
223 } | 236 } |
224 | 237 |
225 protected: | 238 protected: |
226 void InstallViewsDelegate() { | 239 void InstallViewsDelegate() { |
227 views::ViewsDelegate::views_delegate = &views_delegate_; | 240 views::ViewsDelegate::views_delegate = &views_delegate_; |
228 } | 241 } |
229 | 242 |
230 virtual views::View* CreateContentsView() { | 243 virtual views::View* CreateContentsView() { |
231 return bb_view_; | 244 return bb_view_.get(); |
232 } | 245 } |
233 | 246 |
234 virtual gfx::Size GetPreferredSize() { return bb_view_pref_; } | 247 virtual gfx::Size GetPreferredSize() { return bb_view_pref_; } |
235 | 248 |
236 views::TextButton* GetBookmarkButton(int view_index) { | 249 views::TextButton* GetBookmarkButton(int view_index) { |
237 return bb_view_->GetBookmarkButton(view_index); | 250 return bb_view_->GetBookmarkButton(view_index); |
238 } | 251 } |
239 | 252 |
240 // See comment above class description for what this does. | 253 // See comment above class description for what this does. |
241 virtual bool CreateBigMenu() { return false; } | 254 virtual bool CreateBigMenu() { return false; } |
242 | 255 |
243 BookmarkModel* model_; | 256 BookmarkModel* model_; |
244 BookmarkBarView* bb_view_; | 257 scoped_ptr<BookmarkBarView> bb_view_; |
245 TestingPageNavigator navigator_; | 258 TestingPageNavigator navigator_; |
246 | 259 |
247 private: | 260 private: |
248 void AddTestData(bool big_menu) { | 261 void AddTestData(bool big_menu) { |
249 const BookmarkNode* bb_node = model_->bookmark_bar_node(); | 262 const BookmarkNode* bb_node = model_->bookmark_bar_node(); |
250 std::string test_base = "file:///c:/tmp/"; | 263 std::string test_base = "file:///c:/tmp/"; |
251 const BookmarkNode* f1 = model_->AddFolder(bb_node, 0, ASCIIToUTF16("F1")); | 264 const BookmarkNode* f1 = model_->AddFolder(bb_node, 0, ASCIIToUTF16("F1")); |
252 model_->AddURL(f1, 0, ASCIIToUTF16("f1a"), GURL(test_base + "f1a")); | 265 model_->AddURL(f1, 0, ASCIIToUTF16("f1a"), GURL(test_base + "f1a")); |
253 const BookmarkNode* f11 = model_->AddFolder(f1, 1, ASCIIToUTF16("F11")); | 266 const BookmarkNode* f11 = model_->AddFolder(f1, 1, ASCIIToUTF16("F11")); |
254 model_->AddURL(f11, 0, ASCIIToUTF16("f11a"), GURL(test_base + "f11a")); | 267 model_->AddURL(f11, 0, ASCIIToUTF16("f11a"), GURL(test_base + "f11a")); |
(...skipping 13 matching lines...) Expand all Loading... |
268 ASCIIToUTF16("OF")); | 281 ASCIIToUTF16("OF")); |
269 model_->AddURL(of, 0, ASCIIToUTF16("ofa"), GURL(test_base + "ofa")); | 282 model_->AddURL(of, 0, ASCIIToUTF16("ofa"), GURL(test_base + "ofa")); |
270 model_->AddURL(of, 1, ASCIIToUTF16("ofb"), GURL(test_base + "ofb")); | 283 model_->AddURL(of, 1, ASCIIToUTF16("ofb"), GURL(test_base + "ofb")); |
271 const BookmarkNode* of2 = model_->AddFolder(model_->other_node(), 2, | 284 const BookmarkNode* of2 = model_->AddFolder(model_->other_node(), 2, |
272 ASCIIToUTF16("OF2")); | 285 ASCIIToUTF16("OF2")); |
273 model_->AddURL(of2, 0, ASCIIToUTF16("of2a"), GURL(test_base + "of2a")); | 286 model_->AddURL(of2, 0, ASCIIToUTF16("of2a"), GURL(test_base + "of2a")); |
274 model_->AddURL(of2, 1, ASCIIToUTF16("of2b"), GURL(test_base + "of2b")); | 287 model_->AddURL(of2, 1, ASCIIToUTF16("of2b"), GURL(test_base + "of2b")); |
275 } | 288 } |
276 | 289 |
277 gfx::Size bb_view_pref_; | 290 gfx::Size bb_view_pref_; |
| 291 ScopedTestingBrowserProcess testing_browser_process_; |
278 scoped_ptr<TestingProfile> profile_; | 292 scoped_ptr<TestingProfile> profile_; |
| 293 scoped_ptr<Browser> browser_; |
279 BrowserThread ui_thread_; | 294 BrowserThread ui_thread_; |
280 BrowserThread file_thread_; | 295 BrowserThread file_thread_; |
281 ViewsDelegateImpl views_delegate_; | 296 ViewsDelegateImpl views_delegate_; |
282 }; | 297 }; |
283 | 298 |
284 // Clicks on first menu, makes sure button is depressed. Moves mouse to first | 299 // Clicks on first menu, makes sure button is depressed. Moves mouse to first |
285 // child, clicks it and makes sure a navigation occurs. | 300 // child, clicks it and makes sure a navigation occurs. |
286 class BookmarkBarViewTest1 : public BookmarkBarViewEventTestBase { | 301 class BookmarkBarViewTest1 : public BookmarkBarViewEventTestBase { |
287 protected: | 302 protected: |
288 virtual void DoTestOnMessageLoop() { | 303 virtual void DoTestOnMessageLoop() { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 void Step2() { | 366 void Step2() { |
352 // Menu should be showing. | 367 // Menu should be showing. |
353 views::MenuItemView* menu = bb_view_->GetMenu(); | 368 views::MenuItemView* menu = bb_view_->GetMenu(); |
354 ASSERT_TRUE(menu != NULL && menu->GetSubmenu()->IsShowing()); | 369 ASSERT_TRUE(menu != NULL && menu->GetSubmenu()->IsShowing()); |
355 | 370 |
356 // Click on 0x0, which should trigger closing menu. | 371 // Click on 0x0, which should trigger closing menu. |
357 // NOTE: this code assume there is a left margin, which is currently | 372 // NOTE: this code assume there is a left margin, which is currently |
358 // true. If that changes, this code will need to find another empty space | 373 // true. If that changes, this code will need to find another empty space |
359 // to press the mouse on. | 374 // to press the mouse on. |
360 gfx::Point mouse_loc; | 375 gfx::Point mouse_loc; |
361 views::View::ConvertPointToScreen(bb_view_, &mouse_loc); | 376 views::View::ConvertPointToScreen(bb_view_.get(), &mouse_loc); |
362 ui_controls::SendMouseMove(0, 0); | 377 ui_controls::SendMouseMove(0, 0); |
363 ui_controls::SendMouseEventsNotifyWhenDone( | 378 ui_controls::SendMouseEventsNotifyWhenDone( |
364 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, | 379 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, |
365 CreateEventTask(this, &BookmarkBarViewTest2::Step3)); | 380 CreateEventTask(this, &BookmarkBarViewTest2::Step3)); |
366 } | 381 } |
367 | 382 |
368 void Step3() { | 383 void Step3() { |
369 // The menu shouldn't be showing. | 384 // The menu shouldn't be showing. |
370 views::MenuItemView* menu = bb_view_->GetMenu(); | 385 views::MenuItemView* menu = bb_view_->GetMenu(); |
371 ASSERT_TRUE(menu == NULL || !menu->GetSubmenu()->IsShowing()); | 386 ASSERT_TRUE(menu == NULL || !menu->GetSubmenu()->IsShowing()); |
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1036 views::MenuItemView* menu = bb_view_->GetContextMenu(); | 1051 views::MenuItemView* menu = bb_view_->GetContextMenu(); |
1037 ASSERT_TRUE(!menu || !menu->GetSubmenu() || | 1052 ASSERT_TRUE(!menu || !menu->GetSubmenu() || |
1038 !menu->GetSubmenu()->IsShowing()); | 1053 !menu->GetSubmenu()->IsShowing()); |
1039 | 1054 |
1040 // But the menu should be showing. | 1055 // But the menu should be showing. |
1041 menu = bb_view_->GetMenu(); | 1056 menu = bb_view_->GetMenu(); |
1042 ASSERT_TRUE(menu && menu->GetSubmenu() && menu->GetSubmenu()->IsShowing()); | 1057 ASSERT_TRUE(menu && menu->GetSubmenu() && menu->GetSubmenu()->IsShowing()); |
1043 | 1058 |
1044 // Now click on empty space. | 1059 // Now click on empty space. |
1045 gfx::Point mouse_loc; | 1060 gfx::Point mouse_loc; |
1046 views::View::ConvertPointToScreen(bb_view_, &mouse_loc); | 1061 views::View::ConvertPointToScreen(bb_view_.get(), &mouse_loc); |
1047 ui_controls::SendMouseMove(mouse_loc.x(), mouse_loc.y()); | 1062 ui_controls::SendMouseMove(mouse_loc.x(), mouse_loc.y()); |
1048 ui_controls::SendMouseEventsNotifyWhenDone( | 1063 ui_controls::SendMouseEventsNotifyWhenDone( |
1049 ui_controls::LEFT, ui_controls::UP | ui_controls::DOWN, | 1064 ui_controls::LEFT, ui_controls::UP | ui_controls::DOWN, |
1050 CreateEventTask(this, &BookmarkBarViewTest11::Step5)); | 1065 CreateEventTask(this, &BookmarkBarViewTest11::Step5)); |
1051 } | 1066 } |
1052 | 1067 |
1053 void Step5() { | 1068 void Step5() { |
1054 // Make sure the menu is not showing. | 1069 // Make sure the menu is not showing. |
1055 views::MenuItemView* menu = bb_view_->GetMenu(); | 1070 views::MenuItemView* menu = bb_view_->GetMenu(); |
1056 ASSERT_TRUE(!menu || !menu->GetSubmenu() || | 1071 ASSERT_TRUE(!menu || !menu->GetSubmenu() || |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1561 ASSERT_TRUE(menu != NULL); | 1576 ASSERT_TRUE(menu != NULL); |
1562 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); | 1577 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); |
1563 | 1578 |
1564 menu->GetMenuController()->CancelAll(); | 1579 menu->GetMenuController()->CancelAll(); |
1565 | 1580 |
1566 Done(); | 1581 Done(); |
1567 } | 1582 } |
1568 }; | 1583 }; |
1569 | 1584 |
1570 VIEW_TEST(BookmarkBarViewTest19, SiblingMenu) | 1585 VIEW_TEST(BookmarkBarViewTest19, SiblingMenu) |
OLD | NEW |