OLD | NEW |
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/base/model_type.h" | 10 #include "sync/internal_api/public/base/model_type.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 } | 63 } |
64 | 64 |
65 // For each i, we call OnChangesApplied() with the first arg equal | 65 // For each i, we call OnChangesApplied() with the first arg equal |
66 // to i cast to ModelType and the second argument with the changes | 66 // to i cast to ModelType and the second argument with the changes |
67 // starting from changes[i]. | 67 // starting from changes[i]. |
68 | 68 |
69 // Set expectations for each data type. | 69 // Set expectations for each data type. |
70 for (int i = AUTOFILL_PROFILE; i < MODEL_TYPE_COUNT; ++i) { | 70 for (int i = AUTOFILL_PROFILE; i < MODEL_TYPE_COUNT; ++i) { |
71 const std::string& model_type_str = | 71 const std::string& model_type_str = |
72 ModelTypeToString(ModelTypeFromInt(i)); | 72 ModelTypeToString(ModelTypeFromInt(i)); |
73 DictionaryValue expected_details; | 73 base::DictionaryValue expected_details; |
74 expected_details.SetString("modelType", model_type_str); | 74 expected_details.SetString("modelType", model_type_str); |
75 expected_details.SetString("writeTransactionId", "0"); | 75 expected_details.SetString("writeTransactionId", "0"); |
76 ListValue* expected_changes = new ListValue(); | 76 base::ListValue* expected_changes = new base::ListValue(); |
77 expected_details.Set("changes", expected_changes); | 77 expected_details.Set("changes", expected_changes); |
78 for (int j = i; j < MODEL_TYPE_COUNT; ++j) { | 78 for (int j = i; j < MODEL_TYPE_COUNT; ++j) { |
79 expected_changes->Append(changes[j].ToValue()); | 79 expected_changes->Append(changes[j].ToValue()); |
80 } | 80 } |
81 EXPECT_CALL(mock_js_event_handler_, | 81 EXPECT_CALL(mock_js_event_handler_, |
82 HandleJsEvent("onChangesApplied", | 82 HandleJsEvent("onChangesApplied", |
83 HasDetailsAsDictionary(expected_details))); | 83 HasDetailsAsDictionary(expected_details))); |
84 } | 84 } |
85 | 85 |
86 // Fire OnChangesApplied() for each data type. | 86 // Fire OnChangesApplied() for each data type. |
87 for (int i = AUTOFILL_PROFILE; i < MODEL_TYPE_COUNT; ++i) { | 87 for (int i = AUTOFILL_PROFILE; i < MODEL_TYPE_COUNT; ++i) { |
88 ChangeRecordList local_changes(changes + i, changes + arraysize(changes)); | 88 ChangeRecordList local_changes(changes + i, changes + arraysize(changes)); |
89 js_mutation_event_observer_.OnChangesApplied( | 89 js_mutation_event_observer_.OnChangesApplied( |
90 ModelTypeFromInt(i), | 90 ModelTypeFromInt(i), |
91 0, ImmutableChangeRecordList(&local_changes)); | 91 0, ImmutableChangeRecordList(&local_changes)); |
92 } | 92 } |
93 | 93 |
94 PumpLoop(); | 94 PumpLoop(); |
95 } | 95 } |
96 | 96 |
97 TEST_F(JsMutationEventObserverTest, OnChangesComplete) { | 97 TEST_F(JsMutationEventObserverTest, OnChangesComplete) { |
98 InSequence dummy; | 98 InSequence dummy; |
99 | 99 |
100 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { | 100 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { |
101 DictionaryValue expected_details; | 101 base::DictionaryValue expected_details; |
102 expected_details.SetString( | 102 expected_details.SetString( |
103 "modelType", | 103 "modelType", |
104 ModelTypeToString(ModelTypeFromInt(i))); | 104 ModelTypeToString(ModelTypeFromInt(i))); |
105 EXPECT_CALL(mock_js_event_handler_, | 105 EXPECT_CALL(mock_js_event_handler_, |
106 HandleJsEvent("onChangesComplete", | 106 HandleJsEvent("onChangesComplete", |
107 HasDetailsAsDictionary(expected_details))); | 107 HasDetailsAsDictionary(expected_details))); |
108 } | 108 } |
109 | 109 |
110 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { | 110 for (int i = FIRST_REAL_MODEL_TYPE; i < MODEL_TYPE_COUNT; ++i) { |
111 js_mutation_event_observer_.OnChangesComplete( | 111 js_mutation_event_observer_.OnChangesComplete( |
112 ModelTypeFromInt(i)); | 112 ModelTypeFromInt(i)); |
113 } | 113 } |
114 PumpLoop(); | 114 PumpLoop(); |
115 } | 115 } |
116 | 116 |
117 } // namespace | 117 } // namespace |
118 } // namespace syncer | 118 } // namespace syncer |
OLD | NEW |