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" | 12 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" |
13 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h" | 13 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h" |
14 #include "chrome/test/base/testing_pref_service_syncable.h" | 14 #include "chrome/test/base/testing_pref_service_syncable.h" |
15 #include "chrome/test/base/testing_profile.h" | 15 #include "chrome/test/base/testing_profile.h" |
16 #include "components/bookmarks/browser/bookmark_model.h" | 16 #include "components/bookmarks/browser/bookmark_model.h" |
17 #include "components/bookmarks/browser/bookmark_node.h" | 17 #include "components/bookmarks/browser/bookmark_node.h" |
| 18 #include "components/bookmarks/browser/bookmark_utils.h" |
18 #include "components/bookmarks/common/bookmark_pref_names.h" | 19 #include "components/bookmarks/common/bookmark_pref_names.h" |
19 #include "components/bookmarks/test/bookmark_test_helpers.h" | 20 #include "components/bookmarks/test/bookmark_test_helpers.h" |
20 #include "components/bookmarks/test/mock_bookmark_model_observer.h" | 21 #include "components/bookmarks/test/mock_bookmark_model_observer.h" |
21 #include "content/public/test/test_browser_thread_bundle.h" | 22 #include "content/public/test/test_browser_thread_bundle.h" |
22 #include "grit/components_strings.h" | 23 #include "grit/components_strings.h" |
23 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
26 | 27 |
27 using bookmarks::BookmarkModel; | 28 using bookmarks::BookmarkModel; |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 EXPECT_CALL(observer_, BookmarkNodeRemoved(model_, parent, 0, _, _)) | 225 EXPECT_CALL(observer_, BookmarkNodeRemoved(model_, parent, 0, _, _)) |
225 .Times(2); | 226 .Times(2); |
226 prefs_->RemoveManagedPref(bookmarks::prefs::kManagedBookmarks); | 227 prefs_->RemoveManagedPref(bookmarks::prefs::kManagedBookmarks); |
227 Mock::VerifyAndClearExpectations(&observer_); | 228 Mock::VerifyAndClearExpectations(&observer_); |
228 | 229 |
229 EXPECT_TRUE(client_->managed_node()->empty()); | 230 EXPECT_TRUE(client_->managed_node()->empty()); |
230 EXPECT_FALSE(client_->managed_node()->IsVisible()); | 231 EXPECT_FALSE(client_->managed_node()->IsVisible()); |
231 } | 232 } |
232 | 233 |
233 TEST_F(ChromeBookmarkClientTest, IsDescendantOfManagedNode) { | 234 TEST_F(ChromeBookmarkClientTest, IsDescendantOfManagedNode) { |
234 EXPECT_FALSE(client_->IsDescendantOfManagedNode(model_->root_node())); | 235 EXPECT_FALSE(bookmarks::IsDescendantOf(model_->root_node(), |
235 EXPECT_FALSE(client_->IsDescendantOfManagedNode(model_->bookmark_bar_node())); | 236 client_->managed_node())); |
236 EXPECT_FALSE(client_->IsDescendantOfManagedNode(model_->other_node())); | 237 EXPECT_FALSE(bookmarks::IsDescendantOf(model_->bookmark_bar_node(), |
237 EXPECT_FALSE(client_->IsDescendantOfManagedNode(model_->mobile_node())); | 238 client_->managed_node())); |
238 EXPECT_TRUE(client_->IsDescendantOfManagedNode(client_->managed_node())); | 239 EXPECT_FALSE(bookmarks::IsDescendantOf(model_->other_node(), |
| 240 client_->managed_node())); |
| 241 EXPECT_FALSE(bookmarks::IsDescendantOf(model_->mobile_node(), |
| 242 client_->managed_node())); |
| 243 EXPECT_TRUE(bookmarks::IsDescendantOf(client_->managed_node(), |
| 244 client_->managed_node())); |
239 | 245 |
240 const BookmarkNode* parent = client_->managed_node(); | 246 const BookmarkNode* parent = client_->managed_node(); |
241 ASSERT_EQ(2, parent->child_count()); | 247 ASSERT_EQ(2, parent->child_count()); |
242 EXPECT_TRUE(client_->IsDescendantOfManagedNode(parent->GetChild(0))); | 248 EXPECT_TRUE(bookmarks::IsDescendantOf(parent->GetChild(0), |
243 EXPECT_TRUE(client_->IsDescendantOfManagedNode(parent->GetChild(1))); | 249 client_->managed_node())); |
| 250 EXPECT_TRUE(bookmarks::IsDescendantOf(parent->GetChild(1), |
| 251 client_->managed_node())); |
244 | 252 |
245 parent = parent->GetChild(1); | 253 parent = parent->GetChild(1); |
246 ASSERT_EQ(2, parent->child_count()); | 254 ASSERT_EQ(2, parent->child_count()); |
247 EXPECT_TRUE(client_->IsDescendantOfManagedNode(parent->GetChild(0))); | 255 EXPECT_TRUE(bookmarks::IsDescendantOf(parent->GetChild(0), |
248 EXPECT_TRUE(client_->IsDescendantOfManagedNode(parent->GetChild(1))); | 256 client_->managed_node())); |
| 257 EXPECT_TRUE(bookmarks::IsDescendantOf(parent->GetChild(1), |
| 258 client_->managed_node())); |
249 } | 259 } |
250 | 260 |
251 TEST_F(ChromeBookmarkClientTest, RemoveAllDoesntRemoveManaged) { | 261 TEST_F(ChromeBookmarkClientTest, RemoveAllDoesntRemoveManaged) { |
252 EXPECT_EQ(2, client_->managed_node()->child_count()); | 262 EXPECT_EQ(2, client_->managed_node()->child_count()); |
253 | 263 |
254 EXPECT_CALL(observer_, | 264 EXPECT_CALL(observer_, |
255 BookmarkNodeAdded(model_, model_->bookmark_bar_node(), 0)); | 265 BookmarkNodeAdded(model_, model_->bookmark_bar_node(), 0)); |
256 EXPECT_CALL(observer_, | 266 EXPECT_CALL(observer_, |
257 BookmarkNodeAdded(model_, model_->bookmark_bar_node(), 1)); | 267 BookmarkNodeAdded(model_, model_->bookmark_bar_node(), 1)); |
258 model_->AddURL(model_->bookmark_bar_node(), | 268 model_->AddURL(model_->bookmark_bar_node(), |
(...skipping 14 matching lines...) Expand all Loading... |
273 | 283 |
274 TEST_F(ChromeBookmarkClientTest, HasDescendantsOfManagedNode) { | 284 TEST_F(ChromeBookmarkClientTest, HasDescendantsOfManagedNode) { |
275 const BookmarkNode* user_node = model_->AddURL(model_->other_node(), | 285 const BookmarkNode* user_node = model_->AddURL(model_->other_node(), |
276 0, | 286 0, |
277 base::ASCIIToUTF16("foo bar"), | 287 base::ASCIIToUTF16("foo bar"), |
278 GURL("http://www.google.com")); | 288 GURL("http://www.google.com")); |
279 const BookmarkNode* managed_node = client_->managed_node()->GetChild(0); | 289 const BookmarkNode* managed_node = client_->managed_node()->GetChild(0); |
280 ASSERT_TRUE(managed_node); | 290 ASSERT_TRUE(managed_node); |
281 | 291 |
282 std::vector<const BookmarkNode*> nodes; | 292 std::vector<const BookmarkNode*> nodes; |
283 EXPECT_FALSE(client_->HasDescendantsOfManagedNode(nodes)); | 293 EXPECT_FALSE(bookmarks::HasDescendantsOf(nodes, client_->managed_node())); |
284 nodes.push_back(user_node); | 294 nodes.push_back(user_node); |
285 EXPECT_FALSE(client_->HasDescendantsOfManagedNode(nodes)); | 295 EXPECT_FALSE(bookmarks::HasDescendantsOf(nodes, client_->managed_node())); |
286 nodes.push_back(managed_node); | 296 nodes.push_back(managed_node); |
287 EXPECT_TRUE(client_->HasDescendantsOfManagedNode(nodes)); | 297 EXPECT_TRUE(bookmarks::HasDescendantsOf(nodes, client_->managed_node())); |
288 } | 298 } |
OLD | NEW |