OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <utility> | 5 #include <utility> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "chrome/browser/browser_process.h" | 16 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/chrome_notification_types.h" | 17 #include "chrome/browser/chrome_notification_types.h" |
18 #include "chrome/browser/prefs/browser_prefs.h" | 18 #include "chrome/browser/prefs/browser_prefs.h" |
19 #include "chrome/browser/web_resource/notification_promo.h" | 19 #include "chrome/browser/web_resource/notification_promo.h" |
20 #include "chrome/browser/web_resource/promo_resource_service.h" | 20 #include "chrome/browser/web_resource/promo_resource_service.h" |
21 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
22 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
23 #include "chrome/test/base/scoped_testing_local_state.h" | 23 #include "chrome/test/base/scoped_testing_local_state.h" |
24 #include "chrome/test/base/testing_browser_process.h" | 24 #include "chrome/test/base/testing_browser_process.h" |
25 #include "content/public/browser/notification_registrar.h" | 25 #include "content/public/browser/notification_registrar.h" |
26 #include "content/public/browser/notification_service.h" | 26 #include "content/public/browser/notification_service.h" |
| 27 #include "net/base/url_constants.h" |
27 #include "net/url_request/test_url_fetcher_factory.h" | 28 #include "net/url_request/test_url_fetcher_factory.h" |
28 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
29 #include "third_party/icu/source/i18n/unicode/smpdtfmt.h" | 30 #include "third_party/icu/source/i18n/unicode/smpdtfmt.h" |
30 | 31 |
31 namespace { | 32 namespace { |
32 | 33 |
33 const char kDateFormat[] = "dd MMM yyyy HH:mm:ss zzzz"; | 34 const char kDateFormat[] = "dd MMM yyyy HH:mm:ss zzzz"; |
34 | 35 |
35 bool YearFromNow(double* date_epoch, std::string* date_string) { | 36 bool YearFromNow(double* date_epoch, std::string* date_string) { |
36 *date_epoch = (base::Time::Now() + base::TimeDelta::FromDays(365)).ToTimeT(); | 37 *date_epoch = (base::Time::Now() + base::TimeDelta::FromDays(365)).ToTimeT(); |
(...skipping 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 promo_test.InitPromoFromJson(true); | 523 promo_test.InitPromoFromJson(true); |
523 // Second time should not trigger a notification. | 524 // Second time should not trigger a notification. |
524 promo_test.InitPromoFromJson(false); | 525 promo_test.InitPromoFromJson(false); |
525 promo_test.TestInitFromPrefs(); | 526 promo_test.TestInitFromPrefs(); |
526 } | 527 } |
527 | 528 |
528 TEST_F(PromoResourceServiceTest, PromoServerURLTest) { | 529 TEST_F(PromoResourceServiceTest, PromoServerURLTest) { |
529 GURL promo_server_url = NotificationPromo::PromoServerURL(); | 530 GURL promo_server_url = NotificationPromo::PromoServerURL(); |
530 EXPECT_FALSE(promo_server_url.is_empty()); | 531 EXPECT_FALSE(promo_server_url.is_empty()); |
531 EXPECT_TRUE(promo_server_url.is_valid()); | 532 EXPECT_TRUE(promo_server_url.is_valid()); |
532 EXPECT_TRUE(promo_server_url.SchemeIs(content::kHttpsScheme)); | 533 EXPECT_TRUE(promo_server_url.SchemeIs(net::kHttpsScheme)); |
533 // TODO(achuith): Test this better. | 534 // TODO(achuith): Test this better. |
534 } | 535 } |
535 | 536 |
536 #if defined(ENABLE_APP_LIST) | 537 #if defined(ENABLE_APP_LIST) |
537 TEST_F(PromoResourceServiceTest, AppLauncherPromoTest) { | 538 TEST_F(PromoResourceServiceTest, AppLauncherPromoTest) { |
538 // Check that prefs are set correctly. | 539 // Check that prefs are set correctly. |
539 NotificationPromoTest promo_test; | 540 NotificationPromoTest promo_test; |
540 | 541 |
541 // Set up start date and promo line in a Dictionary as if parsed from the | 542 // Set up start date and promo line in a Dictionary as if parsed from the |
542 // service. date[0].end is replaced with a date 1 year in the future. | 543 // service. date[0].end is replaced with a date 1 year in the future. |
(...skipping 30 matching lines...) Expand all Loading... |
573 "What do you think of Chrome?", | 574 "What do you think of Chrome?", |
574 // The starting date is in 1999 to make tests pass | 575 // The starting date is in 1999 to make tests pass |
575 // on Android devices with incorrect or unset date/time. | 576 // on Android devices with incorrect or unset date/time. |
576 933672366, // unix epoch for 3 Aug 1999 9:26:06 GMT. | 577 933672366, // unix epoch for 3 Aug 1999 9:26:06 GMT. |
577 1000, 200, 100, 3600, 400, 30); | 578 1000, 200, 100, 3600, 400, 30); |
578 promo_test.InitPromoFromJson(true); | 579 promo_test.InitPromoFromJson(true); |
579 local_state_.Get()->SetBoolean(prefs::kAppLauncherIsEnabled, true); | 580 local_state_.Get()->SetBoolean(prefs::kAppLauncherIsEnabled, true); |
580 EXPECT_FALSE(promo_test.promo().CanShow()); | 581 EXPECT_FALSE(promo_test.promo().CanShow()); |
581 } | 582 } |
582 #endif | 583 #endif |
OLD | NEW |