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

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

Issue 6825052: Update the web store promo to be clearer and configurable at run-time. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporate Aaron's feedback. Created 9 years, 8 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"
10 #include "chrome/browser/prefs/browser_prefs.h"
9 #include "chrome/browser/prefs/pref_service.h" 11 #include "chrome/browser/prefs/pref_service.h"
10 #include "chrome/browser/web_resource/promo_resource_service.h" 12 #include "chrome/browser/web_resource/promo_resource_service.h"
11 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
14 #include "chrome/test/testing_browser_process.h"
15 #include "chrome/test/testing_pref_service.h"
12 #include "chrome/test/testing_profile.h" 16 #include "chrome/test/testing_profile.h"
13 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
14 18
15 typedef testing::Test PromoResourceServiceTest; 19 typedef testing::Test PromoResourceServiceTest;
16 20
17 namespace {
18
19 // From promo_resource_service.cc
20 enum BuildType {
21 DEV_BUILD = 1,
22 BETA_BUILD = 1 << 1,
23 STABLE_BUILD = 1 << 2,
24 };
25
26 } // namespace
27
28 // Verifies that custom dates read from a web resource server are written to 21 // Verifies that custom dates read from a web resource server are written to
29 // the preferences file. 22 // the preferences file.
30 TEST_F(PromoResourceServiceTest, UnpackLogoSignal) { 23 TEST_F(PromoResourceServiceTest, UnpackLogoSignal) {
31 // Set up a testing profile and create a promo resource service. 24 // Set up a testing profile and create a promo resource service.
32 TestingProfile profile; 25 TestingProfile profile;
26 TestingPrefService local_state;
27 TestingBrowserProcess* testing_browser_process =
28 static_cast<TestingBrowserProcess*>(g_browser_process);
29 testing_browser_process->SetPrefService(&local_state);
30 browser::RegisterLocalState(&local_state);
31
33 scoped_refptr<PromoResourceService> web_resource_service( 32 scoped_refptr<PromoResourceService> web_resource_service(
34 new PromoResourceService(&profile)); 33 new PromoResourceService(&profile));
35 34
36 // Set up start and end dates in a Dictionary as if parsed from the service. 35 // Set up start and end dates in a Dictionary as if parsed from the service.
37 std::string json = "{ " 36 std::string json = "{ "
38 " \"topic\": {" 37 " \"topic\": {"
39 " \"answers\": [" 38 " \"answers\": ["
40 " {" 39 " {"
41 " \"name\": \"custom_logo_start\"," 40 " \"name\": \"custom_logo_start\","
42 " \"inproduct\": \"31/01/10 01:00 GMT\"" 41 " \"inproduct\": \"31/01/10 01:00 GMT\""
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 web_resource_service->UnpackLogoSignal(*(test_json.get())); 104 web_resource_service->UnpackLogoSignal(*(test_json.get()));
106 logo_start = prefs->GetDouble(prefs::kNTPCustomLogoStart); 105 logo_start = prefs->GetDouble(prefs::kNTPCustomLogoStart);
107 EXPECT_EQ(logo_start, 0); // date value reset to 0; 106 EXPECT_EQ(logo_start, 0); // date value reset to 0;
108 logo_end = prefs->GetDouble(prefs::kNTPCustomLogoEnd); 107 logo_end = prefs->GetDouble(prefs::kNTPCustomLogoEnd);
109 EXPECT_EQ(logo_end, 0); // date value reset to 0; 108 EXPECT_EQ(logo_end, 0); // date value reset to 0;
110 } 109 }
111 110
112 TEST_F(PromoResourceServiceTest, UnpackPromoSignal) { 111 TEST_F(PromoResourceServiceTest, UnpackPromoSignal) {
113 // Set up a testing profile and create a promo resource service. 112 // Set up a testing profile and create a promo resource service.
114 TestingProfile profile; 113 TestingProfile profile;
114 TestingPrefService local_state;
115 TestingBrowserProcess* testing_browser_process =
116 static_cast<TestingBrowserProcess*>(g_browser_process);
117 testing_browser_process->SetPrefService(&local_state);
118 browser::RegisterLocalState(&local_state);
119
115 scoped_refptr<PromoResourceService> web_resource_service( 120 scoped_refptr<PromoResourceService> web_resource_service(
116 new PromoResourceService(&profile)); 121 new PromoResourceService(&profile));
117 122
118 // Set up start and end dates and promo line in a Dictionary as if parsed 123 // Set up start and end dates and promo line in a Dictionary as if parsed
119 // from the service. 124 // from the service.
120 std::string json = "{ " 125 std::string json = "{ "
121 " \"topic\": {" 126 " \"topic\": {"
122 " \"answers\": [" 127 " \"answers\": ["
123 " {" 128 " {"
124 " \"name\": \"promo_start\"," 129 " \"name\": \"promo_start\","
(...skipping 20 matching lines...) Expand all
145 ASSERT_TRUE(prefs != NULL); 150 ASSERT_TRUE(prefs != NULL);
146 151
147 std::string promo_line = prefs->GetString(prefs::kNTPPromoLine); 152 std::string promo_line = prefs->GetString(prefs::kNTPPromoLine);
148 EXPECT_EQ(promo_line, "Eat more pie!"); 153 EXPECT_EQ(promo_line, "Eat more pie!");
149 154
150 int promo_group = prefs->GetInteger(prefs::kNTPPromoGroup); 155 int promo_group = prefs->GetInteger(prefs::kNTPPromoGroup);
151 EXPECT_GE(promo_group, 0); 156 EXPECT_GE(promo_group, 0);
152 EXPECT_LT(promo_group, 16); 157 EXPECT_LT(promo_group, 16);
153 158
154 int promo_build_type = prefs->GetInteger(prefs::kNTPPromoBuild); 159 int promo_build_type = prefs->GetInteger(prefs::kNTPPromoBuild);
155 EXPECT_EQ(promo_build_type & DEV_BUILD, DEV_BUILD); 160 EXPECT_EQ(promo_build_type & PromoResourceService::DEV_BUILD,
156 EXPECT_EQ(promo_build_type & BETA_BUILD, BETA_BUILD); 161 PromoResourceService::DEV_BUILD);
157 EXPECT_EQ(promo_build_type & STABLE_BUILD, 0); 162 EXPECT_EQ(promo_build_type & PromoResourceService::BETA_BUILD,
163 PromoResourceService::BETA_BUILD);
164 EXPECT_EQ(promo_build_type & PromoResourceService::STABLE_BUILD, 0);
158 165
159 int promo_time_slice = prefs->GetInteger(prefs::kNTPPromoGroupTimeSlice); 166 int promo_time_slice = prefs->GetInteger(prefs::kNTPPromoGroupTimeSlice);
160 EXPECT_EQ(promo_time_slice, 2); 167 EXPECT_EQ(promo_time_slice, 2);
161 168
162 double promo_start = 169 double promo_start =
163 prefs->GetDouble(prefs::kNTPPromoStart); 170 prefs->GetDouble(prefs::kNTPPromoStart);
164 int64 actual_start = 1264899600 + // unix epoch for Jan 31 2010 0100 GMT. 171 int64 actual_start = 1264899600 + // unix epoch for Jan 31 2010 0100 GMT.
165 promo_group * 2 * 60 * 60; 172 promo_group * 2 * 60 * 60;
166 EXPECT_EQ(promo_start, actual_start); 173 EXPECT_EQ(promo_start, actual_start);
167 174
168 double promo_end = 175 double promo_end =
169 prefs->GetDouble(prefs::kNTPPromoEnd); 176 prefs->GetDouble(prefs::kNTPPromoEnd);
170 EXPECT_EQ(promo_end, 1327971600); // unix epoch for Jan 31 2012 0100 GMT. 177 EXPECT_EQ(promo_end, 1327971600); // unix epoch for Jan 31 2012 0100 GMT.
171 } 178 }
172 179
180 TEST_F(PromoResourceServiceTest, UnpackWebStoreSignal) {
181 // Set up a testing profile and create a promo resource service.
182 TestingProfile profile;
183 TestingPrefService local_state;
184 TestingBrowserProcess* testing_browser_process =
185 static_cast<TestingBrowserProcess*>(g_browser_process);
186 testing_browser_process->SetPrefService(&local_state);
173 187
188 browser::RegisterLocalState(&local_state);
189
190 scoped_refptr<PromoResourceService> web_resource_service(
191 new PromoResourceService(&profile));
192
193 web_resource_service->set_channel("dev");
194
195 // Set up start and end dates and promo line in a Dictionary as if parsed
196 // from the service.
197 std::string json = "{ "
198 " \"topic\": {"
199 " \"answers\": ["
200 " {"
201 " \"answer_id\": \"341252\","
202 " \"name\": \"webstore_promo:15\","
203 " \"question\": \"The header!\","
204 " \"inproduct_target\": \"The button label!\","
205 " \"inproduct\": \"http://link.com\","
206 " \"tooltip\": \"No thanks, hide this.\""
207 " }"
208 " ]"
209 " }"
210 "}";
211 scoped_ptr<DictionaryValue> test_json(static_cast<DictionaryValue*>(
212 base::JSONReader::Read(json, false)));
213
214 // Initialize a message loop for this to run on.
215 MessageLoop loop;
216
217 // Check that prefs are set correctly.
218 web_resource_service->UnpackWebStoreSignal(*(test_json.get()));
219 PrefService* prefs = profile.GetPrefs();
220 ASSERT_TRUE(prefs != NULL);
221
222 EXPECT_EQ("341252", AppsPromo::GetPromoId());
223 EXPECT_EQ("The header!", AppsPromo::GetPromoHeaderText());
224 EXPECT_EQ("The button label!", AppsPromo::GetPromoButtonText());
225 EXPECT_EQ(GURL("http://link.com"), AppsPromo::GetPromoLink());
226 EXPECT_EQ("No thanks, hide this.", AppsPromo::GetPromoExpireText());
227 }
228
229 TEST_F(PromoResourceServiceTest, IsBuildTargeted) {
230 // canary
231 EXPECT_FALSE(PromoResourceService::IsBuildTargeted("canary", 1));
232 EXPECT_FALSE(PromoResourceService::IsBuildTargeted("canary", 3));
233 EXPECT_FALSE(PromoResourceService::IsBuildTargeted("canary", 7));
234 EXPECT_TRUE(PromoResourceService::IsBuildTargeted("canary", 15));
235 EXPECT_TRUE(PromoResourceService::IsBuildTargeted("canary", 8));
236 EXPECT_TRUE(PromoResourceService::IsBuildTargeted("canary", 11));
237
238 // dev
239 EXPECT_TRUE(PromoResourceService::IsBuildTargeted("dev", 1));
240 EXPECT_TRUE(PromoResourceService::IsBuildTargeted("dev", 3));
241 EXPECT_TRUE(PromoResourceService::IsBuildTargeted("dev", 7));
242 EXPECT_TRUE(PromoResourceService::IsBuildTargeted("dev", 15));
243 EXPECT_FALSE(PromoResourceService::IsBuildTargeted("dev", 8));
244 EXPECT_TRUE(PromoResourceService::IsBuildTargeted("dev", 11));
245
246 // beta
247 EXPECT_FALSE(PromoResourceService::IsBuildTargeted("beta", 1));
248 EXPECT_TRUE(PromoResourceService::IsBuildTargeted("beta", 3));
249 EXPECT_TRUE(PromoResourceService::IsBuildTargeted("beta", 7));
250 EXPECT_TRUE(PromoResourceService::IsBuildTargeted("beta", 15));
251 EXPECT_FALSE(PromoResourceService::IsBuildTargeted("beta", 8));
252 EXPECT_TRUE(PromoResourceService::IsBuildTargeted("beta", 11));
253
254 // stable
255 EXPECT_FALSE(PromoResourceService::IsBuildTargeted("", 1));
256 EXPECT_FALSE(PromoResourceService::IsBuildTargeted("", 3));
257 EXPECT_TRUE(PromoResourceService::IsBuildTargeted("", 7));
258 EXPECT_TRUE(PromoResourceService::IsBuildTargeted("", 15));
259 EXPECT_FALSE(PromoResourceService::IsBuildTargeted("", 8));
260 EXPECT_FALSE(PromoResourceService::IsBuildTargeted("", 11));
261 EXPECT_TRUE(PromoResourceService::IsBuildTargeted("", 12));
262 }
OLDNEW
« no previous file with comments | « chrome/browser/web_resource/promo_resource_service.cc ('k') | chrome/browser/web_resource/web_resource_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698