Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #ifndef CHROME_TEST_LIVE_SYNC_LIVE_BOOKMARKS_SYNC_TEST_H_ | 5 #ifndef CHROME_TEST_LIVE_SYNC_LIVE_BOOKMARKS_SYNC_TEST_H_ |
| 6 #define CHROME_TEST_LIVE_SYNC_LIVE_BOOKMARKS_SYNC_TEST_H_ | 6 #define CHROME_TEST_LIVE_SYNC_LIVE_BOOKMARKS_SYNC_TEST_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "chrome/browser/bookmarks/bookmark_model.h" | 13 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 14 #include "chrome/test/live_sync/bookmark_model_verifier.h" | 14 #include "chrome/test/live_sync/bookmark_model_verifier.h" |
| 15 #include "chrome/test/live_sync/live_sync_test.h" | 15 #include "chrome/test/live_sync/live_sync_test.h" |
| 16 #include "chrome/test/ui_test_utils.h" | 16 #include "chrome/test/ui_test_utils.h" |
| 17 #include "gfx/codec/png_codec.h" | |
| 17 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 20 #include "third_party/skia/include/core/SkBitmap.h" | |
| 19 | 21 |
| 20 class LiveBookmarksSyncTest : public LiveSyncTest { | 22 class LiveBookmarksSyncTest : public LiveSyncTest { |
| 21 public: | 23 public: |
| 22 explicit LiveBookmarksSyncTest(TestType test_type) | 24 explicit LiveBookmarksSyncTest(TestType test_type) |
| 23 : LiveSyncTest(test_type) {} | 25 : LiveSyncTest(test_type) {} |
| 24 | 26 |
| 25 virtual ~LiveBookmarksSyncTest() {} | 27 virtual ~LiveBookmarksSyncTest() {} |
| 26 | 28 |
| 27 // Sets up sync profiles and clients and initializes the bookmark verifier. | 29 // Sets up sync profiles and clients and initializes the bookmark verifier. |
| 28 virtual bool SetupClients() WARN_UNUSED_RESULT { | 30 virtual bool SetupClients() WARN_UNUSED_RESULT { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 133 void SetTitle(int profile, | 135 void SetTitle(int profile, |
| 134 const BookmarkNode* node, | 136 const BookmarkNode* node, |
| 135 const std::wstring& new_title) { | 137 const std::wstring& new_title) { |
| 136 ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(node->id()), node) | 138 ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(node->id()), node) |
| 137 << "Node " << node->GetTitle() << " does not belong to " | 139 << "Node " << node->GetTitle() << " does not belong to " |
| 138 << "Profile " << profile; | 140 << "Profile " << profile; |
| 139 verifier_helper_->SetTitle( | 141 verifier_helper_->SetTitle( |
| 140 GetBookmarkModel(profile), node, WideToUTF16(new_title)); | 142 GetBookmarkModel(profile), node, WideToUTF16(new_title)); |
| 141 } | 143 } |
| 142 | 144 |
| 145 // Sets the favicon of the node |node| (of type BookmarkNode::URL) in the | |
| 146 // bookmark model of profile |profile| using the data in |icon_bytes_vector|. | |
| 147 void SetFavicon(int profile, | |
| 148 const BookmarkNode* node, | |
| 149 const std::vector<unsigned char>& icon_bytes_vector) { | |
| 150 ASSERT_EQ(GetBookmarkModel(profile)->GetNodeByID(node->id()), node) | |
| 151 << "Node " << node->GetTitle() << " does not belong to " | |
| 152 << "Profile " << profile; | |
| 153 ASSERT_EQ(BookmarkNode::URL, node->type()) | |
| 154 << "Node " << node->GetTitle() << " must be a url."; | |
| 155 verifier_helper_->SetFavicon( | |
| 156 GetBookmarkModel(profile), node, icon_bytes_vector); | |
| 157 } | |
| 158 | |
| 143 // Changes the url of the node |node| in the bookmark model of profile | 159 // Changes the url of the node |node| in the bookmark model of profile |
| 144 // |profile| to |new_url|. Returns a pointer to the node with the changed url. | 160 // |profile| to |new_url|. Returns a pointer to the node with the changed url. |
| 145 const BookmarkNode* SetURL(int profile, | 161 const BookmarkNode* SetURL(int profile, |
| 146 const BookmarkNode* node, | 162 const BookmarkNode* node, |
| 147 const GURL& new_url) WARN_UNUSED_RESULT { | 163 const GURL& new_url) WARN_UNUSED_RESULT { |
| 148 if (GetBookmarkModel(profile)->GetNodeByID(node->id()) != node) { | 164 if (GetBookmarkModel(profile)->GetNodeByID(node->id()) != node) { |
| 149 LOG(ERROR) << "Node " << node->GetTitle() << " does not belong to " | 165 LOG(ERROR) << "Node " << node->GetTitle() << " does not belong to " |
| 150 << "Profile " << profile; | 166 << "Profile " << profile; |
| 151 return NULL; | 167 return NULL; |
| 152 } | 168 } |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 271 } | 287 } |
| 272 | 288 |
| 273 // Returns the number of bookmark folders in the bookmark model of profile | 289 // Returns the number of bookmark folders in the bookmark model of profile |
| 274 // |profile| whose titles contain the query string |title|. | 290 // |profile| whose titles contain the query string |title|. |
| 275 int CountFoldersWithTitlesMatching(int profile, | 291 int CountFoldersWithTitlesMatching(int profile, |
| 276 const std::wstring& title) WARN_UNUSED_RESULT { | 292 const std::wstring& title) WARN_UNUSED_RESULT { |
| 277 return verifier_helper_->CountNodesWithTitlesMatching( | 293 return verifier_helper_->CountNodesWithTitlesMatching( |
| 278 GetBookmarkModel(profile), BookmarkNode::FOLDER, WideToUTF16(title)); | 294 GetBookmarkModel(profile), BookmarkNode::FOLDER, WideToUTF16(title)); |
| 279 } | 295 } |
| 280 | 296 |
| 297 // Creates a unique favicon using index |i|. | |
|
tim (not reviewing)
2010/11/11 19:25:34
maybe |seed| is a better name?
Raghu Simha
2010/11/11 19:39:45
Done.
| |
| 298 static std::vector<unsigned char> CreateFavicon(int i) { | |
| 299 const int w = 16; | |
| 300 const int h = 16; | |
| 301 SkBitmap bmp; | |
| 302 bmp.setConfig(SkBitmap::kARGB_8888_Config, w, h); | |
| 303 bmp.allocPixels(); | |
| 304 uint32_t* src_data = bmp.getAddr32(0, 0); | |
| 305 for (int j = 0; j < w * h; ++j) { | |
| 306 src_data[j] = SkPreMultiplyARGB((i + j) % 255, | |
| 307 (i + j) % 250, | |
| 308 (i + j) % 245, | |
| 309 (i + j) % 240); | |
| 310 } | |
| 311 std::vector<unsigned char> favicon; | |
| 312 gfx::PNGCodec::EncodeBGRASkBitmap(bmp, false, &favicon); | |
| 313 return favicon; | |
| 314 } | |
| 315 | |
| 281 private: | 316 private: |
| 282 // Helper object that has the functionality to verify changes made to the | 317 // Helper object that has the functionality to verify changes made to the |
| 283 // bookmarks of individual profiles. | 318 // bookmarks of individual profiles. |
| 284 scoped_ptr<BookmarkModelVerifier> verifier_helper_; | 319 scoped_ptr<BookmarkModelVerifier> verifier_helper_; |
| 285 | 320 |
| 286 DISALLOW_COPY_AND_ASSIGN(LiveBookmarksSyncTest); | 321 DISALLOW_COPY_AND_ASSIGN(LiveBookmarksSyncTest); |
| 287 }; | 322 }; |
| 288 | 323 |
| 289 class SingleClientLiveBookmarksSyncTest : public LiveBookmarksSyncTest { | 324 class SingleClientLiveBookmarksSyncTest : public LiveBookmarksSyncTest { |
| 290 public: | 325 public: |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 320 public: | 355 public: |
| 321 ManyClientLiveBookmarksSyncTest() | 356 ManyClientLiveBookmarksSyncTest() |
| 322 : LiveBookmarksSyncTest(MANY_CLIENT) {} | 357 : LiveBookmarksSyncTest(MANY_CLIENT) {} |
| 323 ~ManyClientLiveBookmarksSyncTest() {} | 358 ~ManyClientLiveBookmarksSyncTest() {} |
| 324 | 359 |
| 325 private: | 360 private: |
| 326 DISALLOW_COPY_AND_ASSIGN(ManyClientLiveBookmarksSyncTest); | 361 DISALLOW_COPY_AND_ASSIGN(ManyClientLiveBookmarksSyncTest); |
| 327 }; | 362 }; |
| 328 | 363 |
| 329 #endif // CHROME_TEST_LIVE_SYNC_LIVE_BOOKMARKS_SYNC_TEST_H_ | 364 #endif // CHROME_TEST_LIVE_SYNC_LIVE_BOOKMARKS_SYNC_TEST_H_ |
| OLD | NEW |