Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(437)

Unified Diff: chrome/browser/sync/notifier/chrome_system_resources_unittest.cc

Issue 2979003: Reworked ChromeSystemResources to handle callbacks properly. (Closed)
Patch Set: Fixed compile error Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/sync/notifier/chrome_system_resources.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/sync/notifier/chrome_system_resources_unittest.cc
diff --git a/chrome/browser/sync/notifier/chrome_system_resources_unittest.cc b/chrome/browser/sync/notifier/chrome_system_resources_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cb915f174ec8a3ecce0026e13b8fcb145a4bd9ef
--- /dev/null
+++ b/chrome/browser/sync/notifier/chrome_system_resources_unittest.cc
@@ -0,0 +1,106 @@
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/sync/notifier/chrome_system_resources.h"
+
+#include "base/message_loop.h"
+#include "google/cacheinvalidation/invalidation-client.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace sync_notifier {
+namespace {
+
+void ShouldNotRun() {
+ ADD_FAILURE();
+}
+
+class ChromeSystemResourcesTest : public testing::Test {
+ public:
+ void IncrementCounter() {
+ ++counter_;
+ }
+
+ protected:
+ ChromeSystemResourcesTest() : counter_(0) {}
+
+ virtual ~ChromeSystemResourcesTest() {}
+
+ void ScheduleShouldNotRun() {
+ chrome_system_resources_.ScheduleImmediately(
+ invalidation::NewPermanentCallback(&ShouldNotRun));
+ chrome_system_resources_.ScheduleWithDelay(
+ invalidation::TimeDelta::FromSeconds(0),
+ invalidation::NewPermanentCallback(&ShouldNotRun));
+ }
+
+ // Needed by |chrome_system_resources_|.
+ MessageLoop message_loop_;
+ ChromeSystemResources chrome_system_resources_;
+ int counter_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ChromeSystemResourcesTest);
+};
+
+// Make sure current_time() doesn't crash or leak.
+TEST_F(ChromeSystemResourcesTest, CurrentTime) {
+ invalidation::Time current_time =
+ chrome_system_resources_.current_time();
+ LOG(INFO) << "current_time returned: " << current_time.ToInternalValue();
+}
+
+// Make sure Log() doesn't crash or leak.
+TEST_F(ChromeSystemResourcesTest, Log) {
+ chrome_system_resources_.Log(ChromeSystemResources::INFO_LEVEL,
+ __FILE__, __LINE__, "%s %d",
+ "test string", 5);
+}
+
+TEST_F(ChromeSystemResourcesTest, ScheduleBeforeStart) {
+ ScheduleShouldNotRun();
+ chrome_system_resources_.StartScheduler();
+}
+
+TEST_F(ChromeSystemResourcesTest, ScheduleAfterStop) {
+ chrome_system_resources_.StartScheduler();
+ chrome_system_resources_.StopScheduler();
+ ScheduleShouldNotRun();
+}
+
+TEST_F(ChromeSystemResourcesTest, ScheduleAndStop) {
+ chrome_system_resources_.StartScheduler();
+ ScheduleShouldNotRun();
+ chrome_system_resources_.StopScheduler();
+}
+
+TEST_F(ChromeSystemResourcesTest, ScheduleAndDestroy) {
+ chrome_system_resources_.StartScheduler();
+ ScheduleShouldNotRun();
+}
+
+TEST_F(ChromeSystemResourcesTest, ScheduleImmediately) {
+ chrome_system_resources_.StartScheduler();
+ chrome_system_resources_.ScheduleImmediately(
+ invalidation::NewPermanentCallback(
+ this, &ChromeSystemResourcesTest::IncrementCounter));
+ EXPECT_EQ(0, counter_);
+ message_loop_.RunAllPending();
+ EXPECT_EQ(1, counter_);
+}
+
+TEST_F(ChromeSystemResourcesTest, ScheduleWithZeroDelay) {
+ chrome_system_resources_.StartScheduler();
+ chrome_system_resources_.ScheduleWithDelay(
+ invalidation::TimeDelta::FromSeconds(0),
+ invalidation::NewPermanentCallback(
+ this, &ChromeSystemResourcesTest::IncrementCounter));
+ EXPECT_EQ(0, counter_);
+ message_loop_.RunAllPending();
+ EXPECT_EQ(1, counter_);
+}
+
+// TODO(akalin): Figure out how to test with a non-zero delay.
+
+} // namespace
+} // namespace notifier
« no previous file with comments | « chrome/browser/sync/notifier/chrome_system_resources.cc ('k') | chrome/chrome_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698