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

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: Fix unit tests 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 int max_group = prefs->GetInteger(prefs::kNTPPromoGroupMax);
159 EXPECT_EQ(max_group, 5);
160
158 double promo_start = 161 double promo_start =
159 prefs->GetDouble(prefs::kNTPPromoStart); 162 prefs->GetDouble(prefs::kNTPPromoStart);
160 int64 actual_start = 1264899600 + // unix epoch for Jan 31 2010 0100 GMT. 163 int64 actual_start = 1264899600 + // unix epoch for Jan 31 2010 0100 GMT.
161 promo_group * 2 * 60 * 60; 164 promo_group * 2 * 60 * 60;
162 EXPECT_EQ(promo_start, actual_start); 165 EXPECT_EQ(promo_start, actual_start);
163 166
164 double promo_end = 167 double promo_end =
165 prefs->GetDouble(prefs::kNTPPromoEnd); 168 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.
167 } 170 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 const chrome::VersionInfo::Channel stable = 267 const chrome::VersionInfo::Channel stable =
265 chrome::VersionInfo::CHANNEL_STABLE; 268 chrome::VersionInfo::CHANNEL_STABLE;
266 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 1)); 269 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 1));
267 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 3)); 270 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 3));
268 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 7)); 271 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 7));
269 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 15)); 272 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 15));
270 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 8)); 273 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 8));
271 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 11)); 274 EXPECT_FALSE(PromoResourceService::IsBuildTargeted(stable, 11));
272 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 12)); 275 EXPECT_TRUE(PromoResourceService::IsBuildTargeted(stable, 12));
273 } 276 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698