Chromium Code Reviews| 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/bookmarks/bookmark_bar_view.h" | 5 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 #include "components/bookmarks/browser/bookmark_model.h" | 23 #include "components/bookmarks/browser/bookmark_model.h" |
| 24 #include "components/bookmarks/common/bookmark_pref_names.h" | 24 #include "components/bookmarks/common/bookmark_pref_names.h" |
| 25 #include "components/bookmarks/test/bookmark_test_helpers.h" | 25 #include "components/bookmarks/test/bookmark_test_helpers.h" |
| 26 #include "components/prefs/pref_service.h" | 26 #include "components/prefs/pref_service.h" |
| 27 #include "components/search_engines/search_terms_data.h" | 27 #include "components/search_engines/search_terms_data.h" |
| 28 #include "components/search_engines/template_url_service.h" | 28 #include "components/search_engines/template_url_service.h" |
| 29 #include "components/search_engines/template_url_service_client.h" | 29 #include "components/search_engines/template_url_service_client.h" |
| 30 #include "components/sync_preferences/testing_pref_service_syncable.h" | 30 #include "components/sync_preferences/testing_pref_service_syncable.h" |
| 31 #include "ui/views/controls/button/label_button.h" | 31 #include "ui/views/controls/button/label_button.h" |
| 32 #include "ui/views/controls/button/menu_button.h" | 32 #include "ui/views/controls/button/menu_button.h" |
| 33 #include "ui/views/widget/widget.h" | |
| 34 | |
| 35 #if !defined(USE_ASH) | |
| 36 #include "ui/views/test/scoped_views_test_helper.h" | |
| 37 #include "ui/views/test/test_views_delegate.h" | |
| 38 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | |
| 39 #endif | |
| 33 | 40 |
| 34 using bookmarks::BookmarkModel; | 41 using bookmarks::BookmarkModel; |
| 35 using bookmarks::BookmarkNode; | 42 using bookmarks::BookmarkNode; |
| 36 | 43 |
| 37 class BookmarkBarViewTest : public BrowserWithTestWindowTest { | 44 class BookmarkBarViewTest : public BrowserWithTestWindowTest { |
| 38 public: | 45 public: |
| 39 BookmarkBarViewTest() {} | 46 BookmarkBarViewTest() {} |
| 40 | 47 |
| 41 void SetUp() override { | 48 void SetUp() override { |
| 42 BrowserWithTestWindowTest::SetUp(); | 49 BrowserWithTestWindowTest::SetUp(); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 BookmarkModel* model = | 101 BookmarkModel* model = |
| 95 BookmarkModelFactory::GetForBrowserContext(profile()); | 102 BookmarkModelFactory::GetForBrowserContext(profile()); |
| 96 bookmarks::test::AddNodesFromModelString(model, model->bookmark_bar_node(), | 103 bookmarks::test::AddNodesFromModelString(model, model->bookmark_bar_node(), |
| 97 string); | 104 string); |
| 98 } | 105 } |
| 99 // Creates the BookmarkBarView and BookmarkBarViewTestHelper. Generally you'll | 106 // Creates the BookmarkBarView and BookmarkBarViewTestHelper. Generally you'll |
| 100 // want to use CreateBookmarkModelAndBookmarkBarView(), but use this if | 107 // want to use CreateBookmarkModelAndBookmarkBarView(), but use this if |
| 101 // need to create the BookmarkBarView after the model has populated. | 108 // need to create the BookmarkBarView after the model has populated. |
| 102 void CreateBookmarkBarView() { | 109 void CreateBookmarkBarView() { |
| 103 bookmark_bar_view_.reset(new BookmarkBarView(browser(), nullptr)); | 110 bookmark_bar_view_.reset(new BookmarkBarView(browser(), nullptr)); |
| 111 bookmark_bar_view_->set_owned_by_client(); | |
| 104 test_helper_.reset(new BookmarkBarViewTestHelper(bookmark_bar_view_.get())); | 112 test_helper_.reset(new BookmarkBarViewTestHelper(bookmark_bar_view_.get())); |
| 105 } | 113 } |
| 106 | 114 |
| 107 // Creates the model, blocking until it loads, then creates the | 115 // Creates the model, blocking until it loads, then creates the |
| 108 // BookmarkBarView. | 116 // BookmarkBarView. |
| 109 void CreateBookmarkModelAndBookmarkBarView() { | 117 void CreateBookmarkModelAndBookmarkBarView() { |
| 110 profile()->CreateBookmarkModel(true); | 118 profile()->CreateBookmarkModel(true); |
| 111 WaitForBookmarkModelToLoad(); | 119 WaitForBookmarkModelToLoad(); |
| 112 CreateBookmarkBarView(); | 120 CreateBookmarkBarView(); |
| 113 } | 121 } |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 349 prefs->SetManagedPref(bookmarks::prefs::kShowAppsShortcutInBookmarkBar, | 357 prefs->SetManagedPref(bookmarks::prefs::kShowAppsShortcutInBookmarkBar, |
| 350 new base::FundamentalValue(false)); | 358 new base::FundamentalValue(false)); |
| 351 EXPECT_FALSE(test_helper_->apps_page_shortcut()->visible()); | 359 EXPECT_FALSE(test_helper_->apps_page_shortcut()->visible()); |
| 352 | 360 |
| 353 // And try showing it via policy too. | 361 // And try showing it via policy too. |
| 354 prefs->SetManagedPref(bookmarks::prefs::kShowAppsShortcutInBookmarkBar, | 362 prefs->SetManagedPref(bookmarks::prefs::kShowAppsShortcutInBookmarkBar, |
| 355 new base::FundamentalValue(true)); | 363 new base::FundamentalValue(true)); |
| 356 EXPECT_TRUE(test_helper_->apps_page_shortcut()->visible()); | 364 EXPECT_TRUE(test_helper_->apps_page_shortcut()->visible()); |
| 357 } | 365 } |
| 358 #endif | 366 #endif |
| 367 | |
| 368 TEST_F(BookmarkBarViewTest, UpdateTooltipText) { | |
|
sky
2017/02/14 17:58:04
Would it make more sense to have this test extend
| |
| 369 #if !defined(USE_ASH) | |
| 370 // Setup environment for desktop aura. | |
| 371 std::unique_ptr<views::TestViewsDelegate> views_delegate_for_setup = | |
| 372 base::MakeUnique<views::TestViewsDelegate>(); | |
| 373 views::ScopedViewsTestHelper helper(std::move(views_delegate_for_setup)); | |
|
oshima
2017/02/14 05:14:33
Looks like I need to set up these for desktop aura
| |
| 374 #endif | |
| 375 CreateBookmarkModelAndBookmarkBarView(); | |
| 376 // Create a widget who creates and owns a views::ToolipManager. | |
| 377 views::Widget widget; | |
| 378 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | |
| 379 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
| 380 #if !defined(USE_ASH) | |
| 381 params.native_widget = new views::DesktopNativeWidgetAura(&widget); | |
| 382 params.context = helper.GetContext(); | |
| 383 #endif | |
| 384 widget.Init(params); | |
| 385 widget.Show(); | |
| 386 | |
| 387 widget.GetRootView()->AddChildView(bookmark_bar_view_.get()); | |
| 388 | |
| 389 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); | |
| 390 bookmarks::test::AddNodesFromModelString(model, model->bookmark_bar_node(), | |
| 391 "a b"); | |
| 392 SizeUntilButtonsVisible(1); | |
| 393 ASSERT_EQ(1, test_helper_->GetBookmarkButtonCount()); | |
| 394 | |
| 395 views::LabelButton* button = test_helper_->GetBookmarkButton(0); | |
| 396 ASSERT_TRUE(button); | |
| 397 gfx::Point p; | |
| 398 base::string16 text; | |
| 399 button->GetTooltipText(p, &text); | |
| 400 EXPECT_EQ(base::ASCIIToUTF16("a\na.com"), text); | |
| 401 button->SetText(base::ASCIIToUTF16("new title")); | |
| 402 button->GetTooltipText(p, &text); | |
| 403 EXPECT_EQ(base::ASCIIToUTF16("new title\na.com"), text); | |
| 404 } | |
| OLD | NEW |