| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/sync/notifier/chrome_system_resources.h" |
| 6 |
| 7 #include "base/message_loop.h" |
| 8 #include "google/cacheinvalidation/invalidation-client.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 |
| 11 namespace sync_notifier { |
| 12 namespace { |
| 13 |
| 14 void ShouldNotRun() { |
| 15 ADD_FAILURE(); |
| 16 } |
| 17 |
| 18 class ChromeSystemResourcesTest : public testing::Test { |
| 19 public: |
| 20 void IncrementCounter() { |
| 21 ++counter_; |
| 22 } |
| 23 |
| 24 protected: |
| 25 ChromeSystemResourcesTest() : counter_(0) {} |
| 26 |
| 27 virtual ~ChromeSystemResourcesTest() {} |
| 28 |
| 29 void ScheduleShouldNotRun() { |
| 30 chrome_system_resources_.ScheduleImmediately( |
| 31 invalidation::NewPermanentCallback(&ShouldNotRun)); |
| 32 chrome_system_resources_.ScheduleWithDelay( |
| 33 invalidation::TimeDelta::FromSeconds(0), |
| 34 invalidation::NewPermanentCallback(&ShouldNotRun)); |
| 35 } |
| 36 |
| 37 // Needed by |chrome_system_resources_|. |
| 38 MessageLoop message_loop_; |
| 39 ChromeSystemResources chrome_system_resources_; |
| 40 int counter_; |
| 41 |
| 42 private: |
| 43 DISALLOW_COPY_AND_ASSIGN(ChromeSystemResourcesTest); |
| 44 }; |
| 45 |
| 46 // Make sure current_time() doesn't crash or leak. |
| 47 TEST_F(ChromeSystemResourcesTest, CurrentTime) { |
| 48 invalidation::Time current_time = |
| 49 chrome_system_resources_.current_time(); |
| 50 LOG(INFO) << "current_time returned: " << current_time.ToInternalValue(); |
| 51 } |
| 52 |
| 53 // Make sure Log() doesn't crash or leak. |
| 54 TEST_F(ChromeSystemResourcesTest, Log) { |
| 55 chrome_system_resources_.Log(ChromeSystemResources::INFO_LEVEL, |
| 56 __FILE__, __LINE__, "%s %d", |
| 57 "test string", 5); |
| 58 } |
| 59 |
| 60 TEST_F(ChromeSystemResourcesTest, ScheduleBeforeStart) { |
| 61 ScheduleShouldNotRun(); |
| 62 chrome_system_resources_.StartScheduler(); |
| 63 } |
| 64 |
| 65 TEST_F(ChromeSystemResourcesTest, ScheduleAfterStop) { |
| 66 chrome_system_resources_.StartScheduler(); |
| 67 chrome_system_resources_.StopScheduler(); |
| 68 ScheduleShouldNotRun(); |
| 69 } |
| 70 |
| 71 TEST_F(ChromeSystemResourcesTest, ScheduleAndStop) { |
| 72 chrome_system_resources_.StartScheduler(); |
| 73 ScheduleShouldNotRun(); |
| 74 chrome_system_resources_.StopScheduler(); |
| 75 } |
| 76 |
| 77 TEST_F(ChromeSystemResourcesTest, ScheduleAndDestroy) { |
| 78 chrome_system_resources_.StartScheduler(); |
| 79 ScheduleShouldNotRun(); |
| 80 } |
| 81 |
| 82 TEST_F(ChromeSystemResourcesTest, ScheduleImmediately) { |
| 83 chrome_system_resources_.StartScheduler(); |
| 84 chrome_system_resources_.ScheduleImmediately( |
| 85 invalidation::NewPermanentCallback( |
| 86 this, &ChromeSystemResourcesTest::IncrementCounter)); |
| 87 EXPECT_EQ(0, counter_); |
| 88 message_loop_.RunAllPending(); |
| 89 EXPECT_EQ(1, counter_); |
| 90 } |
| 91 |
| 92 TEST_F(ChromeSystemResourcesTest, ScheduleWithZeroDelay) { |
| 93 chrome_system_resources_.StartScheduler(); |
| 94 chrome_system_resources_.ScheduleWithDelay( |
| 95 invalidation::TimeDelta::FromSeconds(0), |
| 96 invalidation::NewPermanentCallback( |
| 97 this, &ChromeSystemResourcesTest::IncrementCounter)); |
| 98 EXPECT_EQ(0, counter_); |
| 99 message_loop_.RunAllPending(); |
| 100 EXPECT_EQ(1, counter_); |
| 101 } |
| 102 |
| 103 // TODO(akalin): Figure out how to test with a non-zero delay. |
| 104 |
| 105 } // namespace |
| 106 } // namespace notifier |
| OLD | NEW |