Commit babc76f2 authored by dbeam@chromium.org's avatar dbeam@chromium.org

Fix PromoResourceServiceTest.NotificationPromoTest and make it use dynamic [future] dates.

R=rsesek@chromium.org
BUG=168561
TEST=PromoResourceServiceTest.NotificationPromoTest passes after Jan 7 2013 5:40:75 PST

Review URL: https://codereview.chromium.org/11801015

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175428 0039d316-1c4b-4281-b951-d872f2087c98
parent 8928d9fc
...@@ -2,11 +2,13 @@ ...@@ -2,11 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include <utility>
#include <vector> #include <vector>
#include "base/json/json_reader.h" #include "base/json/json_reader.h"
#include "base/message_loop.h" #include "base/message_loop.h"
#include "base/string_number_conversions.h" #include "base/string_number_conversions.h"
#include "base/string_util.h"
#include "base/time.h" #include "base/time.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "base/values.h" #include "base/values.h"
...@@ -24,6 +26,37 @@ ...@@ -24,6 +26,37 @@
#include "content/public/browser/notification_service.h" #include "content/public/browser/notification_service.h"
#include "net/url_request/test_url_fetcher_factory.h" #include "net/url_request/test_url_fetcher_factory.h"
#include "testing/gtest/include/gtest/gtest.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() {
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 { class PromoResourceServiceTest : public testing::Test {
public: public:
...@@ -54,11 +87,18 @@ class NotificationPromoTest { ...@@ -54,11 +87,18 @@ class NotificationPromoTest {
void Init(const std::string& json, void Init(const std::string& json,
const std::string& promo_text, const std::string& promo_text,
double start, double end, double start,
int num_groups, int initial_segment, int increment, int num_groups, int initial_segment, int increment,
int time_slice, int max_group, int max_views) { 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); ASSERT_TRUE(value);
DictionaryValue* dict = NULL; DictionaryValue* dict = NULL;
value->GetAsDictionary(&dict); value->GetAsDictionary(&dict);
ASSERT_TRUE(dict); ASSERT_TRUE(dict);
...@@ -68,7 +108,7 @@ class NotificationPromoTest { ...@@ -68,7 +108,7 @@ class NotificationPromoTest {
promo_text_ = promo_text; promo_text_ = promo_text;
start_ = start; start_ = start;
end_ = end; end_ = year_from_now.first;
num_groups_ = num_groups; num_groups_ = num_groups;
initial_segment_ = initial_segment; initial_segment_ = initial_segment;
...@@ -319,14 +359,12 @@ class NotificationPromoTest { ...@@ -319,14 +359,12 @@ class NotificationPromoTest {
// and CanShow() is handled correctly under variety of conditions. // and CanShow() is handled correctly under variety of conditions.
// Additionally, test that the first string in |strings| is used if // Additionally, test that the first string in |strings| is used if
// no payload.promo_short_message is specified in the JSON response. // no payload.promo_short_message is specified in the JSON response.
TEST_F(PromoResourceServiceTest, NotificationPromoTest) {
// hardcoded a date in Jan 2013. Srzly?? http://crbug.com/168561
TEST_F(PromoResourceServiceTest, DISABLED_NotificationPromoTest) {
// Check that prefs are set correctly. // Check that prefs are set correctly.
NotificationPromoTest promo_test; NotificationPromoTest promo_test;
// Set up start and end dates and promo line in a Dictionary as if parsed // Set up start date and promo line in a Dictionary as if parsed from the
// from the service. // service. date[0].end is replaced with a date 1 year in the future.
promo_test.Init("{" promo_test.Init("{"
" \"ntp_notification_promo\": [" " \"ntp_notification_promo\": ["
" {" " {"
...@@ -334,7 +372,7 @@ TEST_F(PromoResourceServiceTest, DISABLED_NotificationPromoTest) { ...@@ -334,7 +372,7 @@ TEST_F(PromoResourceServiceTest, DISABLED_NotificationPromoTest) {
" [" " ["
" {" " {"
" \"start\":\"3 Aug 1999 9:26:06 GMT\"," " \"start\":\"3 Aug 1999 9:26:06 GMT\","
" \"end\":\"7 Jan 2013 5:40:75 PST\"" " \"end\":\"$1\""
" }" " }"
" ]," " ],"
" \"strings\":" " \"strings\":"
...@@ -363,7 +401,6 @@ TEST_F(PromoResourceServiceTest, DISABLED_NotificationPromoTest) { ...@@ -363,7 +401,6 @@ TEST_F(PromoResourceServiceTest, DISABLED_NotificationPromoTest) {
// The starting date is in 1999 to make tests pass // The starting date is in 1999 to make tests pass
// on Android devices with incorrect or unset date/time. // on Android devices with incorrect or unset date/time.
933672366, // unix epoch for 3 Aug 1999 9:26:06 GMT. 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); 1000, 200, 100, 3600, 400, 30);
promo_test.InitPromoFromJson(true); promo_test.InitPromoFromJson(true);
...@@ -388,8 +425,8 @@ TEST_F(PromoResourceServiceTest, NotificationPromoCompatNoStringsTest) { ...@@ -388,8 +425,8 @@ TEST_F(PromoResourceServiceTest, NotificationPromoCompatNoStringsTest) {
// Check that prefs are set correctly. // Check that prefs are set correctly.
NotificationPromoTest promo_test; NotificationPromoTest promo_test;
// Set up start and end dates and promo line in a Dictionary as if parsed // Set up start date and promo line in a Dictionary as if parsed from the
// from the service. // service. date[0].end is replaced with a date 1 year in the future.
promo_test.Init("{" promo_test.Init("{"
" \"ntp_notification_promo\": [" " \"ntp_notification_promo\": ["
" {" " {"
...@@ -397,7 +434,7 @@ TEST_F(PromoResourceServiceTest, NotificationPromoCompatNoStringsTest) { ...@@ -397,7 +434,7 @@ TEST_F(PromoResourceServiceTest, NotificationPromoCompatNoStringsTest) {
" [" " ["
" {" " {"
" \"start\":\"3 Aug 1999 9:26:06 GMT\"," " \"start\":\"3 Aug 1999 9:26:06 GMT\","
" \"end\":\"7 Jan 2013 5:40:75 PST\"" " \"end\":\"$1\""
" }" " }"
" ]," " ],"
" \"grouping\":" " \"grouping\":"
...@@ -423,7 +460,6 @@ TEST_F(PromoResourceServiceTest, NotificationPromoCompatNoStringsTest) { ...@@ -423,7 +460,6 @@ TEST_F(PromoResourceServiceTest, NotificationPromoCompatNoStringsTest) {
// The starting date is in 1999 to make tests pass // The starting date is in 1999 to make tests pass
// on Android devices with incorrect or unset date/time. // on Android devices with incorrect or unset date/time.
933672366, // unix epoch for 3 Aug 1999 9:26:06 GMT. 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); 1000, 200, 100, 3600, 400, 30);
promo_test.InitPromoFromJson(true); promo_test.InitPromoFromJson(true);
...@@ -437,8 +473,8 @@ TEST_F(PromoResourceServiceTest, NotificationPromoCompatPayloadStringsTest) { ...@@ -437,8 +473,8 @@ TEST_F(PromoResourceServiceTest, NotificationPromoCompatPayloadStringsTest) {
// Check that prefs are set correctly. // Check that prefs are set correctly.
NotificationPromoTest promo_test; NotificationPromoTest promo_test;
// Set up start and end dates and promo line in a Dictionary as if parsed // Set up start date and promo line in a Dictionary as if parsed from the
// from the service. // service. date[0].end is replaced with a date 1 year in the future.
promo_test.Init("{" promo_test.Init("{"
" \"ntp_notification_promo\": [" " \"ntp_notification_promo\": ["
" {" " {"
...@@ -446,7 +482,7 @@ TEST_F(PromoResourceServiceTest, NotificationPromoCompatPayloadStringsTest) { ...@@ -446,7 +482,7 @@ TEST_F(PromoResourceServiceTest, NotificationPromoCompatPayloadStringsTest) {
" [" " ["
" {" " {"
" \"start\":\"3 Aug 1999 9:26:06 GMT\"," " \"start\":\"3 Aug 1999 9:26:06 GMT\","
" \"end\":\"7 Jan 2013 5:40:75 PST\"" " \"end\":\"$1\""
" }" " }"
" ]," " ],"
" \"grouping\":" " \"grouping\":"
...@@ -478,7 +514,6 @@ TEST_F(PromoResourceServiceTest, NotificationPromoCompatPayloadStringsTest) { ...@@ -478,7 +514,6 @@ TEST_F(PromoResourceServiceTest, NotificationPromoCompatPayloadStringsTest) {
// The starting date is in 1999 to make tests pass // The starting date is in 1999 to make tests pass
// on Android devices with incorrect or unset date/time. // on Android devices with incorrect or unset date/time.
933672366, // unix epoch for 3 Aug 1999 9:26:06 GMT. 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); 1000, 200, 100, 3600, 400, 30);
promo_test.InitPromoFromJson(true); promo_test.InitPromoFromJson(true);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment