| 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/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
| 16 #include "chrome/browser/bookmarks/bookmark_model.h" | 16 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 17 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 17 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 18 #include "chrome/browser/bookmarks/bookmark_model_observer.h" | 18 #include "chrome/browser/bookmarks/bookmark_model_observer.h" |
| 19 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| 19 #include "chrome/browser/favicon/favicon_service_factory.h" | 20 #include "chrome/browser/favicon/favicon_service_factory.h" |
| 20 #include "chrome/browser/favicon/favicon_util.h" | 21 #include "chrome/browser/favicon/favicon_util.h" |
| 21 #include "chrome/browser/history/history_db_task.h" | 22 #include "chrome/browser/history/history_db_task.h" |
| 22 #include "chrome/browser/history/history_service_factory.h" | 23 #include "chrome/browser/history/history_service_factory.h" |
| 23 #include "chrome/browser/history/history_types.h" | 24 #include "chrome/browser/history/history_types.h" |
| 24 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 25 #include "chrome/browser/sync/glue/bookmark_change_processor.h" | 26 #include "chrome/browser/sync/glue/bookmark_change_processor.h" |
| 26 #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" |
| 27 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" | 28 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" |
| 28 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" | 29 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 const std::wstring& title, | 415 const std::wstring& title, |
| 415 const GURL& url) { | 416 const GURL& url) { |
| 416 return AddURL(profile, GetBookmarkBarNode(profile), index, title, url); | 417 return AddURL(profile, GetBookmarkBarNode(profile), index, title, url); |
| 417 } | 418 } |
| 418 | 419 |
| 419 const BookmarkNode* AddURL(int profile, | 420 const BookmarkNode* AddURL(int profile, |
| 420 const BookmarkNode* parent, | 421 const BookmarkNode* parent, |
| 421 int index, | 422 int index, |
| 422 const std::wstring& title, | 423 const std::wstring& title, |
| 423 const GURL& url) { | 424 const GURL& url) { |
| 424 if (GetBookmarkModel(profile)->GetNodeByID(parent->id()) != parent) { | 425 BookmarkModel* model = GetBookmarkModel(profile); |
| 426 if (bookmark_utils::GetNodeByID(model, parent->id()) != parent) { |
| 425 LOG(ERROR) << "Node " << parent->GetTitle() << " does not belong to " | 427 LOG(ERROR) << "Node " << parent->GetTitle() << " does not belong to " |
| 426 << "Profile " << profile; | 428 << "Profile " << profile; |
| 427 return NULL; | 429 return NULL; |
| 428 } | 430 } |
| 429 const BookmarkNode* result = GetBookmarkModel(profile)-> | 431 const BookmarkNode* result = |
| 430 AddURL(parent, index, base::WideToUTF16(title), url); | 432 model->AddURL(parent, index, base::WideToUTF16(title), url); |
| 431 if (!result) { | 433 if (!result) { |
| 432 LOG(ERROR) << "Could not add bookmark " << title << " to Profile " | 434 LOG(ERROR) << "Could not add bookmark " << title << " to Profile " |
| 433 << profile; | 435 << profile; |
| 434 return NULL; | 436 return NULL; |
| 435 } | 437 } |
| 436 if (test()->use_verifier()) { | 438 if (test()->use_verifier()) { |
| 437 const BookmarkNode* v_parent = NULL; | 439 const BookmarkNode* v_parent = NULL; |
| 438 FindNodeInVerifier(GetBookmarkModel(profile), parent, &v_parent); | 440 FindNodeInVerifier(model, parent, &v_parent); |
| 439 const BookmarkNode* v_node = GetVerifierBookmarkModel()-> | 441 const BookmarkNode* v_node = GetVerifierBookmarkModel()->AddURL( |
| 440 AddURL(v_parent, index, base::WideToUTF16(title), url); | 442 v_parent, index, base::WideToUTF16(title), url); |
| 441 if (!v_node) { | 443 if (!v_node) { |
| 442 LOG(ERROR) << "Could not add bookmark " << title << " to the verifier"; | 444 LOG(ERROR) << "Could not add bookmark " << title << " to the verifier"; |
| 443 return NULL; | 445 return NULL; |
| 444 } | 446 } |
| 445 EXPECT_TRUE(NodesMatch(v_node, result)); | 447 EXPECT_TRUE(NodesMatch(v_node, result)); |
| 446 } | 448 } |
| 447 return result; | 449 return result; |
| 448 } | 450 } |
| 449 | 451 |
| 450 const BookmarkNode* AddFolder(int profile, | 452 const BookmarkNode* AddFolder(int profile, const std::wstring& title) { |
| 451 const std::wstring& title) { | |
| 452 return AddFolder(profile, GetBookmarkBarNode(profile), 0, title); | 453 return AddFolder(profile, GetBookmarkBarNode(profile), 0, title); |
| 453 } | 454 } |
| 454 | 455 |
| 455 const BookmarkNode* AddFolder(int profile, | 456 const BookmarkNode* AddFolder(int profile, |
| 456 int index, | 457 int index, |
| 457 const std::wstring& title) { | 458 const std::wstring& title) { |
| 458 return AddFolder(profile, GetBookmarkBarNode(profile), index, title); | 459 return AddFolder(profile, GetBookmarkBarNode(profile), index, title); |
| 459 } | 460 } |
| 460 | 461 |
| 461 const BookmarkNode* AddFolder(int profile, | 462 const BookmarkNode* AddFolder(int profile, |
| 462 const BookmarkNode* parent, | 463 const BookmarkNode* parent, |
| 463 int index, | 464 int index, |
| 464 const std::wstring& title) { | 465 const std::wstring& title) { |
| 465 if (GetBookmarkModel(profile)->GetNodeByID(parent->id()) != parent) { | 466 BookmarkModel* model = GetBookmarkModel(profile); |
| 467 if (bookmark_utils::GetNodeByID(model, parent->id()) != parent) { |
| 466 LOG(ERROR) << "Node " << parent->GetTitle() << " does not belong to " | 468 LOG(ERROR) << "Node " << parent->GetTitle() << " does not belong to " |
| 467 << "Profile " << profile; | 469 << "Profile " << profile; |
| 468 return NULL; | 470 return NULL; |
| 469 } | 471 } |
| 470 const BookmarkNode* result = GetBookmarkModel(profile)->AddFolder( | 472 const BookmarkNode* result = |
| 471 parent, index, base::WideToUTF16(title)); | 473 model->AddFolder(parent, index, base::WideToUTF16(title)); |
| 472 EXPECT_TRUE(result); | 474 EXPECT_TRUE(result); |
| 473 if (!result) { | 475 if (!result) { |
| 474 LOG(ERROR) << "Could not add folder " << title << " to Profile " | 476 LOG(ERROR) << "Could not add folder " << title << " to Profile " |
| 475 << profile; | 477 << profile; |
| 476 return NULL; | 478 return NULL; |
| 477 } | 479 } |
| 478 if (test()->use_verifier()) { | 480 if (test()->use_verifier()) { |
| 479 const BookmarkNode* v_parent = NULL; | 481 const BookmarkNode* v_parent = NULL; |
| 480 FindNodeInVerifier(GetBookmarkModel(profile), parent, &v_parent); | 482 FindNodeInVerifier(model, parent, &v_parent); |
| 481 const BookmarkNode* v_node = GetVerifierBookmarkModel()->AddFolder( | 483 const BookmarkNode* v_node = GetVerifierBookmarkModel()->AddFolder( |
| 482 v_parent, index, base::WideToUTF16(title)); | 484 v_parent, index, base::WideToUTF16(title)); |
| 483 if (!v_node) { | 485 if (!v_node) { |
| 484 LOG(ERROR) << "Could not add folder " << title << " to the verifier"; | 486 LOG(ERROR) << "Could not add folder " << title << " to the verifier"; |
| 485 return NULL; | 487 return NULL; |
| 486 } | 488 } |
| 487 EXPECT_TRUE(NodesMatch(v_node, result)); | 489 EXPECT_TRUE(NodesMatch(v_node, result)); |
| 488 } | 490 } |
| 489 return result; | 491 return result; |
| 490 } | 492 } |
| 491 | 493 |
| 492 void SetTitle(int profile, | 494 void SetTitle(int profile, |
| 493 const BookmarkNode* node, | 495 const BookmarkNode* node, |
| 494 const std::wstring& new_title) { | 496 const std::wstring& new_title) { |
| 495 ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(node->id()), node) | 497 BookmarkModel* model = GetBookmarkModel(profile); |
| 498 ASSERT_EQ(bookmark_utils::GetNodeByID(model, node->id()), node) |
| 496 << "Node " << node->GetTitle() << " does not belong to " | 499 << "Node " << node->GetTitle() << " does not belong to " |
| 497 << "Profile " << profile; | 500 << "Profile " << profile; |
| 498 if (test()->use_verifier()) { | 501 if (test()->use_verifier()) { |
| 499 const BookmarkNode* v_node = NULL; | 502 const BookmarkNode* v_node = NULL; |
| 500 FindNodeInVerifier(GetBookmarkModel(profile), node, &v_node); | 503 FindNodeInVerifier(model, node, &v_node); |
| 501 GetVerifierBookmarkModel()->SetTitle(v_node, base::WideToUTF16(new_title)); | 504 GetVerifierBookmarkModel()->SetTitle(v_node, base::WideToUTF16(new_title)); |
| 502 } | 505 } |
| 503 GetBookmarkModel(profile)->SetTitle(node, base::WideToUTF16(new_title)); | 506 model->SetTitle(node, base::WideToUTF16(new_title)); |
| 504 } | 507 } |
| 505 | 508 |
| 506 void SetFavicon(int profile, | 509 void SetFavicon(int profile, |
| 507 const BookmarkNode* node, | 510 const BookmarkNode* node, |
| 508 const GURL& icon_url, | 511 const GURL& icon_url, |
| 509 const gfx::Image& image, | 512 const gfx::Image& image, |
| 510 FaviconSource favicon_source) { | 513 FaviconSource favicon_source) { |
| 511 ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(node->id()), node) | 514 BookmarkModel* model = GetBookmarkModel(profile); |
| 515 ASSERT_EQ(bookmark_utils::GetNodeByID(model, node->id()), node) |
| 512 << "Node " << node->GetTitle() << " does not belong to " | 516 << "Node " << node->GetTitle() << " does not belong to " |
| 513 << "Profile " << profile; | 517 << "Profile " << profile; |
| 514 ASSERT_EQ(BookmarkNode::URL, node->type()) | 518 ASSERT_EQ(BookmarkNode::URL, node->type()) << "Node " << node->GetTitle() |
| 515 << "Node " << node->GetTitle() << " must be a url."; | 519 << " must be a url."; |
| 516 if (urls_with_favicons_ == NULL) | 520 if (urls_with_favicons_ == NULL) |
| 517 urls_with_favicons_ = new std::set<GURL>(); | 521 urls_with_favicons_ = new std::set<GURL>(); |
| 518 urls_with_favicons_->insert(node->url()); | 522 urls_with_favicons_->insert(node->url()); |
| 519 if (test()->use_verifier()) { | 523 if (test()->use_verifier()) { |
| 520 const BookmarkNode* v_node = NULL; | 524 const BookmarkNode* v_node = NULL; |
| 521 FindNodeInVerifier(GetBookmarkModel(profile), node, &v_node); | 525 FindNodeInVerifier(model, node, &v_node); |
| 522 SetFaviconImpl(test()->verifier(), v_node, icon_url, image, favicon_source); | 526 SetFaviconImpl(test()->verifier(), v_node, icon_url, image, favicon_source); |
| 523 } | 527 } |
| 524 SetFaviconImpl(test()->GetProfile(profile), node, icon_url, image, | 528 SetFaviconImpl(test()->GetProfile(profile), node, icon_url, image, |
| 525 favicon_source); | 529 favicon_source); |
| 526 } | 530 } |
| 527 | 531 |
| 528 const BookmarkNode* SetURL(int profile, | 532 const BookmarkNode* SetURL(int profile, |
| 529 const BookmarkNode* node, | 533 const BookmarkNode* node, |
| 530 const GURL& new_url) { | 534 const GURL& new_url) { |
| 531 if (GetBookmarkModel(profile)->GetNodeByID(node->id()) != node) { | 535 BookmarkModel* model = GetBookmarkModel(profile); |
| 536 if (bookmark_utils::GetNodeByID(model, node->id()) != node) { |
| 532 LOG(ERROR) << "Node " << node->GetTitle() << " does not belong to " | 537 LOG(ERROR) << "Node " << node->GetTitle() << " does not belong to " |
| 533 << "Profile " << profile; | 538 << "Profile " << profile; |
| 534 return NULL; | 539 return NULL; |
| 535 } | 540 } |
| 536 if (test()->use_verifier()) { | 541 if (test()->use_verifier()) { |
| 537 const BookmarkNode* v_node = NULL; | 542 const BookmarkNode* v_node = NULL; |
| 538 FindNodeInVerifier(GetBookmarkModel(profile), node, &v_node); | 543 FindNodeInVerifier(model, node, &v_node); |
| 539 if (v_node->is_url()) | 544 if (v_node->is_url()) |
| 540 GetVerifierBookmarkModel()->SetURL(v_node, new_url); | 545 GetVerifierBookmarkModel()->SetURL(v_node, new_url); |
| 541 } | 546 } |
| 542 if (node->is_url()) | 547 if (node->is_url()) |
| 543 GetBookmarkModel(profile)->SetURL(node, new_url); | 548 model->SetURL(node, new_url); |
| 544 return node; | 549 return node; |
| 545 } | 550 } |
| 546 | 551 |
| 547 void Move(int profile, | 552 void Move(int profile, |
| 548 const BookmarkNode* node, | 553 const BookmarkNode* node, |
| 549 const BookmarkNode* new_parent, | 554 const BookmarkNode* new_parent, |
| 550 int index) { | 555 int index) { |
| 551 ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(node->id()), node) | 556 BookmarkModel* model = GetBookmarkModel(profile); |
| 557 ASSERT_EQ(bookmark_utils::GetNodeByID(model, node->id()), node) |
| 552 << "Node " << node->GetTitle() << " does not belong to " | 558 << "Node " << node->GetTitle() << " does not belong to " |
| 553 << "Profile " << profile; | 559 << "Profile " << profile; |
| 554 if (test()->use_verifier()) { | 560 if (test()->use_verifier()) { |
| 555 const BookmarkNode* v_new_parent = NULL; | 561 const BookmarkNode* v_new_parent = NULL; |
| 556 const BookmarkNode* v_node = NULL; | 562 const BookmarkNode* v_node = NULL; |
| 557 FindNodeInVerifier(GetBookmarkModel(profile), new_parent, &v_new_parent); | 563 FindNodeInVerifier(model, new_parent, &v_new_parent); |
| 558 FindNodeInVerifier(GetBookmarkModel(profile), node, &v_node); | 564 FindNodeInVerifier(model, node, &v_node); |
| 559 GetVerifierBookmarkModel()->Move(v_node, v_new_parent, index); | 565 GetVerifierBookmarkModel()->Move(v_node, v_new_parent, index); |
| 560 } | 566 } |
| 561 GetBookmarkModel(profile)->Move(node, new_parent, index); | 567 model->Move(node, new_parent, index); |
| 562 } | 568 } |
| 563 | 569 |
| 564 void Remove(int profile, | 570 void Remove(int profile, const BookmarkNode* parent, int index) { |
| 565 const BookmarkNode* parent, | 571 BookmarkModel* model = GetBookmarkModel(profile); |
| 566 int index) { | 572 ASSERT_EQ(bookmark_utils::GetNodeByID(model, parent->id()), parent) |
| 567 ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(parent->id()), parent) | |
| 568 << "Node " << parent->GetTitle() << " does not belong to " | 573 << "Node " << parent->GetTitle() << " does not belong to " |
| 569 << "Profile " << profile; | 574 << "Profile " << profile; |
| 570 if (test()->use_verifier()) { | 575 if (test()->use_verifier()) { |
| 571 const BookmarkNode* v_parent = NULL; | 576 const BookmarkNode* v_parent = NULL; |
| 572 FindNodeInVerifier(GetBookmarkModel(profile), parent, &v_parent); | 577 FindNodeInVerifier(model, parent, &v_parent); |
| 573 ASSERT_TRUE(NodesMatch(parent->GetChild(index), v_parent->GetChild(index))); | 578 ASSERT_TRUE(NodesMatch(parent->GetChild(index), v_parent->GetChild(index))); |
| 574 GetVerifierBookmarkModel()->Remove(v_parent, index); | 579 GetVerifierBookmarkModel()->Remove(v_parent, index); |
| 575 } | 580 } |
| 576 GetBookmarkModel(profile)->Remove(parent, index); | 581 model->Remove(parent, index); |
| 577 } | 582 } |
| 578 | 583 |
| 579 void RemoveAll(int profile) { | 584 void RemoveAll(int profile) { |
| 580 if (test()->use_verifier()) { | 585 if (test()->use_verifier()) { |
| 581 const BookmarkNode* root_node = GetVerifierBookmarkModel()->root_node(); | 586 const BookmarkNode* root_node = GetVerifierBookmarkModel()->root_node(); |
| 582 for (int i = 0; i < root_node->child_count(); ++i) { | 587 for (int i = 0; i < root_node->child_count(); ++i) { |
| 583 const BookmarkNode* permanent_node = root_node->GetChild(i); | 588 const BookmarkNode* permanent_node = root_node->GetChild(i); |
| 584 for (int j = permanent_node->child_count() - 1; j >= 0; --j) { | 589 for (int j = permanent_node->child_count() - 1; j >= 0; --j) { |
| 585 GetVerifierBookmarkModel()->Remove(permanent_node, j); | 590 GetVerifierBookmarkModel()->Remove(permanent_node, j); |
| 586 } | 591 } |
| 587 } | 592 } |
| 588 } | 593 } |
| 589 GetBookmarkModel(profile)->RemoveAll(); | 594 GetBookmarkModel(profile)->RemoveAll(); |
| 590 } | 595 } |
| 591 | 596 |
| 592 void SortChildren(int profile, const BookmarkNode* parent) { | 597 void SortChildren(int profile, const BookmarkNode* parent) { |
| 593 ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(parent->id()), parent) | 598 BookmarkModel* model = GetBookmarkModel(profile); |
| 599 ASSERT_EQ(bookmark_utils::GetNodeByID(model, parent->id()), parent) |
| 594 << "Node " << parent->GetTitle() << " does not belong to " | 600 << "Node " << parent->GetTitle() << " does not belong to " |
| 595 << "Profile " << profile; | 601 << "Profile " << profile; |
| 596 if (test()->use_verifier()) { | 602 if (test()->use_verifier()) { |
| 597 const BookmarkNode* v_parent = NULL; | 603 const BookmarkNode* v_parent = NULL; |
| 598 FindNodeInVerifier(GetBookmarkModel(profile), parent, &v_parent); | 604 FindNodeInVerifier(model, parent, &v_parent); |
| 599 GetVerifierBookmarkModel()->SortChildren(v_parent); | 605 GetVerifierBookmarkModel()->SortChildren(v_parent); |
| 600 } | 606 } |
| 601 GetBookmarkModel(profile)->SortChildren(parent); | 607 model->SortChildren(parent); |
| 602 } | 608 } |
| 603 | 609 |
| 604 void ReverseChildOrder(int profile, const BookmarkNode* parent) { | 610 void ReverseChildOrder(int profile, const BookmarkNode* parent) { |
| 605 ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(parent->id()), parent) | 611 ASSERT_EQ( |
| 612 bookmark_utils::GetNodeByID(GetBookmarkModel(profile), parent->id()), |
| 613 parent) |
| 606 << "Node " << parent->GetTitle() << " does not belong to " | 614 << "Node " << parent->GetTitle() << " does not belong to " |
| 607 << "Profile " << profile; | 615 << "Profile " << profile; |
| 608 int child_count = parent->child_count(); | 616 int child_count = parent->child_count(); |
| 609 if (child_count <= 0) | 617 if (child_count <= 0) |
| 610 return; | 618 return; |
| 611 for (int index = 0; index < child_count; ++index) { | 619 for (int index = 0; index < child_count; ++index) { |
| 612 Move(profile, parent->GetChild(index), parent, child_count - index); | 620 Move(profile, parent->GetChild(index), parent, child_count - index); |
| 613 } | 621 } |
| 614 } | 622 } |
| 615 | 623 |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 793 | 801 |
| 794 std::wstring IndexedSubfolderName(int i) { | 802 std::wstring IndexedSubfolderName(int i) { |
| 795 return base::StringPrintf(L"Subfolder Name %d", i); | 803 return base::StringPrintf(L"Subfolder Name %d", i); |
| 796 } | 804 } |
| 797 | 805 |
| 798 std::wstring IndexedSubsubfolderName(int i) { | 806 std::wstring IndexedSubsubfolderName(int i) { |
| 799 return base::StringPrintf(L"Subsubfolder Name %d", i); | 807 return base::StringPrintf(L"Subsubfolder Name %d", i); |
| 800 } | 808 } |
| 801 | 809 |
| 802 } // namespace bookmarks_helper | 810 } // namespace bookmarks_helper |
| OLD | NEW |