| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/sync/test/integration/bookmarks_helper.h" | 5 #include "chrome/browser/sync/test/integration/bookmarks_helper.h" |
| 6 | 6 |
| 7 #include "base/bind.h" |
| 7 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 8 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 9 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 10 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
| 11 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
| 16 #include "base/task/cancelable_task_tracker.h" | 17 #include "base/task/cancelable_task_tracker.h" |
| 17 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 18 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 19 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" |
| 20 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h" |
| 18 #include "chrome/browser/favicon/favicon_service.h" | 21 #include "chrome/browser/favicon/favicon_service.h" |
| 19 #include "chrome/browser/favicon/favicon_service_factory.h" | 22 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 20 #include "chrome/browser/history/history_db_task.h" | 23 #include "chrome/browser/history/history_db_task.h" |
| 21 #include "chrome/browser/history/history_service_factory.h" | 24 #include "chrome/browser/history/history_service_factory.h" |
| 22 #include "chrome/browser/history/history_types.h" | 25 #include "chrome/browser/history/history_types.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/sync/glue/bookmark_change_processor.h" | 27 #include "chrome/browser/sync/glue/bookmark_change_processor.h" |
| 25 #include "chrome/browser/sync/test/integration/multi_client_status_change_checke
r.h" | 28 #include "chrome/browser/sync/test/integration/multi_client_status_change_checke
r.h" |
| 26 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" | 29 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" |
| 27 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" | 30 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" |
| 28 #include "chrome/browser/sync/test/integration/sync_test.h" | 31 #include "chrome/browser/sync/test/integration/sync_test.h" |
| 29 #include "chrome/common/chrome_paths.h" | 32 #include "chrome/common/chrome_paths.h" |
| 30 #include "chrome/test/base/ui_test_utils.h" | 33 #include "chrome/test/base/ui_test_utils.h" |
| 34 #include "components/bookmarks/browser/bookmark_client.h" |
| 31 #include "components/bookmarks/browser/bookmark_model.h" | 35 #include "components/bookmarks/browser/bookmark_model.h" |
| 32 #include "components/bookmarks/browser/bookmark_model_observer.h" | 36 #include "components/bookmarks/browser/bookmark_model_observer.h" |
| 33 #include "components/bookmarks/browser/bookmark_utils.h" | 37 #include "components/bookmarks/browser/bookmark_utils.h" |
| 34 #include "components/favicon_base/favicon_util.h" | 38 #include "components/favicon_base/favicon_util.h" |
| 35 #include "testing/gtest/include/gtest/gtest.h" | 39 #include "testing/gtest/include/gtest/gtest.h" |
| 36 #include "third_party/skia/include/core/SkBitmap.h" | 40 #include "third_party/skia/include/core/SkBitmap.h" |
| 37 #include "ui/base/models/tree_node_iterator.h" | 41 #include "ui/base/models/tree_node_iterator.h" |
| 38 #include "ui/gfx/image/image_skia.h" | 42 #include "ui/gfx/image/image_skia.h" |
| 39 | 43 |
| 40 namespace { | 44 namespace { |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 if (node_a->parent()->GetIndexOf(node_a) != | 334 if (node_a->parent()->GetIndexOf(node_a) != |
| 331 node_b->parent()->GetIndexOf(node_b)) { | 335 node_b->parent()->GetIndexOf(node_b)) { |
| 332 LOG(ERROR) << "Index mismatch: " | 336 LOG(ERROR) << "Index mismatch: " |
| 333 << node_a->parent()->GetIndexOf(node_a) << " vs. " | 337 << node_a->parent()->GetIndexOf(node_a) << " vs. " |
| 334 << node_b->parent()->GetIndexOf(node_b); | 338 << node_b->parent()->GetIndexOf(node_b); |
| 335 return false; | 339 return false; |
| 336 } | 340 } |
| 337 return true; | 341 return true; |
| 338 } | 342 } |
| 339 | 343 |
| 344 // Helper for BookmarkModelsMatch. |
| 345 bool NodeCantBeSynced(bookmarks::BookmarkClient* client, |
| 346 const BookmarkNode* node) { |
| 347 // Return true to skip a node. |
| 348 return !client->CanSyncNode(node); |
| 349 } |
| 350 |
| 340 // Checks if the hierarchies in |model_a| and |model_b| are equivalent in | 351 // Checks if the hierarchies in |model_a| and |model_b| are equivalent in |
| 341 // terms of the data model and favicon. Returns true if they both match. | 352 // terms of the data model and favicon. Returns true if they both match. |
| 342 // Note: Some peripheral fields like creation times are allowed to mismatch. | 353 // Note: Some peripheral fields like creation times are allowed to mismatch. |
| 343 bool BookmarkModelsMatch(BookmarkModel* model_a, BookmarkModel* model_b) { | 354 bool BookmarkModelsMatch(BookmarkModel* model_a, BookmarkModel* model_b) { |
| 344 bool ret_val = true; | 355 bool ret_val = true; |
| 345 ui::TreeNodeIterator<const BookmarkNode> iterator_a(model_a->root_node()); | 356 ui::TreeNodeIterator<const BookmarkNode> iterator_a( |
| 346 ui::TreeNodeIterator<const BookmarkNode> iterator_b(model_b->root_node()); | 357 model_a->root_node(), base::Bind(&NodeCantBeSynced, model_a->client())); |
| 358 ui::TreeNodeIterator<const BookmarkNode> iterator_b( |
| 359 model_b->root_node(), base::Bind(&NodeCantBeSynced, model_b->client())); |
| 347 while (iterator_a.has_next()) { | 360 while (iterator_a.has_next()) { |
| 348 const BookmarkNode* node_a = iterator_a.Next(); | 361 const BookmarkNode* node_a = iterator_a.Next(); |
| 349 if (!iterator_b.has_next()) { | 362 if (!iterator_b.has_next()) { |
| 350 LOG(ERROR) << "Models do not match."; | 363 LOG(ERROR) << "Models do not match."; |
| 351 return false; | 364 return false; |
| 352 } | 365 } |
| 353 const BookmarkNode* node_b = iterator_b.Next(); | 366 const BookmarkNode* node_b = iterator_b.Next(); |
| 354 ret_val = ret_val && NodesMatch(node_a, node_b); | 367 ret_val = ret_val && NodesMatch(node_a, node_b); |
| 355 if (node_a->is_folder() || node_b->is_folder()) | 368 if (node_a->is_folder() || node_b->is_folder()) |
| 356 continue; | 369 continue; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 } | 416 } |
| 404 | 417 |
| 405 const BookmarkNode* GetOtherNode(int index) { | 418 const BookmarkNode* GetOtherNode(int index) { |
| 406 return GetBookmarkModel(index)->other_node(); | 419 return GetBookmarkModel(index)->other_node(); |
| 407 } | 420 } |
| 408 | 421 |
| 409 const BookmarkNode* GetSyncedBookmarksNode(int index) { | 422 const BookmarkNode* GetSyncedBookmarksNode(int index) { |
| 410 return GetBookmarkModel(index)->mobile_node(); | 423 return GetBookmarkModel(index)->mobile_node(); |
| 411 } | 424 } |
| 412 | 425 |
| 426 const BookmarkNode* GetManagedNode(int index) { |
| 427 return ChromeBookmarkClientFactory::GetForProfile( |
| 428 sync_datatype_helper::test()->GetProfile(index))->managed_node(); |
| 429 } |
| 430 |
| 413 BookmarkModel* GetVerifierBookmarkModel() { | 431 BookmarkModel* GetVerifierBookmarkModel() { |
| 414 return BookmarkModelFactory::GetForProfile( | 432 return BookmarkModelFactory::GetForProfile( |
| 415 sync_datatype_helper::test()->verifier()); | 433 sync_datatype_helper::test()->verifier()); |
| 416 } | 434 } |
| 417 | 435 |
| 418 const BookmarkNode* AddURL(int profile, | 436 const BookmarkNode* AddURL(int profile, |
| 419 const std::string& title, | 437 const std::string& title, |
| 420 const GURL& url) { | 438 const GURL& url) { |
| 421 return AddURL(profile, GetBookmarkBarNode(profile), 0, title, url); | 439 return AddURL(profile, GetBookmarkBarNode(profile), 0, title, url); |
| 422 } | 440 } |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 816 | 834 |
| 817 std::string IndexedSubfolderName(int i) { | 835 std::string IndexedSubfolderName(int i) { |
| 818 return base::StringPrintf("Subfolder Name %d", i); | 836 return base::StringPrintf("Subfolder Name %d", i); |
| 819 } | 837 } |
| 820 | 838 |
| 821 std::string IndexedSubsubfolderName(int i) { | 839 std::string IndexedSubsubfolderName(int i) { |
| 822 return base::StringPrintf("Subsubfolder Name %d", i); | 840 return base::StringPrintf("Subsubfolder Name %d", i); |
| 823 } | 841 } |
| 824 | 842 |
| 825 } // namespace bookmarks_helper | 843 } // namespace bookmarks_helper |
| OLD | NEW |