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 <set> | 7 #include <set> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
14 #include "base/rand_util.h" | 14 #include "base/rand_util.h" |
15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
19 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
20 #include "base/synchronization/waitable_event.h" | 20 #include "base/synchronization/waitable_event.h" |
21 #include "base/task/cancelable_task_tracker.h" | 21 #include "base/task/cancelable_task_tracker.h" |
22 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 22 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
23 #include "chrome/browser/bookmarks/chrome_bookmark_client.h" | |
24 #include "chrome/browser/bookmarks/chrome_bookmark_client_factory.h" | |
25 #include "chrome/browser/favicon/favicon_service_factory.h" | 23 #include "chrome/browser/favicon/favicon_service_factory.h" |
26 #include "chrome/browser/history/history_service_factory.h" | 24 #include "chrome/browser/history/history_service_factory.h" |
27 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
28 #include "chrome/browser/sync/glue/bookmark_change_processor.h" | 26 #include "chrome/browser/sync/glue/bookmark_change_processor.h" |
29 #include "chrome/browser/sync/test/integration/multi_client_status_change_checke
r.h" | 27 #include "chrome/browser/sync/test/integration/multi_client_status_change_checke
r.h" |
30 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" | 28 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" |
31 #include "chrome/browser/sync/test/integration/single_client_status_change_check
er.h" | 29 #include "chrome/browser/sync/test/integration/single_client_status_change_check
er.h" |
32 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" | 30 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" |
33 #include "chrome/browser/sync/test/integration/sync_test.h" | 31 #include "chrome/browser/sync/test/integration/sync_test.h" |
34 #include "chrome/common/chrome_paths.h" | 32 #include "chrome/common/chrome_paths.h" |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 node_b->parent()->GetIndexOf(node_b)) { | 372 node_b->parent()->GetIndexOf(node_b)) { |
375 LOG(ERROR) << "Index mismatch: " | 373 LOG(ERROR) << "Index mismatch: " |
376 << node_a->parent()->GetIndexOf(node_a) << " vs. " | 374 << node_a->parent()->GetIndexOf(node_a) << " vs. " |
377 << node_b->parent()->GetIndexOf(node_b); | 375 << node_b->parent()->GetIndexOf(node_b); |
378 return false; | 376 return false; |
379 } | 377 } |
380 return true; | 378 return true; |
381 } | 379 } |
382 | 380 |
383 // Helper for BookmarkModelsMatch. | 381 // Helper for BookmarkModelsMatch. |
384 bool NodeCantBeSynced(bookmarks::BookmarkClient* client, | 382 bool NodeCantBeSynced(bookmarks::BookmarkModel* model, |
385 const BookmarkNode* node) { | 383 const BookmarkNode* node) { |
386 // Return true to skip a node. | 384 // Return true to skip a node. |
387 return !client->CanSyncNode(node); | 385 return !model->CanSyncNode(node); |
388 } | 386 } |
389 | 387 |
390 // Checks if the hierarchies in |model_a| and |model_b| are equivalent in | 388 // Checks if the hierarchies in |model_a| and |model_b| are equivalent in |
391 // terms of the data model and favicon. Returns true if they both match. | 389 // terms of the data model and favicon. Returns true if they both match. |
392 // Note: Some peripheral fields like creation times are allowed to mismatch. | 390 // Note: Some peripheral fields like creation times are allowed to mismatch. |
393 bool BookmarkModelsMatch(BookmarkModel* model_a, BookmarkModel* model_b) { | 391 bool BookmarkModelsMatch(BookmarkModel* model_a, BookmarkModel* model_b) { |
394 bool ret_val = true; | 392 bool ret_val = true; |
395 ui::TreeNodeIterator<const BookmarkNode> iterator_a( | 393 ui::TreeNodeIterator<const BookmarkNode> iterator_a( |
396 model_a->root_node(), base::Bind(&NodeCantBeSynced, model_a->client())); | 394 model_a->root_node(), base::Bind(&NodeCantBeSynced, model_a)); |
397 ui::TreeNodeIterator<const BookmarkNode> iterator_b( | 395 ui::TreeNodeIterator<const BookmarkNode> iterator_b( |
398 model_b->root_node(), base::Bind(&NodeCantBeSynced, model_b->client())); | 396 model_b->root_node(), base::Bind(&NodeCantBeSynced, model_b)); |
399 while (iterator_a.has_next()) { | 397 while (iterator_a.has_next()) { |
400 const BookmarkNode* node_a = iterator_a.Next(); | 398 const BookmarkNode* node_a = iterator_a.Next(); |
401 if (!iterator_b.has_next()) { | 399 if (!iterator_b.has_next()) { |
402 LOG(ERROR) << "Models do not match."; | 400 LOG(ERROR) << "Models do not match."; |
403 return false; | 401 return false; |
404 } | 402 } |
405 const BookmarkNode* node_b = iterator_b.Next(); | 403 const BookmarkNode* node_b = iterator_b.Next(); |
406 ret_val = ret_val && NodesMatch(node_a, node_b); | 404 ret_val = ret_val && NodesMatch(node_a, node_b); |
407 if (node_a->is_folder() || node_b->is_folder()) | 405 if (node_a->is_folder() || node_b->is_folder()) |
408 continue; | 406 continue; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 | 454 |
457 const BookmarkNode* GetOtherNode(int index) { | 455 const BookmarkNode* GetOtherNode(int index) { |
458 return GetBookmarkModel(index)->other_node(); | 456 return GetBookmarkModel(index)->other_node(); |
459 } | 457 } |
460 | 458 |
461 const BookmarkNode* GetSyncedBookmarksNode(int index) { | 459 const BookmarkNode* GetSyncedBookmarksNode(int index) { |
462 return GetBookmarkModel(index)->mobile_node(); | 460 return GetBookmarkModel(index)->mobile_node(); |
463 } | 461 } |
464 | 462 |
465 const BookmarkNode* GetManagedNode(int index) { | 463 const BookmarkNode* GetManagedNode(int index) { |
466 return ChromeBookmarkClientFactory::GetForProfile( | 464 return BookmarkModelFactory::GetForProfile( |
467 sync_datatype_helper::test()->GetProfile(index))->managed_node(); | 465 sync_datatype_helper::test()->GetProfile(index))->managed_node(); |
468 } | 466 } |
469 | 467 |
470 BookmarkModel* GetVerifierBookmarkModel() { | 468 BookmarkModel* GetVerifierBookmarkModel() { |
471 return BookmarkModelFactory::GetForProfile( | 469 return BookmarkModelFactory::GetForProfile( |
472 sync_datatype_helper::test()->verifier()); | 470 sync_datatype_helper::test()->verifier()); |
473 } | 471 } |
474 | 472 |
475 const BookmarkNode* AddURL(int profile, | 473 const BookmarkNode* AddURL(int profile, |
476 const std::string& title, | 474 const std::string& title, |
477 const GURL& url) { | 475 const GURL& url) { |
(...skipping 479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
957 | 955 |
958 std::string IndexedSubfolderName(int i) { | 956 std::string IndexedSubfolderName(int i) { |
959 return base::StringPrintf("Subfolder Name %d", i); | 957 return base::StringPrintf("Subfolder Name %d", i); |
960 } | 958 } |
961 | 959 |
962 std::string IndexedSubsubfolderName(int i) { | 960 std::string IndexedSubsubfolderName(int i) { |
963 return base::StringPrintf("Subsubfolder Name %d", i); | 961 return base::StringPrintf("Subsubfolder Name %d", i); |
964 } | 962 } |
965 | 963 |
966 } // namespace bookmarks_helper | 964 } // namespace bookmarks_helper |
OLD | NEW |