Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(755)

Side by Side Diff: chrome/browser/ui/views/bookmarks/bookmark_bar_view_test.cc

Issue 7574021: Remove frontend code that allows for dynamic profile setting, and read the profile off the browse... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 browser_->CloseAllTabs();
225 bb_view_.reset();
226 browser_.reset();
227 profile_.reset();
228 MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask);
sky 2011/08/08 16:02:29 Please add a comment as to why you need to do quit
Peter Kasting 2011/08/08 17:52:07 Sure.
229 MessageLoop::current()->Run();
220 ViewEventTestBase::TearDown(); 230 ViewEventTestBase::TearDown();
221 BookmarkBarView::testing_ = false; 231 BookmarkBarView::testing_ = false;
222 views::ViewsDelegate::views_delegate = NULL; 232 views::ViewsDelegate::views_delegate = NULL;
223 } 233 }
224 234
225 protected: 235 protected:
226 void InstallViewsDelegate() { 236 void InstallViewsDelegate() {
227 views::ViewsDelegate::views_delegate = &views_delegate_; 237 views::ViewsDelegate::views_delegate = &views_delegate_;
228 } 238 }
229 239
230 virtual views::View* CreateContentsView() { 240 virtual views::View* CreateContentsView() {
231 return bb_view_; 241 return bb_view_.get();
232 } 242 }
233 243
234 virtual gfx::Size GetPreferredSize() { return bb_view_pref_; } 244 virtual gfx::Size GetPreferredSize() { return bb_view_pref_; }
235 245
236 views::TextButton* GetBookmarkButton(int view_index) { 246 views::TextButton* GetBookmarkButton(int view_index) {
237 return bb_view_->GetBookmarkButton(view_index); 247 return bb_view_->GetBookmarkButton(view_index);
238 } 248 }
239 249
240 // See comment above class description for what this does. 250 // See comment above class description for what this does.
241 virtual bool CreateBigMenu() { return false; } 251 virtual bool CreateBigMenu() { return false; }
242 252
243 BookmarkModel* model_; 253 BookmarkModel* model_;
244 BookmarkBarView* bb_view_; 254 scoped_ptr<BookmarkBarView> bb_view_;
245 TestingPageNavigator navigator_; 255 TestingPageNavigator navigator_;
246 256
247 private: 257 private:
248 void AddTestData(bool big_menu) { 258 void AddTestData(bool big_menu) {
249 const BookmarkNode* bb_node = model_->bookmark_bar_node(); 259 const BookmarkNode* bb_node = model_->bookmark_bar_node();
250 std::string test_base = "file:///c:/tmp/"; 260 std::string test_base = "file:///c:/tmp/";
251 const BookmarkNode* f1 = model_->AddFolder(bb_node, 0, ASCIIToUTF16("F1")); 261 const BookmarkNode* f1 = model_->AddFolder(bb_node, 0, ASCIIToUTF16("F1"));
252 model_->AddURL(f1, 0, ASCIIToUTF16("f1a"), GURL(test_base + "f1a")); 262 model_->AddURL(f1, 0, ASCIIToUTF16("f1a"), GURL(test_base + "f1a"));
253 const BookmarkNode* f11 = model_->AddFolder(f1, 1, ASCIIToUTF16("F11")); 263 const BookmarkNode* f11 = model_->AddFolder(f1, 1, ASCIIToUTF16("F11"));
254 model_->AddURL(f11, 0, ASCIIToUTF16("f11a"), GURL(test_base + "f11a")); 264 model_->AddURL(f11, 0, ASCIIToUTF16("f11a"), GURL(test_base + "f11a"));
(...skipping 13 matching lines...) Expand all
268 ASCIIToUTF16("OF")); 278 ASCIIToUTF16("OF"));
269 model_->AddURL(of, 0, ASCIIToUTF16("ofa"), GURL(test_base + "ofa")); 279 model_->AddURL(of, 0, ASCIIToUTF16("ofa"), GURL(test_base + "ofa"));
270 model_->AddURL(of, 1, ASCIIToUTF16("ofb"), GURL(test_base + "ofb")); 280 model_->AddURL(of, 1, ASCIIToUTF16("ofb"), GURL(test_base + "ofb"));
271 const BookmarkNode* of2 = model_->AddFolder(model_->other_node(), 2, 281 const BookmarkNode* of2 = model_->AddFolder(model_->other_node(), 2,
272 ASCIIToUTF16("OF2")); 282 ASCIIToUTF16("OF2"));
273 model_->AddURL(of2, 0, ASCIIToUTF16("of2a"), GURL(test_base + "of2a")); 283 model_->AddURL(of2, 0, ASCIIToUTF16("of2a"), GURL(test_base + "of2a"));
274 model_->AddURL(of2, 1, ASCIIToUTF16("of2b"), GURL(test_base + "of2b")); 284 model_->AddURL(of2, 1, ASCIIToUTF16("of2b"), GURL(test_base + "of2b"));
275 } 285 }
276 286
277 gfx::Size bb_view_pref_; 287 gfx::Size bb_view_pref_;
288 ScopedTestingBrowserProcess testing_browser_process_;
278 scoped_ptr<TestingProfile> profile_; 289 scoped_ptr<TestingProfile> profile_;
290 scoped_ptr<Browser> browser_;
279 BrowserThread ui_thread_; 291 BrowserThread ui_thread_;
280 BrowserThread file_thread_; 292 BrowserThread file_thread_;
281 ViewsDelegateImpl views_delegate_; 293 ViewsDelegateImpl views_delegate_;
282 }; 294 };
283 295
284 // Clicks on first menu, makes sure button is depressed. Moves mouse to first 296 // Clicks on first menu, makes sure button is depressed. Moves mouse to first
285 // child, clicks it and makes sure a navigation occurs. 297 // child, clicks it and makes sure a navigation occurs.
286 class BookmarkBarViewTest1 : public BookmarkBarViewEventTestBase { 298 class BookmarkBarViewTest1 : public BookmarkBarViewEventTestBase {
287 protected: 299 protected:
288 virtual void DoTestOnMessageLoop() { 300 virtual void DoTestOnMessageLoop() {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 void Step2() { 363 void Step2() {
352 // Menu should be showing. 364 // Menu should be showing.
353 views::MenuItemView* menu = bb_view_->GetMenu(); 365 views::MenuItemView* menu = bb_view_->GetMenu();
354 ASSERT_TRUE(menu != NULL && menu->GetSubmenu()->IsShowing()); 366 ASSERT_TRUE(menu != NULL && menu->GetSubmenu()->IsShowing());
355 367
356 // Click on 0x0, which should trigger closing menu. 368 // Click on 0x0, which should trigger closing menu.
357 // NOTE: this code assume there is a left margin, which is currently 369 // 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 370 // true. If that changes, this code will need to find another empty space
359 // to press the mouse on. 371 // to press the mouse on.
360 gfx::Point mouse_loc; 372 gfx::Point mouse_loc;
361 views::View::ConvertPointToScreen(bb_view_, &mouse_loc); 373 views::View::ConvertPointToScreen(bb_view_.get(), &mouse_loc);
362 ui_controls::SendMouseMove(0, 0); 374 ui_controls::SendMouseMove(0, 0);
363 ui_controls::SendMouseEventsNotifyWhenDone( 375 ui_controls::SendMouseEventsNotifyWhenDone(
364 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP, 376 ui_controls::LEFT, ui_controls::DOWN | ui_controls::UP,
365 CreateEventTask(this, &BookmarkBarViewTest2::Step3)); 377 CreateEventTask(this, &BookmarkBarViewTest2::Step3));
366 } 378 }
367 379
368 void Step3() { 380 void Step3() {
369 // The menu shouldn't be showing. 381 // The menu shouldn't be showing.
370 views::MenuItemView* menu = bb_view_->GetMenu(); 382 views::MenuItemView* menu = bb_view_->GetMenu();
371 ASSERT_TRUE(menu == NULL || !menu->GetSubmenu()->IsShowing()); 383 ASSERT_TRUE(menu == NULL || !menu->GetSubmenu()->IsShowing());
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after
1036 views::MenuItemView* menu = bb_view_->GetContextMenu(); 1048 views::MenuItemView* menu = bb_view_->GetContextMenu();
1037 ASSERT_TRUE(!menu || !menu->GetSubmenu() || 1049 ASSERT_TRUE(!menu || !menu->GetSubmenu() ||
1038 !menu->GetSubmenu()->IsShowing()); 1050 !menu->GetSubmenu()->IsShowing());
1039 1051
1040 // But the menu should be showing. 1052 // But the menu should be showing.
1041 menu = bb_view_->GetMenu(); 1053 menu = bb_view_->GetMenu();
1042 ASSERT_TRUE(menu && menu->GetSubmenu() && menu->GetSubmenu()->IsShowing()); 1054 ASSERT_TRUE(menu && menu->GetSubmenu() && menu->GetSubmenu()->IsShowing());
1043 1055
1044 // Now click on empty space. 1056 // Now click on empty space.
1045 gfx::Point mouse_loc; 1057 gfx::Point mouse_loc;
1046 views::View::ConvertPointToScreen(bb_view_, &mouse_loc); 1058 views::View::ConvertPointToScreen(bb_view_.get(), &mouse_loc);
1047 ui_controls::SendMouseMove(mouse_loc.x(), mouse_loc.y()); 1059 ui_controls::SendMouseMove(mouse_loc.x(), mouse_loc.y());
1048 ui_controls::SendMouseEventsNotifyWhenDone( 1060 ui_controls::SendMouseEventsNotifyWhenDone(
1049 ui_controls::LEFT, ui_controls::UP | ui_controls::DOWN, 1061 ui_controls::LEFT, ui_controls::UP | ui_controls::DOWN,
1050 CreateEventTask(this, &BookmarkBarViewTest11::Step5)); 1062 CreateEventTask(this, &BookmarkBarViewTest11::Step5));
1051 } 1063 }
1052 1064
1053 void Step5() { 1065 void Step5() {
1054 // Make sure the menu is not showing. 1066 // Make sure the menu is not showing.
1055 views::MenuItemView* menu = bb_view_->GetMenu(); 1067 views::MenuItemView* menu = bb_view_->GetMenu();
1056 ASSERT_TRUE(!menu || !menu->GetSubmenu() || 1068 ASSERT_TRUE(!menu || !menu->GetSubmenu() ||
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
1561 ASSERT_TRUE(menu != NULL); 1573 ASSERT_TRUE(menu != NULL);
1562 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); 1574 ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
1563 1575
1564 menu->GetMenuController()->CancelAll(); 1576 menu->GetMenuController()->CancelAll();
1565 1577
1566 Done(); 1578 Done();
1567 } 1579 }
1568 }; 1580 };
1569 1581
1570 VIEW_TEST(BookmarkBarViewTest19, SiblingMenu) 1582 VIEW_TEST(BookmarkBarViewTest19, SiblingMenu)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698