| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <utility> | 11 #include <utility> |
| 12 | 12 |
| 13 #include "base/base_paths.h" | 13 #include "base/base_paths.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
| 16 #include "base/containers/hash_tables.h" | 16 #include "base/containers/hash_tables.h" |
| 17 #include "base/macros.h" | 17 #include "base/macros.h" |
| 18 #include "base/memory/ptr_util.h" |
| 18 #include "base/strings/string16.h" | 19 #include "base/strings/string16.h" |
| 19 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/strings/string_split.h" | 21 #include "base/strings/string_split.h" |
| 21 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/time/time.h" | 24 #include "base/time/time.h" |
| 24 #include "components/bookmarks/browser/bookmark_model_observer.h" | 25 #include "components/bookmarks/browser/bookmark_model_observer.h" |
| 25 #include "components/bookmarks/browser/bookmark_undo_delegate.h" | 26 #include "components/bookmarks/browser/bookmark_undo_delegate.h" |
| 26 #include "components/bookmarks/browser/bookmark_utils.h" | 27 #include "components/bookmarks/browser/bookmark_utils.h" |
| 27 #include "components/bookmarks/test/bookmark_test_helpers.h" | 28 #include "components/bookmarks/test/bookmark_test_helpers.h" |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 TestNode* parent) { | 123 TestNode* parent) { |
| 123 while (*index < description.size()) { | 124 while (*index < description.size()) { |
| 124 const std::string& element = description[*index]; | 125 const std::string& element = description[*index]; |
| 125 (*index)++; | 126 (*index)++; |
| 126 if (element == "[") { | 127 if (element == "[") { |
| 127 // Create a new folder and recurse to add all the children. | 128 // Create a new folder and recurse to add all the children. |
| 128 // Folders are given a unique named by way of an ever increasing integer | 129 // Folders are given a unique named by way of an ever increasing integer |
| 129 // value. The folders need not have a name, but one is assigned to help | 130 // value. The folders need not have a name, but one is assigned to help |
| 130 // in debugging. | 131 // in debugging. |
| 131 static int next_folder_id = 1; | 132 static int next_folder_id = 1; |
| 132 TestNode* new_node = new TestNode(base::IntToString16(next_folder_id++), | 133 TestNode* new_node = parent->Add( |
| 133 BookmarkNode::FOLDER); | 134 base::MakeUnique<TestNode>(base::IntToString16(next_folder_id++), |
| 134 parent->Add(new_node, parent->child_count()); | 135 BookmarkNode::FOLDER), |
| 136 parent->child_count()); |
| 135 PopulateNodeImpl(description, index, new_node); | 137 PopulateNodeImpl(description, index, new_node); |
| 136 } else if (element == "]") { | 138 } else if (element == "]") { |
| 137 // End the current folder. | 139 // End the current folder. |
| 138 return; | 140 return; |
| 139 } else { | 141 } else { |
| 140 // Add a new URL. | 142 // Add a new URL. |
| 141 | 143 |
| 142 // All tokens must be space separated. If there is a [ or ] in the name it | 144 // All tokens must be space separated. If there is a [ or ] in the name it |
| 143 // likely means a space was forgotten. | 145 // likely means a space was forgotten. |
| 144 DCHECK(element.find('[') == std::string::npos); | 146 DCHECK(element.find('[') == std::string::npos); |
| 145 DCHECK(element.find(']') == std::string::npos); | 147 DCHECK(element.find(']') == std::string::npos); |
| 146 parent->Add(new TestNode(base::UTF8ToUTF16(element), BookmarkNode::URL), | 148 parent->Add(base::MakeUnique<TestNode>(base::UTF8ToUTF16(element), |
| 149 BookmarkNode::URL), |
| 147 parent->child_count()); | 150 parent->child_count()); |
| 148 } | 151 } |
| 149 } | 152 } |
| 150 } | 153 } |
| 151 | 154 |
| 152 // Creates and adds nodes to parent based on description. description consists | 155 // Creates and adds nodes to parent based on description. description consists |
| 153 // of the following tokens (all space separated): | 156 // of the following tokens (all space separated): |
| 154 // [ : creates a new USER_FOLDER node. All elements following the [ until the | 157 // [ : creates a new USER_FOLDER node. All elements following the [ until the |
| 155 // next balanced ] is encountered are added as children to the node. | 158 // next balanced ] is encountered are added as children to the node. |
| 156 // ] : closes the last folder created by [ so that any further nodes are added | 159 // ] : closes the last folder created by [ so that any further nodes are added |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 EXPECT_EQ(grouped_changes_beginning_count, | 421 EXPECT_EQ(grouped_changes_beginning_count, |
| 419 grouped_changes_beginning_count_); | 422 grouped_changes_beginning_count_); |
| 420 EXPECT_EQ(grouped_changes_ended_count, grouped_changes_ended_count_); | 423 EXPECT_EQ(grouped_changes_ended_count, grouped_changes_ended_count_); |
| 421 } | 424 } |
| 422 | 425 |
| 423 int AllNodesRemovedObserverCount() const { return all_bookmarks_removed_; } | 426 int AllNodesRemovedObserverCount() const { return all_bookmarks_removed_; } |
| 424 | 427 |
| 425 BookmarkPermanentNode* ReloadModelWithExtraNode() { | 428 BookmarkPermanentNode* ReloadModelWithExtraNode() { |
| 426 model_->RemoveObserver(this); | 429 model_->RemoveObserver(this); |
| 427 | 430 |
| 428 BookmarkPermanentNode* extra_node = new BookmarkPermanentNode(100); | |
| 429 BookmarkPermanentNodeList extra_nodes; | 431 BookmarkPermanentNodeList extra_nodes; |
| 430 extra_nodes.push_back(extra_node); | 432 extra_nodes.push_back(base::MakeUnique<BookmarkPermanentNode>(100)); |
| 433 BookmarkPermanentNode* extra_node = extra_nodes.back().get(); |
| 431 | 434 |
| 432 std::unique_ptr<TestBookmarkClient> client(new TestBookmarkClient); | 435 std::unique_ptr<TestBookmarkClient> client(new TestBookmarkClient); |
| 433 client->SetExtraNodesToLoad(std::move(extra_nodes)); | 436 client->SetExtraNodesToLoad(std::move(extra_nodes)); |
| 434 | 437 |
| 435 model_ = TestBookmarkClient::CreateModelWithClient(std::move(client)); | 438 model_ = TestBookmarkClient::CreateModelWithClient(std::move(client)); |
| 436 model_->AddObserver(this); | 439 model_->AddObserver(this); |
| 437 ClearCounts(); | 440 ClearCounts(); |
| 438 | 441 |
| 439 if (model_->root_node()->GetIndexOf(extra_node) == -1) | 442 if (model_->root_node()->GetIndexOf(extra_node) == -1) |
| 440 ADD_FAILURE(); | 443 ADD_FAILURE(); |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1010 TEST_F(BookmarkModelTest, DISABLED_Sort) { | 1013 TEST_F(BookmarkModelTest, DISABLED_Sort) { |
| 1011 // Populate the bookmark bar node with nodes for 'B', 'a', 'd' and 'C'. | 1014 // Populate the bookmark bar node with nodes for 'B', 'a', 'd' and 'C'. |
| 1012 // 'C' and 'a' are folders. | 1015 // 'C' and 'a' are folders. |
| 1013 TestNode bbn; | 1016 TestNode bbn; |
| 1014 PopulateNodeFromString("B [ a ] d [ a ]", &bbn); | 1017 PopulateNodeFromString("B [ a ] d [ a ]", &bbn); |
| 1015 const BookmarkNode* parent = model_->bookmark_bar_node(); | 1018 const BookmarkNode* parent = model_->bookmark_bar_node(); |
| 1016 PopulateBookmarkNode(&bbn, model_.get(), parent); | 1019 PopulateBookmarkNode(&bbn, model_.get(), parent); |
| 1017 | 1020 |
| 1018 BookmarkNode* child1 = AsMutable(parent->GetChild(1)); | 1021 BookmarkNode* child1 = AsMutable(parent->GetChild(1)); |
| 1019 child1->SetTitle(ASCIIToUTF16("a")); | 1022 child1->SetTitle(ASCIIToUTF16("a")); |
| 1020 delete child1->Remove(child1->GetChild(0)); | 1023 child1->Remove(child1->GetChild(0)); |
| 1021 BookmarkNode* child3 = AsMutable(parent->GetChild(3)); | 1024 BookmarkNode* child3 = AsMutable(parent->GetChild(3)); |
| 1022 child3->SetTitle(ASCIIToUTF16("C")); | 1025 child3->SetTitle(ASCIIToUTF16("C")); |
| 1023 delete child3->Remove(child3->GetChild(0)); | 1026 child3->Remove(child3->GetChild(0)); |
| 1024 | 1027 |
| 1025 ClearCounts(); | 1028 ClearCounts(); |
| 1026 | 1029 |
| 1027 // Sort the children of the bookmark bar node. | 1030 // Sort the children of the bookmark bar node. |
| 1028 model_->SortChildren(parent); | 1031 model_->SortChildren(parent); |
| 1029 | 1032 |
| 1030 // Make sure we were notified. | 1033 // Make sure we were notified. |
| 1031 AssertObserverCount(0, 0, 0, 0, 1, 0, 0, 1, 0); | 1034 AssertObserverCount(0, 0, 0, 0, 1, 0, 0, 1, 0); |
| 1032 | 1035 |
| 1033 // Make sure the order matches (remember, 'a' and 'C' are folders and | 1036 // Make sure the order matches (remember, 'a' and 'C' are folders and |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1394 std::set<GURL> changed_page_urls; | 1397 std::set<GURL> changed_page_urls; |
| 1395 changed_page_urls.insert(kPageURL1); | 1398 changed_page_urls.insert(kPageURL1); |
| 1396 model_->OnFaviconsChanged(changed_page_urls, kFaviconURL12); | 1399 model_->OnFaviconsChanged(changed_page_urls, kFaviconURL12); |
| 1397 ASSERT_EQ(2u, updated_nodes_.size()); | 1400 ASSERT_EQ(2u, updated_nodes_.size()); |
| 1398 EXPECT_TRUE(WasNodeUpdated(node1)); | 1401 EXPECT_TRUE(WasNodeUpdated(node1)); |
| 1399 EXPECT_TRUE(WasNodeUpdated(node2)); | 1402 EXPECT_TRUE(WasNodeUpdated(node2)); |
| 1400 } | 1403 } |
| 1401 } | 1404 } |
| 1402 | 1405 |
| 1403 } // namespace bookmarks | 1406 } // namespace bookmarks |
| OLD | NEW |