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

Side by Side Diff: chrome/browser/web_resource/promo_resource_service_unittest.cc

Issue 11823007: Fix some pecularities in my C++ style for achuith@. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 7 years, 11 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 | Annotate | Revision Log
« 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 (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.h" 9 #include "base/message_loop.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 14 matching lines...) Expand all
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/url_request/test_url_fetcher_factory.h" 27 #include "net/url_request/test_url_fetcher_factory.h"
28 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
29 #include "unicode/smpdtfmt.h" 29 #include "unicode/smpdtfmt.h"
30 30
31 namespace { 31 namespace {
32 32
33 const char kDateFormat[] = "dd MMM yyyy HH:mm:ss zzz"; 33 const char kDateFormat[] = "dd MMM yyyy HH:mm:ss zzz";
34 34
35 std::pair<double, std::string> YearFromNow() { 35 bool YearFromNow(double* date_double, std::string* date_string) {
achuithb 2013/01/08 22:44:43 You still need a function comment. Can we rename d
Dan Beam 2013/01/08 22:53:06 Done.
36 *date_double = (base::Time::Now() + base::TimeDelta::FromDays(365)).ToTimeT();
37
36 UErrorCode status = U_ZERO_ERROR; 38 UErrorCode status = U_ZERO_ERROR;
37 icu::SimpleDateFormat simple_formatter(icu::UnicodeString(kDateFormat), 39 icu::SimpleDateFormat simple_formatter(icu::UnicodeString(kDateFormat),
38 icu::Locale("en_US"), 40 icu::Locale("en_US"),
39 status); 41 status);
40 DCHECK(U_SUCCESS(status)); 42 if (!U_SUCCESS(status))
41 43 return false;
42 const double year_from_now =
43 (base::Time::Now() + base::TimeDelta::FromDays(365)).ToTimeT();
44 44
45 icu::UnicodeString date_unicode_string; 45 icu::UnicodeString date_unicode_string;
46 simple_formatter.format(static_cast<UDate>(year_from_now * 1000), 46 simple_formatter.format(static_cast<UDate>(*date_double * 1000),
47 date_unicode_string, 47 date_unicode_string,
48 status); 48 status);
49 DCHECK(U_SUCCESS(status)); 49 if (!U_SUCCESS(status))
50 return false;
50 51
51 std::string date_string; 52 return UTF16ToUTF8(date_unicode_string.getBuffer(),
52 UTF16ToUTF8(date_unicode_string.getBuffer(), 53 static_cast<size_t>(date_unicode_string.length()),
53 static_cast<size_t>(date_unicode_string.length()), 54 date_string);
54 &date_string);
55
56 return std::make_pair(year_from_now, date_string);
57 } 55 }
58 56
59 } // namespace 57 } // namespace
60 58
61 class PromoResourceServiceTest : public testing::Test { 59 class PromoResourceServiceTest : public testing::Test {
62 public: 60 public:
63 // |promo_resource_service_| must be created after |local_state_|. 61 // |promo_resource_service_| must be created after |local_state_|.
64 PromoResourceServiceTest() 62 PromoResourceServiceTest()
65 : local_state_(TestingBrowserProcess::GetGlobal()), 63 : local_state_(TestingBrowserProcess::GetGlobal()),
66 promo_resource_service_(new PromoResourceService) {} 64 promo_resource_service_(new PromoResourceService) {}
(...skipping 16 matching lines...) Expand all
83 time_slice_(0), 81 time_slice_(0),
84 max_group_(0), 82 max_group_(0),
85 max_views_(0), 83 max_views_(0),
86 closed_(false) {} 84 closed_(false) {}
87 85
88 void Init(const std::string& json, 86 void Init(const std::string& json,
89 const std::string& promo_text, 87 const std::string& promo_text,
90 double start, 88 double start,
91 int num_groups, int initial_segment, int increment, 89 int num_groups, int initial_segment, int increment,
92 int time_slice, int max_group, int max_views) { 90 int time_slice, int max_group, int max_views) {
93 std::pair<double, std::string> year_from_now = YearFromNow(); 91 double year_from_now_double;
achuithb 2013/01/08 22:44:43 year_from_now_epoch or year_from_now_msec?
Dan Beam 2013/01/08 22:53:06 Done.
92 std::string year_from_now_string;
93 ASSERT_TRUE(YearFromNow(&year_from_now_double, &year_from_now_string));
94
94 std::vector<std::string> replacements; 95 std::vector<std::string> replacements;
95 replacements.push_back(year_from_now.second); 96 replacements.push_back(year_from_now_string);
96 97
97 std::string json_with_year( 98 std::string json_with_end_date(
98 ReplaceStringPlaceholders(json, replacements, NULL)); 99 ReplaceStringPlaceholders(json, replacements, NULL));
99 Value* value(base::JSONReader::Read(json_with_year)); 100 Value* value(base::JSONReader::Read(json_with_end_date));
100 ASSERT_TRUE(value); 101 ASSERT_TRUE(value);
101 102
102 DictionaryValue* dict = NULL; 103 DictionaryValue* dict = NULL;
103 value->GetAsDictionary(&dict); 104 value->GetAsDictionary(&dict);
104 ASSERT_TRUE(dict); 105 ASSERT_TRUE(dict);
105 test_json_.reset(dict); 106 test_json_.reset(dict);
106 107
107 promo_type_ = NotificationPromo::NTP_NOTIFICATION_PROMO; 108 promo_type_ = NotificationPromo::NTP_NOTIFICATION_PROMO;
108 promo_text_ = promo_text; 109 promo_text_ = promo_text;
109 110
110 start_ = start; 111 start_ = start;
111 end_ = year_from_now.first; 112 end_ = year_from_now_double;
112 113
113 num_groups_ = num_groups; 114 num_groups_ = num_groups;
114 initial_segment_ = initial_segment; 115 initial_segment_ = initial_segment;
115 increment_ = increment; 116 increment_ = increment;
116 time_slice_ = time_slice; 117 time_slice_ = time_slice;
117 max_group_ = max_group; 118 max_group_ = max_group;
118 119
119 max_views_ = max_views; 120 max_views_ = max_views;
120 121
121 closed_ = false; 122 closed_ = false;
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 promo_test.TestInitFromPrefs(); 523 promo_test.TestInitFromPrefs();
523 } 524 }
524 525
525 TEST_F(PromoResourceServiceTest, PromoServerURLTest) { 526 TEST_F(PromoResourceServiceTest, PromoServerURLTest) {
526 GURL promo_server_url = NotificationPromo::PromoServerURL(); 527 GURL promo_server_url = NotificationPromo::PromoServerURL();
527 EXPECT_FALSE(promo_server_url.is_empty()); 528 EXPECT_FALSE(promo_server_url.is_empty());
528 EXPECT_TRUE(promo_server_url.is_valid()); 529 EXPECT_TRUE(promo_server_url.is_valid());
529 EXPECT_TRUE(promo_server_url.SchemeIs(chrome::kHttpsScheme)); 530 EXPECT_TRUE(promo_server_url.SchemeIs(chrome::kHttpsScheme));
530 // TODO(achuith): Test this better. 531 // TODO(achuith): Test this better.
531 } 532 }
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