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

Side by Side Diff: chrome/browser/sync/engine/process_commit_response_command_unittest.cc

Issue 1294002: Fix for negative routing info problem. We were replacing tokens after (Closed)
Patch Set: Comment fixes. Created 10 years, 9 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
OLDNEW
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 #include <vector> 5 #include <vector>
6 6
7 #include "base/string_util.h" 7 #include "base/string_util.h"
8 #include "chrome/browser/sync/engine/mock_model_safe_workers.h" 8 #include "chrome/browser/sync/engine/mock_model_safe_workers.h"
9 #include "chrome/browser/sync/engine/process_commit_response_command.h" 9 #include "chrome/browser/sync/engine/process_commit_response_command.h"
10 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h" 10 #include "chrome/browser/sync/protocol/bookmark_specifics.pb.h"
(...skipping 16 matching lines...) Expand all
27 using syncable::IS_UNSYNCED; 27 using syncable::IS_UNSYNCED;
28 using syncable::Id; 28 using syncable::Id;
29 using syncable::MutableEntry; 29 using syncable::MutableEntry;
30 using syncable::NON_UNIQUE_NAME; 30 using syncable::NON_UNIQUE_NAME;
31 using syncable::ReadTransaction; 31 using syncable::ReadTransaction;
32 using syncable::ScopedDirLookup; 32 using syncable::ScopedDirLookup;
33 using syncable::UNITTEST; 33 using syncable::UNITTEST;
34 using syncable::WriteTransaction; 34 using syncable::WriteTransaction;
35 35
36 // A test fixture for tests exercising ProcessCommitResponseCommand. 36 // A test fixture for tests exercising ProcessCommitResponseCommand.
37 class ProcessCommitResponseCommandTest : public SyncerCommandTest { 37 template<typename T>
38 class ProcessCommitResponseCommandTestWithParam
39 : public SyncerCommandTestWithParam<T> {
38 public: 40 public:
39 virtual void SetUp() { 41 virtual void SetUp() {
40 workers()->clear(); 42 workers()->clear();
41 mutable_routing_info()->clear(); 43 mutable_routing_info()->clear();
42 44
43 workers()->push_back(new ModelSafeWorker()); // GROUP_PASSIVE worker. 45 workers()->push_back(new ModelSafeWorker()); // GROUP_PASSIVE worker.
44 workers()->push_back(new MockUIModelWorker()); // GROUP_UI worker. 46 workers()->push_back(new MockUIModelWorker()); // GROUP_UI worker.
45 (*mutable_routing_info())[syncable::BOOKMARKS] = GROUP_UI; 47 (*mutable_routing_info())[syncable::BOOKMARKS] = GROUP_UI;
46 (*mutable_routing_info())[syncable::PREFERENCES] = GROUP_UI; 48 (*mutable_routing_info())[syncable::PREFERENCES] = GROUP_UI;
47 (*mutable_routing_info())[syncable::AUTOFILL] = GROUP_PASSIVE; 49 (*mutable_routing_info())[syncable::AUTOFILL] = GROUP_PASSIVE;
48 50
49 commit_set_.reset(new sessions::OrderedCommitSet(routing_info())); 51 commit_set_.reset(new sessions::OrderedCommitSet(routing_info()));
50 SyncerCommandTest::SetUp(); 52 SyncerCommandTestWithParam::SetUp();
51 } 53 }
52 54
53 protected: 55 protected:
54 ProcessCommitResponseCommandTest() 56 ProcessCommitResponseCommandTestWithParam()
55 : next_old_revision_(1), 57 : next_old_revision_(1),
56 next_new_revision_(4000), 58 next_new_revision_(4000),
57 next_server_position_(10000) { 59 next_server_position_(10000) {
58 } 60 }
59 61
60 void CheckEntry(Entry* e, const std::string& name, 62 void CheckEntry(Entry* e, const std::string& name,
61 syncable::ModelType model_type, const Id& parent_id) { 63 syncable::ModelType model_type, const Id& parent_id) {
62 EXPECT_TRUE(e->good()); 64 EXPECT_TRUE(e->good());
63 ASSERT_EQ(name, e->Get(NON_UNIQUE_NAME)); 65 ASSERT_EQ(name, e->Get(NON_UNIQUE_NAME));
64 ASSERT_EQ(model_type, e->GetModelType()); 66 ASSERT_EQ(model_type, e->GetModelType());
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 entry_response->set_parent_id_string(entity->parent_id_string()); 167 entry_response->set_parent_id_string(entity->parent_id_string());
166 for (int i = 0; i < commit->commit().entries_size(); ++i) { 168 for (int i = 0; i < commit->commit().entries_size(); ++i) {
167 if (commit->commit().entries(i).id_string() == 169 if (commit->commit().entries(i).id_string() ==
168 entity->parent_id_string()) { 170 entity->parent_id_string()) {
169 entry_response->set_parent_id_string( 171 entry_response->set_parent_id_string(
170 response->commit().entryresponse(i).id_string()); 172 response->commit().entryresponse(i).id_string());
171 } 173 }
172 } 174 }
173 } 175 }
174 176
177 void SetLastErrorCode(CommitResponse::ResponseType error_code) {
178 sessions::StatusController* sync_state = session()->status_controller();
179 sync_pb::ClientToServerResponse* response =
180 sync_state->mutable_commit_response();
181 sync_pb::CommitResponse_EntryResponse* entry_response =
182 response->mutable_commit()->mutable_entryresponse(
183 response->mutable_commit()->entryresponse_size() - 1);
184 entry_response->set_response_type(error_code);
185 }
186
175 ProcessCommitResponseCommand command_; 187 ProcessCommitResponseCommand command_;
176 TestIdFactory id_factory_; 188 TestIdFactory id_factory_;
177 scoped_ptr<sessions::OrderedCommitSet> commit_set_; 189 scoped_ptr<sessions::OrderedCommitSet> commit_set_;
178 private: 190 private:
179 int64 next_old_revision_; 191 int64 next_old_revision_;
180 int64 next_new_revision_; 192 int64 next_new_revision_;
181 int64 next_server_position_; 193 int64 next_server_position_;
182 DISALLOW_COPY_AND_ASSIGN(ProcessCommitResponseCommandTest); 194 DISALLOW_COPY_AND_ASSIGN(ProcessCommitResponseCommandTestWithParam);
183 }; 195 };
184 196
197 class ProcessCommitResponseCommandTest
198 : public ProcessCommitResponseCommandTestWithParam<void*> {};
199
185 TEST_F(ProcessCommitResponseCommandTest, MultipleCommitIdProjections) { 200 TEST_F(ProcessCommitResponseCommandTest, MultipleCommitIdProjections) {
186 Id bookmark_folder_id = id_factory_.NewLocalId(); 201 Id bookmark_folder_id = id_factory_.NewLocalId();
187 Id bookmark_id1 = id_factory_.NewLocalId(); 202 Id bookmark_id1 = id_factory_.NewLocalId();
188 Id bookmark_id2 = id_factory_.NewLocalId(); 203 Id bookmark_id2 = id_factory_.NewLocalId();
189 Id pref_id1 = id_factory_.NewLocalId(), pref_id2 = id_factory_.NewLocalId(); 204 Id pref_id1 = id_factory_.NewLocalId(), pref_id2 = id_factory_.NewLocalId();
190 Id autofill_id1 = id_factory_.NewLocalId(); 205 Id autofill_id1 = id_factory_.NewLocalId();
191 Id autofill_id2 = id_factory_.NewLocalId(); 206 Id autofill_id2 = id_factory_.NewLocalId();
192 CreateUnprocessedCommitResult(bookmark_folder_id, id_factory_.root(), 207 CreateUnprocessedCommitResult(bookmark_folder_id, id_factory_.root(),
193 "A bookmark folder", syncable::BOOKMARKS); 208 "A bookmark folder", syncable::BOOKMARKS);
194 CreateUnprocessedCommitResult(bookmark_id1, bookmark_folder_id, 209 CreateUnprocessedCommitResult(bookmark_id1, bookmark_folder_id,
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 ASSERT_LT(0, c.Get(BASE_VERSION)); 352 ASSERT_LT(0, c.Get(BASE_VERSION));
338 } 353 }
339 } 354 }
340 cid = c.Get(syncable::NEXT_ID); 355 cid = c.Get(syncable::NEXT_ID);
341 child_count++; 356 child_count++;
342 } 357 }
343 ASSERT_EQ(batch_size*2, child_count) 358 ASSERT_EQ(batch_size*2, child_count)
344 << "Too few or too many children in parent folder after commit."; 359 << "Too few or too many children in parent folder after commit.";
345 } 360 }
346 361
362 // This test fixture runs across a Cartesian product of per-type fail/success
363 // possibilities.
364 enum {
365 TEST_PARAM_BOOKMARK_ENABLE_BIT,
366 TEST_PARAM_AUTOFILL_ENABLE_BIT,
367 TEST_PARAM_BIT_COUNT
368 };
369 class MixedResult : public ProcessCommitResponseCommandTestWithParam<int> {
370 protected:
371 bool ShouldFailBookmarkCommit() {
372 return (GetParam() & (1 << TEST_PARAM_BOOKMARK_ENABLE_BIT)) == 0;
373 }
374 bool ShouldFailAutofillCommit() {
375 return (GetParam() & (1 << TEST_PARAM_AUTOFILL_ENABLE_BIT)) == 0;
376 }
377 };
378 INSTANTIATE_TEST_CASE_P(ProcessCommitResponse,
379 MixedResult,
380 testing::Range(0, 1 << TEST_PARAM_BIT_COUNT));
tim (not reviewing) 2010/03/25 21:16:14 this is cool
381
382 // This test commits 2 items (one bookmark, one autofill) and validates what
383 // happens to the extensions activity records. Commits could fail or succeed,
384 // depending on the test parameter.
385 TEST_P(MixedResult, ExtensionActivity) {
386 EXPECT_NE(routing_info().find(syncable::BOOKMARKS)->second,
387 routing_info().find(syncable::AUTOFILL)->second)
388 << "To not be lame, this test requires more than one active group.";
389
390 // Bookmark item setup.
391 CreateUnprocessedCommitResult(id_factory_.NewServerId(),
392 id_factory_.root(), "Some bookmark", syncable::BOOKMARKS);
393 if (ShouldFailBookmarkCommit())
394 SetLastErrorCode(CommitResponse::TRANSIENT_ERROR);
395 // Autofill item setup.
396 CreateUnprocessedCommitResult(id_factory_.NewServerId(),
397 id_factory_.root(), "Some autofill", syncable::AUTOFILL);
398 if (ShouldFailAutofillCommit())
399 SetLastErrorCode(CommitResponse::TRANSIENT_ERROR);
400
401 // Put some extensions activity in the session.
402 {
403 ExtensionsActivityMonitor::Records* records =
404 session()->mutable_extensions_activity();
405 (*records)["ABC"].extension_id = "ABC";
406 (*records)["ABC"].bookmark_write_count = 2049U;
407 (*records)["xyz"].extension_id = "xyz";
408 (*records)["xyz"].bookmark_write_count = 4U;
409 }
410 command_.ExecuteImpl(session());
411
412 ExtensionsActivityMonitor::Records final_monitor_records;
413 context()->extensions_monitor()->GetAndClearRecords(&final_monitor_records);
414
415 if (ShouldFailBookmarkCommit()) {
416 ASSERT_EQ(2U, final_monitor_records.size())
417 << "Should restore records after unsuccessful bookmark commit.";
418 EXPECT_EQ("ABC", final_monitor_records["ABC"].extension_id);
419 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id);
420 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count);
421 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count);
422 } else {
423 EXPECT_TRUE(final_monitor_records.empty())
424 << "Should not restore records after successful bookmark commit.";
425 }
426 }
427
428
347 } // namespace browser_sync 429 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/process_commit_response_command.cc ('k') | chrome/browser/sync/sessions/status_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698