Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(430)

Side by Side Diff: chrome/browser/sync/test/integration/bookmarks_helper.cc

Issue 310103004: Add integraton test for sync backup/rollback. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 const BookmarkNode* GetSyncedBookmarksNode(int index) { 405 const BookmarkNode* GetSyncedBookmarksNode(int index) {
406 return GetBookmarkModel(index)->mobile_node(); 406 return GetBookmarkModel(index)->mobile_node();
407 } 407 }
408 408
409 BookmarkModel* GetVerifierBookmarkModel() { 409 BookmarkModel* GetVerifierBookmarkModel() {
410 return BookmarkModelFactory::GetForProfile( 410 return BookmarkModelFactory::GetForProfile(
411 sync_datatype_helper::test()->verifier()); 411 sync_datatype_helper::test()->verifier());
412 } 412 }
413 413
414 const BookmarkNode* AddURL(int profile, 414 const BookmarkNode* AddURL(int profile,
415 const std::wstring& title, 415 const std::string& title,
416 const GURL& url) { 416 const GURL& url) {
417 return AddURL(profile, GetBookmarkBarNode(profile), 0, title, url); 417 return AddURL(profile, GetBookmarkBarNode(profile), 0, title, url);
418 } 418 }
419 419
420 const BookmarkNode* AddURL(int profile, 420 const BookmarkNode* AddURL(int profile,
421 int index, 421 int index,
422 const std::wstring& title, 422 const std::string& title,
423 const GURL& url) { 423 const GURL& url) {
424 return AddURL(profile, GetBookmarkBarNode(profile), index, title, url); 424 return AddURL(profile, GetBookmarkBarNode(profile), index, title, url);
425 } 425 }
426 426
427 const BookmarkNode* AddURL(int profile, 427 const BookmarkNode* AddURL(int profile,
428 const BookmarkNode* parent, 428 const BookmarkNode* parent,
429 int index, 429 int index,
430 const std::wstring& title, 430 const std::string& title,
431 const GURL& url) { 431 const GURL& url) {
432 BookmarkModel* model = GetBookmarkModel(profile); 432 BookmarkModel* model = GetBookmarkModel(profile);
433 if (GetBookmarkNodeByID(model, parent->id()) != parent) { 433 if (GetBookmarkNodeByID(model, parent->id()) != parent) {
434 LOG(ERROR) << "Node " << parent->GetTitle() << " does not belong to " 434 LOG(ERROR) << "Node " << parent->GetTitle() << " does not belong to "
435 << "Profile " << profile; 435 << "Profile " << profile;
436 return NULL; 436 return NULL;
437 } 437 }
438 const BookmarkNode* result = 438 const BookmarkNode* result =
439 model->AddURL(parent, index, base::WideToUTF16(title), url); 439 model->AddURL(parent, index, base::UTF8ToUTF16(title), url);
440 if (!result) { 440 if (!result) {
441 LOG(ERROR) << "Could not add bookmark " << title << " to Profile " 441 LOG(ERROR) << "Could not add bookmark " << title << " to Profile "
442 << profile; 442 << profile;
443 return NULL; 443 return NULL;
444 } 444 }
445 if (sync_datatype_helper::test()->use_verifier()) { 445 if (sync_datatype_helper::test()->use_verifier()) {
446 const BookmarkNode* v_parent = NULL; 446 const BookmarkNode* v_parent = NULL;
447 FindNodeInVerifier(model, parent, &v_parent); 447 FindNodeInVerifier(model, parent, &v_parent);
448 const BookmarkNode* v_node = GetVerifierBookmarkModel()->AddURL( 448 const BookmarkNode* v_node = GetVerifierBookmarkModel()->AddURL(
449 v_parent, index, base::WideToUTF16(title), url); 449 v_parent, index, base::UTF8ToUTF16(title), url);
450 if (!v_node) { 450 if (!v_node) {
451 LOG(ERROR) << "Could not add bookmark " << title << " to the verifier"; 451 LOG(ERROR) << "Could not add bookmark " << title << " to the verifier";
452 return NULL; 452 return NULL;
453 } 453 }
454 EXPECT_TRUE(NodesMatch(v_node, result)); 454 EXPECT_TRUE(NodesMatch(v_node, result));
455 } 455 }
456 return result; 456 return result;
457 } 457 }
458 458
459 const BookmarkNode* AddFolder(int profile, 459 const BookmarkNode* AddFolder(int profile,
460 const std::wstring& title) { 460 const std::string& title) {
461 return AddFolder(profile, GetBookmarkBarNode(profile), 0, title); 461 return AddFolder(profile, GetBookmarkBarNode(profile), 0, title);
462 } 462 }
463 463
464 const BookmarkNode* AddFolder(int profile, 464 const BookmarkNode* AddFolder(int profile,
465 int index, 465 int index,
466 const std::wstring& title) { 466 const std::string& title) {
467 return AddFolder(profile, GetBookmarkBarNode(profile), index, title); 467 return AddFolder(profile, GetBookmarkBarNode(profile), index, title);
468 } 468 }
469 469
470 const BookmarkNode* AddFolder(int profile, 470 const BookmarkNode* AddFolder(int profile,
471 const BookmarkNode* parent, 471 const BookmarkNode* parent,
472 int index, 472 int index,
473 const std::wstring& title) { 473 const std::string& title) {
474 BookmarkModel* model = GetBookmarkModel(profile); 474 BookmarkModel* model = GetBookmarkModel(profile);
475 if (GetBookmarkNodeByID(model, parent->id()) != parent) { 475 if (GetBookmarkNodeByID(model, parent->id()) != parent) {
476 LOG(ERROR) << "Node " << parent->GetTitle() << " does not belong to " 476 LOG(ERROR) << "Node " << parent->GetTitle() << " does not belong to "
477 << "Profile " << profile; 477 << "Profile " << profile;
478 return NULL; 478 return NULL;
479 } 479 }
480 const BookmarkNode* result = 480 const BookmarkNode* result =
481 model->AddFolder(parent, index, base::WideToUTF16(title)); 481 model->AddFolder(parent, index, base::UTF8ToUTF16(title));
482 EXPECT_TRUE(result); 482 EXPECT_TRUE(result);
483 if (!result) { 483 if (!result) {
484 LOG(ERROR) << "Could not add folder " << title << " to Profile " 484 LOG(ERROR) << "Could not add folder " << title << " to Profile "
485 << profile; 485 << profile;
486 return NULL; 486 return NULL;
487 } 487 }
488 if (sync_datatype_helper::test()->use_verifier()) { 488 if (sync_datatype_helper::test()->use_verifier()) {
489 const BookmarkNode* v_parent = NULL; 489 const BookmarkNode* v_parent = NULL;
490 FindNodeInVerifier(model, parent, &v_parent); 490 FindNodeInVerifier(model, parent, &v_parent);
491 const BookmarkNode* v_node = GetVerifierBookmarkModel()->AddFolder( 491 const BookmarkNode* v_node = GetVerifierBookmarkModel()->AddFolder(
492 v_parent, index, base::WideToUTF16(title)); 492 v_parent, index, base::UTF8ToUTF16(title));
493 if (!v_node) { 493 if (!v_node) {
494 LOG(ERROR) << "Could not add folder " << title << " to the verifier"; 494 LOG(ERROR) << "Could not add folder " << title << " to the verifier";
495 return NULL; 495 return NULL;
496 } 496 }
497 EXPECT_TRUE(NodesMatch(v_node, result)); 497 EXPECT_TRUE(NodesMatch(v_node, result));
498 } 498 }
499 return result; 499 return result;
500 } 500 }
501 501
502 void SetTitle(int profile, 502 void SetTitle(int profile,
503 const BookmarkNode* node, 503 const BookmarkNode* node,
504 const std::wstring& new_title) { 504 const std::string& new_title) {
505 BookmarkModel* model = GetBookmarkModel(profile); 505 BookmarkModel* model = GetBookmarkModel(profile);
506 ASSERT_EQ(GetBookmarkNodeByID(model, node->id()), node) 506 ASSERT_EQ(GetBookmarkNodeByID(model, node->id()), node)
507 << "Node " << node->GetTitle() << " does not belong to " 507 << "Node " << node->GetTitle() << " does not belong to "
508 << "Profile " << profile; 508 << "Profile " << profile;
509 if (sync_datatype_helper::test()->use_verifier()) { 509 if (sync_datatype_helper::test()->use_verifier()) {
510 const BookmarkNode* v_node = NULL; 510 const BookmarkNode* v_node = NULL;
511 FindNodeInVerifier(model, node, &v_node); 511 FindNodeInVerifier(model, node, &v_node);
512 GetVerifierBookmarkModel()->SetTitle(v_node, base::WideToUTF16(new_title)); 512 GetVerifierBookmarkModel()->SetTitle(v_node, base::UTF8ToUTF16(new_title));
513 } 513 }
514 model->SetTitle(node, base::WideToUTF16(new_title)); 514 model->SetTitle(node, base::UTF8ToUTF16(new_title));
515 } 515 }
516 516
517 void SetFavicon(int profile, 517 void SetFavicon(int profile,
518 const BookmarkNode* node, 518 const BookmarkNode* node,
519 const GURL& icon_url, 519 const GURL& icon_url,
520 const gfx::Image& image, 520 const gfx::Image& image,
521 FaviconSource favicon_source) { 521 FaviconSource favicon_source) {
522 BookmarkModel* model = GetBookmarkModel(profile); 522 BookmarkModel* model = GetBookmarkModel(profile);
523 ASSERT_EQ(GetBookmarkNodeByID(model, node->id()), node) 523 ASSERT_EQ(GetBookmarkNodeByID(model, node->id()), node)
524 << "Node " << node->GetTitle() << " does not belong to " 524 << "Node " << node->GetTitle() << " does not belong to "
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 745
746 const BookmarkNode* GetUniqueNodeByURL(int profile, const GURL& url) { 746 const BookmarkNode* GetUniqueNodeByURL(int profile, const GURL& url) {
747 std::vector<const BookmarkNode*> nodes; 747 std::vector<const BookmarkNode*> nodes;
748 GetBookmarkModel(profile)->GetNodesByURL(url, &nodes); 748 GetBookmarkModel(profile)->GetNodesByURL(url, &nodes);
749 EXPECT_EQ(1U, nodes.size()); 749 EXPECT_EQ(1U, nodes.size());
750 if (nodes.empty()) 750 if (nodes.empty())
751 return NULL; 751 return NULL;
752 return nodes[0]; 752 return nodes[0];
753 } 753 }
754 754
755 int CountBookmarksWithTitlesMatching(int profile, const std::wstring& title) { 755 int CountBookmarksWithTitlesMatching(int profile, const std::string& title) {
756 return CountNodesWithTitlesMatching(GetBookmarkModel(profile), 756 return CountNodesWithTitlesMatching(GetBookmarkModel(profile),
757 BookmarkNode::URL, 757 BookmarkNode::URL,
758 base::WideToUTF16(title)); 758 base::UTF8ToUTF16(title));
759 } 759 }
760 760
761 int CountFoldersWithTitlesMatching(int profile, const std::wstring& title) { 761 int CountFoldersWithTitlesMatching(int profile, const std::string& title) {
762 return CountNodesWithTitlesMatching(GetBookmarkModel(profile), 762 return CountNodesWithTitlesMatching(GetBookmarkModel(profile),
763 BookmarkNode::FOLDER, 763 BookmarkNode::FOLDER,
764 base::WideToUTF16(title)); 764 base::UTF8ToUTF16(title));
765 } 765 }
766 766
767 gfx::Image CreateFavicon(SkColor color) { 767 gfx::Image CreateFavicon(SkColor color) {
768 const int dip_width = 16; 768 const int dip_width = 16;
769 const int dip_height = 16; 769 const int dip_height = 16;
770 std::vector<ui::ScaleFactor> favicon_scale_factors = 770 std::vector<ui::ScaleFactor> favicon_scale_factors =
771 FaviconUtil::GetFaviconScaleFactors(); 771 FaviconUtil::GetFaviconScaleFactors();
772 gfx::ImageSkia favicon; 772 gfx::ImageSkia favicon;
773 for (size_t i = 0; i < favicon_scale_factors.size(); ++i) { 773 for (size_t i = 0; i < favicon_scale_factors.size(); ++i) {
774 float scale = ui::GetScaleForScaleFactor(favicon_scale_factors[i]); 774 float scale = ui::GetScaleForScaleFactor(favicon_scale_factors[i]);
(...skipping 21 matching lines...) Expand all
796 std::string contents; 796 std::string contents;
797 base::ReadFileToString(full_path, &contents); 797 base::ReadFileToString(full_path, &contents);
798 return gfx::Image::CreateFrom1xPNGBytes( 798 return gfx::Image::CreateFrom1xPNGBytes(
799 base::RefCountedString::TakeString(&contents)); 799 base::RefCountedString::TakeString(&contents));
800 } 800 }
801 801
802 std::string IndexedURL(int i) { 802 std::string IndexedURL(int i) {
803 return base::StringPrintf("http://www.host.ext:1234/path/filename/%d", i); 803 return base::StringPrintf("http://www.host.ext:1234/path/filename/%d", i);
804 } 804 }
805 805
806 std::wstring IndexedURLTitle(int i) { 806 std::string IndexedURLTitle(int i) {
807 return base::StringPrintf(L"URL Title %d", i); 807 return base::StringPrintf("URL Title %d", i);
808 } 808 }
809 809
810 std::wstring IndexedFolderName(int i) { 810 std::string IndexedFolderName(int i) {
811 return base::StringPrintf(L"Folder Name %d", i); 811 return base::StringPrintf("Folder Name %d", i);
812 } 812 }
813 813
814 std::wstring IndexedSubfolderName(int i) { 814 std::string IndexedSubfolderName(int i) {
815 return base::StringPrintf(L"Subfolder Name %d", i); 815 return base::StringPrintf("Subfolder Name %d", i);
816 } 816 }
817 817
818 std::wstring IndexedSubsubfolderName(int i) { 818 std::string IndexedSubsubfolderName(int i) {
819 return base::StringPrintf(L"Subsubfolder Name %d", i); 819 return base::StringPrintf("Subsubfolder Name %d", i);
820 } 820 }
821 821
822 } // namespace bookmarks_helper 822 } // namespace bookmarks_helper
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698