| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/scoped_ptr.h" | 5 #include "base/scoped_ptr.h" |
| 6 #include "base/string_util.h" | 6 #include "base/string_util.h" |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "chrome/browser/bookmarks/bookmark_codec.h" | 8 #include "chrome/browser/bookmarks/bookmark_codec.h" |
| 9 #include "chrome/browser/bookmarks/bookmark_model.h" | 9 #include "chrome/browser/bookmarks/bookmark_model.h" |
| 10 #include "chrome/browser/bookmarks/bookmark_model_test_utils.h" | 10 #include "chrome/browser/bookmarks/bookmark_model_test_utils.h" |
| 11 #include "chrome/browser/bookmarks/bookmark_utils.h" | 11 #include "chrome/browser/bookmarks/bookmark_utils.h" |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 std::string enc_checksum; | 195 std::string enc_checksum; |
| 196 scoped_ptr<Value> value(EncodeHelper(model_to_encode.get(), &enc_checksum)); | 196 scoped_ptr<Value> value(EncodeHelper(model_to_encode.get(), &enc_checksum)); |
| 197 | 197 |
| 198 EXPECT_TRUE(value.get() != NULL); | 198 EXPECT_TRUE(value.get() != NULL); |
| 199 | 199 |
| 200 // Change something in the encoded value before decoding it. | 200 // Change something in the encoded value before decoding it. |
| 201 DictionaryValue* child1_value; | 201 DictionaryValue* child1_value; |
| 202 GetBookmarksBarChildValue(value.get(), 0, &child1_value); | 202 GetBookmarksBarChildValue(value.get(), 0, &child1_value); |
| 203 std::wstring title; | 203 std::wstring title; |
| 204 ASSERT_TRUE(child1_value->GetString(BookmarkCodec::kNameKey, &title)); | 204 ASSERT_TRUE(child1_value->GetString(BookmarkCodec::kNameKey, &title)); |
| 205 ASSERT_TRUE(child1_value->SetString(BookmarkCodec::kNameKey, title + L"1")); | 205 child1_value->SetString(BookmarkCodec::kNameKey, title + L"1"); |
| 206 | 206 |
| 207 std::string dec_checksum; | 207 std::string dec_checksum; |
| 208 scoped_ptr<BookmarkModel> decoded_model1(DecodeHelper( | 208 scoped_ptr<BookmarkModel> decoded_model1(DecodeHelper( |
| 209 *value.get(), enc_checksum, &dec_checksum, true)); | 209 *value.get(), enc_checksum, &dec_checksum, true)); |
| 210 | 210 |
| 211 // Undo the change and make sure the checksum is same as original. | 211 // Undo the change and make sure the checksum is same as original. |
| 212 ASSERT_TRUE(child1_value->SetString(BookmarkCodec::kNameKey, title)); | 212 child1_value->SetString(BookmarkCodec::kNameKey, title); |
| 213 scoped_ptr<BookmarkModel> decoded_model2(DecodeHelper( | 213 scoped_ptr<BookmarkModel> decoded_model2(DecodeHelper( |
| 214 *value.get(), enc_checksum, &dec_checksum, false)); | 214 *value.get(), enc_checksum, &dec_checksum, false)); |
| 215 } | 215 } |
| 216 | 216 |
| 217 TEST_F(BookmarkCodecTest, ChecksumManualEditIDsTest) { | 217 TEST_F(BookmarkCodecTest, ChecksumManualEditIDsTest) { |
| 218 scoped_ptr<BookmarkModel> model_to_encode(CreateTestModel3()); | 218 scoped_ptr<BookmarkModel> model_to_encode(CreateTestModel3()); |
| 219 | 219 |
| 220 // The test depends on existence of multiple children under bookmark bar, so | 220 // The test depends on existence of multiple children under bookmark bar, so |
| 221 // make sure that's the case. | 221 // make sure that's the case. |
| 222 int bb_child_count = model_to_encode->GetBookmarkBarNode()->GetChildCount(); | 222 int bb_child_count = model_to_encode->GetBookmarkBarNode()->GetChildCount(); |
| 223 ASSERT_GT(bb_child_count, 1); | 223 ASSERT_GT(bb_child_count, 1); |
| 224 | 224 |
| 225 std::string enc_checksum; | 225 std::string enc_checksum; |
| 226 scoped_ptr<Value> value(EncodeHelper(model_to_encode.get(), &enc_checksum)); | 226 scoped_ptr<Value> value(EncodeHelper(model_to_encode.get(), &enc_checksum)); |
| 227 | 227 |
| 228 EXPECT_TRUE(value.get() != NULL); | 228 EXPECT_TRUE(value.get() != NULL); |
| 229 | 229 |
| 230 // Change IDs for all children of bookmark bar to be 1. | 230 // Change IDs for all children of bookmark bar to be 1. |
| 231 DictionaryValue* child_value; | 231 DictionaryValue* child_value; |
| 232 for (int i = 0; i < bb_child_count; ++i) { | 232 for (int i = 0; i < bb_child_count; ++i) { |
| 233 GetBookmarksBarChildValue(value.get(), i, &child_value); | 233 GetBookmarksBarChildValue(value.get(), i, &child_value); |
| 234 std::string id; | 234 std::string id; |
| 235 ASSERT_TRUE(child_value->GetString(BookmarkCodec::kIdKey, &id)); | 235 ASSERT_TRUE(child_value->GetString(BookmarkCodec::kIdKey, &id)); |
| 236 ASSERT_TRUE(child_value->SetString(BookmarkCodec::kIdKey, "1")); | 236 child_value->SetString(BookmarkCodec::kIdKey, "1"); |
| 237 } | 237 } |
| 238 | 238 |
| 239 std::string dec_checksum; | 239 std::string dec_checksum; |
| 240 scoped_ptr<BookmarkModel> decoded_model(DecodeHelper( | 240 scoped_ptr<BookmarkModel> decoded_model(DecodeHelper( |
| 241 *value.get(), enc_checksum, &dec_checksum, true)); | 241 *value.get(), enc_checksum, &dec_checksum, true)); |
| 242 | 242 |
| 243 ExpectIDsUnique(decoded_model.get()); | 243 ExpectIDsUnique(decoded_model.get()); |
| 244 | 244 |
| 245 // add a few extra nodes to bookmark model and make sure IDs are still uniuqe. | 245 // add a few extra nodes to bookmark model and make sure IDs are still uniuqe. |
| 246 const BookmarkNode* bb_node = decoded_model->GetBookmarkBarNode(); | 246 const BookmarkNode* bb_node = decoded_model->GetBookmarkBarNode(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 274 BookmarkCodec encoder2; | 274 BookmarkCodec encoder2; |
| 275 scoped_ptr<Value> model_value2(encoder2.Encode(&decoded_model)); | 275 scoped_ptr<Value> model_value2(encoder2.Encode(&decoded_model)); |
| 276 | 276 |
| 277 BookmarkModel decoded_model2(NULL); | 277 BookmarkModel decoded_model2(NULL); |
| 278 BookmarkCodec decoder2; | 278 BookmarkCodec decoder2; |
| 279 ASSERT_TRUE(Decode(&decoder2, &decoded_model2, *model_value2.get())); | 279 ASSERT_TRUE(Decode(&decoder2, &decoded_model2, *model_value2.get())); |
| 280 BookmarkModelTestUtils::AssertModelsEqual(&decoded_model, | 280 BookmarkModelTestUtils::AssertModelsEqual(&decoded_model, |
| 281 &decoded_model2, | 281 &decoded_model2, |
| 282 true); | 282 true); |
| 283 } | 283 } |
| OLD | NEW |