| 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 <memory> | 
|  | 6 #include <vector> | 
|  | 7 | 
| 5 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" | 
| 6 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" | 
| 7 #include "base/time/time.h" | 10 #include "base/time/time.h" | 
| 8 #include "components/bookmarks/browser/bookmark_model.h" | 11 #include "components/bookmarks/browser/bookmark_model.h" | 
| 9 #include "ios/chrome/browser/experimental_flags.h" | 12 #include "ios/chrome/browser/experimental_flags.h" | 
| 10 #include "ios/chrome/browser/ui/bookmarks/bookmark_ios_unittest.h" | 13 #include "ios/chrome/browser/ui/bookmarks/bookmark_ios_unittest.h" | 
| 11 #import "ios/chrome/browser/ui/bookmarks/bookmark_menu_item.h" | 14 #import "ios/chrome/browser/ui/bookmarks/bookmark_menu_item.h" | 
| 12 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" | 15 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" | 
| 13 #include "testing/gtest_mac.h" | 16 #include "testing/gtest_mac.h" | 
| 14 | 17 | 
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 55   _bookmarkModel->SetDateAdded(f2b, timeFromEpoch(10, 5)); | 58   _bookmarkModel->SetDateAdded(f2b, timeFromEpoch(10, 5)); | 
| 56 | 59 | 
| 57   std::vector<const BookmarkNode*> toSort; | 60   std::vector<const BookmarkNode*> toSort; | 
| 58   toSort.push_back(a); | 61   toSort.push_back(a); | 
| 59   toSort.push_back(b); | 62   toSort.push_back(b); | 
| 60   toSort.push_back(f1a); | 63   toSort.push_back(f1a); | 
| 61   toSort.push_back(f1b); | 64   toSort.push_back(f1b); | 
| 62   toSort.push_back(f2a); | 65   toSort.push_back(f2a); | 
| 63   toSort.push_back(f2b); | 66   toSort.push_back(f2b); | 
| 64 | 67 | 
| 65   ScopedVector<NodesSection> nodesSectionVector; | 68   std::vector<std::unique_ptr<NodesSection>> nodesSectionVector; | 
| 66   bookmark_utils_ios::segregateNodes(toSort, nodesSectionVector); | 69   bookmark_utils_ios::segregateNodes(toSort, nodesSectionVector); | 
| 67 | 70 | 
| 68   // Expect the nodes to be sorted in reverse chronological order, grouped by | 71   // Expect the nodes to be sorted in reverse chronological order, grouped by | 
| 69   // month. | 72   // month. | 
| 70   ASSERT_EQ(nodesSectionVector.size(), 4u); | 73   ASSERT_EQ(nodesSectionVector.size(), 4u); | 
| 71   NodesSection* section = nodesSectionVector[0]; | 74   NodesSection* section = nodesSectionVector[0].get(); | 
| 72   ASSERT_EQ(section->vector.size(), 1u); | 75   ASSERT_EQ(section->vector.size(), 1u); | 
| 73   EXPECT_EQ(section->vector[0], f2a); | 76   EXPECT_EQ(section->vector[0], f2a); | 
| 74 | 77 | 
| 75   section = nodesSectionVector[1]; | 78   section = nodesSectionVector[1].get(); | 
| 76   ASSERT_EQ(section->vector.size(), 2u); | 79   ASSERT_EQ(section->vector.size(), 2u); | 
| 77   EXPECT_EQ(section->vector[0], b); | 80   EXPECT_EQ(section->vector[0], b); | 
| 78   EXPECT_EQ(section->vector[1], a); | 81   EXPECT_EQ(section->vector[1], a); | 
| 79 | 82 | 
| 80   section = nodesSectionVector[2]; | 83   section = nodesSectionVector[2].get(); | 
| 81   ASSERT_EQ(section->vector.size(), 2u); | 84   ASSERT_EQ(section->vector.size(), 2u); | 
| 82   EXPECT_EQ(section->vector[0], f1b); | 85   EXPECT_EQ(section->vector[0], f1b); | 
| 83   EXPECT_EQ(section->vector[1], f1a); | 86   EXPECT_EQ(section->vector[1], f1a); | 
| 84 | 87 | 
| 85   section = nodesSectionVector[3]; | 88   section = nodesSectionVector[3].get(); | 
| 86   ASSERT_EQ(section->vector.size(), 1u); | 89   ASSERT_EQ(section->vector.size(), 1u); | 
| 87   EXPECT_EQ(section->vector[0], f2b); | 90   EXPECT_EQ(section->vector[0], f2b); | 
| 88 } | 91 } | 
| 89 | 92 | 
| 90 TEST_F(BookmarkIOSUtilsUnitTest, DeleteNodes) { | 93 TEST_F(BookmarkIOSUtilsUnitTest, DeleteNodes) { | 
| 91   const BookmarkNode* mobileNode = _bookmarkModel->mobile_node(); | 94   const BookmarkNode* mobileNode = _bookmarkModel->mobile_node(); | 
| 92   const BookmarkNode* f1 = AddFolder(mobileNode, @"f1"); | 95   const BookmarkNode* f1 = AddFolder(mobileNode, @"f1"); | 
| 93   const BookmarkNode* a = AddBookmark(mobileNode, @"a"); | 96   const BookmarkNode* a = AddBookmark(mobileNode, @"a"); | 
| 94   const BookmarkNode* b = AddBookmark(mobileNode, @"b"); | 97   const BookmarkNode* b = AddBookmark(mobileNode, @"b"); | 
| 95   const BookmarkNode* f2 = AddFolder(mobileNode, @"f2"); | 98   const BookmarkNode* f2 = AddFolder(mobileNode, @"f2"); | 
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 396   vector1.push_back(bookmark1); | 399   vector1.push_back(bookmark1); | 
| 397   vector2.insert(vector2.begin(), bookmark1); | 400   vector2.insert(vector2.begin(), bookmark1); | 
| 398   missingNodesIndices = | 401   missingNodesIndices = | 
| 399       bookmark_utils_ios::MissingNodesIndices(vector1, vector2); | 402       bookmark_utils_ios::MissingNodesIndices(vector1, vector2); | 
| 400   EXPECT_EQ(2u, missingNodesIndices.size()); | 403   EXPECT_EQ(2u, missingNodesIndices.size()); | 
| 401   EXPECT_EQ(2u, missingNodesIndices[0]); | 404   EXPECT_EQ(2u, missingNodesIndices[0]); | 
| 402   EXPECT_EQ(3u, missingNodesIndices[1]); | 405   EXPECT_EQ(3u, missingNodesIndices[1]); | 
| 403 } | 406 } | 
| 404 | 407 | 
| 405 }  // namespace | 408 }  // namespace | 
| OLD | NEW | 
|---|