Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/bookmarks/browser/bookmark_model.h" | 5 #include "components/bookmarks/browser/bookmark_model.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/base_paths.h" | 10 #include "base/base_paths.h" |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 void AssertExtensiveChangesObserverCount( | 260 void AssertExtensiveChangesObserverCount( |
| 261 int extensive_changes_beginning_count, | 261 int extensive_changes_beginning_count, |
| 262 int extensive_changes_ended_count) { | 262 int extensive_changes_ended_count) { |
| 263 EXPECT_EQ(extensive_changes_beginning_count_, | 263 EXPECT_EQ(extensive_changes_beginning_count_, |
| 264 extensive_changes_beginning_count); | 264 extensive_changes_beginning_count); |
| 265 EXPECT_EQ(extensive_changes_ended_count_, extensive_changes_ended_count); | 265 EXPECT_EQ(extensive_changes_ended_count_, extensive_changes_ended_count); |
| 266 } | 266 } |
| 267 | 267 |
| 268 int AllNodesRemovedObserverCount() const { return all_bookmarks_removed_; } | 268 int AllNodesRemovedObserverCount() const { return all_bookmarks_removed_; } |
| 269 | 269 |
| 270 void ResetModel() { | |
| 271 model_->RemoveObserver(this); | |
| 272 model_ = client_.CreateModel(false); | |
| 273 model_->AddObserver(this); | |
| 274 ClearCounts(); | |
| 275 } | |
| 276 | |
| 270 protected: | 277 protected: |
| 271 test::TestBookmarkClient client_; | 278 test::TestBookmarkClient client_; |
| 272 scoped_ptr<BookmarkModel> model_; | 279 scoped_ptr<BookmarkModel> model_; |
| 273 ObserverDetails observer_details_; | 280 ObserverDetails observer_details_; |
| 274 | 281 |
| 275 private: | 282 private: |
| 276 int added_count_; | 283 int added_count_; |
| 277 int moved_count_; | 284 int moved_count_; |
| 278 int removed_count_; | 285 int removed_count_; |
| 279 int changed_count_; | 286 int changed_count_; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 const GURL url("http://foo.com"); | 323 const GURL url("http://foo.com"); |
| 317 | 324 |
| 318 const BookmarkNode* new_node = model_->AddURL(root, 0, title, url); | 325 const BookmarkNode* new_node = model_->AddURL(root, 0, title, url); |
| 319 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); | 326 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); |
| 320 observer_details_.ExpectEquals(root, NULL, 0, -1); | 327 observer_details_.ExpectEquals(root, NULL, 0, -1); |
| 321 | 328 |
| 322 ASSERT_EQ(1, root->child_count()); | 329 ASSERT_EQ(1, root->child_count()); |
| 323 ASSERT_EQ(title, new_node->GetTitle()); | 330 ASSERT_EQ(title, new_node->GetTitle()); |
| 324 ASSERT_TRUE(url == new_node->url()); | 331 ASSERT_TRUE(url == new_node->url()); |
| 325 ASSERT_EQ(BookmarkNode::URL, new_node->type()); | 332 ASSERT_EQ(BookmarkNode::URL, new_node->type()); |
| 326 ASSERT_TRUE(new_node == model_->GetMostRecentlyAddedNodeForURL(url)); | 333 ASSERT_TRUE(new_node == model_->GetMostRecentlyAddedUserNodeForURL(url)); |
| 327 | 334 |
| 328 EXPECT_TRUE(new_node->id() != root->id() && | 335 EXPECT_TRUE(new_node->id() != root->id() && |
| 329 new_node->id() != model_->other_node()->id() && | 336 new_node->id() != model_->other_node()->id() && |
| 330 new_node->id() != model_->mobile_node()->id()); | 337 new_node->id() != model_->mobile_node()->id()); |
| 331 } | 338 } |
| 332 | 339 |
| 333 TEST_F(BookmarkModelTest, AddURLWithUnicodeTitle) { | 340 TEST_F(BookmarkModelTest, AddURLWithUnicodeTitle) { |
| 334 const BookmarkNode* root = model_->bookmark_bar_node(); | 341 const BookmarkNode* root = model_->bookmark_bar_node(); |
| 335 const base::string16 title(base::WideToUTF16( | 342 const base::string16 title(base::WideToUTF16( |
| 336 L"\u767e\u5ea6\u4e00\u4e0b\uff0c\u4f60\u5c31\u77e5\u9053")); | 343 L"\u767e\u5ea6\u4e00\u4e0b\uff0c\u4f60\u5c31\u77e5\u9053")); |
| 337 const GURL url("https://www.baidu.com/"); | 344 const GURL url("https://www.baidu.com/"); |
| 338 | 345 |
| 339 const BookmarkNode* new_node = model_->AddURL(root, 0, title, url); | 346 const BookmarkNode* new_node = model_->AddURL(root, 0, title, url); |
| 340 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); | 347 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); |
| 341 observer_details_.ExpectEquals(root, NULL, 0, -1); | 348 observer_details_.ExpectEquals(root, NULL, 0, -1); |
| 342 | 349 |
| 343 ASSERT_EQ(1, root->child_count()); | 350 ASSERT_EQ(1, root->child_count()); |
| 344 ASSERT_EQ(title, new_node->GetTitle()); | 351 ASSERT_EQ(title, new_node->GetTitle()); |
| 345 ASSERT_TRUE(url == new_node->url()); | 352 ASSERT_TRUE(url == new_node->url()); |
| 346 ASSERT_EQ(BookmarkNode::URL, new_node->type()); | 353 ASSERT_EQ(BookmarkNode::URL, new_node->type()); |
| 347 ASSERT_TRUE(new_node == model_->GetMostRecentlyAddedNodeForURL(url)); | 354 ASSERT_TRUE(new_node == model_->GetMostRecentlyAddedUserNodeForURL(url)); |
| 348 | 355 |
| 349 EXPECT_TRUE(new_node->id() != root->id() && | 356 EXPECT_TRUE(new_node->id() != root->id() && |
| 350 new_node->id() != model_->other_node()->id() && | 357 new_node->id() != model_->other_node()->id() && |
| 351 new_node->id() != model_->mobile_node()->id()); | 358 new_node->id() != model_->mobile_node()->id()); |
| 352 } | 359 } |
| 353 | 360 |
| 354 TEST_F(BookmarkModelTest, AddURLWithWhitespaceTitle) { | 361 TEST_F(BookmarkModelTest, AddURLWithWhitespaceTitle) { |
| 355 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(url_whitespace_test_cases); ++i) { | 362 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(url_whitespace_test_cases); ++i) { |
| 356 const BookmarkNode* root = model_->bookmark_bar_node(); | 363 const BookmarkNode* root = model_->bookmark_bar_node(); |
| 357 const base::string16 title( | 364 const base::string16 title( |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 381 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); | 388 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); |
| 382 observer_details_.ExpectEquals(root, NULL, 0, -1); | 389 observer_details_.ExpectEquals(root, NULL, 0, -1); |
| 383 | 390 |
| 384 ASSERT_EQ(1, root->child_count()); | 391 ASSERT_EQ(1, root->child_count()); |
| 385 ASSERT_EQ(title, new_node->GetTitle()); | 392 ASSERT_EQ(title, new_node->GetTitle()); |
| 386 ASSERT_TRUE(url == new_node->url()); | 393 ASSERT_TRUE(url == new_node->url()); |
| 387 ASSERT_EQ(BookmarkNode::URL, new_node->type()); | 394 ASSERT_EQ(BookmarkNode::URL, new_node->type()); |
| 388 ASSERT_EQ(time, new_node->date_added()); | 395 ASSERT_EQ(time, new_node->date_added()); |
| 389 ASSERT_TRUE(new_node->GetMetaInfoMap()); | 396 ASSERT_TRUE(new_node->GetMetaInfoMap()); |
| 390 ASSERT_EQ(meta_info, *new_node->GetMetaInfoMap()); | 397 ASSERT_EQ(meta_info, *new_node->GetMetaInfoMap()); |
| 391 ASSERT_TRUE(new_node == model_->GetMostRecentlyAddedNodeForURL(url)); | 398 ASSERT_TRUE(new_node == model_->GetMostRecentlyAddedUserNodeForURL(url)); |
| 392 | 399 |
| 393 EXPECT_TRUE(new_node->id() != root->id() && | 400 EXPECT_TRUE(new_node->id() != root->id() && |
| 394 new_node->id() != model_->other_node()->id() && | 401 new_node->id() != model_->other_node()->id() && |
| 395 new_node->id() != model_->mobile_node()->id()); | 402 new_node->id() != model_->mobile_node()->id()); |
| 396 } | 403 } |
| 397 | 404 |
| 398 TEST_F(BookmarkModelTest, AddURLToMobileBookmarks) { | 405 TEST_F(BookmarkModelTest, AddURLToMobileBookmarks) { |
| 399 const BookmarkNode* root = model_->mobile_node(); | 406 const BookmarkNode* root = model_->mobile_node(); |
| 400 const base::string16 title(ASCIIToUTF16("foo")); | 407 const base::string16 title(ASCIIToUTF16("foo")); |
| 401 const GURL url("http://foo.com"); | 408 const GURL url("http://foo.com"); |
| 402 | 409 |
| 403 const BookmarkNode* new_node = model_->AddURL(root, 0, title, url); | 410 const BookmarkNode* new_node = model_->AddURL(root, 0, title, url); |
| 404 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); | 411 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); |
| 405 observer_details_.ExpectEquals(root, NULL, 0, -1); | 412 observer_details_.ExpectEquals(root, NULL, 0, -1); |
| 406 | 413 |
| 407 ASSERT_EQ(1, root->child_count()); | 414 ASSERT_EQ(1, root->child_count()); |
| 408 ASSERT_EQ(title, new_node->GetTitle()); | 415 ASSERT_EQ(title, new_node->GetTitle()); |
| 409 ASSERT_TRUE(url == new_node->url()); | 416 ASSERT_TRUE(url == new_node->url()); |
| 410 ASSERT_EQ(BookmarkNode::URL, new_node->type()); | 417 ASSERT_EQ(BookmarkNode::URL, new_node->type()); |
| 411 ASSERT_TRUE(new_node == model_->GetMostRecentlyAddedNodeForURL(url)); | 418 ASSERT_TRUE(new_node == model_->GetMostRecentlyAddedUserNodeForURL(url)); |
| 412 | 419 |
| 413 EXPECT_TRUE(new_node->id() != root->id() && | 420 EXPECT_TRUE(new_node->id() != root->id() && |
| 414 new_node->id() != model_->other_node()->id() && | 421 new_node->id() != model_->other_node()->id() && |
| 415 new_node->id() != model_->mobile_node()->id()); | 422 new_node->id() != model_->mobile_node()->id()); |
| 416 } | 423 } |
| 417 | 424 |
| 418 TEST_F(BookmarkModelTest, AddFolder) { | 425 TEST_F(BookmarkModelTest, AddFolder) { |
| 419 const BookmarkNode* root = model_->bookmark_bar_node(); | 426 const BookmarkNode* root = model_->bookmark_bar_node(); |
| 420 const base::string16 title(ASCIIToUTF16("foo")); | 427 const base::string16 title(ASCIIToUTF16("foo")); |
| 421 | 428 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 460 const GURL url("http://foo.com"); | 467 const GURL url("http://foo.com"); |
| 461 model_->AddURL(root, 0, title, url); | 468 model_->AddURL(root, 0, title, url); |
| 462 ClearCounts(); | 469 ClearCounts(); |
| 463 | 470 |
| 464 model_->Remove(root, 0); | 471 model_->Remove(root, 0); |
| 465 ASSERT_EQ(0, root->child_count()); | 472 ASSERT_EQ(0, root->child_count()); |
| 466 AssertObserverCount(0, 0, 1, 0, 0, 1, 0, 0, 0); | 473 AssertObserverCount(0, 0, 1, 0, 0, 1, 0, 0, 0); |
| 467 observer_details_.ExpectEquals(root, NULL, 0, -1); | 474 observer_details_.ExpectEquals(root, NULL, 0, -1); |
| 468 | 475 |
| 469 // Make sure there is no mapping for the URL. | 476 // Make sure there is no mapping for the URL. |
| 470 ASSERT_TRUE(model_->GetMostRecentlyAddedNodeForURL(url) == NULL); | 477 ASSERT_TRUE(model_->GetMostRecentlyAddedUserNodeForURL(url) == NULL); |
| 471 } | 478 } |
| 472 | 479 |
| 473 TEST_F(BookmarkModelTest, RemoveFolder) { | 480 TEST_F(BookmarkModelTest, RemoveFolder) { |
| 474 const BookmarkNode* root = model_->bookmark_bar_node(); | 481 const BookmarkNode* root = model_->bookmark_bar_node(); |
| 475 const BookmarkNode* folder = model_->AddFolder(root, 0, ASCIIToUTF16("foo")); | 482 const BookmarkNode* folder = model_->AddFolder(root, 0, ASCIIToUTF16("foo")); |
| 476 | 483 |
| 477 ClearCounts(); | 484 ClearCounts(); |
| 478 | 485 |
| 479 // Add a URL as a child. | 486 // Add a URL as a child. |
| 480 const base::string16 title(ASCIIToUTF16("foo")); | 487 const base::string16 title(ASCIIToUTF16("foo")); |
| 481 const GURL url("http://foo.com"); | 488 const GURL url("http://foo.com"); |
| 482 model_->AddURL(folder, 0, title, url); | 489 model_->AddURL(folder, 0, title, url); |
| 483 | 490 |
| 484 ClearCounts(); | 491 ClearCounts(); |
| 485 | 492 |
| 486 // Now remove the folder. | 493 // Now remove the folder. |
| 487 model_->Remove(root, 0); | 494 model_->Remove(root, 0); |
| 488 ASSERT_EQ(0, root->child_count()); | 495 ASSERT_EQ(0, root->child_count()); |
| 489 AssertObserverCount(0, 0, 1, 0, 0, 1, 0, 0, 0); | 496 AssertObserverCount(0, 0, 1, 0, 0, 1, 0, 0, 0); |
| 490 observer_details_.ExpectEquals(root, NULL, 0, -1); | 497 observer_details_.ExpectEquals(root, NULL, 0, -1); |
| 491 | 498 |
| 492 // Make sure there is no mapping for the URL. | 499 // Make sure there is no mapping for the URL. |
| 493 ASSERT_TRUE(model_->GetMostRecentlyAddedNodeForURL(url) == NULL); | 500 ASSERT_TRUE(model_->GetMostRecentlyAddedUserNodeForURL(url) == NULL); |
| 494 } | 501 } |
| 495 | 502 |
| 496 TEST_F(BookmarkModelTest, RemoveAll) { | 503 TEST_F(BookmarkModelTest, RemoveAll) { |
| 497 const BookmarkNode* bookmark_bar_node = model_->bookmark_bar_node(); | 504 const BookmarkNode* bookmark_bar_node = model_->bookmark_bar_node(); |
| 498 | 505 |
| 499 ClearCounts(); | 506 ClearCounts(); |
| 500 | 507 |
| 501 // Add a url to bookmark bar. | 508 // Add a url to bookmark bar. |
| 502 base::string16 title(ASCIIToUTF16("foo")); | 509 base::string16 title(ASCIIToUTF16("foo")); |
| 503 GURL url("http://foo.com"); | 510 GURL url("http://foo.com"); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 595 EXPECT_EQ(1, root->child_count()); | 602 EXPECT_EQ(1, root->child_count()); |
| 596 EXPECT_EQ(folder1, root->GetChild(0)); | 603 EXPECT_EQ(folder1, root->GetChild(0)); |
| 597 EXPECT_EQ(1, folder1->child_count()); | 604 EXPECT_EQ(1, folder1->child_count()); |
| 598 EXPECT_EQ(node, folder1->GetChild(0)); | 605 EXPECT_EQ(node, folder1->GetChild(0)); |
| 599 | 606 |
| 600 // And remove the folder. | 607 // And remove the folder. |
| 601 ClearCounts(); | 608 ClearCounts(); |
| 602 model_->Remove(root, 0); | 609 model_->Remove(root, 0); |
| 603 AssertObserverCount(0, 0, 1, 0, 0, 1, 0, 0, 0); | 610 AssertObserverCount(0, 0, 1, 0, 0, 1, 0, 0, 0); |
| 604 observer_details_.ExpectEquals(root, NULL, 0, -1); | 611 observer_details_.ExpectEquals(root, NULL, 0, -1); |
| 605 EXPECT_TRUE(model_->GetMostRecentlyAddedNodeForURL(url) == NULL); | 612 EXPECT_TRUE(model_->GetMostRecentlyAddedUserNodeForURL(url) == NULL); |
| 606 EXPECT_EQ(0, root->child_count()); | 613 EXPECT_EQ(0, root->child_count()); |
| 607 } | 614 } |
| 608 | 615 |
| 609 TEST_F(BookmarkModelTest, NonMovingMoveCall) { | 616 TEST_F(BookmarkModelTest, NonMovingMoveCall) { |
| 610 const BookmarkNode* root = model_->bookmark_bar_node(); | 617 const BookmarkNode* root = model_->bookmark_bar_node(); |
| 611 const base::string16 title(ASCIIToUTF16("foo")); | 618 const base::string16 title(ASCIIToUTF16("foo")); |
| 612 const GURL url("http://foo.com"); | 619 const GURL url("http://foo.com"); |
| 613 const base::Time old_date(base::Time::Now() - base::TimeDelta::FromDays(1)); | 620 const base::Time old_date(base::Time::Now() - base::TimeDelta::FromDays(1)); |
| 614 | 621 |
| 615 const BookmarkNode* node = model_->AddURL(root, 0, title, url); | 622 const BookmarkNode* node = model_->AddURL(root, 0, title, url); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 702 // Make sure recently modified stays in sync when adding a URL. | 709 // Make sure recently modified stays in sync when adding a URL. |
| 703 TEST_F(BookmarkModelTest, MostRecentlyModifiedFolders) { | 710 TEST_F(BookmarkModelTest, MostRecentlyModifiedFolders) { |
| 704 // Add a folder. | 711 // Add a folder. |
| 705 const BookmarkNode* folder = | 712 const BookmarkNode* folder = |
| 706 model_->AddFolder(model_->other_node(), 0, ASCIIToUTF16("foo")); | 713 model_->AddFolder(model_->other_node(), 0, ASCIIToUTF16("foo")); |
| 707 // Add a URL to it. | 714 // Add a URL to it. |
| 708 model_->AddURL(folder, 0, ASCIIToUTF16("blah"), GURL("http://foo.com")); | 715 model_->AddURL(folder, 0, ASCIIToUTF16("blah"), GURL("http://foo.com")); |
| 709 | 716 |
| 710 // Make sure folder is in the most recently modified. | 717 // Make sure folder is in the most recently modified. |
| 711 std::vector<const BookmarkNode*> most_recent_folders = | 718 std::vector<const BookmarkNode*> most_recent_folders = |
| 712 bookmark_utils::GetMostRecentlyModifiedFolders(model_.get(), 1); | 719 bookmark_utils::GetMostRecentlyModifiedUserFolders(model_.get(), 1); |
| 713 ASSERT_EQ(1U, most_recent_folders.size()); | 720 ASSERT_EQ(1U, most_recent_folders.size()); |
| 714 ASSERT_EQ(folder, most_recent_folders[0]); | 721 ASSERT_EQ(folder, most_recent_folders[0]); |
| 715 | 722 |
| 716 // Nuke the folder and do another fetch, making sure folder isn't in the | 723 // Nuke the folder and do another fetch, making sure folder isn't in the |
| 717 // returned list. | 724 // returned list. |
| 718 model_->Remove(folder->parent(), 0); | 725 model_->Remove(folder->parent(), 0); |
| 719 most_recent_folders = | 726 most_recent_folders = |
| 720 bookmark_utils::GetMostRecentlyModifiedFolders(model_.get(), 1); | 727 bookmark_utils::GetMostRecentlyModifiedUserFolders(model_.get(), 1); |
| 721 ASSERT_EQ(1U, most_recent_folders.size()); | 728 ASSERT_EQ(1U, most_recent_folders.size()); |
| 722 ASSERT_TRUE(most_recent_folders[0] != folder); | 729 ASSERT_TRUE(most_recent_folders[0] != folder); |
| 723 } | 730 } |
| 724 | 731 |
| 725 // Make sure MostRecentlyAddedEntries stays in sync. | 732 // Make sure MostRecentlyAddedEntries stays in sync. |
| 726 TEST_F(BookmarkModelTest, MostRecentlyAddedEntries) { | 733 TEST_F(BookmarkModelTest, MostRecentlyAddedEntries) { |
| 727 // Add a couple of nodes such that the following holds for the time of the | 734 // Add a couple of nodes such that the following holds for the time of the |
| 728 // nodes: n1 > n2 > n3 > n4. | 735 // nodes: n1 > n2 > n3 > n4. |
| 729 Time base_time = Time::Now(); | 736 Time base_time = Time::Now(); |
| 730 BookmarkNode* n1 = AsMutable(model_->AddURL(model_->bookmark_bar_node(), | 737 BookmarkNode* n1 = AsMutable(model_->AddURL(model_->bookmark_bar_node(), |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 759 recently_added.clear(); | 766 recently_added.clear(); |
| 760 SwapDateAdded(n1, n2); | 767 SwapDateAdded(n1, n2); |
| 761 bookmark_utils::GetMostRecentlyAddedEntries(model_.get(), 4, &recently_added); | 768 bookmark_utils::GetMostRecentlyAddedEntries(model_.get(), 4, &recently_added); |
| 762 ASSERT_EQ(4U, recently_added.size()); | 769 ASSERT_EQ(4U, recently_added.size()); |
| 763 ASSERT_TRUE(n2 == recently_added[0]); | 770 ASSERT_TRUE(n2 == recently_added[0]); |
| 764 ASSERT_TRUE(n1 == recently_added[1]); | 771 ASSERT_TRUE(n1 == recently_added[1]); |
| 765 ASSERT_TRUE(n3 == recently_added[2]); | 772 ASSERT_TRUE(n3 == recently_added[2]); |
| 766 ASSERT_TRUE(n4 == recently_added[3]); | 773 ASSERT_TRUE(n4 == recently_added[3]); |
| 767 } | 774 } |
| 768 | 775 |
| 769 // Makes sure GetMostRecentlyAddedNodeForURL stays in sync. | 776 // Makes sure GetMostRecentlyAddedUserNodeForURL stays in sync. |
| 770 TEST_F(BookmarkModelTest, GetMostRecentlyAddedNodeForURL) { | 777 TEST_F(BookmarkModelTest, GetMostRecentlyAddedUserNodeForURL) { |
| 771 // Add a couple of nodes such that the following holds for the time of the | 778 // Add a couple of nodes such that the following holds for the time of the |
| 772 // nodes: n1 > n2 | 779 // nodes: n1 > n2 |
| 773 Time base_time = Time::Now(); | 780 Time base_time = Time::Now(); |
| 774 const GURL url("http://foo.com/0"); | 781 const GURL url("http://foo.com/0"); |
| 775 BookmarkNode* n1 = AsMutable(model_->AddURL( | 782 BookmarkNode* n1 = AsMutable(model_->AddURL( |
| 776 model_->bookmark_bar_node(), 0, ASCIIToUTF16("blah"), url)); | 783 model_->bookmark_bar_node(), 0, ASCIIToUTF16("blah"), url)); |
| 777 BookmarkNode* n2 = AsMutable(model_->AddURL( | 784 BookmarkNode* n2 = AsMutable(model_->AddURL( |
| 778 model_->bookmark_bar_node(), 1, ASCIIToUTF16("blah"), url)); | 785 model_->bookmark_bar_node(), 1, ASCIIToUTF16("blah"), url)); |
| 779 n1->set_date_added(base_time + TimeDelta::FromDays(4)); | 786 n1->set_date_added(base_time + TimeDelta::FromDays(4)); |
| 780 n2->set_date_added(base_time + TimeDelta::FromDays(3)); | 787 n2->set_date_added(base_time + TimeDelta::FromDays(3)); |
| 781 | 788 |
| 782 // Make sure order is honored. | 789 // Make sure order is honored. |
| 783 ASSERT_EQ(n1, model_->GetMostRecentlyAddedNodeForURL(url)); | 790 ASSERT_EQ(n1, model_->GetMostRecentlyAddedUserNodeForURL(url)); |
| 784 | 791 |
| 785 // swap 1 and 2, then check again. | 792 // swap 1 and 2, then check again. |
| 786 SwapDateAdded(n1, n2); | 793 SwapDateAdded(n1, n2); |
| 787 ASSERT_EQ(n2, model_->GetMostRecentlyAddedNodeForURL(url)); | 794 ASSERT_EQ(n2, model_->GetMostRecentlyAddedUserNodeForURL(url)); |
| 788 } | 795 } |
| 789 | 796 |
| 790 // Makes sure GetBookmarks removes duplicates. | 797 // Makes sure GetBookmarks removes duplicates. |
| 791 TEST_F(BookmarkModelTest, GetBookmarksWithDups) { | 798 TEST_F(BookmarkModelTest, GetBookmarksWithDups) { |
| 792 const GURL url("http://foo.com/0"); | 799 const GURL url("http://foo.com/0"); |
| 793 const base::string16 title(ASCIIToUTF16("blah")); | 800 const base::string16 title(ASCIIToUTF16("blah")); |
| 794 model_->AddURL(model_->bookmark_bar_node(), 0, title, url); | 801 model_->AddURL(model_->bookmark_bar_node(), 0, title, url); |
| 795 model_->AddURL(model_->bookmark_bar_node(), 1, title, url); | 802 model_->AddURL(model_->bookmark_bar_node(), 1, title, url); |
| 796 | 803 |
| 797 std::vector<BookmarkService::URLAndTitle> bookmarks; | 804 std::vector<BookmarkService::URLAndTitle> bookmarks; |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1090 EXPECT_TRUE(model_->IsDoingExtensiveChanges()); | 1097 EXPECT_TRUE(model_->IsDoingExtensiveChanges()); |
| 1091 AssertExtensiveChangesObserverCount(1, 0); | 1098 AssertExtensiveChangesObserverCount(1, 0); |
| 1092 model_->EndExtensiveChanges(); | 1099 model_->EndExtensiveChanges(); |
| 1093 EXPECT_TRUE(model_->IsDoingExtensiveChanges()); | 1100 EXPECT_TRUE(model_->IsDoingExtensiveChanges()); |
| 1094 AssertExtensiveChangesObserverCount(1, 0); | 1101 AssertExtensiveChangesObserverCount(1, 0); |
| 1095 model_->EndExtensiveChanges(); | 1102 model_->EndExtensiveChanges(); |
| 1096 EXPECT_FALSE(model_->IsDoingExtensiveChanges()); | 1103 EXPECT_FALSE(model_->IsDoingExtensiveChanges()); |
| 1097 AssertExtensiveChangesObserverCount(1, 1); | 1104 AssertExtensiveChangesObserverCount(1, 1); |
| 1098 } | 1105 } |
| 1099 | 1106 |
| 1107 TEST_F(BookmarkModelTest, IsBookmarked) { | |
|
sky
2014/06/05 23:46:47
Please add descriptions for what you are trying to
Joao da Silva
2014/06/06 15:41:03
Done.
| |
| 1108 // Reload the model with an extra node. | |
| 1109 BookmarkPermanentNode* extra_node = new BookmarkPermanentNode(100); | |
| 1110 bookmarks::BookmarkPermanentNodeList extra_nodes; | |
| 1111 extra_nodes.push_back(extra_node); | |
| 1112 client_.SetExtraNodesToLoad(extra_nodes.Pass()); | |
| 1113 ResetModel(); | |
| 1114 ASSERT_NE(-1, model_->root_node()->GetIndexOf(extra_node)); | |
| 1115 | |
| 1116 model_->AddURL(model_->other_node(), 0, base::ASCIIToUTF16("User"), | |
| 1117 GURL("http://google.com")); | |
| 1118 model_->AddURL(extra_node, 0, base::ASCIIToUTF16("Extra"), | |
| 1119 GURL("http://youtube.com")); | |
| 1120 | |
| 1121 EXPECT_TRUE(model_->IsBookmarked(GURL("http://google.com"))); | |
| 1122 EXPECT_TRUE(model_->IsBookmarked(GURL("http://youtube.com"))); | |
| 1123 EXPECT_FALSE(model_->IsBookmarked(GURL("http://reddit.com"))); | |
| 1124 | |
| 1125 EXPECT_TRUE(model_->IsBookmarkedByUser(GURL("http://google.com"))); | |
| 1126 EXPECT_FALSE(model_->IsBookmarkedByUser(GURL("http://youtube.com"))); | |
| 1127 EXPECT_FALSE(model_->IsBookmarkedByUser(GURL("http://reddit.com"))); | |
| 1128 } | |
| 1129 | |
| 1100 TEST(BookmarkNodeTest, NodeMetaInfo) { | 1130 TEST(BookmarkNodeTest, NodeMetaInfo) { |
| 1101 GURL url; | 1131 GURL url; |
| 1102 BookmarkNode node(url); | 1132 BookmarkNode node(url); |
| 1103 EXPECT_FALSE(node.GetMetaInfoMap()); | 1133 EXPECT_FALSE(node.GetMetaInfoMap()); |
| 1104 | 1134 |
| 1105 EXPECT_TRUE(node.SetMetaInfo("key1", "value1")); | 1135 EXPECT_TRUE(node.SetMetaInfo("key1", "value1")); |
| 1106 std::string out_value; | 1136 std::string out_value; |
| 1107 EXPECT_TRUE(node.GetMetaInfo("key1", &out_value)); | 1137 EXPECT_TRUE(node.GetMetaInfo("key1", &out_value)); |
| 1108 EXPECT_EQ("value1", out_value); | 1138 EXPECT_EQ("value1", out_value); |
| 1109 EXPECT_FALSE(node.SetMetaInfo("key1", "value1")); | 1139 EXPECT_FALSE(node.SetMetaInfo("key1", "value1")); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1123 EXPECT_TRUE(node.DeleteMetaInfo("key2.subkey2.leaf")); | 1153 EXPECT_TRUE(node.DeleteMetaInfo("key2.subkey2.leaf")); |
| 1124 EXPECT_FALSE(node.DeleteMetaInfo("key3")); | 1154 EXPECT_FALSE(node.DeleteMetaInfo("key3")); |
| 1125 EXPECT_FALSE(node.GetMetaInfo("key1", &out_value)); | 1155 EXPECT_FALSE(node.GetMetaInfo("key1", &out_value)); |
| 1126 EXPECT_FALSE(node.GetMetaInfo("key2.subkey1", &out_value)); | 1156 EXPECT_FALSE(node.GetMetaInfo("key2.subkey1", &out_value)); |
| 1127 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2", &out_value)); | 1157 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2", &out_value)); |
| 1128 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2.leaf", &out_value)); | 1158 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2.leaf", &out_value)); |
| 1129 EXPECT_FALSE(node.GetMetaInfoMap()); | 1159 EXPECT_FALSE(node.GetMetaInfoMap()); |
| 1130 } | 1160 } |
| 1131 | 1161 |
| 1132 } // namespace | 1162 } // namespace |
| OLD | NEW |