| 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 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 ASSERT_TRUE(url == new_node->url()); | 363 ASSERT_TRUE(url == new_node->url()); |
| 364 ASSERT_EQ(BookmarkNode::URL, new_node->type()); | 364 ASSERT_EQ(BookmarkNode::URL, new_node->type()); |
| 365 ASSERT_TRUE(new_node == model_->GetMostRecentlyAddedUserNodeForURL(url)); | 365 ASSERT_TRUE(new_node == model_->GetMostRecentlyAddedUserNodeForURL(url)); |
| 366 | 366 |
| 367 EXPECT_TRUE(new_node->id() != root->id() && | 367 EXPECT_TRUE(new_node->id() != root->id() && |
| 368 new_node->id() != model_->other_node()->id() && | 368 new_node->id() != model_->other_node()->id() && |
| 369 new_node->id() != model_->mobile_node()->id()); | 369 new_node->id() != model_->mobile_node()->id()); |
| 370 } | 370 } |
| 371 | 371 |
| 372 TEST_F(BookmarkModelTest, AddURLWithWhitespaceTitle) { | 372 TEST_F(BookmarkModelTest, AddURLWithWhitespaceTitle) { |
| 373 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(url_whitespace_test_cases); ++i) { | 373 for (size_t i = 0; i < arraysize(url_whitespace_test_cases); ++i) { |
| 374 const BookmarkNode* root = model_->bookmark_bar_node(); | 374 const BookmarkNode* root = model_->bookmark_bar_node(); |
| 375 const base::string16 title( | 375 const base::string16 title( |
| 376 ASCIIToUTF16(url_whitespace_test_cases[i].input_title)); | 376 ASCIIToUTF16(url_whitespace_test_cases[i].input_title)); |
| 377 const GURL url("http://foo.com"); | 377 const GURL url("http://foo.com"); |
| 378 | 378 |
| 379 const BookmarkNode* new_node = model_->AddURL(root, i, title, url); | 379 const BookmarkNode* new_node = model_->AddURL(root, i, title, url); |
| 380 | 380 |
| 381 int size = i + 1; | 381 int size = i + 1; |
| 382 EXPECT_EQ(size, root->child_count()); | 382 EXPECT_EQ(size, root->child_count()); |
| 383 EXPECT_EQ(ASCIIToUTF16(url_whitespace_test_cases[i].expected_title), | 383 EXPECT_EQ(ASCIIToUTF16(url_whitespace_test_cases[i].expected_title), |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 new_node->id() != model_->mobile_node()->id()); | 450 new_node->id() != model_->mobile_node()->id()); |
| 451 | 451 |
| 452 // Add another folder, just to make sure folder_ids are incremented correctly. | 452 // Add another folder, just to make sure folder_ids are incremented correctly. |
| 453 ClearCounts(); | 453 ClearCounts(); |
| 454 model_->AddFolder(root, 0, title); | 454 model_->AddFolder(root, 0, title); |
| 455 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); | 455 AssertObserverCount(1, 0, 0, 0, 0, 0, 0, 0, 0); |
| 456 observer_details_.ExpectEquals(root, NULL, 0, -1); | 456 observer_details_.ExpectEquals(root, NULL, 0, -1); |
| 457 } | 457 } |
| 458 | 458 |
| 459 TEST_F(BookmarkModelTest, AddFolderWithWhitespaceTitle) { | 459 TEST_F(BookmarkModelTest, AddFolderWithWhitespaceTitle) { |
| 460 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(title_whitespace_test_cases); ++i) { | 460 for (size_t i = 0; i < arraysize(title_whitespace_test_cases); ++i) { |
| 461 const BookmarkNode* root = model_->bookmark_bar_node(); | 461 const BookmarkNode* root = model_->bookmark_bar_node(); |
| 462 const base::string16 title( | 462 const base::string16 title( |
| 463 ASCIIToUTF16(title_whitespace_test_cases[i].input_title)); | 463 ASCIIToUTF16(title_whitespace_test_cases[i].input_title)); |
| 464 | 464 |
| 465 const BookmarkNode* new_node = model_->AddFolder(root, i, title); | 465 const BookmarkNode* new_node = model_->AddFolder(root, i, title); |
| 466 | 466 |
| 467 int size = i + 1; | 467 int size = i + 1; |
| 468 EXPECT_EQ(size, root->child_count()); | 468 EXPECT_EQ(size, root->child_count()); |
| 469 EXPECT_EQ(ASCIIToUTF16(title_whitespace_test_cases[i].expected_title), | 469 EXPECT_EQ(ASCIIToUTF16(title_whitespace_test_cases[i].expected_title), |
| 470 new_node->GetTitle()); | 470 new_node->GetTitle()); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 ClearCounts(); | 547 ClearCounts(); |
| 548 | 548 |
| 549 title = ASCIIToUTF16("foo2"); | 549 title = ASCIIToUTF16("foo2"); |
| 550 model_->SetTitle(node, title); | 550 model_->SetTitle(node, title); |
| 551 AssertObserverCount(0, 0, 0, 1, 0, 0, 1, 0, 0); | 551 AssertObserverCount(0, 0, 0, 1, 0, 0, 1, 0, 0); |
| 552 observer_details_.ExpectEquals(node, NULL, -1, -1); | 552 observer_details_.ExpectEquals(node, NULL, -1, -1); |
| 553 EXPECT_EQ(title, node->GetTitle()); | 553 EXPECT_EQ(title, node->GetTitle()); |
| 554 } | 554 } |
| 555 | 555 |
| 556 TEST_F(BookmarkModelTest, SetTitleWithWhitespace) { | 556 TEST_F(BookmarkModelTest, SetTitleWithWhitespace) { |
| 557 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(title_whitespace_test_cases); ++i) { | 557 for (size_t i = 0; i < arraysize(title_whitespace_test_cases); ++i) { |
| 558 const BookmarkNode* root = model_->bookmark_bar_node(); | 558 const BookmarkNode* root = model_->bookmark_bar_node(); |
| 559 base::string16 title(ASCIIToUTF16("dummy")); | 559 base::string16 title(ASCIIToUTF16("dummy")); |
| 560 const GURL url("http://foo.com"); | 560 const GURL url("http://foo.com"); |
| 561 const BookmarkNode* node = model_->AddURL(root, 0, title, url); | 561 const BookmarkNode* node = model_->AddURL(root, 0, title, url); |
| 562 | 562 |
| 563 title = ASCIIToUTF16(title_whitespace_test_cases[i].input_title); | 563 title = ASCIIToUTF16(title_whitespace_test_cases[i].input_title); |
| 564 model_->SetTitle(node, title); | 564 model_->SetTitle(node, title); |
| 565 EXPECT_EQ(ASCIIToUTF16(title_whitespace_test_cases[i].expected_title), | 565 EXPECT_EQ(ASCIIToUTF16(title_whitespace_test_cases[i].expected_title), |
| 566 node->GetTitle()); | 566 node->GetTitle()); |
| 567 } | 567 } |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 962 const std::string mobile_contents; | 962 const std::string mobile_contents; |
| 963 } data[] = { | 963 } data[] = { |
| 964 // See PopulateNodeFromString for a description of these strings. | 964 // See PopulateNodeFromString for a description of these strings. |
| 965 { "", "" }, | 965 { "", "" }, |
| 966 { "a", "b" }, | 966 { "a", "b" }, |
| 967 { "a [ b ]", "" }, | 967 { "a [ b ]", "" }, |
| 968 { "", "[ b ] a [ c [ d e [ f ] ] ]" }, | 968 { "", "[ b ] a [ c [ d e [ f ] ] ]" }, |
| 969 { "a [ b ]", "" }, | 969 { "a [ b ]", "" }, |
| 970 { "a b c [ d e [ f ] ]", "g h i [ j k [ l ] ]"}, | 970 { "a b c [ d e [ f ] ]", "g h i [ j k [ l ] ]"}, |
| 971 }; | 971 }; |
| 972 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { | 972 for (size_t i = 0; i < arraysize(data); ++i) { |
| 973 model_ = client_.CreateModel(); | 973 model_ = client_.CreateModel(); |
| 974 | 974 |
| 975 TestNode bbn; | 975 TestNode bbn; |
| 976 PopulateNodeFromString(data[i].bbn_contents, &bbn); | 976 PopulateNodeFromString(data[i].bbn_contents, &bbn); |
| 977 PopulateBookmarkNode(&bbn, model_.get(), model_->bookmark_bar_node()); | 977 PopulateBookmarkNode(&bbn, model_.get(), model_->bookmark_bar_node()); |
| 978 | 978 |
| 979 TestNode other; | 979 TestNode other; |
| 980 PopulateNodeFromString(data[i].other_contents, &other); | 980 PopulateNodeFromString(data[i].other_contents, &other); |
| 981 PopulateBookmarkNode(&other, model_.get(), model_->other_node()); | 981 PopulateBookmarkNode(&other, model_.get(), model_->other_node()); |
| 982 | 982 |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1196 EXPECT_FALSE(node.DeleteMetaInfo("key3")); | 1196 EXPECT_FALSE(node.DeleteMetaInfo("key3")); |
| 1197 EXPECT_FALSE(node.GetMetaInfo("key1", &out_value)); | 1197 EXPECT_FALSE(node.GetMetaInfo("key1", &out_value)); |
| 1198 EXPECT_FALSE(node.GetMetaInfo("key2.subkey1", &out_value)); | 1198 EXPECT_FALSE(node.GetMetaInfo("key2.subkey1", &out_value)); |
| 1199 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2", &out_value)); | 1199 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2", &out_value)); |
| 1200 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2.leaf", &out_value)); | 1200 EXPECT_FALSE(node.GetMetaInfo("key2.subkey2.leaf", &out_value)); |
| 1201 EXPECT_FALSE(node.GetMetaInfoMap()); | 1201 EXPECT_FALSE(node.GetMetaInfoMap()); |
| 1202 } | 1202 } |
| 1203 | 1203 |
| 1204 } // namespace | 1204 } // namespace |
| 1205 } // namespace bookmarks | 1205 } // namespace bookmarks |
| OLD | NEW |