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

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

Issue 1019763002: Added test to ensure app banner settings are per-origin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 <vector> 5 #include <vector>
6 6
7 #include "chrome/browser/banners/app_banner_settings_helper.h" 7 #include "chrome/browser/banners/app_banner_settings_helper.h"
8 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 8 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
9 9
10 namespace { 10 namespace {
11 11
12 const char kTestURL[] = "https://www.google.com"; 12 const char kTestURL[] = "https://www.google.com";
13 const char kSameOriginTestURL[] = "https://www.google.com/foo.html";
13 const char kTestPackageName[] = "test.package"; 14 const char kTestPackageName[] = "test.package";
14 15
15 base::Time GetReferenceTime() { 16 base::Time GetReferenceTime() {
16 base::Time::Exploded exploded_reference_time; 17 base::Time::Exploded exploded_reference_time;
17 exploded_reference_time.year = 2015; 18 exploded_reference_time.year = 2015;
18 exploded_reference_time.month = 1; 19 exploded_reference_time.month = 1;
19 exploded_reference_time.day_of_month = 30; 20 exploded_reference_time.day_of_month = 30;
20 exploded_reference_time.day_of_week = 5; 21 exploded_reference_time.day_of_week = 5;
21 exploded_reference_time.hour = 11; 22 exploded_reference_time.hour = 11;
22 exploded_reference_time.minute = 0; 23 exploded_reference_time.minute = 0;
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 web_contents(), url, kTestPackageName, reference_time)); 284 web_contents(), url, kTestPackageName, reference_time));
284 285
285 // Add the site a long time ago. It should not be shown. 286 // Add the site a long time ago. It should not be shown.
286 AppBannerSettingsHelper::RecordBannerEvent( 287 AppBannerSettingsHelper::RecordBannerEvent(
287 web_contents(), url, kTestPackageName, 288 web_contents(), url, kTestPackageName,
288 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN, 289 AppBannerSettingsHelper::APP_BANNER_EVENT_DID_ADD_TO_HOMESCREEN,
289 one_year_ago); 290 one_year_ago);
290 EXPECT_FALSE(AppBannerSettingsHelper::ShouldShowBanner( 291 EXPECT_FALSE(AppBannerSettingsHelper::ShouldShowBanner(
291 web_contents(), url, kTestPackageName, reference_time)); 292 web_contents(), url, kTestPackageName, reference_time));
292 } 293 }
294
295 TEST_F(AppBannerSettingsHelperTest, OperatesOnOrigins) {
296 GURL url(kTestURL);
297 NavigateAndCommit(url);
298
299 base::Time reference_time = GetReferenceTime();
300 base::Time one_day_ago = reference_time - base::TimeDelta::FromDays(1);
301
302 // By default the banner should not be shown.
303 EXPECT_FALSE(AppBannerSettingsHelper::ShouldShowBanner(
304 web_contents(), url, kTestPackageName, reference_time));
305
306 // Record events such that the banner should show.
307 AppBannerSettingsHelper::RecordBannerEvent(
308 web_contents(), url, kTestPackageName,
309 AppBannerSettingsHelper::APP_BANNER_EVENT_COULD_SHOW, one_day_ago);
310 AppBannerSettingsHelper::RecordBannerEvent(
311 web_contents(), url, kTestPackageName,
312 AppBannerSettingsHelper::APP_BANNER_EVENT_COULD_SHOW, reference_time);
313
314 // Navigate to another page on the same origin.
315 url = GURL(kSameOriginTestURL);
316 NavigateAndCommit(url);
317
318 // The banner should show as settings are per-origin.
319 EXPECT_TRUE(AppBannerSettingsHelper::ShouldShowBanner(
320 web_contents(), url, kTestPackageName, reference_time));
321 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698