| OLD | NEW |
| 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 "chrome/browser/sync/js_sync_manager_observer.h" | 5 #include "chrome/browser/sync/js_sync_manager_observer.h" |
| 6 | 6 |
| 7 #include <cstddef> | 7 #include <cstddef> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/values.h" | 10 #include "base/values.h" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 | 172 |
| 173 TestDirectorySetterUpper setter_upper; | 173 TestDirectorySetterUpper setter_upper; |
| 174 sync_api::UserShare share; | 174 sync_api::UserShare share; |
| 175 setter_upper.SetUp(); | 175 setter_upper.SetUp(); |
| 176 share.dir_manager.reset(setter_upper.manager()); | 176 share.dir_manager.reset(setter_upper.manager()); |
| 177 share.name = setter_upper.name(); | 177 share.name = setter_upper.name(); |
| 178 | 178 |
| 179 // We don't test with passwords as that requires additional setup. | 179 // We don't test with passwords as that requires additional setup. |
| 180 | 180 |
| 181 // Build a list of example ChangeRecords. | 181 // Build a list of example ChangeRecords. |
| 182 sync_api::SyncManager::ChangeRecord changes[syncable::PASSWORDS]; | 182 sync_api::SyncManager::ChangeRecord changes[syncable::MODEL_TYPE_COUNT]; |
| 183 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 183 for (int i = syncable::AUTOFILL_PROFILE; |
| 184 i < syncable::PASSWORDS; ++i) { | 184 i < syncable::MODEL_TYPE_COUNT; ++i) { |
| 185 changes[i].id = MakeNode(&share, syncable::ModelTypeFromInt(i)); | 185 changes[i].id = MakeNode(&share, syncable::ModelTypeFromInt(i)); |
| 186 switch (i % 3) { | 186 switch (i % 3) { |
| 187 case 0: | 187 case 0: |
| 188 changes[i].action = | 188 changes[i].action = |
| 189 sync_api::SyncManager::ChangeRecord::ACTION_ADD; | 189 sync_api::SyncManager::ChangeRecord::ACTION_ADD; |
| 190 break; | 190 break; |
| 191 case 1: | 191 case 1: |
| 192 changes[i].action = | 192 changes[i].action = |
| 193 sync_api::SyncManager::ChangeRecord::ACTION_UPDATE; | 193 sync_api::SyncManager::ChangeRecord::ACTION_UPDATE; |
| 194 break; | 194 break; |
| 195 default: | 195 default: |
| 196 changes[i].action = | 196 changes[i].action = |
| 197 sync_api::SyncManager::ChangeRecord::ACTION_DELETE; | 197 sync_api::SyncManager::ChangeRecord::ACTION_DELETE; |
| 198 break; | 198 break; |
| 199 } | 199 } |
| 200 { | 200 { |
| 201 sync_api::ReadTransaction trans(&share); | 201 sync_api::ReadTransaction trans(&share); |
| 202 sync_api::ReadNode node(&trans); | 202 sync_api::ReadNode node(&trans); |
| 203 EXPECT_TRUE(node.InitByIdLookup(changes[i].id)); | 203 EXPECT_TRUE(node.InitByIdLookup(changes[i].id)); |
| 204 changes[i].specifics = node.GetEntry()->Get(syncable::SPECIFICS); | 204 changes[i].specifics = node.GetEntry()->Get(syncable::SPECIFICS); |
| 205 } | 205 } |
| 206 } | 206 } |
| 207 | 207 |
| 208 // For each i, we call OnChangesApplied() with the first arg equal |
| 209 // to i cast to ModelType and the second argument with the changes |
| 210 // starting from changes[i]. |
| 211 |
| 208 // Set expectations for each data type. | 212 // Set expectations for each data type. |
| 209 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 213 for (int i = syncable::AUTOFILL_PROFILE; |
| 210 i < syncable::PASSWORDS; ++i) { | 214 i < syncable::MODEL_TYPE_COUNT; ++i) { |
| 211 const std::string& model_type_str = | 215 const std::string& model_type_str = |
| 212 syncable::ModelTypeToString(syncable::ModelTypeFromInt(i)); | 216 syncable::ModelTypeToString(syncable::ModelTypeFromInt(i)); |
| 213 ListValue expected_args; | 217 ListValue expected_args; |
| 214 expected_args.Append(Value::CreateStringValue(model_type_str)); | 218 expected_args.Append(Value::CreateStringValue(model_type_str)); |
| 215 ListValue* expected_changes = new ListValue(); | 219 ListValue* expected_changes = new ListValue(); |
| 216 expected_args.Append(expected_changes); | 220 expected_args.Append(expected_changes); |
| 217 for (int j = i; j < syncable::PASSWORDS; ++j) { | 221 for (int j = i; j < syncable::MODEL_TYPE_COUNT; ++j) { |
| 218 sync_api::ReadTransaction trans(&share); | 222 sync_api::ReadTransaction trans(&share); |
| 219 expected_changes->Append(changes[i].ToValue(&trans)); | 223 expected_changes->Append(changes[j].ToValue(&trans)); |
| 220 } | 224 } |
| 221 EXPECT_CALL(mock_router_, | 225 EXPECT_CALL(mock_router_, |
| 222 RouteJsEvent("onChangesApplied", | 226 RouteJsEvent("onChangesApplied", |
| 223 HasArgsAsList(expected_args), NULL)); | 227 HasArgsAsList(expected_args), NULL)); |
| 224 } | 228 } |
| 225 | 229 |
| 226 // Fire OnChangesApplied() for each data type. | 230 // Fire OnChangesApplied() for each data type. |
| 227 for (int i = syncable::FIRST_REAL_MODEL_TYPE; | 231 for (int i = syncable::AUTOFILL_PROFILE; |
| 228 i < syncable::PASSWORDS; ++i) { | 232 i < syncable::MODEL_TYPE_COUNT; ++i) { |
| 229 sync_api::ReadTransaction trans(&share); | 233 sync_api::ReadTransaction trans(&share); |
| 230 sync_manager_observer_.OnChangesApplied(syncable::ModelTypeFromInt(i), | 234 sync_manager_observer_.OnChangesApplied(syncable::ModelTypeFromInt(i), |
| 231 &trans, &changes[i], | 235 &trans, &changes[i], |
| 232 syncable::PASSWORDS - i); | 236 syncable::MODEL_TYPE_COUNT - i); |
| 233 } | 237 } |
| 234 | 238 |
| 235 // |share.dir_manager| does not actually own its value. | 239 // |share.dir_manager| does not actually own its value. |
| 236 ignore_result(share.dir_manager.release()); | 240 ignore_result(share.dir_manager.release()); |
| 237 setter_upper.TearDown(); | 241 setter_upper.TearDown(); |
| 238 } | 242 } |
| 239 | 243 |
| 240 } // namespace | 244 } // namespace |
| 241 } // namespace browser_sync | 245 } // namespace browser_sync |
| OLD | NEW |