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

Side by Side Diff: chrome/browser/banners/app_banner_settings_helper_unittest.cc

Issue 884373002: Update content setting for app banners to store more information. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add OWNERS for new folder; remove unwanted change Created 5 years, 10 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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 <vector>
6
7 #include "chrome/browser/banners/app_banner_settings_helper.h"
8 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
9
10 namespace {
11
12 const char kTestURL[] = "http://www.google.com";
13 const char kTestPackageName[] = "test.package";
14
15 bool IsWithinDay(base::Time time1, base::Time time2) {
16 return time1 - time2 < base::TimeDelta::FromDays(1) ||
17 time2 - time1 < base::TimeDelta::FromDays(1);
18 }
19
20 class AppBannerSettingsHelperTest : public ChromeRenderViewHostTestHarness {};
21
22 } // namespace
23
24 TEST_F(AppBannerSettingsHelperTest, Block) {
25 GURL url(kTestURL);
26 NavigateAndCommit(url);
27
28 // Check that by default, showing the banner is allowed.
29 EXPECT_TRUE(AppBannerSettingsHelper::IsAllowed(web_contents(), url,
30 kTestPackageName));
31
32 // Block the banner and test it is no longer allowed.
33 AppBannerSettingsHelper::Block(web_contents(), url, kTestPackageName);
34 EXPECT_FALSE(AppBannerSettingsHelper::IsAllowed(web_contents(), url,
35 kTestPackageName));
36 }
37
38 TEST_F(AppBannerSettingsHelperTest, CouldShowEvents) {
39 GURL url(kTestURL);
40 NavigateAndCommit(url);
41
42 // Check that by default, there are no events recorded.
43 std::vector<base::Time> events =
44 AppBannerSettingsHelper::GetCouldShowBannerEvents(web_contents(), url,
45 kTestPackageName);
46 EXPECT_TRUE(events.empty());
47
48 base::Time::Exploded exploded_reference_time;
49 exploded_reference_time.year = 2015;
50 exploded_reference_time.month = 1;
51 exploded_reference_time.day_of_month = 30;
52 exploded_reference_time.day_of_week = 5;
53 exploded_reference_time.hour = 11;
54
55 base::Time reference_time =
56 base::Time::FromLocalExploded(exploded_reference_time);
57 base::Time same_day = reference_time + base::TimeDelta::FromHours(2);
58 base::Time three_days_prior = reference_time - base::TimeDelta::FromDays(3);
59 base::Time previous_fortnight =
60 reference_time - base::TimeDelta::FromDays(14);
61
62 // Test adding the first date.
63 AppBannerSettingsHelper::RecordCouldShowBannerEvent(
64 web_contents(), url, kTestPackageName, previous_fortnight);
65
66 // It should be the only date recorded.
67 events = AppBannerSettingsHelper::GetCouldShowBannerEvents(
68 web_contents(), url, kTestPackageName);
69 EXPECT_EQ(1u, events.size());
70 EXPECT_TRUE(IsWithinDay(events[0], previous_fortnight));
71
72 // Now add the next date.
73 AppBannerSettingsHelper::RecordCouldShowBannerEvent(
74 web_contents(), url, kTestPackageName, three_days_prior);
75
76 // Now there should be two days.
77 events = AppBannerSettingsHelper::GetCouldShowBannerEvents(
78 web_contents(), url, kTestPackageName);
79 EXPECT_EQ(2u, events.size());
80 EXPECT_TRUE(IsWithinDay(events[0], previous_fortnight));
81 EXPECT_TRUE(IsWithinDay(events[1], three_days_prior));
82
83 // Now add the reference date.
84 AppBannerSettingsHelper::RecordCouldShowBannerEvent(
85 web_contents(), url, kTestPackageName, reference_time);
86
87 // Now there should still be two days, but the first date should have been
88 // removed.
89 events = AppBannerSettingsHelper::GetCouldShowBannerEvents(
90 web_contents(), url, kTestPackageName);
91 EXPECT_EQ(2u, events.size());
92 EXPECT_TRUE(IsWithinDay(events[0], three_days_prior));
93 EXPECT_TRUE(IsWithinDay(events[1], reference_time));
94
95 // Now add the the other day on the reference date.
96 AppBannerSettingsHelper::RecordCouldShowBannerEvent(
97 web_contents(), url, kTestPackageName, same_day);
98
99 // Now there should still be the same two days.
100 events = AppBannerSettingsHelper::GetCouldShowBannerEvents(
101 web_contents(), url, kTestPackageName);
102 EXPECT_EQ(2u, events.size());
103 EXPECT_TRUE(IsWithinDay(events[0], three_days_prior));
104 EXPECT_TRUE(IsWithinDay(events[1], reference_time));
105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698