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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/callback.h" | 6 #include "base/callback.h" |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 // the names f1-f100. | 101 // the names f1-f100. |
102 // | 102 // |
103 // Subclasses should be sure and invoke super's implementation of SetUp and | 103 // Subclasses should be sure and invoke super's implementation of SetUp and |
104 // TearDown. | 104 // TearDown. |
105 class BookmarkBarViewEventTestBase : public ViewEventTestBase { | 105 class BookmarkBarViewEventTestBase : public ViewEventTestBase { |
106 public: | 106 public: |
107 BookmarkBarViewEventTestBase() | 107 BookmarkBarViewEventTestBase() |
108 : ViewEventTestBase(), | 108 : ViewEventTestBase(), |
109 model_(NULL), | 109 model_(NULL), |
110 bb_view_(NULL), | 110 bb_view_(NULL), |
111 file_thread_(BrowserThread::FILE, MessageLoop::current()) { | 111 file_thread_(BrowserThread::FILE, base::MessageLoop::current()) {} |
112 } | |
113 | 112 |
114 virtual void SetUp() OVERRIDE { | 113 virtual void SetUp() OVERRIDE { |
115 views::MenuController::TurnOffContextMenuSelectionHoldForTest(); | 114 views::MenuController::TurnOffContextMenuSelectionHoldForTest(); |
116 BookmarkBarView::DisableAnimationsForTesting(true); | 115 BookmarkBarView::DisableAnimationsForTesting(true); |
117 | 116 |
118 profile_.reset(new TestingProfile()); | 117 profile_.reset(new TestingProfile()); |
119 profile_->CreateBookmarkModel(true); | 118 profile_->CreateBookmarkModel(true); |
120 model_ = BookmarkModelFactory::GetForProfile(profile_.get()); | 119 model_ = BookmarkModelFactory::GetForProfile(profile_.get()); |
121 ui_test_utils::WaitForBookmarkModelToLoad(model_); | 120 ui_test_utils::WaitForBookmarkModelToLoad(model_); |
122 profile_->GetPrefs()->SetBoolean(prefs::kShowBookmarkBar, true); | 121 profile_->GetPrefs()->SetBoolean(prefs::kShowBookmarkBar, true); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 | 166 |
168 virtual void TearDown() { | 167 virtual void TearDown() { |
169 // Destroy everything, then run the message loop to ensure we delete all | 168 // Destroy everything, then run the message loop to ensure we delete all |
170 // Tasks and fully shut down. | 169 // Tasks and fully shut down. |
171 browser_->tab_strip_model()->CloseAllTabs(); | 170 browser_->tab_strip_model()->CloseAllTabs(); |
172 bb_view_.reset(); | 171 bb_view_.reset(); |
173 browser_.reset(); | 172 browser_.reset(); |
174 profile_.reset(); | 173 profile_.reset(); |
175 | 174 |
176 // Run the message loop to ensure we delete allTasks and fully shut down. | 175 // Run the message loop to ensure we delete allTasks and fully shut down. |
177 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 176 base::MessageLoop::current()->PostTask(FROM_HERE, |
178 MessageLoop::current()->Run(); | 177 base::MessageLoop::QuitClosure()); |
| 178 base::MessageLoop::current()->Run(); |
179 | 179 |
180 ViewEventTestBase::TearDown(); | 180 ViewEventTestBase::TearDown(); |
181 BookmarkBarView::DisableAnimationsForTesting(false); | 181 BookmarkBarView::DisableAnimationsForTesting(false); |
182 views::ViewsDelegate::views_delegate = NULL; | 182 views::ViewsDelegate::views_delegate = NULL; |
183 } | 183 } |
184 | 184 |
185 protected: | 185 protected: |
186 virtual views::View* CreateContentsView() OVERRIDE { | 186 virtual views::View* CreateContentsView() OVERRIDE { |
187 return bb_view_.get(); | 187 return bb_view_.get(); |
188 } | 188 } |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 explicit ContextMenuNotificationObserver(const base::Closure& task) | 426 explicit ContextMenuNotificationObserver(const base::Closure& task) |
427 : task_(task) { | 427 : task_(task) { |
428 registrar_.Add(this, | 428 registrar_.Add(this, |
429 chrome::NOTIFICATION_BOOKMARK_CONTEXT_MENU_SHOWN, | 429 chrome::NOTIFICATION_BOOKMARK_CONTEXT_MENU_SHOWN, |
430 content::NotificationService::AllSources()); | 430 content::NotificationService::AllSources()); |
431 } | 431 } |
432 | 432 |
433 virtual void Observe(int type, | 433 virtual void Observe(int type, |
434 const content::NotificationSource& source, | 434 const content::NotificationSource& source, |
435 const content::NotificationDetails& details) OVERRIDE { | 435 const content::NotificationDetails& details) OVERRIDE { |
436 MessageLoop::current()->PostTask(FROM_HERE, task_); | 436 base::MessageLoop::current()->PostTask(FROM_HERE, task_); |
437 } | 437 } |
438 | 438 |
439 // Sets the task that is posted when the context menu is shown. | 439 // Sets the task that is posted when the context menu is shown. |
440 void set_task(const base::Closure& task) { task_ = task; } | 440 void set_task(const base::Closure& task) { task_ = task; } |
441 | 441 |
442 private: | 442 private: |
443 content::NotificationRegistrar registrar_; | 443 content::NotificationRegistrar registrar_; |
444 base::Closure task_; | 444 base::Closure task_; |
445 | 445 |
446 DISALLOW_COPY_AND_ASSIGN(ContextMenuNotificationObserver); | 446 DISALLOW_COPY_AND_ASSIGN(ContextMenuNotificationObserver); |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 scroll_down_button->height() / 2); | 859 scroll_down_button->height() / 2); |
860 views::View::ConvertPointToScreen(scroll_down_button, &loc); | 860 views::View::ConvertPointToScreen(scroll_down_button, &loc); |
861 | 861 |
862 // On linux, the sending one location isn't enough. | 862 // On linux, the sending one location isn't enough. |
863 ui_controls::SendMouseMove(loc.x() - 1 , loc.y() - 1); | 863 ui_controls::SendMouseMove(loc.x() - 1 , loc.y() - 1); |
864 ui_controls::SendMouseMoveNotifyWhenDone( | 864 ui_controls::SendMouseMoveNotifyWhenDone( |
865 loc.x(), loc.y(), CreateEventTask(this, &BookmarkBarViewTest9::Step3)); | 865 loc.x(), loc.y(), CreateEventTask(this, &BookmarkBarViewTest9::Step3)); |
866 } | 866 } |
867 | 867 |
868 void Step3() { | 868 void Step3() { |
869 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 869 base::MessageLoop::current()->PostDelayedTask( |
| 870 FROM_HERE, |
870 base::Bind(&BookmarkBarViewTest9::Step4, this), | 871 base::Bind(&BookmarkBarViewTest9::Step4, this), |
871 base::TimeDelta::FromMilliseconds(200)); | 872 base::TimeDelta::FromMilliseconds(200)); |
872 } | 873 } |
873 | 874 |
874 void Step4() { | 875 void Step4() { |
875 gfx::Point menu_loc; | 876 gfx::Point menu_loc; |
876 views::View::ConvertPointToScreen(first_menu_, &menu_loc); | 877 views::View::ConvertPointToScreen(first_menu_, &menu_loc); |
877 ASSERT_NE(start_y_, menu_loc.y()); | 878 ASSERT_NE(start_y_, menu_loc.y()); |
878 | 879 |
879 // Hide menu. | 880 // Hide menu. |
880 bb_view_->GetMenu()->GetMenuController()->CancelAll(); | 881 bb_view_->GetMenu()->GetMenuController()->CancelAll(); |
881 | 882 |
882 // On linux, Cancelling menu will call Quit on the message loop, | 883 // On linux, Cancelling menu will call Quit on the message loop, |
883 // which can interfere with Done. We need to run Done in the | 884 // which can interfere with Done. We need to run Done in the |
884 // next execution loop. | 885 // next execution loop. |
885 MessageLoop::current()->PostTask( | 886 base::MessageLoop::current()->PostTask( |
886 FROM_HERE, | 887 FROM_HERE, base::Bind(&ViewEventTestBase::Done, this)); |
887 base::Bind(&ViewEventTestBase::Done, this)); | |
888 } | 888 } |
889 | 889 |
890 int start_y_; | 890 int start_y_; |
891 views::MenuItemView* first_menu_; | 891 views::MenuItemView* first_menu_; |
892 }; | 892 }; |
893 | 893 |
894 VIEW_TEST(BookmarkBarViewTest9, ScrollButtonScrolls) | 894 VIEW_TEST(BookmarkBarViewTest9, ScrollButtonScrolls) |
895 | 895 |
896 // Tests up/down/left/enter key messages. | 896 // Tests up/down/left/enter key messages. |
897 class BookmarkBarViewTest10 : public BookmarkBarViewEventTestBase { | 897 class BookmarkBarViewTest10 : public BookmarkBarViewEventTestBase { |
898 protected: | 898 protected: |
899 virtual void DoTestOnMessageLoop() OVERRIDE { | 899 virtual void DoTestOnMessageLoop() OVERRIDE { |
900 // Move the mouse to the first folder on the bookmark bar and press the | 900 // Move the mouse to the first folder on the bookmark bar and press the |
901 // mouse. | 901 // mouse. |
902 views::TextButton* button = GetBookmarkButton(0); | 902 views::TextButton* button = GetBookmarkButton(0); |
903 ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT, | 903 ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT, |
904 ui_controls::DOWN | ui_controls::UP, | 904 ui_controls::DOWN | ui_controls::UP, |
905 CreateEventTask(this, &BookmarkBarViewTest10::Step2)); | 905 CreateEventTask(this, &BookmarkBarViewTest10::Step2)); |
906 MessageLoop::current()->RunUntilIdle(); | 906 base::MessageLoop::current()->RunUntilIdle(); |
907 } | 907 } |
908 | 908 |
909 private: | 909 private: |
910 void Step2() { | 910 void Step2() { |
911 // Menu should be showing. | 911 // Menu should be showing. |
912 views::MenuItemView* menu = bb_view_->GetMenu(); | 912 views::MenuItemView* menu = bb_view_->GetMenu(); |
913 ASSERT_TRUE(menu != NULL); | 913 ASSERT_TRUE(menu != NULL); |
914 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); | 914 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); |
915 | 915 |
916 // Send a down event, which should select the first item. | 916 // Send a down event, which should select the first item. |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1115 | 1115 |
1116 // Select the first item in the context menu (open all). | 1116 // Select the first item in the context menu (open all). |
1117 views::MenuItemView* child_menu = | 1117 views::MenuItemView* child_menu = |
1118 menu->GetSubmenu()->GetMenuItemAt(0); | 1118 menu->GetSubmenu()->GetMenuItemAt(0); |
1119 ASSERT_TRUE(child_menu != NULL); | 1119 ASSERT_TRUE(child_menu != NULL); |
1120 ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::LEFT, | 1120 ui_test_utils::MoveMouseToCenterAndPress(child_menu, ui_controls::LEFT, |
1121 ui_controls::DOWN | ui_controls::UP, base::Closure()); | 1121 ui_controls::DOWN | ui_controls::UP, base::Closure()); |
1122 | 1122 |
1123 // Delay until we send tab, otherwise the message box doesn't appear | 1123 // Delay until we send tab, otherwise the message box doesn't appear |
1124 // correctly. | 1124 // correctly. |
1125 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 1125 base::MessageLoop::current()->PostDelayedTask( |
| 1126 FROM_HERE, |
1126 CreateEventTask(this, &BookmarkBarViewTest12::Step4), | 1127 CreateEventTask(this, &BookmarkBarViewTest12::Step4), |
1127 base::TimeDelta::FromSeconds(1)); | 1128 base::TimeDelta::FromSeconds(1)); |
1128 } | 1129 } |
1129 | 1130 |
1130 void Step4() { | 1131 void Step4() { |
1131 // Press tab to give focus to the cancel button. | 1132 // Press tab to give focus to the cancel button. |
1132 ui_controls::SendKeyPress( | 1133 ui_controls::SendKeyPress( |
1133 window_->GetNativeWindow(), ui::VKEY_TAB, false, false, false, false); | 1134 window_->GetNativeWindow(), ui::VKEY_TAB, false, false, false, false); |
1134 | 1135 |
1135 // For some reason return isn't processed correctly unless we delay. | 1136 // For some reason return isn't processed correctly unless we delay. |
1136 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 1137 base::MessageLoop::current()->PostDelayedTask( |
| 1138 FROM_HERE, |
1137 CreateEventTask(this, &BookmarkBarViewTest12::Step5), | 1139 CreateEventTask(this, &BookmarkBarViewTest12::Step5), |
1138 base::TimeDelta::FromSeconds(1)); | 1140 base::TimeDelta::FromSeconds(1)); |
1139 } | 1141 } |
1140 | 1142 |
1141 void Step5() { | 1143 void Step5() { |
1142 // And press enter so that the cancel button is selected. | 1144 // And press enter so that the cancel button is selected. |
1143 ui_controls::SendKeyPressNotifyWhenDone( | 1145 ui_controls::SendKeyPressNotifyWhenDone( |
1144 window_->GetNativeWindow(), ui::VKEY_RETURN, false, false, false, false, | 1146 window_->GetNativeWindow(), ui::VKEY_RETURN, false, false, false, false, |
1145 CreateEventTask(this, &BookmarkBarViewTest12::Step6)); | 1147 CreateEventTask(this, &BookmarkBarViewTest12::Step6)); |
1146 } | 1148 } |
1147 | 1149 |
1148 void Step6() { | 1150 void Step6() { |
1149 // Do a delayed task to give the dialog time to exit. | 1151 // Do a delayed task to give the dialog time to exit. |
1150 MessageLoop::current()->PostTask( | 1152 base::MessageLoop::current()->PostTask( |
1151 FROM_HERE, CreateEventTask(this, &BookmarkBarViewTest12::Step7)); | 1153 FROM_HERE, CreateEventTask(this, &BookmarkBarViewTest12::Step7)); |
1152 } | 1154 } |
1153 | 1155 |
1154 void Step7() { | 1156 void Step7() { |
1155 Done(); | 1157 Done(); |
1156 } | 1158 } |
1157 }; | 1159 }; |
1158 | 1160 |
1159 VIEW_TEST(BookmarkBarViewTest12, CloseWithModalDialog) | 1161 VIEW_TEST(BookmarkBarViewTest12, CloseWithModalDialog) |
1160 | 1162 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1379 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); | 1381 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); |
1380 | 1382 |
1381 // Button should be depressed. | 1383 // Button should be depressed. |
1382 views::TextButton* button = GetBookmarkButton(0); | 1384 views::TextButton* button = GetBookmarkButton(0); |
1383 ASSERT_TRUE(button->state() == views::CustomButton::STATE_PRESSED); | 1385 ASSERT_TRUE(button->state() == views::CustomButton::STATE_PRESSED); |
1384 | 1386 |
1385 // Close the window. | 1387 // Close the window. |
1386 window_->Close(); | 1388 window_->Close(); |
1387 window_ = NULL; | 1389 window_ = NULL; |
1388 | 1390 |
1389 MessageLoop::current()->PostTask( | 1391 base::MessageLoop::current()->PostTask( |
1390 FROM_HERE, CreateEventTask(this, &BookmarkBarViewTest16::Done)); | 1392 FROM_HERE, CreateEventTask(this, &BookmarkBarViewTest16::Done)); |
1391 } | 1393 } |
1392 }; | 1394 }; |
1393 | 1395 |
1394 VIEW_TEST(BookmarkBarViewTest16, DeleteMenu) | 1396 VIEW_TEST(BookmarkBarViewTest16, DeleteMenu) |
1395 | 1397 |
1396 // Makes sure right clicking on an item while a context menu is already showing | 1398 // Makes sure right clicking on an item while a context menu is already showing |
1397 // doesn't crash and works. | 1399 // doesn't crash and works. |
1398 class BookmarkBarViewTest17 : public BookmarkBarViewEventTestBase { | 1400 class BookmarkBarViewTest17 : public BookmarkBarViewEventTestBase { |
1399 public: | 1401 public: |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1768 EXPECT_TRUE(bb_view_->GetContextMenu() == NULL); | 1770 EXPECT_TRUE(bb_view_->GetContextMenu() == NULL); |
1769 EXPECT_TRUE(bb_view_->GetMenu() == NULL); | 1771 EXPECT_TRUE(bb_view_->GetMenu() == NULL); |
1770 | 1772 |
1771 Done(); | 1773 Done(); |
1772 } | 1774 } |
1773 | 1775 |
1774 ContextMenuNotificationObserver observer_; | 1776 ContextMenuNotificationObserver observer_; |
1775 }; | 1777 }; |
1776 | 1778 |
1777 VIEW_TEST(BookmarkBarViewTest21, ContextMenusForEmptyFolder) | 1779 VIEW_TEST(BookmarkBarViewTest21, ContextMenusForEmptyFolder) |
OLD | NEW |