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

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

Issue 2687893002: Clear the text cache when the tooltip text is updated. (Closed)
Patch Set: updated test Created 3 years, 10 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
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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/test/native_widget_factory.h"
34 #include "ui/views/widget/widget.h"
33 35
34 using bookmarks::BookmarkModel; 36 using bookmarks::BookmarkModel;
35 using bookmarks::BookmarkNode; 37 using bookmarks::BookmarkNode;
36 38
37 class BookmarkBarViewTest : public BrowserWithTestWindowTest { 39 class BookmarkBarViewTest : public BrowserWithTestWindowTest {
38 public: 40 public:
39 BookmarkBarViewTest() {} 41 BookmarkBarViewTest() {}
40 42
41 void SetUp() override { 43 void SetUp() override {
42 BrowserWithTestWindowTest::SetUp(); 44 BrowserWithTestWindowTest::SetUp();
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 BookmarkModel* model = 96 BookmarkModel* model =
95 BookmarkModelFactory::GetForBrowserContext(profile()); 97 BookmarkModelFactory::GetForBrowserContext(profile());
96 bookmarks::test::AddNodesFromModelString(model, model->bookmark_bar_node(), 98 bookmarks::test::AddNodesFromModelString(model, model->bookmark_bar_node(),
97 string); 99 string);
98 } 100 }
99 // Creates the BookmarkBarView and BookmarkBarViewTestHelper. Generally you'll 101 // Creates the BookmarkBarView and BookmarkBarViewTestHelper. Generally you'll
100 // want to use CreateBookmarkModelAndBookmarkBarView(), but use this if 102 // want to use CreateBookmarkModelAndBookmarkBarView(), but use this if
101 // need to create the BookmarkBarView after the model has populated. 103 // need to create the BookmarkBarView after the model has populated.
102 void CreateBookmarkBarView() { 104 void CreateBookmarkBarView() {
103 bookmark_bar_view_.reset(new BookmarkBarView(browser(), nullptr)); 105 bookmark_bar_view_.reset(new BookmarkBarView(browser(), nullptr));
106 bookmark_bar_view_->set_owned_by_client();
104 test_helper_.reset(new BookmarkBarViewTestHelper(bookmark_bar_view_.get())); 107 test_helper_.reset(new BookmarkBarViewTestHelper(bookmark_bar_view_.get()));
105 } 108 }
106 109
107 // Creates the model, blocking until it loads, then creates the 110 // Creates the model, blocking until it loads, then creates the
108 // BookmarkBarView. 111 // BookmarkBarView.
109 void CreateBookmarkModelAndBookmarkBarView() { 112 void CreateBookmarkModelAndBookmarkBarView() {
110 profile()->CreateBookmarkModel(true); 113 profile()->CreateBookmarkModel(true);
111 WaitForBookmarkModelToLoad(); 114 WaitForBookmarkModelToLoad();
112 CreateBookmarkBarView(); 115 CreateBookmarkBarView();
113 } 116 }
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 prefs->SetManagedPref(bookmarks::prefs::kShowAppsShortcutInBookmarkBar, 352 prefs->SetManagedPref(bookmarks::prefs::kShowAppsShortcutInBookmarkBar,
350 new base::FundamentalValue(false)); 353 new base::FundamentalValue(false));
351 EXPECT_FALSE(test_helper_->apps_page_shortcut()->visible()); 354 EXPECT_FALSE(test_helper_->apps_page_shortcut()->visible());
352 355
353 // And try showing it via policy too. 356 // And try showing it via policy too.
354 prefs->SetManagedPref(bookmarks::prefs::kShowAppsShortcutInBookmarkBar, 357 prefs->SetManagedPref(bookmarks::prefs::kShowAppsShortcutInBookmarkBar,
355 new base::FundamentalValue(true)); 358 new base::FundamentalValue(true));
356 EXPECT_TRUE(test_helper_->apps_page_shortcut()->visible()); 359 EXPECT_TRUE(test_helper_->apps_page_shortcut()->visible());
357 } 360 }
358 #endif 361 #endif
362
363 TEST_F(BookmarkBarViewTest, UpdateTooltipText) {
364 CreateBookmarkModelAndBookmarkBarView();
365 // Create a widget who creates and owns a views::ToolipManager.
366 views::Widget widget;
367 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW);
368 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
369 params.native_widget = views::test::CreatePlatformDesktopNativeWidgetImpl(
370 params, &widget, nullptr);
oshima 2017/02/17 17:30:25 looks like this is how views unit test should do f
371 widget.Init(params);
372 widget.Show();
373 widget.GetRootView()->AddChildView(bookmark_bar_view_.get());
374
375 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile());
376 bookmarks::test::AddNodesFromModelString(model, model->bookmark_bar_node(),
377 "a b");
378 SizeUntilButtonsVisible(1);
379 ASSERT_EQ(1, test_helper_->GetBookmarkButtonCount());
380
381 views::LabelButton* button = test_helper_->GetBookmarkButton(0);
382 ASSERT_TRUE(button);
383 gfx::Point p;
384 base::string16 text;
385 button->GetTooltipText(p, &text);
386 EXPECT_EQ(base::ASCIIToUTF16("a\na.com"), text);
387 button->SetText(base::ASCIIToUTF16("new title"));
388 button->GetTooltipText(p, &text);
389 EXPECT_EQ(base::ASCIIToUTF16("new title\na.com"), text);
390
391 widget.CloseNow();
392 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/bookmarks/bookmark_bar_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698