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

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

Issue 10143001: Work in progress: Adds MessagePumpDispatcher::ShouldExit(). This is used to handle the (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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
« no previous file with comments | « base/message_pump_glib.cc ('k') | chrome/browser/ui/views/simple_message_box_views.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/string_number_conversions.h" 8 #include "base/string_number_conversions.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/app/chrome_command_ids.h" 10 #include "chrome/app/chrome_command_ids.h"
11 #include "chrome/browser/bookmarks/bookmark_model.h" 11 #include "chrome/browser/bookmarks/bookmark_model.h"
12 #include "chrome/browser/bookmarks/bookmark_utils.h" 12 #include "chrome/browser/bookmarks/bookmark_utils.h"
13 #include "chrome/browser/prefs/pref_service.h" 13 #include "chrome/browser/prefs/pref_service.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_window.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/common/chrome_notification_types.h" 18 #include "chrome/common/chrome_notification_types.h"
18 #include "chrome/common/pref_names.h" 19 #include "chrome/common/pref_names.h"
19 #include "chrome/test/base/testing_browser_process.h" 20 #include "chrome/test/base/testing_browser_process.h"
20 #include "chrome/test/base/testing_profile.h" 21 #include "chrome/test/base/testing_profile.h"
21 #include "chrome/test/base/ui_test_utils.h" 22 #include "chrome/test/base/ui_test_utils.h"
22 #include "chrome/test/base/view_event_test_base.h" 23 #include "chrome/test/base/view_event_test_base.h"
23 #include "content/public/browser/notification_service.h" 24 #include "content/public/browser/notification_service.h"
24 #include "content/public/browser/page_navigator.h" 25 #include "content/public/browser/page_navigator.h"
25 #include "content/test/test_browser_thread.h" 26 #include "content/test/test_browser_thread.h"
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 profile_->CreateBookmarkModel(true); 183 profile_->CreateBookmarkModel(true);
183 profile_->BlockUntilBookmarkModelLoaded(); 184 profile_->BlockUntilBookmarkModelLoaded();
184 profile_->GetPrefs()->SetBoolean(prefs::kShowBookmarkBar, true); 185 profile_->GetPrefs()->SetBoolean(prefs::kShowBookmarkBar, true);
185 186
186 browser_.reset(new Browser(Browser::TYPE_TABBED, profile_.get())); 187 browser_.reset(new Browser(Browser::TYPE_TABBED, profile_.get()));
187 188
188 model_ = profile_->GetBookmarkModel(); 189 model_ = profile_->GetBookmarkModel();
189 model_->ClearStore(); 190 model_->ClearStore();
190 191
191 bb_view_.reset(new BookmarkBarView(browser_.get())); 192 bb_view_.reset(new BookmarkBarView(browser_.get()));
193 bb_view_->set_parent_owned(false);
192 bb_view_->SetPageNavigator(&navigator_); 194 bb_view_->SetPageNavigator(&navigator_);
193 195
194 AddTestData(CreateBigMenu()); 196 AddTestData(CreateBigMenu());
195 197
196 // Calculate the preferred size so that one button doesn't fit, which 198 // Calculate the preferred size so that one button doesn't fit, which
197 // triggers the overflow button to appear. 199 // triggers the overflow button to appear.
198 // 200 //
199 // BookmarkBarView::Layout does nothing if the parent is NULL and 201 // BookmarkBarView::Layout does nothing if the parent is NULL and
200 // GetPreferredSize hard codes a width of 1. For that reason we add the 202 // GetPreferredSize hard codes a width of 1. For that reason we add the
201 // BookmarkBarView to a dumby view as the parent. 203 // BookmarkBarView to a dumby view as the parent.
(...skipping 13 matching lines...) Expand all
215 bb_view_->SetBounds(0, 0, bb_view_pref_.width(), bb_view_pref_.height()); 217 bb_view_->SetBounds(0, 0, bb_view_pref_.width(), bb_view_pref_.height());
216 bb_view_->Layout(); 218 bb_view_->Layout();
217 } 219 }
218 220
219 tmp_parent.RemoveChildView(bb_view_.get()); 221 tmp_parent.RemoveChildView(bb_view_.get());
220 222
221 ViewEventTestBase::SetUp(); 223 ViewEventTestBase::SetUp();
222 } 224 }
223 225
224 virtual void TearDown() { 226 virtual void TearDown() {
225 // Destroy everything, then run the message loop to ensure we delete all 227 DestroyBrowser();
226 // Tasks and fully shut down.
227 browser_->CloseAllTabs();
228 bb_view_.reset();
229 browser_.reset();
230 profile_.reset(); 228 profile_.reset();
229
230 // Run the message loop to ensure we delete allTasks and fully shut down.
231 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 231 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure());
232 MessageLoop::current()->Run(); 232 MessageLoop::current()->Run();
233 233
234 ViewEventTestBase::TearDown(); 234 ViewEventTestBase::TearDown();
235 BookmarkBarView::testing_ = false; 235 BookmarkBarView::testing_ = false;
236 views::ViewsDelegate::views_delegate = NULL; 236 views::ViewsDelegate::views_delegate = NULL;
237 } 237 }
238 238
239 protected: 239 protected:
240 void InstallViewsDelegate() { 240 void InstallViewsDelegate() {
241 views::ViewsDelegate::views_delegate = &views_delegate_; 241 views::ViewsDelegate::views_delegate = &views_delegate_;
242 } 242 }
243 243
244 virtual views::View* CreateContentsView() { 244 virtual views::View* CreateContentsView() {
245 return bb_view_.get(); 245 return bb_view_.get();
246 } 246 }
247 247
248 virtual gfx::Size GetPreferredSize() { return bb_view_pref_; } 248 virtual gfx::Size GetPreferredSize() { return bb_view_pref_; }
249 249
250 views::TextButton* GetBookmarkButton(int view_index) { 250 views::TextButton* GetBookmarkButton(int view_index) {
251 return bb_view_->GetBookmarkButton(view_index); 251 return bb_view_->GetBookmarkButton(view_index);
252 } 252 }
253 253
254 void DestroyBrowser() {
255 if (!browser_.get())
256 return;
257
258 browser_->CloseAllTabs();
259 bb_view_.reset();
260 browser_.reset();
261 }
262
254 // See comment above class description for what this does. 263 // See comment above class description for what this does.
255 virtual bool CreateBigMenu() { return false; } 264 virtual bool CreateBigMenu() { return false; }
256 265
266 Browser* browser() { return browser_.get(); }
267
257 BookmarkModel* model_; 268 BookmarkModel* model_;
258 scoped_ptr<BookmarkBarView> bb_view_; 269 scoped_ptr<BookmarkBarView> bb_view_;
259 TestingPageNavigator navigator_; 270 TestingPageNavigator navigator_;
260 271
261 private: 272 private:
262 void AddTestData(bool big_menu) { 273 void AddTestData(bool big_menu) {
263 const BookmarkNode* bb_node = model_->bookmark_bar_node(); 274 const BookmarkNode* bb_node = model_->bookmark_bar_node();
264 std::string test_base = "file:///c:/tmp/"; 275 std::string test_base = "file:///c:/tmp/";
265 const BookmarkNode* f1 = model_->AddFolder(bb_node, 0, ASCIIToUTF16("F1")); 276 const BookmarkNode* f1 = model_->AddFolder(bb_node, 0, ASCIIToUTF16("F1"));
266 model_->AddURL(f1, 0, ASCIIToUTF16("f1a"), GURL(test_base + "f1a")); 277 model_->AddURL(f1, 0, ASCIIToUTF16("f1a"), GURL(test_base + "f1a"));
(...skipping 1317 matching lines...) Expand 10 before | Expand all | Expand 10 after
1584 ASSERT_TRUE(menu != NULL); 1595 ASSERT_TRUE(menu != NULL);
1585 ASSERT_TRUE(menu->GetSubmenu()->IsShowing()); 1596 ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
1586 1597
1587 menu->GetMenuController()->CancelAll(); 1598 menu->GetMenuController()->CancelAll();
1588 1599
1589 Done(); 1600 Done();
1590 } 1601 }
1591 }; 1602 };
1592 1603
1593 VIEW_TEST(BookmarkBarViewTest19, SiblingMenu) 1604 VIEW_TEST(BookmarkBarViewTest19, SiblingMenu)
1605
1606 // Verifies mousing over an already open sibling menu doesn't prematurely cancel
1607 // the menu.
1608 class BookmarkBarViewTest20 : public BookmarkBarViewEventTestBase {
1609 public:
1610 BookmarkBarViewTest20() {}
1611
1612 protected:
1613 virtual void DoTestOnMessageLoop() OVERRIDE {
1614 // Press the mouse button on the overflow button. Don't release it though.
1615 /*
1616 views::TextButton* button = bb_view_->overflow_button();
1617 ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT,
1618 ui_controls::DOWN, CreateEventTask(this,
1619 &BookmarkBarViewTest20::Step2));
1620 */
1621 views::TextButton* button = bb_view_->other_bookmarked_button();
1622 ui_test_utils::MoveMouseToCenterAndPress(button, ui_controls::LEFT,
1623 ui_controls::DOWN | ui_controls::UP,
1624 CreateEventTask(this, &BookmarkBarViewTest20::Step2));
1625 }
1626
1627 private:
1628 void Step2() {
1629 printf("menu showing\n");
1630 // Menu should be showing.
1631 views::MenuItemView* menu = bb_view_->GetMenu();
1632 ASSERT_TRUE(menu != NULL);
1633 ASSERT_TRUE(menu->GetSubmenu()->IsShowing());
1634
1635 // Destroy the window.
1636 window_->Close();
1637 window_ = NULL;
1638
1639 MessageLoop::current()->PostTask(
1640 FROM_HERE, CreateEventTask(this, &BookmarkBarViewTest12::Done));
1641 }
1642
1643 DISALLOW_COPY_AND_ASSIGN(BookmarkBarViewTest20);
1644 };
1645
1646 VIEW_TEST(BookmarkBarViewTest20, DestroyBrowserWhileMenuRunning)
OLDNEW
« no previous file with comments | « base/message_pump_glib.cc ('k') | chrome/browser/ui/views/simple_message_box_views.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698