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

Side by Side Diff: sync/internal_api/js_mutation_event_observer_unittest.cc

Issue 10698014: [Sync] Rename csync namespace to syncer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 8 years, 5 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) 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 "sync/internal_api/js_mutation_event_observer.h" 5 #include "sync/internal_api/js_mutation_event_observer.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "sync/internal_api/public/syncable/model_type.h" 10 #include "sync/internal_api/public/syncable/model_type.h"
11 #include "sync/internal_api/public/util/weak_handle.h" 11 #include "sync/internal_api/public/util/weak_handle.h"
12 #include "sync/js/js_event_details.h" 12 #include "sync/js/js_event_details.h"
13 #include "sync/js/js_test_util.h" 13 #include "sync/js/js_test_util.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 15
16 namespace csync { 16 namespace syncer {
17 namespace { 17 namespace {
18 18
19 using ::testing::InSequence; 19 using ::testing::InSequence;
20 using ::testing::StrictMock; 20 using ::testing::StrictMock;
21 21
22 class JsMutationEventObserverTest : public testing::Test { 22 class JsMutationEventObserverTest : public testing::Test {
23 protected: 23 protected:
24 JsMutationEventObserverTest() { 24 JsMutationEventObserverTest() {
25 js_mutation_event_observer_.SetJsEventHandler( 25 js_mutation_event_observer_.SetJsEventHandler(
26 mock_js_event_handler_.AsWeakHandle()); 26 mock_js_event_handler_.AsWeakHandle());
(...skipping 12 matching lines...) Expand all
39 message_loop_.RunAllPending(); 39 message_loop_.RunAllPending();
40 } 40 }
41 }; 41 };
42 42
43 TEST_F(JsMutationEventObserverTest, OnChangesApplied) { 43 TEST_F(JsMutationEventObserverTest, OnChangesApplied) {
44 InSequence dummy; 44 InSequence dummy;
45 45
46 // We don't test with passwords as that requires additional setup. 46 // We don't test with passwords as that requires additional setup.
47 47
48 // Build a list of example ChangeRecords. 48 // Build a list of example ChangeRecords.
49 csync::ChangeRecord changes[syncable::MODEL_TYPE_COUNT]; 49 syncer::ChangeRecord changes[syncable::MODEL_TYPE_COUNT];
50 for (int i = syncable::AUTOFILL_PROFILE; 50 for (int i = syncable::AUTOFILL_PROFILE;
51 i < syncable::MODEL_TYPE_COUNT; ++i) { 51 i < syncable::MODEL_TYPE_COUNT; ++i) {
52 changes[i].id = i; 52 changes[i].id = i;
53 switch (i % 3) { 53 switch (i % 3) {
54 case 0: 54 case 0:
55 changes[i].action = 55 changes[i].action =
56 csync::ChangeRecord::ACTION_ADD; 56 syncer::ChangeRecord::ACTION_ADD;
57 break; 57 break;
58 case 1: 58 case 1:
59 changes[i].action = 59 changes[i].action =
60 csync::ChangeRecord::ACTION_UPDATE; 60 syncer::ChangeRecord::ACTION_UPDATE;
61 break; 61 break;
62 default: 62 default:
63 changes[i].action = 63 changes[i].action =
64 csync::ChangeRecord::ACTION_DELETE; 64 syncer::ChangeRecord::ACTION_DELETE;
65 break; 65 break;
66 } 66 }
67 } 67 }
68 68
69 // For each i, we call OnChangesApplied() with the first arg equal 69 // For each i, we call OnChangesApplied() with the first arg equal
70 // to i cast to ModelType and the second argument with the changes 70 // to i cast to ModelType and the second argument with the changes
71 // starting from changes[i]. 71 // starting from changes[i].
72 72
73 // Set expectations for each data type. 73 // Set expectations for each data type.
74 for (int i = syncable::AUTOFILL_PROFILE; 74 for (int i = syncable::AUTOFILL_PROFILE;
75 i < syncable::MODEL_TYPE_COUNT; ++i) { 75 i < syncable::MODEL_TYPE_COUNT; ++i) {
76 const std::string& model_type_str = 76 const std::string& model_type_str =
77 syncable::ModelTypeToString(syncable::ModelTypeFromInt(i)); 77 syncable::ModelTypeToString(syncable::ModelTypeFromInt(i));
78 DictionaryValue expected_details; 78 DictionaryValue expected_details;
79 expected_details.SetString("modelType", model_type_str); 79 expected_details.SetString("modelType", model_type_str);
80 expected_details.SetString("writeTransactionId", "0"); 80 expected_details.SetString("writeTransactionId", "0");
81 ListValue* expected_changes = new ListValue(); 81 ListValue* expected_changes = new ListValue();
82 expected_details.Set("changes", expected_changes); 82 expected_details.Set("changes", expected_changes);
83 for (int j = i; j < syncable::MODEL_TYPE_COUNT; ++j) { 83 for (int j = i; j < syncable::MODEL_TYPE_COUNT; ++j) {
84 expected_changes->Append(changes[j].ToValue()); 84 expected_changes->Append(changes[j].ToValue());
85 } 85 }
86 EXPECT_CALL(mock_js_event_handler_, 86 EXPECT_CALL(mock_js_event_handler_,
87 HandleJsEvent("onChangesApplied", 87 HandleJsEvent("onChangesApplied",
88 HasDetailsAsDictionary(expected_details))); 88 HasDetailsAsDictionary(expected_details)));
89 } 89 }
90 90
91 // Fire OnChangesApplied() for each data type. 91 // Fire OnChangesApplied() for each data type.
92 for (int i = syncable::AUTOFILL_PROFILE; 92 for (int i = syncable::AUTOFILL_PROFILE;
93 i < syncable::MODEL_TYPE_COUNT; ++i) { 93 i < syncable::MODEL_TYPE_COUNT; ++i) {
94 csync::ChangeRecordList 94 syncer::ChangeRecordList
95 local_changes(changes + i, changes + arraysize(changes)); 95 local_changes(changes + i, changes + arraysize(changes));
96 js_mutation_event_observer_.OnChangesApplied( 96 js_mutation_event_observer_.OnChangesApplied(
97 syncable::ModelTypeFromInt(i), 97 syncable::ModelTypeFromInt(i),
98 0, csync::ImmutableChangeRecordList(&local_changes)); 98 0, syncer::ImmutableChangeRecordList(&local_changes));
99 } 99 }
100 100
101 PumpLoop(); 101 PumpLoop();
102 } 102 }
103 103
104 TEST_F(JsMutationEventObserverTest, OnChangesComplete) { 104 TEST_F(JsMutationEventObserverTest, OnChangesComplete) {
105 InSequence dummy; 105 InSequence dummy;
106 106
107 for (int i = syncable::FIRST_REAL_MODEL_TYPE; 107 for (int i = syncable::FIRST_REAL_MODEL_TYPE;
108 i < syncable::MODEL_TYPE_COUNT; ++i) { 108 i < syncable::MODEL_TYPE_COUNT; ++i) {
109 DictionaryValue expected_details; 109 DictionaryValue expected_details;
110 expected_details.SetString( 110 expected_details.SetString(
111 "modelType", 111 "modelType",
112 syncable::ModelTypeToString(syncable::ModelTypeFromInt(i))); 112 syncable::ModelTypeToString(syncable::ModelTypeFromInt(i)));
113 EXPECT_CALL(mock_js_event_handler_, 113 EXPECT_CALL(mock_js_event_handler_,
114 HandleJsEvent("onChangesComplete", 114 HandleJsEvent("onChangesComplete",
115 HasDetailsAsDictionary(expected_details))); 115 HasDetailsAsDictionary(expected_details)));
116 } 116 }
117 117
118 for (int i = syncable::FIRST_REAL_MODEL_TYPE; 118 for (int i = syncable::FIRST_REAL_MODEL_TYPE;
119 i < syncable::MODEL_TYPE_COUNT; ++i) { 119 i < syncable::MODEL_TYPE_COUNT; ++i) {
120 js_mutation_event_observer_.OnChangesComplete( 120 js_mutation_event_observer_.OnChangesComplete(
121 syncable::ModelTypeFromInt(i)); 121 syncable::ModelTypeFromInt(i));
122 } 122 }
123 PumpLoop(); 123 PumpLoop();
124 } 124 }
125 125
126 } // namespace 126 } // namespace
127 } // namespace csync 127 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/internal_api/js_mutation_event_observer.cc ('k') | sync/internal_api/js_sync_manager_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698