| 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 "chrome/browser/bookmarks/chrome_bookmark_client.h" | 5 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| 11 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 11 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 12 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" | |
| 13 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h" | |
| 14 #include "chrome/test/base/testing_pref_service_syncable.h" | 12 #include "chrome/test/base/testing_pref_service_syncable.h" |
| 15 #include "chrome/test/base/testing_profile.h" | 13 #include "chrome/test/base/testing_profile.h" |
| 16 #include "components/bookmarks/browser/bookmark_model.h" | 14 #include "components/bookmarks/browser/bookmark_model.h" |
| 17 #include "components/bookmarks/browser/bookmark_node.h" | 15 #include "components/bookmarks/browser/bookmark_node.h" |
| 18 #include "components/bookmarks/browser/bookmark_utils.h" | 16 #include "components/bookmarks/browser/bookmark_utils.h" |
| 19 #include "components/bookmarks/common/bookmark_pref_names.h" | 17 #include "components/bookmarks/common/bookmark_pref_names.h" |
| 20 #include "components/bookmarks/test/bookmark_test_helpers.h" | 18 #include "components/bookmarks/test/bookmark_test_helpers.h" |
| 21 #include "components/bookmarks/test/mock_bookmark_model_observer.h" | 19 #include "components/bookmarks/test/mock_bookmark_model_observer.h" |
| 22 #include "content/public/test/test_browser_thread_bundle.h" | 20 #include "content/public/test/test_browser_thread_bundle.h" |
| 23 #include "grit/components_strings.h" | 21 #include "grit/components_strings.h" |
| 24 #include "testing/gmock/include/gmock/gmock.h" | 22 #include "testing/gmock/include/gmock/gmock.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 27 | 25 |
| 28 using bookmarks::BookmarkModel; | 26 using bookmarks::BookmarkModel; |
| 29 using bookmarks::BookmarkNode; | 27 using bookmarks::BookmarkNode; |
| 30 using testing::Mock; | 28 using testing::Mock; |
| 31 using testing::_; | 29 using testing::_; |
| 32 | 30 |
| 33 class ChromeBookmarkClientTest : public testing::Test { | 31 class ChromeBookmarkClientTest : public testing::Test { |
| 34 public: | 32 public: |
| 35 ChromeBookmarkClientTest() : client_(NULL), model_(NULL) {} | 33 ChromeBookmarkClientTest() : model_(nullptr) {} |
| 36 ~ChromeBookmarkClientTest() override {} | 34 ~ChromeBookmarkClientTest() override {} |
| 37 | 35 |
| 38 void SetUp() override { | 36 void SetUp() override { |
| 39 prefs_ = profile_.GetTestingPrefService(); | 37 prefs_ = profile_.GetTestingPrefService(); |
| 40 ASSERT_FALSE(prefs_->HasPrefPath(bookmarks::prefs::kManagedBookmarks)); | 38 ASSERT_FALSE(prefs_->HasPrefPath(bookmarks::prefs::kManagedBookmarks)); |
| 41 | 39 |
| 42 prefs_->SetManagedPref(bookmarks::prefs::kManagedBookmarks, | 40 prefs_->SetManagedPref(bookmarks::prefs::kManagedBookmarks, |
| 43 CreateTestTree()); | 41 CreateTestTree()); |
| 44 ResetModel(); | 42 ResetModel(); |
| 45 | 43 |
| 46 // The managed node always exists. | 44 // The managed node always exists. |
| 47 ASSERT_TRUE(client_->managed_node()); | 45 ASSERT_TRUE(model_->managed_node()); |
| 48 ASSERT_TRUE(client_->managed_node()->parent() == model_->root_node()); | 46 ASSERT_TRUE(model_->managed_node()->parent() == model_->root_node()); |
| 49 EXPECT_NE(-1, model_->root_node()->GetIndexOf(client_->managed_node())); | 47 EXPECT_NE(-1, model_->root_node()->GetIndexOf(model_->managed_node())); |
| 50 } | 48 } |
| 51 | 49 |
| 52 void TearDown() override { model_->RemoveObserver(&observer_); } | 50 void TearDown() override { model_->RemoveObserver(&observer_); } |
| 53 | 51 |
| 54 void ResetModel() { | 52 void ResetModel() { |
| 55 profile_.CreateBookmarkModel(false); | 53 profile_.CreateBookmarkModel(false); |
| 56 model_ = BookmarkModelFactory::GetForProfile(&profile_); | 54 model_ = BookmarkModelFactory::GetForProfile(&profile_); |
| 57 bookmarks::test::WaitForBookmarkModelToLoad(model_); | 55 bookmarks::test::WaitForBookmarkModelToLoad(model_); |
| 58 model_->AddObserver(&observer_); | 56 model_->AddObserver(&observer_); |
| 59 client_ = ChromeBookmarkClientFactory::GetForProfile(&profile_); | |
| 60 DCHECK(client_); | |
| 61 } | 57 } |
| 62 | 58 |
| 63 static base::DictionaryValue* CreateBookmark(const std::string& title, | 59 static base::DictionaryValue* CreateBookmark(const std::string& title, |
| 64 const std::string& url) { | 60 const std::string& url) { |
| 65 EXPECT_TRUE(GURL(url).is_valid()); | 61 EXPECT_TRUE(GURL(url).is_valid()); |
| 66 base::DictionaryValue* dict = new base::DictionaryValue(); | 62 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 67 dict->SetString("name", title); | 63 dict->SetString("name", title); |
| 68 dict->SetString("url", GURL(url).spec()); | 64 dict->SetString("url", GURL(url).spec()); |
| 69 return dict; | 65 return dict; |
| 70 } | 66 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 99 IDS_BOOKMARK_BAR_MANAGED_FOLDER_DEFAULT_NAME); | 95 IDS_BOOKMARK_BAR_MANAGED_FOLDER_DEFAULT_NAME); |
| 100 } | 96 } |
| 101 | 97 |
| 102 static bool NodeMatchesValue(const BookmarkNode* node, | 98 static bool NodeMatchesValue(const BookmarkNode* node, |
| 103 const base::DictionaryValue* dict) { | 99 const base::DictionaryValue* dict) { |
| 104 base::string16 title; | 100 base::string16 title; |
| 105 if (!dict->GetString("name", &title) || node->GetTitle() != title) | 101 if (!dict->GetString("name", &title) || node->GetTitle() != title) |
| 106 return false; | 102 return false; |
| 107 | 103 |
| 108 if (node->is_folder()) { | 104 if (node->is_folder()) { |
| 109 const base::ListValue* children = NULL; | 105 const base::ListValue* children = nullptr; |
| 110 if (!dict->GetList("children", &children) || | 106 if (!dict->GetList("children", &children) || |
| 111 node->child_count() != static_cast<int>(children->GetSize())) { | 107 node->child_count() != static_cast<int>(children->GetSize())) { |
| 112 return false; | 108 return false; |
| 113 } | 109 } |
| 114 for (int i = 0; i < node->child_count(); ++i) { | 110 for (int i = 0; i < node->child_count(); ++i) { |
| 115 const base::DictionaryValue* child = NULL; | 111 const base::DictionaryValue* child = nullptr; |
| 116 if (!children->GetDictionary(i, &child) || | 112 if (!children->GetDictionary(i, &child) || |
| 117 !NodeMatchesValue(node->GetChild(i), child)) { | 113 !NodeMatchesValue(node->GetChild(i), child)) { |
| 118 return false; | 114 return false; |
| 119 } | 115 } |
| 120 } | 116 } |
| 121 } else if (node->is_url()) { | 117 } else if (node->is_url()) { |
| 122 std::string url; | 118 std::string url; |
| 123 if (!dict->GetString("url", &url) || node->url() != GURL(url)) | 119 if (!dict->GetString("url", &url) || node->url() != GURL(url)) |
| 124 return false; | 120 return false; |
| 125 } else { | 121 } else { |
| 126 return false; | 122 return false; |
| 127 } | 123 } |
| 128 return true; | 124 return true; |
| 129 } | 125 } |
| 130 | 126 |
| 131 content::TestBrowserThreadBundle thread_bundle_; | 127 content::TestBrowserThreadBundle thread_bundle_; |
| 132 TestingProfile profile_; | 128 TestingProfile profile_; |
| 133 TestingPrefServiceSyncable* prefs_; | 129 TestingPrefServiceSyncable* prefs_; |
| 134 bookmarks::MockBookmarkModelObserver observer_; | 130 bookmarks::MockBookmarkModelObserver observer_; |
| 135 ChromeBookmarkClient* client_; | |
| 136 BookmarkModel* model_; | 131 BookmarkModel* model_; |
| 137 | 132 |
| 138 DISALLOW_COPY_AND_ASSIGN(ChromeBookmarkClientTest); | 133 DISALLOW_COPY_AND_ASSIGN(ChromeBookmarkClientTest); |
| 139 }; | 134 }; |
| 140 | 135 |
| 141 TEST_F(ChromeBookmarkClientTest, EmptyManagedNode) { | 136 TEST_F(ChromeBookmarkClientTest, EmptyManagedNode) { |
| 142 // Verifies that the managed node is empty and invisible when the policy is | 137 // Verifies that the managed node is empty and invisible when the policy is |
| 143 // not set. | 138 // not set. |
| 144 model_->RemoveObserver(&observer_); | 139 model_->RemoveObserver(&observer_); |
| 145 prefs_->RemoveManagedPref(bookmarks::prefs::kManagedBookmarks); | 140 prefs_->RemoveManagedPref(bookmarks::prefs::kManagedBookmarks); |
| 146 ResetModel(); | 141 ResetModel(); |
| 147 | 142 |
| 148 ASSERT_TRUE(client_->managed_node()); | 143 ASSERT_TRUE(model_->managed_node()); |
| 149 EXPECT_TRUE(client_->managed_node()->empty()); | 144 EXPECT_TRUE(model_->managed_node()->empty()); |
| 150 EXPECT_FALSE(client_->managed_node()->IsVisible()); | 145 EXPECT_FALSE(model_->managed_node()->IsVisible()); |
| 151 } | 146 } |
| 152 | 147 |
| 153 TEST_F(ChromeBookmarkClientTest, LoadInitial) { | 148 TEST_F(ChromeBookmarkClientTest, LoadInitial) { |
| 154 // Verifies that the initial load picks up the initial policy too. | 149 // Verifies that the initial load picks up the initial policy too. |
| 155 EXPECT_TRUE(model_->bookmark_bar_node()->empty()); | 150 EXPECT_TRUE(model_->bookmark_bar_node()->empty()); |
| 156 EXPECT_TRUE(model_->other_node()->empty()); | 151 EXPECT_TRUE(model_->other_node()->empty()); |
| 157 EXPECT_FALSE(client_->managed_node()->empty()); | 152 EXPECT_FALSE(model_->managed_node()->empty()); |
| 158 EXPECT_TRUE(client_->managed_node()->IsVisible()); | 153 EXPECT_TRUE(model_->managed_node()->IsVisible()); |
| 159 | 154 |
| 160 scoped_ptr<base::DictionaryValue> expected(CreateExpectedTree()); | 155 scoped_ptr<base::DictionaryValue> expected(CreateExpectedTree()); |
| 161 EXPECT_TRUE(NodeMatchesValue(client_->managed_node(), expected.get())); | 156 EXPECT_TRUE(NodeMatchesValue(model_->managed_node(), expected.get())); |
| 162 } | 157 } |
| 163 | 158 |
| 164 TEST_F(ChromeBookmarkClientTest, SwapNodes) { | 159 TEST_F(ChromeBookmarkClientTest, SwapNodes) { |
| 165 // Swap the Google bookmark with the Folder. | 160 // Swap the Google bookmark with the Folder. |
| 166 scoped_ptr<base::ListValue> updated(CreateTestTree()); | 161 scoped_ptr<base::ListValue> updated(CreateTestTree()); |
| 167 scoped_ptr<base::Value> removed; | 162 scoped_ptr<base::Value> removed; |
| 168 ASSERT_TRUE(updated->Remove(0, &removed)); | 163 ASSERT_TRUE(updated->Remove(0, &removed)); |
| 169 updated->Append(removed.release()); | 164 updated->Append(removed.release()); |
| 170 | 165 |
| 171 // These two nodes should just be swapped. | 166 // These two nodes should just be swapped. |
| 172 const BookmarkNode* parent = client_->managed_node(); | 167 const BookmarkNode* parent = model_->managed_node(); |
| 173 EXPECT_CALL(observer_, BookmarkNodeMoved(model_, parent, 1, parent, 0)); | 168 EXPECT_CALL(observer_, BookmarkNodeMoved(model_, parent, 1, parent, 0)); |
| 174 prefs_->SetManagedPref(bookmarks::prefs::kManagedBookmarks, | 169 prefs_->SetManagedPref(bookmarks::prefs::kManagedBookmarks, |
| 175 updated->DeepCopy()); | 170 updated->DeepCopy()); |
| 176 Mock::VerifyAndClearExpectations(&observer_); | 171 Mock::VerifyAndClearExpectations(&observer_); |
| 177 | 172 |
| 178 // Verify the final tree. | 173 // Verify the final tree. |
| 179 scoped_ptr<base::DictionaryValue> expected( | 174 scoped_ptr<base::DictionaryValue> expected( |
| 180 CreateFolder(GetManagedFolderTitle(), updated.release())); | 175 CreateFolder(GetManagedFolderTitle(), updated.release())); |
| 181 EXPECT_TRUE(NodeMatchesValue(client_->managed_node(), expected.get())); | 176 EXPECT_TRUE(NodeMatchesValue(model_->managed_node(), expected.get())); |
| 182 } | 177 } |
| 183 | 178 |
| 184 TEST_F(ChromeBookmarkClientTest, RemoveNode) { | 179 TEST_F(ChromeBookmarkClientTest, RemoveNode) { |
| 185 // Remove the Folder. | 180 // Remove the Folder. |
| 186 scoped_ptr<base::ListValue> updated(CreateTestTree()); | 181 scoped_ptr<base::ListValue> updated(CreateTestTree()); |
| 187 ASSERT_TRUE(updated->Remove(1, NULL)); | 182 ASSERT_TRUE(updated->Remove(1, nullptr)); |
| 188 | 183 |
| 189 const BookmarkNode* parent = client_->managed_node(); | 184 const BookmarkNode* parent = model_->managed_node(); |
| 190 EXPECT_CALL(observer_, BookmarkNodeRemoved(model_, parent, 1, _, _)); | 185 EXPECT_CALL(observer_, BookmarkNodeRemoved(model_, parent, 1, _, _)); |
| 191 prefs_->SetManagedPref(bookmarks::prefs::kManagedBookmarks, | 186 prefs_->SetManagedPref(bookmarks::prefs::kManagedBookmarks, |
| 192 updated->DeepCopy()); | 187 updated->DeepCopy()); |
| 193 Mock::VerifyAndClearExpectations(&observer_); | 188 Mock::VerifyAndClearExpectations(&observer_); |
| 194 | 189 |
| 195 // Verify the final tree. | 190 // Verify the final tree. |
| 196 scoped_ptr<base::DictionaryValue> expected( | 191 scoped_ptr<base::DictionaryValue> expected( |
| 197 CreateFolder(GetManagedFolderTitle(), updated.release())); | 192 CreateFolder(GetManagedFolderTitle(), updated.release())); |
| 198 EXPECT_TRUE(NodeMatchesValue(client_->managed_node(), expected.get())); | 193 EXPECT_TRUE(NodeMatchesValue(model_->managed_node(), expected.get())); |
| 199 } | 194 } |
| 200 | 195 |
| 201 TEST_F(ChromeBookmarkClientTest, CreateNewNodes) { | 196 TEST_F(ChromeBookmarkClientTest, CreateNewNodes) { |
| 202 // Put all the nodes inside another folder. | 197 // Put all the nodes inside another folder. |
| 203 scoped_ptr<base::ListValue> updated(new base::ListValue); | 198 scoped_ptr<base::ListValue> updated(new base::ListValue); |
| 204 updated->Append(CreateFolder("Container", CreateTestTree())); | 199 updated->Append(CreateFolder("Container", CreateTestTree())); |
| 205 | 200 |
| 206 EXPECT_CALL(observer_, BookmarkNodeAdded(model_, _, _)).Times(5); | 201 EXPECT_CALL(observer_, BookmarkNodeAdded(model_, _, _)).Times(5); |
| 207 // The remaining nodes have been pushed to positions 1 and 2; they'll both be | 202 // The remaining nodes have been pushed to positions 1 and 2; they'll both be |
| 208 // removed when at position 1. | 203 // removed when at position 1. |
| 209 const BookmarkNode* parent = client_->managed_node(); | 204 const BookmarkNode* parent = model_->managed_node(); |
| 210 EXPECT_CALL(observer_, BookmarkNodeRemoved(model_, parent, 1, _, _)) | 205 EXPECT_CALL(observer_, BookmarkNodeRemoved(model_, parent, 1, _, _)) |
| 211 .Times(2); | 206 .Times(2); |
| 212 prefs_->SetManagedPref(bookmarks::prefs::kManagedBookmarks, | 207 prefs_->SetManagedPref(bookmarks::prefs::kManagedBookmarks, |
| 213 updated->DeepCopy()); | 208 updated->DeepCopy()); |
| 214 Mock::VerifyAndClearExpectations(&observer_); | 209 Mock::VerifyAndClearExpectations(&observer_); |
| 215 | 210 |
| 216 // Verify the final tree. | 211 // Verify the final tree. |
| 217 scoped_ptr<base::DictionaryValue> expected( | 212 scoped_ptr<base::DictionaryValue> expected( |
| 218 CreateFolder(GetManagedFolderTitle(), updated.release())); | 213 CreateFolder(GetManagedFolderTitle(), updated.release())); |
| 219 EXPECT_TRUE(NodeMatchesValue(client_->managed_node(), expected.get())); | 214 EXPECT_TRUE(NodeMatchesValue(model_->managed_node(), expected.get())); |
| 220 } | 215 } |
| 221 | 216 |
| 222 TEST_F(ChromeBookmarkClientTest, RemoveAllUserBookmarks) { | 217 TEST_F(ChromeBookmarkClientTest, RemoveAllUserBookmarks) { |
| 223 // Remove the policy. | 218 // Remove the policy. |
| 224 const BookmarkNode* parent = client_->managed_node(); | 219 const BookmarkNode* parent = model_->managed_node(); |
| 225 EXPECT_CALL(observer_, BookmarkNodeRemoved(model_, parent, 0, _, _)) | 220 EXPECT_CALL(observer_, BookmarkNodeRemoved(model_, parent, 0, _, _)) |
| 226 .Times(2); | 221 .Times(2); |
| 227 prefs_->RemoveManagedPref(bookmarks::prefs::kManagedBookmarks); | 222 prefs_->RemoveManagedPref(bookmarks::prefs::kManagedBookmarks); |
| 228 Mock::VerifyAndClearExpectations(&observer_); | 223 Mock::VerifyAndClearExpectations(&observer_); |
| 229 | 224 |
| 230 EXPECT_TRUE(client_->managed_node()->empty()); | 225 EXPECT_TRUE(model_->managed_node()->empty()); |
| 231 EXPECT_FALSE(client_->managed_node()->IsVisible()); | 226 EXPECT_FALSE(model_->managed_node()->IsVisible()); |
| 232 } | 227 } |
| 233 | 228 |
| 234 TEST_F(ChromeBookmarkClientTest, IsDescendantOfManagedNode) { | 229 TEST_F(ChromeBookmarkClientTest, IsDescendantOfManagedNode) { |
| 235 EXPECT_FALSE(bookmarks::IsDescendantOf(model_->root_node(), | 230 EXPECT_FALSE( |
| 236 client_->managed_node())); | 231 bookmarks::IsDescendantOf(model_->root_node(), model_->managed_node())); |
| 237 EXPECT_FALSE(bookmarks::IsDescendantOf(model_->bookmark_bar_node(), | 232 EXPECT_FALSE(bookmarks::IsDescendantOf(model_->bookmark_bar_node(), |
| 238 client_->managed_node())); | 233 model_->managed_node())); |
| 239 EXPECT_FALSE(bookmarks::IsDescendantOf(model_->other_node(), | 234 EXPECT_FALSE( |
| 240 client_->managed_node())); | 235 bookmarks::IsDescendantOf(model_->other_node(), model_->managed_node())); |
| 241 EXPECT_FALSE(bookmarks::IsDescendantOf(model_->mobile_node(), | 236 EXPECT_FALSE( |
| 242 client_->managed_node())); | 237 bookmarks::IsDescendantOf(model_->mobile_node(), model_->managed_node())); |
| 243 EXPECT_TRUE(bookmarks::IsDescendantOf(client_->managed_node(), | 238 EXPECT_TRUE(bookmarks::IsDescendantOf(model_->managed_node(), |
| 244 client_->managed_node())); | 239 model_->managed_node())); |
| 245 | 240 |
| 246 const BookmarkNode* parent = client_->managed_node(); | 241 const BookmarkNode* parent = model_->managed_node(); |
| 247 ASSERT_EQ(2, parent->child_count()); | 242 ASSERT_EQ(2, parent->child_count()); |
| 248 EXPECT_TRUE(bookmarks::IsDescendantOf(parent->GetChild(0), | 243 EXPECT_TRUE( |
| 249 client_->managed_node())); | 244 bookmarks::IsDescendantOf(parent->GetChild(0), model_->managed_node())); |
| 250 EXPECT_TRUE(bookmarks::IsDescendantOf(parent->GetChild(1), | 245 EXPECT_TRUE( |
| 251 client_->managed_node())); | 246 bookmarks::IsDescendantOf(parent->GetChild(1), model_->managed_node())); |
| 252 | 247 |
| 253 parent = parent->GetChild(1); | 248 parent = parent->GetChild(1); |
| 254 ASSERT_EQ(2, parent->child_count()); | 249 ASSERT_EQ(2, parent->child_count()); |
| 255 EXPECT_TRUE(bookmarks::IsDescendantOf(parent->GetChild(0), | 250 EXPECT_TRUE( |
| 256 client_->managed_node())); | 251 bookmarks::IsDescendantOf(parent->GetChild(0), model_->managed_node())); |
| 257 EXPECT_TRUE(bookmarks::IsDescendantOf(parent->GetChild(1), | 252 EXPECT_TRUE( |
| 258 client_->managed_node())); | 253 bookmarks::IsDescendantOf(parent->GetChild(1), model_->managed_node())); |
| 259 } | 254 } |
| 260 | 255 |
| 261 TEST_F(ChromeBookmarkClientTest, RemoveAllDoesntRemoveManaged) { | 256 TEST_F(ChromeBookmarkClientTest, RemoveAllDoesntRemoveManaged) { |
| 262 EXPECT_EQ(2, client_->managed_node()->child_count()); | 257 EXPECT_EQ(2, model_->managed_node()->child_count()); |
| 263 | 258 |
| 264 EXPECT_CALL(observer_, | 259 EXPECT_CALL(observer_, |
| 265 BookmarkNodeAdded(model_, model_->bookmark_bar_node(), 0)); | 260 BookmarkNodeAdded(model_, model_->bookmark_bar_node(), 0)); |
| 266 EXPECT_CALL(observer_, | 261 EXPECT_CALL(observer_, |
| 267 BookmarkNodeAdded(model_, model_->bookmark_bar_node(), 1)); | 262 BookmarkNodeAdded(model_, model_->bookmark_bar_node(), 1)); |
| 268 model_->AddURL(model_->bookmark_bar_node(), | 263 model_->AddURL(model_->bookmark_bar_node(), |
| 269 0, | 264 0, |
| 270 base::ASCIIToUTF16("Test"), | 265 base::ASCIIToUTF16("Test"), |
| 271 GURL("http://google.com/")); | 266 GURL("http://google.com/")); |
| 272 model_->AddFolder( | 267 model_->AddFolder( |
| 273 model_->bookmark_bar_node(), 1, base::ASCIIToUTF16("Test Folder")); | 268 model_->bookmark_bar_node(), 1, base::ASCIIToUTF16("Test Folder")); |
| 274 EXPECT_EQ(2, model_->bookmark_bar_node()->child_count()); | 269 EXPECT_EQ(2, model_->bookmark_bar_node()->child_count()); |
| 275 Mock::VerifyAndClearExpectations(&observer_); | 270 Mock::VerifyAndClearExpectations(&observer_); |
| 276 | 271 |
| 277 EXPECT_CALL(observer_, BookmarkAllUserNodesRemoved(model_, _)); | 272 EXPECT_CALL(observer_, BookmarkAllUserNodesRemoved(model_, _)); |
| 278 model_->RemoveAllUserBookmarks(); | 273 model_->RemoveAllUserBookmarks(); |
| 279 EXPECT_EQ(2, client_->managed_node()->child_count()); | 274 EXPECT_EQ(2, model_->managed_node()->child_count()); |
| 280 EXPECT_EQ(0, model_->bookmark_bar_node()->child_count()); | 275 EXPECT_EQ(0, model_->bookmark_bar_node()->child_count()); |
| 281 Mock::VerifyAndClearExpectations(&observer_); | 276 Mock::VerifyAndClearExpectations(&observer_); |
| 282 } | 277 } |
| 283 | 278 |
| 284 TEST_F(ChromeBookmarkClientTest, HasDescendantsOfManagedNode) { | 279 TEST_F(ChromeBookmarkClientTest, HasDescendantsOfManagedNode) { |
| 285 const BookmarkNode* user_node = model_->AddURL(model_->other_node(), | 280 const BookmarkNode* user_node = model_->AddURL(model_->other_node(), |
| 286 0, | 281 0, |
| 287 base::ASCIIToUTF16("foo bar"), | 282 base::ASCIIToUTF16("foo bar"), |
| 288 GURL("http://www.google.com")); | 283 GURL("http://www.google.com")); |
| 289 const BookmarkNode* managed_node = client_->managed_node()->GetChild(0); | 284 const BookmarkNode* managed_node = model_->managed_node()->GetChild(0); |
| 290 ASSERT_TRUE(managed_node); | 285 ASSERT_TRUE(managed_node); |
| 291 | 286 |
| 292 std::vector<const BookmarkNode*> nodes; | 287 std::vector<const BookmarkNode*> nodes; |
| 293 EXPECT_FALSE(bookmarks::HasDescendantsOf(nodes, client_->managed_node())); | 288 EXPECT_FALSE(bookmarks::HasDescendantsOf(nodes, model_->managed_node())); |
| 294 nodes.push_back(user_node); | 289 nodes.push_back(user_node); |
| 295 EXPECT_FALSE(bookmarks::HasDescendantsOf(nodes, client_->managed_node())); | 290 EXPECT_FALSE(bookmarks::HasDescendantsOf(nodes, model_->managed_node())); |
| 296 nodes.push_back(managed_node); | 291 nodes.push_back(managed_node); |
| 297 EXPECT_TRUE(bookmarks::HasDescendantsOf(nodes, client_->managed_node())); | 292 EXPECT_TRUE(bookmarks::HasDescendantsOf(nodes, model_->managed_node())); |
| 298 } | 293 } |
| OLD | NEW |