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