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

Side by Side Diff: chrome/browser/bookmarks/bookmark_codec_unittest.cc

Issue 7012005: Revert "Revert 84829 - Initial implementation of "Synced Bookmarks" folder." (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Slight tweak to starred_url_database to make sync come after other Created 9 years, 7 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/command_line.h"
5 #include "base/memory/scoped_ptr.h" 6 #include "base/memory/scoped_ptr.h"
6 #include "base/string_util.h" 7 #include "base/string_util.h"
7 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
8 #include "base/values.h" 9 #include "base/values.h"
9 #include "chrome/browser/bookmarks/bookmark_codec.h" 10 #include "chrome/browser/bookmarks/bookmark_codec.h"
10 #include "chrome/browser/bookmarks/bookmark_model.h" 11 #include "chrome/browser/bookmarks/bookmark_model.h"
11 #include "chrome/browser/bookmarks/bookmark_model_test_utils.h" 12 #include "chrome/browser/bookmarks/bookmark_model_test_utils.h"
12 #include "chrome/browser/bookmarks/bookmark_utils.h" 13 #include "chrome/browser/bookmarks/bookmark_utils.h"
14 #include "chrome/common/chrome_switches.h"
13 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
14 16
15 namespace { 17 namespace {
16 18
17 const char kUrl1Title[] = "url1"; 19 const char kUrl1Title[] = "url1";
18 const char kUrl1Url[] = "http://www.url1.com"; 20 const char kUrl1Url[] = "http://www.url1.com";
19 const char kUrl2Title[] = "url2"; 21 const char kUrl2Title[] = "url2";
20 const char kUrl2Url[] = "http://www.url2.com"; 22 const char kUrl2Url[] = "http://www.url2.com";
21 const char kUrl3Title[] = "url3"; 23 const char kUrl3Title[] = "url3";
22 const char kUrl3Url[] = "http://www.url3.com"; 24 const char kUrl3Url[] = "http://www.url3.com";
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 EXPECT_EQ(computed_checksum, stored_checksum); 106 EXPECT_EQ(computed_checksum, stored_checksum);
105 107
106 *checksum = computed_checksum; 108 *checksum = computed_checksum;
107 return value.release(); 109 return value.release();
108 } 110 }
109 111
110 bool Decode(BookmarkCodec* codec, BookmarkModel* model, const Value& value) { 112 bool Decode(BookmarkCodec* codec, BookmarkModel* model, const Value& value) {
111 int64 max_id; 113 int64 max_id;
112 bool result = codec->Decode(AsMutable(model->GetBookmarkBarNode()), 114 bool result = codec->Decode(AsMutable(model->GetBookmarkBarNode()),
113 AsMutable(model->other_node()), 115 AsMutable(model->other_node()),
116 AsMutable(model->synced_node()),
114 &max_id, value); 117 &max_id, value);
115 model->set_next_node_id(max_id); 118 model->set_next_node_id(max_id);
116 return result; 119 return result;
117 } 120 }
118 121
119 BookmarkModel* DecodeHelper(const Value& value, 122 BookmarkModel* DecodeHelper(const Value& value,
120 const std::string& expected_stored_checksum, 123 const std::string& expected_stored_checksum,
121 std::string* computed_checksum, 124 std::string* computed_checksum,
122 bool expected_changes) { 125 bool expected_changes) {
123 BookmarkCodec decoder; 126 BookmarkCodec decoder;
(...skipping 30 matching lines...) Expand all
154 EXPECT_TRUE(assigned_ids->find(node_id) == assigned_ids->end()); 157 EXPECT_TRUE(assigned_ids->find(node_id) == assigned_ids->end());
155 assigned_ids->insert(node_id); 158 assigned_ids->insert(node_id);
156 for (int i = 0; i < node->child_count(); ++i) 159 for (int i = 0; i < node->child_count(); ++i)
157 CheckIDs(node->GetChild(i), assigned_ids); 160 CheckIDs(node->GetChild(i), assigned_ids);
158 } 161 }
159 162
160 void ExpectIDsUnique(BookmarkModel* model) { 163 void ExpectIDsUnique(BookmarkModel* model) {
161 std::set<int64> assigned_ids; 164 std::set<int64> assigned_ids;
162 CheckIDs(model->GetBookmarkBarNode(), &assigned_ids); 165 CheckIDs(model->GetBookmarkBarNode(), &assigned_ids);
163 CheckIDs(model->other_node(), &assigned_ids); 166 CheckIDs(model->other_node(), &assigned_ids);
167 CheckIDs(model->synced_node(), &assigned_ids);
164 } 168 }
165 }; 169 };
166 170
167 TEST_F(BookmarkCodecTest, ChecksumEncodeDecodeTest) { 171 TEST_F(BookmarkCodecTest, ChecksumEncodeDecodeTest) {
168 scoped_ptr<BookmarkModel> model_to_encode(CreateTestModel1()); 172 scoped_ptr<BookmarkModel> model_to_encode(CreateTestModel1());
169 std::string enc_checksum; 173 std::string enc_checksum;
170 scoped_ptr<Value> value(EncodeHelper(model_to_encode.get(), &enc_checksum)); 174 scoped_ptr<Value> value(EncodeHelper(model_to_encode.get(), &enc_checksum));
171 175
172 EXPECT_TRUE(value.get() != NULL); 176 EXPECT_TRUE(value.get() != NULL);
173 177
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 BookmarkCodec encoder2; 284 BookmarkCodec encoder2;
281 scoped_ptr<Value> model_value2(encoder2.Encode(&decoded_model)); 285 scoped_ptr<Value> model_value2(encoder2.Encode(&decoded_model));
282 286
283 BookmarkModel decoded_model2(NULL); 287 BookmarkModel decoded_model2(NULL);
284 BookmarkCodec decoder2; 288 BookmarkCodec decoder2;
285 ASSERT_TRUE(Decode(&decoder2, &decoded_model2, *model_value2.get())); 289 ASSERT_TRUE(Decode(&decoder2, &decoded_model2, *model_value2.get()));
286 BookmarkModelTestUtils::AssertModelsEqual(&decoded_model, 290 BookmarkModelTestUtils::AssertModelsEqual(&decoded_model,
287 &decoded_model2, 291 &decoded_model2,
288 true); 292 true);
289 } 293 }
294
295 TEST_F(BookmarkCodecTest, CanDecodeModelWithoutSyncedBookmarks) {
sky 2011/05/12 16:29:13 I assume we aren't going to have the switch foreve
296 scoped_ptr<BookmarkModel> model_to_encode(CreateTestModel3());
297 BookmarkCodec encoder;
298 scoped_ptr<Value> model_value(encoder.Encode(model_to_encode.get()));
299
300 // New model will be created with synced bookmarks.
301 CommandLine::ForCurrentProcess()->AppendSwitch(
302 switches::kEnableSyncedBookmarksFolder);
303
304 BookmarkModel decoded_model(NULL);
305 BookmarkCodec decoder;
306 ASSERT_TRUE(Decode(&decoder, &decoded_model, *model_value.get()));
307 BookmarkModelTestUtils::AssertNodesEqual(
308 model_to_encode->GetBookmarkBarNode(),
309 decoded_model.GetBookmarkBarNode(),
310 false);
311 BookmarkModelTestUtils::AssertNodesEqual(model_to_encode->other_node(),
312 decoded_model.other_node(),
313 false);
314 // Note: Explicitly don't check synced_node since it's not present in the old
315 // model.
316 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698