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" |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 const BookmarkNode* parent, | 419 const BookmarkNode* parent, |
420 int index, | 420 int index, |
421 const std::wstring& title, | 421 const std::wstring& title, |
422 const GURL& url) { | 422 const GURL& url) { |
423 if (GetBookmarkModel(profile)->GetNodeByID(parent->id()) != parent) { | 423 if (GetBookmarkModel(profile)->GetNodeByID(parent->id()) != parent) { |
424 LOG(ERROR) << "Node " << parent->GetTitle() << " does not belong to " | 424 LOG(ERROR) << "Node " << parent->GetTitle() << " does not belong to " |
425 << "Profile " << profile; | 425 << "Profile " << profile; |
426 return NULL; | 426 return NULL; |
427 } | 427 } |
428 const BookmarkNode* result = GetBookmarkModel(profile)-> | 428 const BookmarkNode* result = GetBookmarkModel(profile)-> |
429 AddURL(parent, index, WideToUTF16(title), url); | 429 AddURL(parent, index, base::WideToUTF16(title), url); |
430 if (!result) { | 430 if (!result) { |
431 LOG(ERROR) << "Could not add bookmark " << title << " to Profile " | 431 LOG(ERROR) << "Could not add bookmark " << title << " to Profile " |
432 << profile; | 432 << profile; |
433 return NULL; | 433 return NULL; |
434 } | 434 } |
435 if (test()->use_verifier()) { | 435 if (test()->use_verifier()) { |
436 const BookmarkNode* v_parent = NULL; | 436 const BookmarkNode* v_parent = NULL; |
437 FindNodeInVerifier(GetBookmarkModel(profile), parent, &v_parent); | 437 FindNodeInVerifier(GetBookmarkModel(profile), parent, &v_parent); |
438 const BookmarkNode* v_node = GetVerifierBookmarkModel()-> | 438 const BookmarkNode* v_node = GetVerifierBookmarkModel()-> |
439 AddURL(v_parent, index, WideToUTF16(title), url); | 439 AddURL(v_parent, index, base::WideToUTF16(title), url); |
440 if (!v_node) { | 440 if (!v_node) { |
441 LOG(ERROR) << "Could not add bookmark " << title << " to the verifier"; | 441 LOG(ERROR) << "Could not add bookmark " << title << " to the verifier"; |
442 return NULL; | 442 return NULL; |
443 } | 443 } |
444 EXPECT_TRUE(NodesMatch(v_node, result)); | 444 EXPECT_TRUE(NodesMatch(v_node, result)); |
445 } | 445 } |
446 return result; | 446 return result; |
447 } | 447 } |
448 | 448 |
449 const BookmarkNode* AddFolder(int profile, | 449 const BookmarkNode* AddFolder(int profile, |
(...skipping 10 matching lines...) Expand all Loading... |
460 const BookmarkNode* AddFolder(int profile, | 460 const BookmarkNode* AddFolder(int profile, |
461 const BookmarkNode* parent, | 461 const BookmarkNode* parent, |
462 int index, | 462 int index, |
463 const std::wstring& title) { | 463 const std::wstring& title) { |
464 if (GetBookmarkModel(profile)->GetNodeByID(parent->id()) != parent) { | 464 if (GetBookmarkModel(profile)->GetNodeByID(parent->id()) != parent) { |
465 LOG(ERROR) << "Node " << parent->GetTitle() << " does not belong to " | 465 LOG(ERROR) << "Node " << parent->GetTitle() << " does not belong to " |
466 << "Profile " << profile; | 466 << "Profile " << profile; |
467 return NULL; | 467 return NULL; |
468 } | 468 } |
469 const BookmarkNode* result = | 469 const BookmarkNode* result = |
470 GetBookmarkModel(profile)->AddFolder(parent, index, WideToUTF16(title)); | 470 GetBookmarkModel(profile)->AddFolder(parent, index, |
| 471 base::WideToUTF16(title)); |
471 EXPECT_TRUE(result); | 472 EXPECT_TRUE(result); |
472 if (!result) { | 473 if (!result) { |
473 LOG(ERROR) << "Could not add folder " << title << " to Profile " | 474 LOG(ERROR) << "Could not add folder " << title << " to Profile " |
474 << profile; | 475 << profile; |
475 return NULL; | 476 return NULL; |
476 } | 477 } |
477 if (test()->use_verifier()) { | 478 if (test()->use_verifier()) { |
478 const BookmarkNode* v_parent = NULL; | 479 const BookmarkNode* v_parent = NULL; |
479 FindNodeInVerifier(GetBookmarkModel(profile), parent, &v_parent); | 480 FindNodeInVerifier(GetBookmarkModel(profile), parent, &v_parent); |
480 const BookmarkNode* v_node = GetVerifierBookmarkModel()->AddFolder( | 481 const BookmarkNode* v_node = GetVerifierBookmarkModel()->AddFolder( |
481 v_parent, index, WideToUTF16(title)); | 482 v_parent, index, base::WideToUTF16(title)); |
482 if (!v_node) { | 483 if (!v_node) { |
483 LOG(ERROR) << "Could not add folder " << title << " to the verifier"; | 484 LOG(ERROR) << "Could not add folder " << title << " to the verifier"; |
484 return NULL; | 485 return NULL; |
485 } | 486 } |
486 EXPECT_TRUE(NodesMatch(v_node, result)); | 487 EXPECT_TRUE(NodesMatch(v_node, result)); |
487 } | 488 } |
488 return result; | 489 return result; |
489 } | 490 } |
490 | 491 |
491 void SetTitle(int profile, | 492 void SetTitle(int profile, |
492 const BookmarkNode* node, | 493 const BookmarkNode* node, |
493 const std::wstring& new_title) { | 494 const std::wstring& new_title) { |
494 ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(node->id()), node) | 495 ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(node->id()), node) |
495 << "Node " << node->GetTitle() << " does not belong to " | 496 << "Node " << node->GetTitle() << " does not belong to " |
496 << "Profile " << profile; | 497 << "Profile " << profile; |
497 if (test()->use_verifier()) { | 498 if (test()->use_verifier()) { |
498 const BookmarkNode* v_node = NULL; | 499 const BookmarkNode* v_node = NULL; |
499 FindNodeInVerifier(GetBookmarkModel(profile), node, &v_node); | 500 FindNodeInVerifier(GetBookmarkModel(profile), node, &v_node); |
500 GetVerifierBookmarkModel()->SetTitle(v_node, WideToUTF16(new_title)); | 501 GetVerifierBookmarkModel()->SetTitle(v_node, base::WideToUTF16(new_title)); |
501 } | 502 } |
502 GetBookmarkModel(profile)->SetTitle(node, WideToUTF16(new_title)); | 503 GetBookmarkModel(profile)->SetTitle(node, base::WideToUTF16(new_title)); |
503 } | 504 } |
504 | 505 |
505 void SetFavicon(int profile, | 506 void SetFavicon(int profile, |
506 const BookmarkNode* node, | 507 const BookmarkNode* node, |
507 const GURL& icon_url, | 508 const GURL& icon_url, |
508 const gfx::Image& image, | 509 const gfx::Image& image, |
509 FaviconSource favicon_source) { | 510 FaviconSource favicon_source) { |
510 ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(node->id()), node) | 511 ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(node->id()), node) |
511 << "Node " << node->GetTitle() << " does not belong to " | 512 << "Node " << node->GetTitle() << " does not belong to " |
512 << "Profile " << profile; | 513 << "Profile " << profile; |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 GetBookmarkModel(profile)->GetNodesByURL(url, &nodes); | 685 GetBookmarkModel(profile)->GetNodesByURL(url, &nodes); |
685 EXPECT_EQ(1U, nodes.size()); | 686 EXPECT_EQ(1U, nodes.size()); |
686 if (nodes.empty()) | 687 if (nodes.empty()) |
687 return NULL; | 688 return NULL; |
688 return nodes[0]; | 689 return nodes[0]; |
689 } | 690 } |
690 | 691 |
691 int CountBookmarksWithTitlesMatching(int profile, const std::wstring& title) { | 692 int CountBookmarksWithTitlesMatching(int profile, const std::wstring& title) { |
692 return CountNodesWithTitlesMatching(GetBookmarkModel(profile), | 693 return CountNodesWithTitlesMatching(GetBookmarkModel(profile), |
693 BookmarkNode::URL, | 694 BookmarkNode::URL, |
694 WideToUTF16(title)); | 695 base::WideToUTF16(title)); |
695 } | 696 } |
696 | 697 |
697 int CountFoldersWithTitlesMatching(int profile, const std::wstring& title) { | 698 int CountFoldersWithTitlesMatching(int profile, const std::wstring& title) { |
698 return CountNodesWithTitlesMatching(GetBookmarkModel(profile), | 699 return CountNodesWithTitlesMatching(GetBookmarkModel(profile), |
699 BookmarkNode::FOLDER, | 700 BookmarkNode::FOLDER, |
700 WideToUTF16(title)); | 701 base::WideToUTF16(title)); |
701 } | 702 } |
702 | 703 |
703 gfx::Image CreateFavicon(SkColor color) { | 704 gfx::Image CreateFavicon(SkColor color) { |
704 const int dip_width = 16; | 705 const int dip_width = 16; |
705 const int dip_height = 16; | 706 const int dip_height = 16; |
706 std::vector<ui::ScaleFactor> favicon_scale_factors = | 707 std::vector<ui::ScaleFactor> favicon_scale_factors = |
707 FaviconUtil::GetFaviconScaleFactors(); | 708 FaviconUtil::GetFaviconScaleFactors(); |
708 gfx::ImageSkia favicon; | 709 gfx::ImageSkia favicon; |
709 for (size_t i = 0; i < favicon_scale_factors.size(); ++i) { | 710 for (size_t i = 0; i < favicon_scale_factors.size(); ++i) { |
710 float scale = ui::GetScaleFactorScale(favicon_scale_factors[i]); | 711 float scale = ui::GetScaleFactorScale(favicon_scale_factors[i]); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
749 | 750 |
750 std::wstring IndexedSubfolderName(int i) { | 751 std::wstring IndexedSubfolderName(int i) { |
751 return StringPrintf(L"Subfolder Name %d", i); | 752 return StringPrintf(L"Subfolder Name %d", i); |
752 } | 753 } |
753 | 754 |
754 std::wstring IndexedSubsubfolderName(int i) { | 755 std::wstring IndexedSubsubfolderName(int i) { |
755 return StringPrintf(L"Subsubfolder Name %d", i); | 756 return StringPrintf(L"Subsubfolder Name %d", i); |
756 } | 757 } |
757 | 758 |
758 } // namespace bookmarks_helper | 759 } // namespace bookmarks_helper |
OLD | NEW |