| 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 BookmarkPermanentNode* ReloadModelWithExtraNode() { |
| 271 BookmarkPermanentNode* extra_node = new BookmarkPermanentNode(100); |
| 272 bookmarks::BookmarkPermanentNodeList extra_nodes; |
| 273 extra_nodes.push_back(extra_node); |
| 274 client_.SetExtraNodesToLoad(extra_nodes.Pass()); |
| 275 |
| 276 model_->RemoveObserver(this); |
| 277 model_ = client_.CreateModel(false); |
| 278 model_->AddObserver(this); |
| 279 ClearCounts(); |
| 280 |
| 281 if (model_->root_node()->GetIndexOf(extra_node) == -1) |
| 282 ADD_FAILURE(); |
| 283 |
| 284 return extra_node; |
| 285 } |
| 286 |
| 270 protected: | 287 protected: |
| 271 test::TestBookmarkClient client_; | 288 test::TestBookmarkClient client_; |
| 272 scoped_ptr<BookmarkModel> model_; | 289 scoped_ptr<BookmarkModel> model_; |
| 273 ObserverDetails observer_details_; | 290 ObserverDetails observer_details_; |
| 274 | 291 |
| 275 private: | 292 private: |
| 276 int added_count_; | 293 int added_count_; |
| 277 int moved_count_; | 294 int moved_count_; |
| 278 int removed_count_; | 295 int removed_count_; |
| 279 int changed_count_; | 296 int changed_count_; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 const GURL url("http://foo.com"); | 333 const GURL url("http://foo.com"); |
| 317 | 334 |
| 318 const BookmarkNode* new_node = model_->AddURL(root, 0, title, url); | 335 const BookmarkNode* new_node = model_->AddURL(root, 0, title, url); |
| 319 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); | 336 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); |
| 320 observer_details_.ExpectEquals(root, NULL, 0, -1); | 337 observer_details_.ExpectEquals(root, NULL, 0, -1); |
| 321 | 338 |
| 322 ASSERT_EQ(1, root->child_count()); | 339 ASSERT_EQ(1, root->child_count()); |
| 323 ASSERT_EQ(title, new_node->GetTitle()); | 340 ASSERT_EQ(title, new_node->GetTitle()); |
| 324 ASSERT_TRUE(url == new_node->url()); | 341 ASSERT_TRUE(url == new_node->url()); |
| 325 ASSERT_EQ(BookmarkNode::URL, new_node->type()); | 342 ASSERT_EQ(BookmarkNode::URL, new_node->type()); |
| 326 ASSERT_TRUE(new_node == model_->GetMostRecentlyAddedNodeForURL(url)); | 343 ASSERT_TRUE(new_node == model_->GetMostRecentlyAddedUserNodeForURL(url)); |
| 327 | 344 |
| 328 EXPECT_TRUE(new_node->id() != root->id() && | 345 EXPECT_TRUE(new_node->id() != root->id() && |
| 329 new_node->id() != model_->other_node()->id() && | 346 new_node->id() != model_->other_node()->id() && |
| 330 new_node->id() != model_->mobile_node()->id()); | 347 new_node->id() != model_->mobile_node()->id()); |
| 331 } | 348 } |
| 332 | 349 |
| 333 TEST_F(BookmarkModelTest, AddURLWithUnicodeTitle) { | 350 TEST_F(BookmarkModelTest, AddURLWithUnicodeTitle) { |
| 334 const BookmarkNode* root = model_->bookmark_bar_node(); | 351 const BookmarkNode* root = model_->bookmark_bar_node(); |
| 335 const base::string16 title(base::WideToUTF16( | 352 const base::string16 title(base::WideToUTF16( |
| 336 L"\u767e\u5ea6\u4e00\u4e0b\uff0c\u4f60\u5c31\u77e5\u9053")); | 353 L"\u767e\u5ea6\u4e00\u4e0b\uff0c\u4f60\u5c31\u77e5\u9053")); |
| 337 const GURL url("https://www.baidu.com/"); | 354 const GURL url("https://www.baidu.com/"); |
| 338 | 355 |
| 339 const BookmarkNode* new_node = model_->AddURL(root, 0, title, url); | 356 const BookmarkNode* new_node = model_->AddURL(root, 0, title, url); |
| 340 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); | 357 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); |
| 341 observer_details_.ExpectEquals(root, NULL, 0, -1); | 358 observer_details_.ExpectEquals(root, NULL, 0, -1); |
| 342 | 359 |
| 343 ASSERT_EQ(1, root->child_count()); | 360 ASSERT_EQ(1, root->child_count()); |
| 344 ASSERT_EQ(title, new_node->GetTitle()); | 361 ASSERT_EQ(title, new_node->GetTitle()); |
| 345 ASSERT_TRUE(url == new_node->url()); | 362 ASSERT_TRUE(url == new_node->url()); |
| 346 ASSERT_EQ(BookmarkNode::URL, new_node->type()); | 363 ASSERT_EQ(BookmarkNode::URL, new_node->type()); |
| 347 ASSERT_TRUE(new_node == model_->GetMostRecentlyAddedNodeForURL(url)); | 364 ASSERT_TRUE(new_node == model_->GetMostRecentlyAddedUserNodeForURL(url)); |
| 348 | 365 |
| 349 EXPECT_TRUE(new_node->id() != root->id() && | 366 EXPECT_TRUE(new_node->id() != root->id() && |
| 350 new_node->id() != model_->other_node()->id() && | 367 new_node->id() != model_->other_node()->id() && |
| 351 new_node->id() != model_->mobile_node()->id()); | 368 new_node->id() != model_->mobile_node()->id()); |
| 352 } | 369 } |
| 353 | 370 |
| 354 TEST_F(BookmarkModelTest, AddURLWithWhitespaceTitle) { | 371 TEST_F(BookmarkModelTest, AddURLWithWhitespaceTitle) { |
| 355 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(url_whitespace_test_cases); ++i) { | 372 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(url_whitespace_test_cases); ++i) { |
| 356 const BookmarkNode* root = model_->bookmark_bar_node(); | 373 const BookmarkNode* root = model_->bookmark_bar_node(); |
| 357 const base::string16 title( | 374 const base::string16 title( |
| (...skipping 23 matching lines...) Expand all Loading... |
| 381 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); | 398 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); |
| 382 observer_details_.ExpectEquals(root, NULL, 0, -1); | 399 observer_details_.ExpectEquals(root, NULL, 0, -1); |
| 383 | 400 |
| 384 ASSERT_EQ(1, root->child_count()); | 401 ASSERT_EQ(1, root->child_count()); |
| 385 ASSERT_EQ(title, new_node->GetTitle()); | 402 ASSERT_EQ(title, new_node->GetTitle()); |
| 386 ASSERT_TRUE(url == new_node->url()); | 403 ASSERT_TRUE(url == new_node->url()); |
| 387 ASSERT_EQ(BookmarkNode::URL, new_node->type()); | 404 ASSERT_EQ(BookmarkNode::URL, new_node->type()); |
| 388 ASSERT_EQ(time, new_node->date_added()); | 405 ASSERT_EQ(time, new_node->date_added()); |
| 389 ASSERT_TRUE(new_node->GetMetaInfoMap()); | 406 ASSERT_TRUE(new_node->GetMetaInfoMap()); |
| 390 ASSERT_EQ(meta_info, *new_node->GetMetaInfoMap()); | 407 ASSERT_EQ(meta_info, *new_node->GetMetaInfoMap()); |
| 391 ASSERT_TRUE(new_node == model_->GetMostRecentlyAddedNodeForURL(url)); | 408 ASSERT_TRUE(new_node == model_->GetMostRecentlyAddedUserNodeForURL(url)); |
| 392 | 409 |
| 393 EXPECT_TRUE(new_node->id() != root->id() && | 410 EXPECT_TRUE(new_node->id() != root->id() && |
| 394 new_node->id() != model_->other_node()->id() && | 411 new_node->id() != model_->other_node()->id() && |
| 395 new_node->id() != model_->mobile_node()->id()); | 412 new_node->id() != model_->mobile_node()->id()); |
| 396 } | 413 } |
| 397 | 414 |
| 398 TEST_F(BookmarkModelTest, AddURLToMobileBookmarks) { | 415 TEST_F(BookmarkModelTest, AddURLToMobileBookmarks) { |
| 399 const BookmarkNode* root = model_->mobile_node(); | 416 const BookmarkNode* root = model_->mobile_node(); |
| 400 const base::string16 title(ASCIIToUTF16("foo")); | 417 const base::string16 title(ASCIIToUTF16("foo")); |
| 401 const GURL url("http://foo.com"); | 418 const GURL url("http://foo.com"); |
| 402 | 419 |
| 403 const BookmarkNode* new_node = model_->AddURL(root, 0, title, url); | 420 const BookmarkNode* new_node = model_->AddURL(root, 0, title, url); |
| 404 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); | 421 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); |
| 405 observer_details_.ExpectEquals(root, NULL, 0, -1); | 422 observer_details_.ExpectEquals(root, NULL, 0, -1); |
| 406 | 423 |
| 407 ASSERT_EQ(1, root->child_count()); | 424 ASSERT_EQ(1, root->child_count()); |
| 408 ASSERT_EQ(title, new_node->GetTitle()); | 425 ASSERT_EQ(title, new_node->GetTitle()); |
| 409 ASSERT_TRUE(url == new_node->url()); | 426 ASSERT_TRUE(url == new_node->url()); |
| 410 ASSERT_EQ(BookmarkNode::URL, new_node->type()); | 427 ASSERT_EQ(BookmarkNode::URL, new_node->type()); |
| 411 ASSERT_TRUE(new_node == model_->GetMostRecentlyAddedNodeForURL(url)); | 428 ASSERT_TRUE(new_node == model_->GetMostRecentlyAddedUserNodeForURL(url)); |
| 412 | 429 |
| 413 EXPECT_TRUE(new_node->id() != root->id() && | 430 EXPECT_TRUE(new_node->id() != root->id() && |
| 414 new_node->id() != model_->other_node()->id() && | 431 new_node->id() != model_->other_node()->id() && |
| 415 new_node->id() != model_->mobile_node()->id()); | 432 new_node->id() != model_->mobile_node()->id()); |
| 416 } | 433 } |
| 417 | 434 |
| 418 TEST_F(BookmarkModelTest, AddFolder) { | 435 TEST_F(BookmarkModelTest, AddFolder) { |
| 419 const BookmarkNode* root = model_->bookmark_bar_node(); | 436 const BookmarkNode* root = model_->bookmark_bar_node(); |
| 420 const base::string16 title(ASCIIToUTF16("foo")); | 437 const base::string16 title(ASCIIToUTF16("foo")); |
| 421 | 438 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 const GURL url("http://foo.com"); | 477 const GURL url("http://foo.com"); |
| 461 model_->AddURL(root, 0, title, url); | 478 model_->AddURL(root, 0, title, url); |
| 462 ClearCounts(); | 479 ClearCounts(); |
| 463 | 480 |
| 464 model_->Remove(root, 0); | 481 model_->Remove(root, 0); |
| 465 ASSERT_EQ(0, root->child_count()); | 482 ASSERT_EQ(0, root->child_count()); |
| 466 AssertObserverCount(0, 0, 1, 0, 0, 1, 0, 0, 0); | 483 AssertObserverCount(0, 0, 1, 0, 0, 1, 0, 0, 0); |
| 467 observer_details_.ExpectEquals(root, NULL, 0, -1); | 484 observer_details_.ExpectEquals(root, NULL, 0, -1); |
| 468 | 485 |
| 469 // Make sure there is no mapping for the URL. | 486 // Make sure there is no mapping for the URL. |
| 470 ASSERT_TRUE(model_->GetMostRecentlyAddedNodeForURL(url) == NULL); | 487 ASSERT_TRUE(model_->GetMostRecentlyAddedUserNodeForURL(url) == NULL); |
| 471 } | 488 } |
| 472 | 489 |
| 473 TEST_F(BookmarkModelTest, RemoveFolder) { | 490 TEST_F(BookmarkModelTest, RemoveFolder) { |
| 474 const BookmarkNode* root = model_->bookmark_bar_node(); | 491 const BookmarkNode* root = model_->bookmark_bar_node(); |
| 475 const BookmarkNode* folder = model_->AddFolder(root, 0, ASCIIToUTF16("foo")); | 492 const BookmarkNode* folder = model_->AddFolder(root, 0, ASCIIToUTF16("foo")); |
| 476 | 493 |
| 477 ClearCounts(); | 494 ClearCounts(); |
| 478 | 495 |
| 479 // Add a URL as a child. | 496 // Add a URL as a child. |
| 480 const base::string16 title(ASCIIToUTF16("foo")); | 497 const base::string16 title(ASCIIToUTF16("foo")); |
| 481 const GURL url("http://foo.com"); | 498 const GURL url("http://foo.com"); |
| 482 model_->AddURL(folder, 0, title, url); | 499 model_->AddURL(folder, 0, title, url); |
| 483 | 500 |
| 484 ClearCounts(); | 501 ClearCounts(); |
| 485 | 502 |
| 486 // Now remove the folder. | 503 // Now remove the folder. |
| 487 model_->Remove(root, 0); | 504 model_->Remove(root, 0); |
| 488 ASSERT_EQ(0, root->child_count()); | 505 ASSERT_EQ(0, root->child_count()); |
| 489 AssertObserverCount(0, 0, 1, 0, 0, 1, 0, 0, 0); | 506 AssertObserverCount(0, 0, 1, 0, 0, 1, 0, 0, 0); |
| 490 observer_details_.ExpectEquals(root, NULL, 0, -1); | 507 observer_details_.ExpectEquals(root, NULL, 0, -1); |
| 491 | 508 |
| 492 // Make sure there is no mapping for the URL. | 509 // Make sure there is no mapping for the URL. |
| 493 ASSERT_TRUE(model_->GetMostRecentlyAddedNodeForURL(url) == NULL); | 510 ASSERT_TRUE(model_->GetMostRecentlyAddedUserNodeForURL(url) == NULL); |
| 494 } | 511 } |
| 495 | 512 |
| 496 TEST_F(BookmarkModelTest, RemoveAll) { | 513 TEST_F(BookmarkModelTest, RemoveAll) { |
| 497 const BookmarkNode* bookmark_bar_node = model_->bookmark_bar_node(); | 514 const BookmarkNode* bookmark_bar_node = model_->bookmark_bar_node(); |
| 498 | 515 |
| 499 ClearCounts(); | 516 ClearCounts(); |
| 500 | 517 |
| 501 // Add a url to bookmark bar. | 518 // Add a url to bookmark bar. |
| 502 base::string16 title(ASCIIToUTF16("foo")); | 519 base::string16 title(ASCIIToUTF16("foo")); |
| 503 GURL url("http://foo.com"); | 520 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()); | 612 EXPECT_EQ(1, root->child_count()); |
| 596 EXPECT_EQ(folder1, root->GetChild(0)); | 613 EXPECT_EQ(folder1, root->GetChild(0)); |
| 597 EXPECT_EQ(1, folder1->child_count()); | 614 EXPECT_EQ(1, folder1->child_count()); |
| 598 EXPECT_EQ(node, folder1->GetChild(0)); | 615 EXPECT_EQ(node, folder1->GetChild(0)); |
| 599 | 616 |
| 600 // And remove the folder. | 617 // And remove the folder. |
| 601 ClearCounts(); | 618 ClearCounts(); |
| 602 model_->Remove(root, 0); | 619 model_->Remove(root, 0); |
| 603 AssertObserverCount(0, 0, 1, 0, 0, 1, 0, 0, 0); | 620 AssertObserverCount(0, 0, 1, 0, 0, 1, 0, 0, 0); |
| 604 observer_details_.ExpectEquals(root, NULL, 0, -1); | 621 observer_details_.ExpectEquals(root, NULL, 0, -1); |
| 605 EXPECT_TRUE(model_->GetMostRecentlyAddedNodeForURL(url) == NULL); | 622 EXPECT_TRUE(model_->GetMostRecentlyAddedUserNodeForURL(url) == NULL); |
| 606 EXPECT_EQ(0, root->child_count()); | 623 EXPECT_EQ(0, root->child_count()); |
| 607 } | 624 } |
| 608 | 625 |
| 609 TEST_F(BookmarkModelTest, NonMovingMoveCall) { | 626 TEST_F(BookmarkModelTest, NonMovingMoveCall) { |
| 610 const BookmarkNode* root = model_->bookmark_bar_node(); | 627 const BookmarkNode* root = model_->bookmark_bar_node(); |
| 611 const base::string16 title(ASCIIToUTF16("foo")); | 628 const base::string16 title(ASCIIToUTF16("foo")); |
| 612 const GURL url("http://foo.com"); | 629 const GURL url("http://foo.com"); |
| 613 const base::Time old_date(base::Time::Now() - base::TimeDelta::FromDays(1)); | 630 const base::Time old_date(base::Time::Now() - base::TimeDelta::FromDays(1)); |
| 614 | 631 |
| 615 const BookmarkNode* node = model_->AddURL(root, 0, title, url); | 632 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. | 719 // Make sure recently modified stays in sync when adding a URL. |
| 703 TEST_F(BookmarkModelTest, MostRecentlyModifiedFolders) { | 720 TEST_F(BookmarkModelTest, MostRecentlyModifiedFolders) { |
| 704 // Add a folder. | 721 // Add a folder. |
| 705 const BookmarkNode* folder = | 722 const BookmarkNode* folder = |
| 706 model_->AddFolder(model_->other_node(), 0, ASCIIToUTF16("foo")); | 723 model_->AddFolder(model_->other_node(), 0, ASCIIToUTF16("foo")); |
| 707 // Add a URL to it. | 724 // Add a URL to it. |
| 708 model_->AddURL(folder, 0, ASCIIToUTF16("blah"), GURL("http://foo.com")); | 725 model_->AddURL(folder, 0, ASCIIToUTF16("blah"), GURL("http://foo.com")); |
| 709 | 726 |
| 710 // Make sure folder is in the most recently modified. | 727 // Make sure folder is in the most recently modified. |
| 711 std::vector<const BookmarkNode*> most_recent_folders = | 728 std::vector<const BookmarkNode*> most_recent_folders = |
| 712 bookmark_utils::GetMostRecentlyModifiedFolders(model_.get(), 1); | 729 bookmark_utils::GetMostRecentlyModifiedUserFolders(model_.get(), 1); |
| 713 ASSERT_EQ(1U, most_recent_folders.size()); | 730 ASSERT_EQ(1U, most_recent_folders.size()); |
| 714 ASSERT_EQ(folder, most_recent_folders[0]); | 731 ASSERT_EQ(folder, most_recent_folders[0]); |
| 715 | 732 |
| 716 // Nuke the folder and do another fetch, making sure folder isn't in the | 733 // Nuke the folder and do another fetch, making sure folder isn't in the |
| 717 // returned list. | 734 // returned list. |
| 718 model_->Remove(folder->parent(), 0); | 735 model_->Remove(folder->parent(), 0); |
| 719 most_recent_folders = | 736 most_recent_folders = |
| 720 bookmark_utils::GetMostRecentlyModifiedFolders(model_.get(), 1); | 737 bookmark_utils::GetMostRecentlyModifiedUserFolders(model_.get(), 1); |
| 721 ASSERT_EQ(1U, most_recent_folders.size()); | 738 ASSERT_EQ(1U, most_recent_folders.size()); |
| 722 ASSERT_TRUE(most_recent_folders[0] != folder); | 739 ASSERT_TRUE(most_recent_folders[0] != folder); |
| 723 } | 740 } |
| 724 | 741 |
| 725 // Make sure MostRecentlyAddedEntries stays in sync. | 742 // Make sure MostRecentlyAddedEntries stays in sync. |
| 726 TEST_F(BookmarkModelTest, MostRecentlyAddedEntries) { | 743 TEST_F(BookmarkModelTest, MostRecentlyAddedEntries) { |
| 727 // Add a couple of nodes such that the following holds for the time of the | 744 // Add a couple of nodes such that the following holds for the time of the |
| 728 // nodes: n1 > n2 > n3 > n4. | 745 // nodes: n1 > n2 > n3 > n4. |
| 729 Time base_time = Time::Now(); | 746 Time base_time = Time::Now(); |
| 730 BookmarkNode* n1 = AsMutable(model_->AddURL(model_->bookmark_bar_node(), | 747 BookmarkNode* n1 = AsMutable(model_->AddURL(model_->bookmark_bar_node(), |
| (...skipping 28 matching lines...) Expand all Loading... |
| 759 recently_added.clear(); | 776 recently_added.clear(); |
| 760 SwapDateAdded(n1, n2); | 777 SwapDateAdded(n1, n2); |
| 761 bookmark_utils::GetMostRecentlyAddedEntries(model_.get(), 4, &recently_added); | 778 bookmark_utils::GetMostRecentlyAddedEntries(model_.get(), 4, &recently_added); |
| 762 ASSERT_EQ(4U, recently_added.size()); | 779 ASSERT_EQ(4U, recently_added.size()); |
| 763 ASSERT_TRUE(n2 == recently_added[0]); | 780 ASSERT_TRUE(n2 == recently_added[0]); |
| 764 ASSERT_TRUE(n1 == recently_added[1]); | 781 ASSERT_TRUE(n1 == recently_added[1]); |
| 765 ASSERT_TRUE(n3 == recently_added[2]); | 782 ASSERT_TRUE(n3 == recently_added[2]); |
| 766 ASSERT_TRUE(n4 == recently_added[3]); | 783 ASSERT_TRUE(n4 == recently_added[3]); |
| 767 } | 784 } |
| 768 | 785 |
| 769 // Makes sure GetMostRecentlyAddedNodeForURL stays in sync. | 786 // Makes sure GetMostRecentlyAddedUserNodeForURL stays in sync. |
| 770 TEST_F(BookmarkModelTest, GetMostRecentlyAddedNodeForURL) { | 787 TEST_F(BookmarkModelTest, GetMostRecentlyAddedUserNodeForURL) { |
| 771 // Add a couple of nodes such that the following holds for the time of the | 788 // Add a couple of nodes such that the following holds for the time of the |
| 772 // nodes: n1 > n2 | 789 // nodes: n1 > n2 |
| 773 Time base_time = Time::Now(); | 790 Time base_time = Time::Now(); |
| 774 const GURL url("http://foo.com/0"); | 791 const GURL url("http://foo.com/0"); |
| 775 BookmarkNode* n1 = AsMutable(model_->AddURL( | 792 BookmarkNode* n1 = AsMutable(model_->AddURL( |
| 776 model_->bookmark_bar_node(), 0, ASCIIToUTF16("blah"), url)); | 793 model_->bookmark_bar_node(), 0, ASCIIToUTF16("blah"), url)); |
| 777 BookmarkNode* n2 = AsMutable(model_->AddURL( | 794 BookmarkNode* n2 = AsMutable(model_->AddURL( |
| 778 model_->bookmark_bar_node(), 1, ASCIIToUTF16("blah"), url)); | 795 model_->bookmark_bar_node(), 1, ASCIIToUTF16("blah"), url)); |
| 779 n1->set_date_added(base_time + TimeDelta::FromDays(4)); | 796 n1->set_date_added(base_time + TimeDelta::FromDays(4)); |
| 780 n2->set_date_added(base_time + TimeDelta::FromDays(3)); | 797 n2->set_date_added(base_time + TimeDelta::FromDays(3)); |
| 781 | 798 |
| 782 // Make sure order is honored. | 799 // Make sure order is honored. |
| 783 ASSERT_EQ(n1, model_->GetMostRecentlyAddedNodeForURL(url)); | 800 ASSERT_EQ(n1, model_->GetMostRecentlyAddedUserNodeForURL(url)); |
| 784 | 801 |
| 785 // swap 1 and 2, then check again. | 802 // swap 1 and 2, then check again. |
| 786 SwapDateAdded(n1, n2); | 803 SwapDateAdded(n1, n2); |
| 787 ASSERT_EQ(n2, model_->GetMostRecentlyAddedNodeForURL(url)); | 804 ASSERT_EQ(n2, model_->GetMostRecentlyAddedUserNodeForURL(url)); |
| 788 } | 805 } |
| 789 | 806 |
| 790 // Makes sure GetBookmarks removes duplicates. | 807 // Makes sure GetBookmarks removes duplicates. |
| 791 TEST_F(BookmarkModelTest, GetBookmarksWithDups) { | 808 TEST_F(BookmarkModelTest, GetBookmarksWithDups) { |
| 792 const GURL url("http://foo.com/0"); | 809 const GURL url("http://foo.com/0"); |
| 793 const base::string16 title(ASCIIToUTF16("blah")); | 810 const base::string16 title(ASCIIToUTF16("blah")); |
| 794 model_->AddURL(model_->bookmark_bar_node(), 0, title, url); | 811 model_->AddURL(model_->bookmark_bar_node(), 0, title, url); |
| 795 model_->AddURL(model_->bookmark_bar_node(), 1, title, url); | 812 model_->AddURL(model_->bookmark_bar_node(), 1, title, url); |
| 796 | 813 |
| 797 std::vector<BookmarkModel::URLAndTitle> bookmarks; | 814 std::vector<BookmarkModel::URLAndTitle> bookmarks; |
| (...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1090 EXPECT_TRUE(model_->IsDoingExtensiveChanges()); | 1107 EXPECT_TRUE(model_->IsDoingExtensiveChanges()); |
| 1091 AssertExtensiveChangesObserverCount(1, 0); | 1108 AssertExtensiveChangesObserverCount(1, 0); |
| 1092 model_->EndExtensiveChanges(); | 1109 model_->EndExtensiveChanges(); |
| 1093 EXPECT_TRUE(model_->IsDoingExtensiveChanges()); | 1110 EXPECT_TRUE(model_->IsDoingExtensiveChanges()); |
| 1094 AssertExtensiveChangesObserverCount(1, 0); | 1111 AssertExtensiveChangesObserverCount(1, 0); |
| 1095 model_->EndExtensiveChanges(); | 1112 model_->EndExtensiveChanges(); |
| 1096 EXPECT_FALSE(model_->IsDoingExtensiveChanges()); | 1113 EXPECT_FALSE(model_->IsDoingExtensiveChanges()); |
| 1097 AssertExtensiveChangesObserverCount(1, 1); | 1114 AssertExtensiveChangesObserverCount(1, 1); |
| 1098 } | 1115 } |
| 1099 | 1116 |
| 1117 // Verifies that IsBookmarked is true if any bookmark matches the given URL, |
| 1118 // and that IsBookmarkedByUser is true only if at least one of the matching |
| 1119 // bookmarks can be edited by the user. |
| 1120 TEST_F(BookmarkModelTest, IsBookmarked) { |
| 1121 // Reload the model with an extra node that is not editable by the user. |
| 1122 BookmarkPermanentNode* extra_node = ReloadModelWithExtraNode(); |
| 1123 |
| 1124 // "google.com" is a "user" bookmark. |
| 1125 model_->AddURL(model_->other_node(), 0, base::ASCIIToUTF16("User"), |
| 1126 GURL("http://google.com")); |
| 1127 // "youtube.com" is not. |
| 1128 model_->AddURL(extra_node, 0, base::ASCIIToUTF16("Extra"), |
| 1129 GURL("http://youtube.com")); |
| 1130 |
| 1131 EXPECT_TRUE(model_->IsBookmarked(GURL("http://google.com"))); |
| 1132 EXPECT_TRUE(model_->IsBookmarked(GURL("http://youtube.com"))); |
| 1133 EXPECT_FALSE(model_->IsBookmarked(GURL("http://reddit.com"))); |
| 1134 |
| 1135 EXPECT_TRUE(bookmark_utils::IsBookmarkedByUser(model_.get(), |
| 1136 GURL("http://google.com"))); |
| 1137 EXPECT_FALSE(bookmark_utils::IsBookmarkedByUser(model_.get(), |
| 1138 GURL("http://youtube.com"))); |
| 1139 EXPECT_FALSE(bookmark_utils::IsBookmarkedByUser(model_.get(), |
| 1140 GURL("http://reddit.com"))); |
| 1141 } |
| 1142 |
| 1143 // Verifies that GetMostRecentlyAddedUserNodeForURL skips bookmarks that |
| 1144 // are not owned by the user. |
| 1145 TEST_F(BookmarkModelTest, GetMostRecentlyAddedUserNodeForURLSkipsManagedNodes) { |
| 1146 // Reload the model with an extra node that is not editable by the user. |
| 1147 BookmarkPermanentNode* extra_node = ReloadModelWithExtraNode(); |
| 1148 |
| 1149 const base::string16 title = base::ASCIIToUTF16("Title"); |
| 1150 const BookmarkNode* user_parent = model_->other_node(); |
| 1151 const BookmarkNode* managed_parent = extra_node; |
| 1152 const GURL url("http://google.com"); |
| 1153 |
| 1154 // |url| is not bookmarked yet. |
| 1155 EXPECT_TRUE(model_->GetMostRecentlyAddedUserNodeForURL(url) == NULL); |
| 1156 |
| 1157 // Having a managed node doesn't count. |
| 1158 model_->AddURL(managed_parent, 0, title, url); |
| 1159 EXPECT_TRUE(model_->GetMostRecentlyAddedUserNodeForURL(url) == NULL); |
| 1160 |
| 1161 // Now add a user node. |
| 1162 const BookmarkNode* user = model_->AddURL(user_parent, 0, title, url); |
| 1163 EXPECT_EQ(user, model_->GetMostRecentlyAddedUserNodeForURL(url)); |
| 1164 |
| 1165 // Having a more recent managed node doesn't count either. |
| 1166 const BookmarkNode* managed = model_->AddURL(managed_parent, 0, title, url); |
| 1167 EXPECT_GT(managed->date_added(), user->date_added()); |
| 1168 EXPECT_EQ(user, model_->GetMostRecentlyAddedUserNodeForURL(url)); |
| 1169 } |
| 1170 |
| 1100 TEST(BookmarkNodeTest, NodeMetaInfo) { | 1171 TEST(BookmarkNodeTest, NodeMetaInfo) { |
| 1101 GURL url; | 1172 GURL url; |
| 1102 BookmarkNode node(url); | 1173 BookmarkNode node(url); |
| 1103 EXPECT_FALSE(node.GetMetaInfoMap()); | 1174 EXPECT_FALSE(node.GetMetaInfoMap()); |
| 1104 | 1175 |
| 1105 EXPECT_TRUE(node.SetMetaInfo("key1", "value1")); | 1176 EXPECT_TRUE(node.SetMetaInfo("key1", "value1")); |
| 1106 std::string out_value; | 1177 std::string out_value; |
| 1107 EXPECT_TRUE(node.GetMetaInfo("key1", &out_value)); | 1178 EXPECT_TRUE(node.GetMetaInfo("key1", &out_value)); |
| 1108 EXPECT_EQ("value1", out_value); | 1179 EXPECT_EQ("value1", out_value); |
| 1109 EXPECT_FALSE(node.SetMetaInfo("key1", "value1")); | 1180 EXPECT_FALSE(node.SetMetaInfo("key1", "value1")); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1123 EXPECT_TRUE(node.DeleteMetaInfo("key2.subkey2.leaf")); | 1194 EXPECT_TRUE(node.DeleteMetaInfo("key2.subkey2.leaf")); |
| 1124 EXPECT_FALSE(node.DeleteMetaInfo("key3")); | 1195 EXPECT_FALSE(node.DeleteMetaInfo("key3")); |
| 1125 EXPECT_FALSE(node.GetMetaInfo("key1", &out_value)); | 1196 EXPECT_FALSE(node.GetMetaInfo("key1", &out_value)); |
| 1126 EXPECT_FALSE(node.GetMetaInfo("key2.subkey1", &out_value)); | 1197 EXPECT_FALSE(node.GetMetaInfo("key2.subkey1", &out_value)); |
| 1127 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2", &out_value)); | 1198 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2", &out_value)); |
| 1128 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2.leaf", &out_value)); | 1199 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2.leaf", &out_value)); |
| 1129 EXPECT_FALSE(node.GetMetaInfoMap()); | 1200 EXPECT_FALSE(node.GetMetaInfoMap()); |
| 1130 } | 1201 } |
| 1131 | 1202 |
| 1132 } // namespace | 1203 } // namespace |
| OLD | NEW |