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

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

Issue 7655008: promo_resource_service fixes/cleanup for promos. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: unit test for UnpackPromoSignal reentrancy Created 9 years, 4 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
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/json/json_reader.h" 5 #include "base/json/json_reader.h"
6 #include "base/time.h" 6 #include "base/time.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "chrome/browser/extensions/apps_promo.h" 9 #include "chrome/browser/extensions/apps_promo.h"
10 #include "chrome/browser/prefs/browser_prefs.h" 10 #include "chrome/browser/prefs/browser_prefs.h"
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 } 109 }
110 110
111 TEST_F(PromoResourceServiceTest, UnpackPromoSignal) { 111 TEST_F(PromoResourceServiceTest, UnpackPromoSignal) {
112 // Set up start and end dates and promo line in a Dictionary as if parsed 112 // Set up start and end dates and promo line in a Dictionary as if parsed
113 // from the service. 113 // from the service.
114 std::string json = "{ " 114 std::string json = "{ "
115 " \"topic\": {" 115 " \"topic\": {"
116 " \"answers\": [" 116 " \"answers\": ["
117 " {" 117 " {"
118 " \"name\": \"promo_start\"," 118 " \"name\": \"promo_start\","
119 " \"question\": \"3:2\"," 119 " \"question\": \"3:2:5\","
120 " \"tooltip\": \"Eat more pie!\"," 120 " \"tooltip\": \"Eat more pie!\","
121 " \"inproduct\": \"31/01/10 01:00 GMT\"" 121 " \"inproduct\": \"31/01/10 01:00 GMT\""
122 " }," 122 " },"
123 " {" 123 " {"
124 " \"name\": \"promo_end\"," 124 " \"name\": \"promo_end\","
125 " \"inproduct\": \"31/01/12 01:00 GMT\"" 125 " \"inproduct\": \"31/01/12 01:00 GMT\""
126 " }" 126 " }"
127 " ]" 127 " ]"
128 " }" 128 " }"
129 "}"; 129 "}";
130 scoped_ptr<DictionaryValue> test_json(static_cast<DictionaryValue*>( 130 scoped_ptr<DictionaryValue> test_json(static_cast<DictionaryValue*>(
131 base::JSONReader::Read(json, false))); 131 base::JSONReader::Read(json, false)));
132 132
133 // Initialize a message loop for this to run on. 133 // Initialize a message loop for this to run on.
134 MessageLoop loop; 134 MessageLoop loop;
135 135
136 // Check that prefs are set correctly. 136 // Check that prefs are set correctly.
137 web_resource_service_->UnpackPromoSignal(*(test_json.get())); 137 web_resource_service_->UnpackPromoSignal(*(test_json.get()));
138 PrefService* prefs = profile_.GetPrefs(); 138 PrefService* prefs = profile_.GetPrefs();
139 ASSERT_TRUE(prefs != NULL); 139 ASSERT_TRUE(prefs != NULL);
140 140
141 std::string promo_line = prefs->GetString(prefs::kNTPPromoLine); 141 std::string promo_line = prefs->GetString(prefs::kNTPPromoLine);
142 EXPECT_EQ(promo_line, "Eat more pie!"); 142 EXPECT_EQ(promo_line, "Eat more pie!");
143 143
144 int promo_group = prefs->GetInteger(prefs::kNTPPromoGroup); 144 int promo_group = prefs->GetInteger(prefs::kNTPPromoGroup);
145 EXPECT_GE(promo_group, 0); 145 EXPECT_GE(promo_group, 0);
146 EXPECT_LT(promo_group, 16); 146 EXPECT_LT(promo_group, 100);
147 147
148 int promo_build_type = prefs->GetInteger(prefs::kNTPPromoBuild); 148 int promo_build_type = prefs->GetInteger(prefs::kNTPPromoBuild);
149 EXPECT_EQ(promo_build_type & PromoResourceService::DEV_BUILD, 149 EXPECT_EQ(promo_build_type & PromoResourceService::DEV_BUILD,
150 PromoResourceService::DEV_BUILD); 150 PromoResourceService::DEV_BUILD);
151 EXPECT_EQ(promo_build_type & PromoResourceService::BETA_BUILD, 151 EXPECT_EQ(promo_build_type & PromoResourceService::BETA_BUILD,
152 PromoResourceService::BETA_BUILD); 152 PromoResourceService::BETA_BUILD);
153 EXPECT_EQ(promo_build_type & PromoResourceService::STABLE_BUILD, 0); 153 EXPECT_EQ(promo_build_type & PromoResourceService::STABLE_BUILD, 0);
154 154
155 int promo_time_slice = prefs->GetInteger(prefs::kNTPPromoGroupTimeSlice); 155 int promo_time_slice = prefs->GetInteger(prefs::kNTPPromoGroupTimeSlice);
156 EXPECT_EQ(promo_time_slice, 2); 156 EXPECT_EQ(promo_time_slice, 2);
157 157
158 double promo_start = 158 int promo_group_max = prefs->GetInteger(prefs::kNTPPromoGroupMax);
159 prefs->GetDouble(prefs::kNTPPromoStart); 159 EXPECT_EQ(promo_group_max, 5);
160 int64 actual_start = 1264899600 + // unix epoch for Jan 31 2010 0100 GMT. 160
161 promo_group * 2 * 60 * 60; 161 double promo_start = prefs->GetDouble(prefs::kNTPPromoStart);
162 double actual_start = 1264899600; // unix epoch for Jan 31 2010 0100 GMT.
162 EXPECT_EQ(promo_start, actual_start); 163 EXPECT_EQ(promo_start, actual_start);
163 164
164 double promo_end = 165 double modified_start = actual_start + promo_group * 2 * 60 * 60;
165 prefs->GetDouble(prefs::kNTPPromoEnd); 166 EXPECT_EQ(PromoResourceService::GetPromoStartTime(prefs), modified_start);
167
168 double promo_end = prefs->GetDouble(prefs::kNTPPromoEnd);
166 EXPECT_EQ(promo_end, 1327971600); // unix epoch for Jan 31 2012 0100 GMT. 169 EXPECT_EQ(promo_end, 1327971600); // unix epoch for Jan 31 2012 0100 GMT.
170
171 // Unpack the same json a second time.
172 web_resource_service_->UnpackPromoSignal(*(test_json.get()));
173
174 // All the data should be unchanged.
175 EXPECT_EQ(promo_line, prefs->GetString(prefs::kNTPPromoLine));
176 EXPECT_EQ(promo_group, prefs->GetInteger(prefs::kNTPPromoGroup));
177 EXPECT_EQ(promo_build_type, prefs->GetInteger(prefs::kNTPPromoBuild));
178 EXPECT_EQ(promo_time_slice,
179 prefs->GetInteger(prefs::kNTPPromoGroupTimeSlice));
180 EXPECT_EQ(promo_group_max, prefs->GetInteger(prefs::kNTPPromoGroupMax));
181 EXPECT_EQ(promo_start, prefs->GetDouble(prefs::kNTPPromoStart));
182 EXPECT_EQ(modified_start, PromoResourceService::GetPromoStartTime(prefs));
183 EXPECT_EQ(promo_end, prefs->GetDouble(prefs::kNTPPromoEnd));
167 } 184 }
168 185
169 TEST_F(PromoResourceServiceTest, UnpackWebStoreSignal) { 186 TEST_F(PromoResourceServiceTest, UnpackWebStoreSignal) {
170 web_resource_service_->set_channel(chrome::VersionInfo::CHANNEL_DEV); 187 web_resource_service_->set_channel(chrome::VersionInfo::CHANNEL_DEV);
171 188
172 std::string json = "{ " 189 std::string json = "{ "
173 " \"topic\": {" 190 " \"topic\": {"
174 " \"answers\": [" 191 " \"answers\": ["
175 " {" 192 " {"
176 " \"answer_id\": \"341252\"," 193 " \"answer_id\": \"341252\","
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 const chrome::VersionInfo::Channel stable = 281 const chrome::VersionInfo::Channel stable =
265 chrome::VersionInfo::CHANNEL_STABLE; 282 chrome::VersionInfo::CHANNEL_STABLE;
266 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 1)); 283 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 1));
267 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 3)); 284 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 3));
268 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 7)); 285 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 7));
269 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 15)); 286 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 15));
270 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 8)); 287 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 8));
271 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 11)); 288 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 11));
272 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 12)); 289 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 12));
273 } 290 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698