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

Unified Diff: chrome/browser/instant/promo_counter_unittest.cc

Issue 5023001: Handful of related instant changes: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix linux build Created 10 years, 1 month 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/instant/promo_counter.cc ('k') | chrome/browser/profile.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/instant/promo_counter_unittest.cc
diff --git a/chrome/browser/instant/promo_counter_unittest.cc b/chrome/browser/instant/promo_counter_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..43cda777070890523b287b792493101572b98b8b
--- /dev/null
+++ b/chrome/browser/instant/promo_counter_unittest.cc
@@ -0,0 +1,81 @@
+// 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/instant/promo_counter.h"
+#include "chrome/test/testing_profile.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+typedef testing::Test PromoCounterTest;
+
+// Makes sure ShouldShow returns false after the max number of days.
+TEST_F(PromoCounterTest, MaxTimeElapsed) {
+ TestingProfile profile;
+ PromoCounter::RegisterUserPrefs(profile.GetPrefs(), "test");
+
+ base::Time test_time(base::Time::Now());
+ PromoCounter counter(&profile, "test", "test", 2, 2);
+ ASSERT_TRUE(counter.ShouldShow(test_time));
+ ASSERT_TRUE(counter.ShouldShow(test_time + base::TimeDelta::FromHours(2)));
+ ASSERT_FALSE(counter.ShouldShow(test_time + base::TimeDelta::FromDays(4)));
+}
+
+// Makes sure ShouldShow returns false after max number of sessions encountered.
+TEST_F(PromoCounterTest, MaxSessionsLapsed) {
+ TestingProfile profile;
+ PromoCounter::RegisterUserPrefs(profile.GetPrefs(), "test");
+
+ base::Time test_time(base::Time::Now());
+ {
+ PromoCounter counter(&profile, "test", "test", 2, 2);
+ ASSERT_TRUE(counter.ShouldShow(test_time));
+ }
+
+ {
+ PromoCounter counter(&profile, "test", "test", 2, 2);
+ ASSERT_TRUE(counter.ShouldShow(test_time));
+ }
+
+ {
+ PromoCounter counter(&profile, "test", "test", 2, 2);
+ ASSERT_FALSE(counter.ShouldShow(test_time));
+ }
+}
+
+// Makes sure invoking Hide make ShouldShow return false.
+TEST_F(PromoCounterTest, Hide) {
+ TestingProfile profile;
+ PromoCounter::RegisterUserPrefs(profile.GetPrefs(), "test");
+
+ base::Time test_time(base::Time::Now());
+ {
+ PromoCounter counter(&profile, "test", "test", 2, 2);
+ counter.Hide();
+ ASSERT_FALSE(counter.ShouldShow(test_time));
+ }
+
+ // Recreate to make sure pref was correctly written.
+ {
+ PromoCounter counter(&profile, "test", "test", 2, 2);
+ ASSERT_FALSE(counter.ShouldShow(test_time));
+ }
+}
+
+// Same as Hide, but invokes ShouldShow first.
+TEST_F(PromoCounterTest, Hide2) {
+ TestingProfile profile;
+ PromoCounter::RegisterUserPrefs(profile.GetPrefs(), "test");
+
+ base::Time test_time(base::Time::Now());
+ {
+ PromoCounter counter(&profile, "test", "test", 2, 2);
+ ASSERT_TRUE(counter.ShouldShow(test_time));
+ counter.Hide();
+ ASSERT_FALSE(counter.ShouldShow(test_time));
+ }
+
+ {
+ PromoCounter counter(&profile, "test", "test", 2, 2);
+ ASSERT_FALSE(counter.ShouldShow(test_time));
+ }
+}
« no previous file with comments | « chrome/browser/instant/promo_counter.cc ('k') | chrome/browser/profile.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698