Chromium Code Reviews| 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/notifier/chrome_system_resources.h" | 5 #include "sync/notifier/sync_system_resources.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 | 13 |
| 14 #include "google/cacheinvalidation/include/types.h" | 14 #include "google/cacheinvalidation/include/types.h" |
| 15 #include "jingle/notifier/listener/fake_push_client.h" | 15 #include "jingle/notifier/listener/fake_push_client.h" |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 39 | 39 |
| 40 class MockStorageCallback { | 40 class MockStorageCallback { |
| 41 public: | 41 public: |
| 42 MOCK_CONST_METHOD1(Run, void(invalidation::Status)); | 42 MOCK_CONST_METHOD1(Run, void(invalidation::Status)); |
| 43 base::Callback<void(invalidation::Status)>* CreateCallback() { | 43 base::Callback<void(invalidation::Status)>* CreateCallback() { |
| 44 return new base::Callback<void(invalidation::Status)>( | 44 return new base::Callback<void(invalidation::Status)>( |
| 45 base::Bind(&MockStorageCallback::Run, base::Unretained(this))); | 45 base::Bind(&MockStorageCallback::Run, base::Unretained(this))); |
| 46 } | 46 } |
| 47 }; | 47 }; |
| 48 | 48 |
| 49 class ChromeSystemResourcesTest : public testing::Test { | 49 class SyncSystemResourcesTest : public testing::Test { |
| 50 protected: | 50 protected: |
| 51 ChromeSystemResourcesTest() | 51 SyncSystemResourcesTest() |
| 52 : chrome_system_resources_( | 52 : chrome_system_resources_( |
|
rlarocque
2012/09/05 00:58:31
Missed one?
| |
| 53 scoped_ptr<notifier::PushClient>(new notifier::FakePushClient()), | 53 scoped_ptr<notifier::PushClient>(new notifier::FakePushClient()), |
| 54 &mock_state_writer_) {} | 54 &mock_state_writer_) {} |
| 55 | 55 |
| 56 virtual ~ChromeSystemResourcesTest() {} | 56 virtual ~SyncSystemResourcesTest() {} |
| 57 | 57 |
| 58 void ScheduleShouldNotRun() { | 58 void ScheduleShouldNotRun() { |
| 59 { | 59 { |
| 60 // Owned by ScheduleImmediately. | 60 // Owned by ScheduleImmediately. |
| 61 MockClosure mock_closure; | 61 MockClosure mock_closure; |
| 62 base::Closure* should_not_run = mock_closure.CreateClosure(); | 62 base::Closure* should_not_run = mock_closure.CreateClosure(); |
| 63 EXPECT_CALL(mock_closure, Run()).Times(0); | 63 EXPECT_CALL(mock_closure, Run()).Times(0); |
| 64 chrome_system_resources_.internal_scheduler()->Schedule( | 64 chrome_system_resources_.internal_scheduler()->Schedule( |
| 65 invalidation::Scheduler::NoDelay(), should_not_run); | 65 invalidation::Scheduler::NoDelay(), should_not_run); |
| 66 } | 66 } |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 78 base::Closure* should_not_run = mock_closure.CreateClosure(); | 78 base::Closure* should_not_run = mock_closure.CreateClosure(); |
| 79 EXPECT_CALL(mock_closure, Run()).Times(0); | 79 EXPECT_CALL(mock_closure, Run()).Times(0); |
| 80 chrome_system_resources_.internal_scheduler()->Schedule( | 80 chrome_system_resources_.internal_scheduler()->Schedule( |
| 81 invalidation::TimeDelta::FromSeconds(0), should_not_run); | 81 invalidation::TimeDelta::FromSeconds(0), should_not_run); |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 | 84 |
| 85 // Needed by |chrome_system_resources_|. | 85 // Needed by |chrome_system_resources_|. |
| 86 MessageLoop message_loop_; | 86 MessageLoop message_loop_; |
| 87 MockStateWriter mock_state_writer_; | 87 MockStateWriter mock_state_writer_; |
| 88 ChromeSystemResources chrome_system_resources_; | 88 SyncSystemResources chrome_system_resources_; |
| 89 | 89 |
| 90 private: | 90 private: |
| 91 DISALLOW_COPY_AND_ASSIGN(ChromeSystemResourcesTest); | 91 DISALLOW_COPY_AND_ASSIGN(SyncSystemResourcesTest); |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 // Make sure current_time() doesn't crash or leak. | 94 // Make sure current_time() doesn't crash or leak. |
| 95 TEST_F(ChromeSystemResourcesTest, CurrentTime) { | 95 TEST_F(SyncSystemResourcesTest, CurrentTime) { |
| 96 invalidation::Time current_time = | 96 invalidation::Time current_time = |
| 97 chrome_system_resources_.internal_scheduler()->GetCurrentTime(); | 97 chrome_system_resources_.internal_scheduler()->GetCurrentTime(); |
| 98 DVLOG(1) << "current_time returned: " << current_time.ToInternalValue(); | 98 DVLOG(1) << "current_time returned: " << current_time.ToInternalValue(); |
| 99 } | 99 } |
| 100 | 100 |
| 101 // Make sure Log() doesn't crash or leak. | 101 // Make sure Log() doesn't crash or leak. |
| 102 TEST_F(ChromeSystemResourcesTest, Log) { | 102 TEST_F(SyncSystemResourcesTest, Log) { |
| 103 chrome_system_resources_.logger()->Log(ChromeLogger::INFO_LEVEL, | 103 chrome_system_resources_.logger()->Log(SyncLogger::INFO_LEVEL, |
| 104 __FILE__, __LINE__, "%s %d", | 104 __FILE__, __LINE__, "%s %d", |
| 105 "test string", 5); | 105 "test string", 5); |
| 106 } | 106 } |
| 107 | 107 |
| 108 TEST_F(ChromeSystemResourcesTest, ScheduleBeforeStart) { | 108 TEST_F(SyncSystemResourcesTest, ScheduleBeforeStart) { |
| 109 ScheduleShouldNotRun(); | 109 ScheduleShouldNotRun(); |
| 110 chrome_system_resources_.Start(); | 110 chrome_system_resources_.Start(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 TEST_F(ChromeSystemResourcesTest, ScheduleAfterStop) { | 113 TEST_F(SyncSystemResourcesTest, ScheduleAfterStop) { |
| 114 chrome_system_resources_.Start(); | 114 chrome_system_resources_.Start(); |
| 115 chrome_system_resources_.Stop(); | 115 chrome_system_resources_.Stop(); |
| 116 ScheduleShouldNotRun(); | 116 ScheduleShouldNotRun(); |
| 117 } | 117 } |
| 118 | 118 |
| 119 TEST_F(ChromeSystemResourcesTest, ScheduleAndStop) { | 119 TEST_F(SyncSystemResourcesTest, ScheduleAndStop) { |
| 120 chrome_system_resources_.Start(); | 120 chrome_system_resources_.Start(); |
| 121 ScheduleShouldNotRun(); | 121 ScheduleShouldNotRun(); |
| 122 chrome_system_resources_.Stop(); | 122 chrome_system_resources_.Stop(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 TEST_F(ChromeSystemResourcesTest, ScheduleAndDestroy) { | 125 TEST_F(SyncSystemResourcesTest, ScheduleAndDestroy) { |
| 126 chrome_system_resources_.Start(); | 126 chrome_system_resources_.Start(); |
| 127 ScheduleShouldNotRun(); | 127 ScheduleShouldNotRun(); |
| 128 } | 128 } |
| 129 | 129 |
| 130 TEST_F(ChromeSystemResourcesTest, ScheduleImmediately) { | 130 TEST_F(SyncSystemResourcesTest, ScheduleImmediately) { |
| 131 chrome_system_resources_.Start(); | 131 chrome_system_resources_.Start(); |
| 132 MockClosure mock_closure; | 132 MockClosure mock_closure; |
| 133 EXPECT_CALL(mock_closure, Run()); | 133 EXPECT_CALL(mock_closure, Run()); |
| 134 chrome_system_resources_.internal_scheduler()->Schedule( | 134 chrome_system_resources_.internal_scheduler()->Schedule( |
| 135 invalidation::Scheduler::NoDelay(), mock_closure.CreateClosure()); | 135 invalidation::Scheduler::NoDelay(), mock_closure.CreateClosure()); |
| 136 message_loop_.RunAllPending(); | 136 message_loop_.RunAllPending(); |
| 137 } | 137 } |
| 138 | 138 |
| 139 TEST_F(ChromeSystemResourcesTest, ScheduleOnListenerThread) { | 139 TEST_F(SyncSystemResourcesTest, ScheduleOnListenerThread) { |
| 140 chrome_system_resources_.Start(); | 140 chrome_system_resources_.Start(); |
| 141 MockClosure mock_closure; | 141 MockClosure mock_closure; |
| 142 EXPECT_CALL(mock_closure, Run()); | 142 EXPECT_CALL(mock_closure, Run()); |
| 143 chrome_system_resources_.listener_scheduler()->Schedule( | 143 chrome_system_resources_.listener_scheduler()->Schedule( |
| 144 invalidation::Scheduler::NoDelay(), mock_closure.CreateClosure()); | 144 invalidation::Scheduler::NoDelay(), mock_closure.CreateClosure()); |
| 145 EXPECT_TRUE( | 145 EXPECT_TRUE( |
| 146 chrome_system_resources_.internal_scheduler()->IsRunningOnThread()); | 146 chrome_system_resources_.internal_scheduler()->IsRunningOnThread()); |
| 147 message_loop_.RunAllPending(); | 147 message_loop_.RunAllPending(); |
| 148 } | 148 } |
| 149 | 149 |
| 150 TEST_F(ChromeSystemResourcesTest, ScheduleWithZeroDelay) { | 150 TEST_F(SyncSystemResourcesTest, ScheduleWithZeroDelay) { |
| 151 chrome_system_resources_.Start(); | 151 chrome_system_resources_.Start(); |
| 152 MockClosure mock_closure; | 152 MockClosure mock_closure; |
| 153 EXPECT_CALL(mock_closure, Run()); | 153 EXPECT_CALL(mock_closure, Run()); |
| 154 chrome_system_resources_.internal_scheduler()->Schedule( | 154 chrome_system_resources_.internal_scheduler()->Schedule( |
| 155 invalidation::TimeDelta::FromSeconds(0), mock_closure.CreateClosure()); | 155 invalidation::TimeDelta::FromSeconds(0), mock_closure.CreateClosure()); |
| 156 message_loop_.RunAllPending(); | 156 message_loop_.RunAllPending(); |
| 157 } | 157 } |
| 158 | 158 |
| 159 // TODO(akalin): Figure out how to test with a non-zero delay. | 159 // TODO(akalin): Figure out how to test with a non-zero delay. |
| 160 | 160 |
| 161 TEST_F(ChromeSystemResourcesTest, WriteState) { | 161 TEST_F(SyncSystemResourcesTest, WriteState) { |
| 162 chrome_system_resources_.Start(); | 162 chrome_system_resources_.Start(); |
| 163 EXPECT_CALL(mock_state_writer_, WriteState(_)); | 163 EXPECT_CALL(mock_state_writer_, WriteState(_)); |
| 164 // Owned by WriteState. | 164 // Owned by WriteState. |
| 165 MockStorageCallback mock_storage_callback; | 165 MockStorageCallback mock_storage_callback; |
| 166 invalidation::Status results(invalidation::Status::PERMANENT_FAILURE, | 166 invalidation::Status results(invalidation::Status::PERMANENT_FAILURE, |
| 167 "fake-failure"); | 167 "fake-failure"); |
| 168 EXPECT_CALL(mock_storage_callback, Run(_)) | 168 EXPECT_CALL(mock_storage_callback, Run(_)) |
| 169 .WillOnce(SaveArg<0>(&results)); | 169 .WillOnce(SaveArg<0>(&results)); |
| 170 chrome_system_resources_.storage()->WriteKey( | 170 chrome_system_resources_.storage()->WriteKey( |
| 171 "", "state", mock_storage_callback.CreateCallback()); | 171 "", "state", mock_storage_callback.CreateCallback()); |
| 172 message_loop_.RunAllPending(); | 172 message_loop_.RunAllPending(); |
| 173 EXPECT_EQ(invalidation::Status(invalidation::Status::SUCCESS, ""), results); | 173 EXPECT_EQ(invalidation::Status(invalidation::Status::SUCCESS, ""), results); |
| 174 } | 174 } |
| 175 | 175 |
| 176 } // namespace | 176 } // namespace |
| 177 } // namespace syncer | 177 } // namespace syncer |
| OLD | NEW |