| 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 "testing/gmock/include/gmock/gmock.h" | 5 #include "testing/gmock/include/gmock/gmock.h" |
| 6 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
| 7 | 7 |
| 8 #include "chrome/browser/sync/glue/fake_data_type_controller.h" | 8 #include "chrome/browser/sync/glue/fake_data_type_controller.h" |
| 9 | 9 |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 12 |
| 13 using syncable::ModelType; | 13 using syncable::ModelType; |
| 14 namespace browser_sync { | 14 namespace browser_sync { |
| 15 | 15 |
| 16 FakeDataTypeController::FakeDataTypeController(ModelType type) | 16 FakeDataTypeController::FakeDataTypeController(ModelType type) |
| 17 : state_(NOT_RUNNING), type_(type) {} | 17 : state_(NOT_RUNNING), model_load_delayed_(false), type_(type) {} |
| 18 | 18 |
| 19 FakeDataTypeController::~FakeDataTypeController() { | 19 FakeDataTypeController::~FakeDataTypeController() { |
| 20 } | 20 } |
| 21 | 21 |
| 22 // NOT_RUNNING ->MODEL_LOADED. | 22 // NOT_RUNNING ->MODEL_LOADED |MODEL_STARTING. |
| 23 void FakeDataTypeController::LoadModels( | 23 void FakeDataTypeController::LoadModels( |
| 24 const ModelLoadCallback& model_load_callback) { | 24 const ModelLoadCallback& model_load_callback) { |
| 25 if (state_ != NOT_RUNNING) { | 25 if (state_ != NOT_RUNNING) { |
| 26 ADD_FAILURE(); | 26 ADD_FAILURE(); |
| 27 return; | 27 return; |
| 28 } | 28 } |
| 29 model_load_callback.Run(type(), SyncError()); | 29 |
| 30 state_ = MODEL_LOADED; | 30 if (model_load_delayed_ == false) { |
| 31 model_load_callback.Run(type(), SyncError()); |
| 32 state_ = MODEL_LOADED; |
| 33 } else { |
| 34 model_load_callback_ = model_load_callback; |
| 35 state_ = MODEL_STARTING; |
| 36 } |
| 31 } | 37 } |
| 32 | 38 |
| 33 void FakeDataTypeController::OnModelLoaded() { | 39 void FakeDataTypeController::OnModelLoaded() { |
| 34 NOTREACHED(); | 40 NOTREACHED(); |
| 35 } | 41 } |
| 36 | 42 |
| 37 // MODEL_LOADED -> MODEL_STARTING. | 43 // MODEL_LOADED -> MODEL_STARTING. |
| 38 void FakeDataTypeController::StartAssociating( | 44 void FakeDataTypeController::StartAssociating( |
| 39 const StartCallback& start_callback) { | 45 const StartCallback& start_callback) { |
| 40 last_start_callback_ = start_callback; | 46 last_start_callback_ = start_callback; |
| 41 state_ = MODEL_STARTING; | 47 state_ = ASSOCIATING; |
| 42 } | 48 } |
| 43 | 49 |
| 44 // MODEL_STARTING | ASSOCIATING -> RUNNING | DISABLED | NOT_RUNNING | 50 // MODEL_STARTING | ASSOCIATING -> RUNNING | DISABLED | NOT_RUNNING |
| 45 // (depending on |result|) | 51 // (depending on |result|) |
| 46 void FakeDataTypeController::FinishStart(StartResult result) { | 52 void FakeDataTypeController::FinishStart(StartResult result) { |
| 47 // We should have a callback from Start(). | 53 // We should have a callback from Start(). |
| 48 if (last_start_callback_.is_null()) { | 54 if (last_start_callback_.is_null()) { |
| 49 ADD_FAILURE(); | 55 ADD_FAILURE(); |
| 50 return; | 56 return; |
| 51 } | 57 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 const std::string& message) { | 110 const std::string& message) { |
| 105 ADD_FAILURE() << message; | 111 ADD_FAILURE() << message; |
| 106 } | 112 } |
| 107 | 113 |
| 108 void FakeDataTypeController::RecordUnrecoverableError( | 114 void FakeDataTypeController::RecordUnrecoverableError( |
| 109 const tracked_objects::Location& from_here, | 115 const tracked_objects::Location& from_here, |
| 110 const std::string& message) { | 116 const std::string& message) { |
| 111 ADD_FAILURE() << message; | 117 ADD_FAILURE() << message; |
| 112 } | 118 } |
| 113 | 119 |
| 120 void FakeDataTypeController::SetDelayModelLoad() { |
| 121 model_load_delayed_ = true; |
| 122 } |
| 123 |
| 124 void FakeDataTypeController::FinishModelLoad() { |
| 125 ModelLoadCallback model_load_callback = model_load_callback_; |
| 126 model_load_callback.Run(type(), SyncError()); |
| 127 } |
| 128 |
| 114 } // namespace browser_sync | 129 } // namespace browser_sync |
| 115 | 130 |
| OLD | NEW |