Index: chrome/browser/web_resource/promo_resource_service_unittest.cc |
diff --git a/chrome/browser/web_resource/promo_resource_service_unittest.cc b/chrome/browser/web_resource/promo_resource_service_unittest.cc |
index 6ddadfaab98b207b38060a8b70a094ff34392f57..57dfad684a337efbf90759dbb1c0fc4b0d9f078a 100644 |
--- a/chrome/browser/web_resource/promo_resource_service_unittest.cc |
+++ b/chrome/browser/web_resource/promo_resource_service_unittest.cc |
@@ -2,11 +2,13 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include <utility> |
#include <vector> |
#include "base/json/json_reader.h" |
#include "base/message_loop.h" |
#include "base/string_number_conversions.h" |
+#include "base/string_util.h" |
#include "base/time.h" |
#include "base/utf_string_conversions.h" |
#include "base/values.h" |
@@ -24,6 +26,37 @@ |
#include "content/public/browser/notification_service.h" |
#include "net/url_request/test_url_fetcher_factory.h" |
#include "testing/gtest/include/gtest/gtest.h" |
+#include "unicode/smpdtfmt.h" |
+ |
+namespace { |
+ |
+const char kDateFormat[] = "dd MMM yyyy HH:mm:ss zzz"; |
+ |
+std::pair<double, std::string> YearFromNow() { |
achuithb
2013/01/08 21:44:36
Please add a function comment explaining the retur
|
+ UErrorCode status = U_ZERO_ERROR; |
+ icu::SimpleDateFormat simple_formatter(icu::UnicodeString(kDateFormat), |
+ icu::Locale("en_US"), |
+ status); |
+ DCHECK(U_SUCCESS(status)); |
+ |
+ const double year_from_now = |
+ (base::Time::Now() + base::TimeDelta::FromDays(365)).ToTimeT(); |
+ |
+ icu::UnicodeString date_unicode_string; |
+ simple_formatter.format(static_cast<UDate>(year_from_now * 1000), |
+ date_unicode_string, |
+ status); |
+ DCHECK(U_SUCCESS(status)); |
+ |
+ std::string date_string; |
+ UTF16ToUTF8(date_unicode_string.getBuffer(), |
+ static_cast<size_t>(date_unicode_string.length()), |
+ &date_string); |
+ |
+ return std::make_pair(year_from_now, date_string); |
+} |
+ |
+} // namespace |
class PromoResourceServiceTest : public testing::Test { |
public: |
@@ -54,11 +87,18 @@ class NotificationPromoTest { |
void Init(const std::string& json, |
const std::string& promo_text, |
- double start, double end, |
+ double start, |
int num_groups, int initial_segment, int increment, |
int time_slice, int max_group, int max_views) { |
- Value* value(base::JSONReader::Read(json)); |
+ std::pair<double, std::string> year_from_now = YearFromNow(); |
+ std::vector<std::string> replacements; |
+ replacements.push_back(year_from_now.second); |
+ |
+ std::string json_with_year( |
+ ReplaceStringPlaceholders(json, replacements, NULL)); |
+ Value* value(base::JSONReader::Read(json_with_year)); |
ASSERT_TRUE(value); |
+ |
DictionaryValue* dict = NULL; |
value->GetAsDictionary(&dict); |
ASSERT_TRUE(dict); |
@@ -68,7 +108,7 @@ class NotificationPromoTest { |
promo_text_ = promo_text; |
start_ = start; |
- end_ = end; |
+ end_ = year_from_now.first; |
num_groups_ = num_groups; |
initial_segment_ = initial_segment; |
@@ -319,14 +359,12 @@ class NotificationPromoTest { |
// and CanShow() is handled correctly under variety of conditions. |
// Additionally, test that the first string in |strings| is used if |
// no payload.promo_short_message is specified in the JSON response. |
- |
-// hardcoded a date in Jan 2013. Srzly?? http://crbug.com/168561 |
-TEST_F(PromoResourceServiceTest, DISABLED_NotificationPromoTest) { |
+TEST_F(PromoResourceServiceTest, NotificationPromoTest) { |
// Check that prefs are set correctly. |
NotificationPromoTest promo_test; |
- // Set up start and end dates and promo line in a Dictionary as if parsed |
- // from the service. |
+ // Set up start date and promo line in a Dictionary as if parsed from the |
+ // service. date[0].end is replaced with a date 1 year in the future. |
promo_test.Init("{" |
" \"ntp_notification_promo\": [" |
" {" |
@@ -334,7 +372,7 @@ TEST_F(PromoResourceServiceTest, DISABLED_NotificationPromoTest) { |
" [" |
" {" |
" \"start\":\"3 Aug 1999 9:26:06 GMT\"," |
- " \"end\":\"7 Jan 2013 5:40:75 PST\"" |
+ " \"end\":\"$1\"" |
" }" |
" ]," |
" \"strings\":" |
@@ -363,7 +401,6 @@ TEST_F(PromoResourceServiceTest, DISABLED_NotificationPromoTest) { |
// The starting date is in 1999 to make tests pass |
// on Android devices with incorrect or unset date/time. |
933672366, // unix epoch for 3 Aug 1999 9:26:06 GMT. |
- 1357566075, // unix epoch for 7 Jan 2013 5:40:75 PST. |
1000, 200, 100, 3600, 400, 30); |
promo_test.InitPromoFromJson(true); |
@@ -388,8 +425,8 @@ TEST_F(PromoResourceServiceTest, NotificationPromoCompatNoStringsTest) { |
// Check that prefs are set correctly. |
NotificationPromoTest promo_test; |
- // Set up start and end dates and promo line in a Dictionary as if parsed |
- // from the service. |
+ // Set up start date and promo line in a Dictionary as if parsed from the |
+ // service. date[0].end is replaced with a date 1 year in the future. |
promo_test.Init("{" |
" \"ntp_notification_promo\": [" |
" {" |
@@ -397,7 +434,7 @@ TEST_F(PromoResourceServiceTest, NotificationPromoCompatNoStringsTest) { |
" [" |
" {" |
" \"start\":\"3 Aug 1999 9:26:06 GMT\"," |
- " \"end\":\"7 Jan 2013 5:40:75 PST\"" |
+ " \"end\":\"$1\"" |
" }" |
" ]," |
" \"grouping\":" |
@@ -423,7 +460,6 @@ TEST_F(PromoResourceServiceTest, NotificationPromoCompatNoStringsTest) { |
// The starting date is in 1999 to make tests pass |
// on Android devices with incorrect or unset date/time. |
933672366, // unix epoch for 3 Aug 1999 9:26:06 GMT. |
- 1357566075, // unix epoch for 7 Jan 2013 5:40:75 PST. |
1000, 200, 100, 3600, 400, 30); |
promo_test.InitPromoFromJson(true); |
@@ -437,8 +473,8 @@ TEST_F(PromoResourceServiceTest, NotificationPromoCompatPayloadStringsTest) { |
// Check that prefs are set correctly. |
NotificationPromoTest promo_test; |
- // Set up start and end dates and promo line in a Dictionary as if parsed |
- // from the service. |
+ // Set up start date and promo line in a Dictionary as if parsed from the |
+ // service. date[0].end is replaced with a date 1 year in the future. |
promo_test.Init("{" |
" \"ntp_notification_promo\": [" |
" {" |
@@ -446,7 +482,7 @@ TEST_F(PromoResourceServiceTest, NotificationPromoCompatPayloadStringsTest) { |
" [" |
" {" |
" \"start\":\"3 Aug 1999 9:26:06 GMT\"," |
- " \"end\":\"7 Jan 2013 5:40:75 PST\"" |
+ " \"end\":\"$1\"" |
" }" |
" ]," |
" \"grouping\":" |
@@ -478,7 +514,6 @@ TEST_F(PromoResourceServiceTest, NotificationPromoCompatPayloadStringsTest) { |
// The starting date is in 1999 to make tests pass |
// on Android devices with incorrect or unset date/time. |
933672366, // unix epoch for 3 Aug 1999 9:26:06 GMT. |
- 1357566075, // unix epoch for 7 Jan 2013 5:40:75 PST. |
1000, 200, 100, 3600, 400, 30); |
promo_test.InitPromoFromJson(true); |