| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 i < 100 && (test_helper_->GetBookmarkButtonCount() < count || | 78 i < 100 && (test_helper_->GetBookmarkButtonCount() < count || |
| 79 !test_helper_->GetBookmarkButton(count - 1)->visible()); | 79 !test_helper_->GetBookmarkButton(count - 1)->visible()); |
| 80 ++i) { | 80 ++i) { |
| 81 bookmark_bar_view_->SetBounds(0, 0, start_width + i * 10, height); | 81 bookmark_bar_view_->SetBounds(0, 0, start_width + i * 10, height); |
| 82 bookmark_bar_view_->Layout(); | 82 bookmark_bar_view_->Layout(); |
| 83 } | 83 } |
| 84 } | 84 } |
| 85 | 85 |
| 86 void WaitForBookmarkModelToLoad() { | 86 void WaitForBookmarkModelToLoad() { |
| 87 bookmarks::test::WaitForBookmarkModelToLoad( | 87 bookmarks::test::WaitForBookmarkModelToLoad( |
| 88 BookmarkModelFactory::GetForProfile(profile())); | 88 BookmarkModelFactory::GetForBrowserContext(profile())); |
| 89 } | 89 } |
| 90 | 90 |
| 91 // Adds nodes to the bookmark bar node from |string|. See | 91 // Adds nodes to the bookmark bar node from |string|. See |
| 92 // bookmarks::test::AddNodesFromModelString() for details on |string|. | 92 // bookmarks::test::AddNodesFromModelString() for details on |string|. |
| 93 void AddNodesToBookmarkBarFromModelString(const std::string& string) { | 93 void AddNodesToBookmarkBarFromModelString(const std::string& string) { |
| 94 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 94 BookmarkModel* model = |
| 95 BookmarkModelFactory::GetForBrowserContext(profile()); |
| 95 bookmarks::test::AddNodesFromModelString(model, model->bookmark_bar_node(), | 96 bookmarks::test::AddNodesFromModelString(model, model->bookmark_bar_node(), |
| 96 string); | 97 string); |
| 97 } | 98 } |
| 98 // Creates the BookmarkBarView and BookmarkBarViewTestHelper. Generally you'll | 99 // Creates the BookmarkBarView and BookmarkBarViewTestHelper. Generally you'll |
| 99 // want to use CreateBookmarkModelAndBookmarkBarView(), but use this if | 100 // want to use CreateBookmarkModelAndBookmarkBarView(), but use this if |
| 100 // need to create the BookmarkBarView after the model has populated. | 101 // need to create the BookmarkBarView after the model has populated. |
| 101 void CreateBookmarkBarView() { | 102 void CreateBookmarkBarView() { |
| 102 bookmark_bar_view_.reset(new BookmarkBarView(browser(), nullptr)); | 103 bookmark_bar_view_.reset(new BookmarkBarView(browser(), nullptr)); |
| 103 test_helper_.reset(new BookmarkBarViewTestHelper(bookmark_bar_view_.get())); | 104 test_helper_.reset(new BookmarkBarViewTestHelper(bookmark_bar_view_.get())); |
| 104 } | 105 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 0, 0, width_for_one, bookmark_bar_view_->bounds().height()); | 190 0, 0, width_for_one, bookmark_bar_view_->bounds().height()); |
| 190 bookmark_bar_view_->Layout(); | 191 bookmark_bar_view_->Layout(); |
| 191 EXPECT_TRUE(test_helper_->overflow_button()->visible()); | 192 EXPECT_TRUE(test_helper_->overflow_button()->visible()); |
| 192 } | 193 } |
| 193 | 194 |
| 194 // Verifies buttons get added correctly when BookmarkBarView is created after | 195 // Verifies buttons get added correctly when BookmarkBarView is created after |
| 195 // the model and the model has nodes. | 196 // the model and the model has nodes. |
| 196 TEST_F(BookmarkBarViewTest, ButtonsDynamicallyAddedAfterModelHasNodes) { | 197 TEST_F(BookmarkBarViewTest, ButtonsDynamicallyAddedAfterModelHasNodes) { |
| 197 profile()->CreateBookmarkModel(true); | 198 profile()->CreateBookmarkModel(true); |
| 198 WaitForBookmarkModelToLoad(); | 199 WaitForBookmarkModelToLoad(); |
| 199 EXPECT_TRUE(BookmarkModelFactory::GetForProfile(profile())->loaded()); | 200 EXPECT_TRUE(BookmarkModelFactory::GetForBrowserContext(profile())->loaded()); |
| 200 AddNodesToBookmarkBarFromModelString("a b c d e f "); | 201 AddNodesToBookmarkBarFromModelString("a b c d e f "); |
| 201 CreateBookmarkBarView(); | 202 CreateBookmarkBarView(); |
| 202 EXPECT_EQ(0, test_helper_->GetBookmarkButtonCount()); | 203 EXPECT_EQ(0, test_helper_->GetBookmarkButtonCount()); |
| 203 | 204 |
| 204 SizeUntilButtonsVisible(1); | 205 SizeUntilButtonsVisible(1); |
| 205 EXPECT_EQ(2, test_helper_->GetBookmarkButtonCount()); | 206 EXPECT_EQ(2, test_helper_->GetBookmarkButtonCount()); |
| 206 | 207 |
| 207 // Go really big, which should force all buttons to be added. | 208 // Go really big, which should force all buttons to be added. |
| 208 bookmark_bar_view_->SetBounds( | 209 bookmark_bar_view_->SetBounds( |
| 209 0, 0, 5000, bookmark_bar_view_->bounds().height()); | 210 0, 0, 5000, bookmark_bar_view_->bounds().height()); |
| 210 bookmark_bar_view_->Layout(); | 211 bookmark_bar_view_->Layout(); |
| 211 EXPECT_EQ(6, test_helper_->GetBookmarkButtonCount()); | 212 EXPECT_EQ(6, test_helper_->GetBookmarkButtonCount()); |
| 212 } | 213 } |
| 213 | 214 |
| 214 // Verifies buttons are added as the model and size change. | 215 // Verifies buttons are added as the model and size change. |
| 215 TEST_F(BookmarkBarViewTest, ButtonsDynamicallyAdded) { | 216 TEST_F(BookmarkBarViewTest, ButtonsDynamicallyAdded) { |
| 216 CreateBookmarkModelAndBookmarkBarView(); | 217 CreateBookmarkModelAndBookmarkBarView(); |
| 217 EXPECT_TRUE(BookmarkModelFactory::GetForProfile(profile())->loaded()); | 218 EXPECT_TRUE(BookmarkModelFactory::GetForBrowserContext(profile())->loaded()); |
| 218 AddNodesToBookmarkBarFromModelString("a b c d e f "); | 219 AddNodesToBookmarkBarFromModelString("a b c d e f "); |
| 219 EXPECT_EQ(0, test_helper_->GetBookmarkButtonCount()); | 220 EXPECT_EQ(0, test_helper_->GetBookmarkButtonCount()); |
| 220 SizeUntilButtonsVisible(1); | 221 SizeUntilButtonsVisible(1); |
| 221 EXPECT_EQ(2, test_helper_->GetBookmarkButtonCount()); | 222 EXPECT_EQ(2, test_helper_->GetBookmarkButtonCount()); |
| 222 | 223 |
| 223 // Go really big, which should force all buttons to be added. | 224 // Go really big, which should force all buttons to be added. |
| 224 bookmark_bar_view_->SetBounds( | 225 bookmark_bar_view_->SetBounds( |
| 225 0, 0, 5000, bookmark_bar_view_->bounds().height()); | 226 0, 0, 5000, bookmark_bar_view_->bounds().height()); |
| 226 bookmark_bar_view_->Layout(); | 227 bookmark_bar_view_->Layout(); |
| 227 EXPECT_EQ(6, test_helper_->GetBookmarkButtonCount()); | 228 EXPECT_EQ(6, test_helper_->GetBookmarkButtonCount()); |
| 228 } | 229 } |
| 229 | 230 |
| 230 TEST_F(BookmarkBarViewTest, AddNodesWhenBarAlreadySized) { | 231 TEST_F(BookmarkBarViewTest, AddNodesWhenBarAlreadySized) { |
| 231 CreateBookmarkModelAndBookmarkBarView(); | 232 CreateBookmarkModelAndBookmarkBarView(); |
| 232 bookmark_bar_view_->SetBounds( | 233 bookmark_bar_view_->SetBounds( |
| 233 0, 0, 5000, bookmark_bar_view_->bounds().height()); | 234 0, 0, 5000, bookmark_bar_view_->bounds().height()); |
| 234 AddNodesToBookmarkBarFromModelString("a b c d e f "); | 235 AddNodesToBookmarkBarFromModelString("a b c d e f "); |
| 235 bookmark_bar_view_->Layout(); | 236 bookmark_bar_view_->Layout(); |
| 236 EXPECT_EQ("a b c d e f", GetStringForVisibleButtons()); | 237 EXPECT_EQ("a b c d e f", GetStringForVisibleButtons()); |
| 237 } | 238 } |
| 238 | 239 |
| 239 // Various assertions for removing nodes. | 240 // Various assertions for removing nodes. |
| 240 TEST_F(BookmarkBarViewTest, RemoveNode) { | 241 TEST_F(BookmarkBarViewTest, RemoveNode) { |
| 241 CreateBookmarkModelAndBookmarkBarView(); | 242 CreateBookmarkModelAndBookmarkBarView(); |
| 242 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 243 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
| 243 const BookmarkNode* bookmark_bar_node = model->bookmark_bar_node(); | 244 const BookmarkNode* bookmark_bar_node = model->bookmark_bar_node(); |
| 244 AddNodesToBookmarkBarFromModelString("a b c d e f "); | 245 AddNodesToBookmarkBarFromModelString("a b c d e f "); |
| 245 EXPECT_EQ(0, test_helper_->GetBookmarkButtonCount()); | 246 EXPECT_EQ(0, test_helper_->GetBookmarkButtonCount()); |
| 246 SizeUntilButtonsVisible(1); | 247 SizeUntilButtonsVisible(1); |
| 247 EXPECT_EQ(2, test_helper_->GetBookmarkButtonCount()); | 248 EXPECT_EQ(2, test_helper_->GetBookmarkButtonCount()); |
| 248 | 249 |
| 249 // Remove the 2nd node, should still only have 1 visible. | 250 // Remove the 2nd node, should still only have 1 visible. |
| 250 model->Remove(bookmark_bar_node->GetChild(1)); | 251 model->Remove(bookmark_bar_node->GetChild(1)); |
| 251 EXPECT_EQ("a", GetStringForVisibleButtons()); | 252 EXPECT_EQ("a", GetStringForVisibleButtons()); |
| 252 | 253 |
| 253 // Remove the first node, should force a new button (for the 'c' node). | 254 // Remove the first node, should force a new button (for the 'c' node). |
| 254 model->Remove(bookmark_bar_node->GetChild(0)); | 255 model->Remove(bookmark_bar_node->GetChild(0)); |
| 255 ASSERT_EQ("c", GetStringForVisibleButtons()); | 256 ASSERT_EQ("c", GetStringForVisibleButtons()); |
| 256 } | 257 } |
| 257 | 258 |
| 258 // Assertions for moving a node on the bookmark bar. | 259 // Assertions for moving a node on the bookmark bar. |
| 259 TEST_F(BookmarkBarViewTest, MoveNode) { | 260 TEST_F(BookmarkBarViewTest, MoveNode) { |
| 260 CreateBookmarkModelAndBookmarkBarView(); | 261 CreateBookmarkModelAndBookmarkBarView(); |
| 261 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 262 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
| 262 const BookmarkNode* bookmark_bar_node = model->bookmark_bar_node(); | 263 const BookmarkNode* bookmark_bar_node = model->bookmark_bar_node(); |
| 263 AddNodesToBookmarkBarFromModelString("a b c d e f "); | 264 AddNodesToBookmarkBarFromModelString("a b c d e f "); |
| 264 EXPECT_EQ(0, test_helper_->GetBookmarkButtonCount()); | 265 EXPECT_EQ(0, test_helper_->GetBookmarkButtonCount()); |
| 265 | 266 |
| 266 // Move 'c' first resulting in 'c a b d e f'. | 267 // Move 'c' first resulting in 'c a b d e f'. |
| 267 model->Move(bookmark_bar_node->GetChild(2), bookmark_bar_node, 0); | 268 model->Move(bookmark_bar_node->GetChild(2), bookmark_bar_node, 0); |
| 268 EXPECT_EQ(0, test_helper_->GetBookmarkButtonCount()); | 269 EXPECT_EQ(0, test_helper_->GetBookmarkButtonCount()); |
| 269 | 270 |
| 270 // Make enough room for 1 node. | 271 // Make enough room for 1 node. |
| 271 SizeUntilButtonsVisible(1); | 272 SizeUntilButtonsVisible(1); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 283 | 284 |
| 284 // Move 'c' after 'a', resulting in 'a c b d e f'. | 285 // Move 'c' after 'a', resulting in 'a c b d e f'. |
| 285 model->Move(bookmark_bar_node->GetChild(0), bookmark_bar_node, 2); | 286 model->Move(bookmark_bar_node->GetChild(0), bookmark_bar_node, 2); |
| 286 SizeUntilButtonsVisible(2); | 287 SizeUntilButtonsVisible(2); |
| 287 EXPECT_EQ("a c", GetStringForVisibleButtons()); | 288 EXPECT_EQ("a c", GetStringForVisibleButtons()); |
| 288 } | 289 } |
| 289 | 290 |
| 290 // Assertions for changing the title of a node. | 291 // Assertions for changing the title of a node. |
| 291 TEST_F(BookmarkBarViewTest, ChangeTitle) { | 292 TEST_F(BookmarkBarViewTest, ChangeTitle) { |
| 292 CreateBookmarkModelAndBookmarkBarView(); | 293 CreateBookmarkModelAndBookmarkBarView(); |
| 293 BookmarkModel* model = BookmarkModelFactory::GetForProfile(profile()); | 294 BookmarkModel* model = BookmarkModelFactory::GetForBrowserContext(profile()); |
| 294 const BookmarkNode* bookmark_bar_node = model->bookmark_bar_node(); | 295 const BookmarkNode* bookmark_bar_node = model->bookmark_bar_node(); |
| 295 AddNodesToBookmarkBarFromModelString("a b c d e f "); | 296 AddNodesToBookmarkBarFromModelString("a b c d e f "); |
| 296 EXPECT_EQ(0, test_helper_->GetBookmarkButtonCount()); | 297 EXPECT_EQ(0, test_helper_->GetBookmarkButtonCount()); |
| 297 | 298 |
| 298 model->SetTitle(bookmark_bar_node->GetChild(0), base::ASCIIToUTF16("a1")); | 299 model->SetTitle(bookmark_bar_node->GetChild(0), base::ASCIIToUTF16("a1")); |
| 299 EXPECT_EQ(0, test_helper_->GetBookmarkButtonCount()); | 300 EXPECT_EQ(0, test_helper_->GetBookmarkButtonCount()); |
| 300 | 301 |
| 301 // Make enough room for 1 node. | 302 // Make enough room for 1 node. |
| 302 SizeUntilButtonsVisible(1); | 303 SizeUntilButtonsVisible(1); |
| 303 EXPECT_EQ("a1", GetStringForVisibleButtons()); | 304 EXPECT_EQ("a1", GetStringForVisibleButtons()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 prefs->SetManagedPref(bookmarks::prefs::kShowAppsShortcutInBookmarkBar, | 349 prefs->SetManagedPref(bookmarks::prefs::kShowAppsShortcutInBookmarkBar, |
| 349 new base::FundamentalValue(false)); | 350 new base::FundamentalValue(false)); |
| 350 EXPECT_FALSE(test_helper_->apps_page_shortcut()->visible()); | 351 EXPECT_FALSE(test_helper_->apps_page_shortcut()->visible()); |
| 351 | 352 |
| 352 // And try showing it via policy too. | 353 // And try showing it via policy too. |
| 353 prefs->SetManagedPref(bookmarks::prefs::kShowAppsShortcutInBookmarkBar, | 354 prefs->SetManagedPref(bookmarks::prefs::kShowAppsShortcutInBookmarkBar, |
| 354 new base::FundamentalValue(true)); | 355 new base::FundamentalValue(true)); |
| 355 EXPECT_TRUE(test_helper_->apps_page_shortcut()->visible()); | 356 EXPECT_TRUE(test_helper_->apps_page_shortcut()->visible()); |
| 356 } | 357 } |
| 357 #endif | 358 #endif |
| OLD | NEW |