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

Side by Side Diff: chrome/browser/metrics/variations/variations_service_unittest.cc

Issue 739173002: Remove dependencies of ResourceRequestAllowedNotifier on chrome/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and cleanup Created 6 years, 1 month 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
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 "chrome/browser/metrics/variations/variations_service.h" 5 #include "chrome/browser/metrics/variations/variations_service.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/prefs/testing_pref_service.h" 10 #include "base/prefs/testing_pref_service.h"
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 259
260 TEST_F(VariationsServiceTest, RequestsInitiallyNotAllowed) { 260 TEST_F(VariationsServiceTest, RequestsInitiallyNotAllowed) {
261 base::MessageLoopForUI message_loop; 261 base::MessageLoopForUI message_loop;
262 content::TestBrowserThread ui_thread(content::BrowserThread::UI, 262 content::TestBrowserThread ui_thread(content::BrowserThread::UI,
263 &message_loop); 263 &message_loop);
264 TestingPrefServiceSimple prefs; 264 TestingPrefServiceSimple prefs;
265 VariationsService::RegisterPrefs(prefs.registry()); 265 VariationsService::RegisterPrefs(prefs.registry());
266 266
267 // Pass ownership to TestVariationsService, but keep a weak pointer to 267 // Pass ownership to TestVariationsService, but keep a weak pointer to
268 // manipulate it for this test. 268 // manipulate it for this test.
269 TestRequestAllowedNotifier* test_notifier = new TestRequestAllowedNotifier; 269 TestRequestAllowedNotifier* test_notifier =
270 new TestRequestAllowedNotifier(&prefs);
270 TestVariationsService test_service(test_notifier, &prefs); 271 TestVariationsService test_service(test_notifier, &prefs);
271 272
272 // Force the notifier to initially disallow requests. 273 // Force the notifier to initially disallow requests.
273 test_notifier->SetRequestsAllowedOverride(false); 274 test_notifier->SetRequestsAllowedOverride(false);
274 test_service.StartRepeatedVariationsSeedFetch(); 275 test_service.StartRepeatedVariationsSeedFetch();
275 EXPECT_FALSE(test_service.fetch_attempted()); 276 EXPECT_FALSE(test_service.fetch_attempted());
276 277
277 test_notifier->NotifyObserver(); 278 test_notifier->NotifyObserver();
278 EXPECT_TRUE(test_service.fetch_attempted()); 279 EXPECT_TRUE(test_service.fetch_attempted());
279 } 280 }
280 281
281 TEST_F(VariationsServiceTest, RequestsInitiallyAllowed) { 282 TEST_F(VariationsServiceTest, RequestsInitiallyAllowed) {
282 base::MessageLoopForUI message_loop; 283 base::MessageLoopForUI message_loop;
283 content::TestBrowserThread ui_thread(content::BrowserThread::UI, 284 content::TestBrowserThread ui_thread(content::BrowserThread::UI,
284 &message_loop); 285 &message_loop);
285 TestingPrefServiceSimple prefs; 286 TestingPrefServiceSimple prefs;
286 VariationsService::RegisterPrefs(prefs.registry()); 287 VariationsService::RegisterPrefs(prefs.registry());
287 288
288 // Pass ownership to TestVariationsService, but keep a weak pointer to 289 // Pass ownership to TestVariationsService, but keep a weak pointer to
289 // manipulate it for this test. 290 // manipulate it for this test.
290 TestRequestAllowedNotifier* test_notifier = new TestRequestAllowedNotifier; 291 TestRequestAllowedNotifier* test_notifier =
292 new TestRequestAllowedNotifier(&prefs);
291 TestVariationsService test_service(test_notifier, &prefs); 293 TestVariationsService test_service(test_notifier, &prefs);
292 294
293 test_notifier->SetRequestsAllowedOverride(true); 295 test_notifier->SetRequestsAllowedOverride(true);
294 test_service.StartRepeatedVariationsSeedFetch(); 296 test_service.StartRepeatedVariationsSeedFetch();
295 EXPECT_TRUE(test_service.fetch_attempted()); 297 EXPECT_TRUE(test_service.fetch_attempted());
296 } 298 }
297 299
298 TEST_F(VariationsServiceTest, SeedStoredWhenOKStatus) { 300 TEST_F(VariationsServiceTest, SeedStoredWhenOKStatus) {
299 base::MessageLoop message_loop; 301 base::MessageLoop message_loop;
300 content::TestBrowserThread io_thread(content::BrowserThread::IO, 302 content::TestBrowserThread io_thread(content::BrowserThread::IO,
301 &message_loop); 303 &message_loop);
302 TestingPrefServiceSimple prefs; 304 TestingPrefServiceSimple prefs;
303 VariationsService::RegisterPrefs(prefs.registry()); 305 VariationsService::RegisterPrefs(prefs.registry());
304 306
305 TestVariationsService service(new TestRequestAllowedNotifier, &prefs); 307 TestVariationsService service(new TestRequestAllowedNotifier(&prefs), &prefs);
306 const GURL url = VariationsService::GetVariationsServerURL(&prefs); 308 const GURL url = VariationsService::GetVariationsServerURL(&prefs);
307 service.variations_server_url_ = url; 309 service.variations_server_url_ = url;
308 service.set_intercepts_fetch(false); 310 service.set_intercepts_fetch(false);
309 311
310 net::TestURLFetcherFactory factory; 312 net::TestURLFetcherFactory factory;
311 service.DoActualFetch(); 313 service.DoActualFetch();
312 314
313 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); 315 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
314 SimulateServerResponse(net::HTTP_OK, fetcher); 316 SimulateServerResponse(net::HTTP_OK, fetcher);
315 fetcher->SetResponseString(SerializeSeed(CreateTestSeed())); 317 fetcher->SetResponseString(SerializeSeed(CreateTestSeed()));
(...skipping 11 matching lines...) Expand all
327 net::HTTP_INTERNAL_SERVER_ERROR, 329 net::HTTP_INTERNAL_SERVER_ERROR,
328 net::HTTP_SERVICE_UNAVAILABLE, 330 net::HTTP_SERVICE_UNAVAILABLE,
329 }; 331 };
330 332
331 base::MessageLoop message_loop; 333 base::MessageLoop message_loop;
332 content::TestBrowserThread io_thread(content::BrowserThread::IO, 334 content::TestBrowserThread io_thread(content::BrowserThread::IO,
333 &message_loop); 335 &message_loop);
334 TestingPrefServiceSimple prefs; 336 TestingPrefServiceSimple prefs;
335 VariationsService::RegisterPrefs(prefs.registry()); 337 VariationsService::RegisterPrefs(prefs.registry());
336 338
337 VariationsService service(new TestRequestAllowedNotifier, &prefs, NULL); 339 VariationsService service(new TestRequestAllowedNotifier(&prefs), &prefs,
340 NULL);
338 const GURL url = VariationsService::GetVariationsServerURL(&prefs); 341 const GURL url = VariationsService::GetVariationsServerURL(&prefs);
339 service.variations_server_url_ = url; 342 service.variations_server_url_ = url;
340 for (size_t i = 0; i < arraysize(non_ok_status_codes); ++i) { 343 for (size_t i = 0; i < arraysize(non_ok_status_codes); ++i) {
341 net::TestURLFetcherFactory factory; 344 net::TestURLFetcherFactory factory;
342 service.DoActualFetch(); 345 service.DoActualFetch();
343 EXPECT_TRUE(prefs.FindPreference(prefs::kVariationsSeed)->IsDefaultValue()); 346 EXPECT_TRUE(prefs.FindPreference(prefs::kVariationsSeed)->IsDefaultValue());
344 347
345 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); 348 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
346 SimulateServerResponse(non_ok_status_codes[i], fetcher); 349 SimulateServerResponse(non_ok_status_codes[i], fetcher);
347 service.OnURLFetchComplete(fetcher); 350 service.OnURLFetchComplete(fetcher);
348 351
349 EXPECT_TRUE(prefs.FindPreference(prefs::kVariationsSeed)->IsDefaultValue()); 352 EXPECT_TRUE(prefs.FindPreference(prefs::kVariationsSeed)->IsDefaultValue());
350 } 353 }
351 } 354 }
352 355
353 TEST_F(VariationsServiceTest, SeedDateUpdatedOn304Status) { 356 TEST_F(VariationsServiceTest, SeedDateUpdatedOn304Status) {
354 base::MessageLoop message_loop; 357 base::MessageLoop message_loop;
355 content::TestBrowserThread io_thread(content::BrowserThread::IO, 358 content::TestBrowserThread io_thread(content::BrowserThread::IO,
356 &message_loop); 359 &message_loop);
357 TestingPrefServiceSimple prefs; 360 TestingPrefServiceSimple prefs;
358 VariationsService::RegisterPrefs(prefs.registry()); 361 VariationsService::RegisterPrefs(prefs.registry());
359 362
360 net::TestURLFetcherFactory factory; 363 net::TestURLFetcherFactory factory;
361 VariationsService service(new TestRequestAllowedNotifier, &prefs, NULL); 364 VariationsService service(new TestRequestAllowedNotifier(&prefs), &prefs,
365 NULL);
362 const GURL url = VariationsService::GetVariationsServerURL(&prefs); 366 const GURL url = VariationsService::GetVariationsServerURL(&prefs);
363 service.variations_server_url_ = url; 367 service.variations_server_url_ = url;
364 service.DoActualFetch(); 368 service.DoActualFetch();
365 EXPECT_TRUE( 369 EXPECT_TRUE(
366 prefs.FindPreference(prefs::kVariationsSeedDate)->IsDefaultValue()); 370 prefs.FindPreference(prefs::kVariationsSeedDate)->IsDefaultValue());
367 371
368 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); 372 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
369 SimulateServerResponse(net::HTTP_NOT_MODIFIED, fetcher); 373 SimulateServerResponse(net::HTTP_NOT_MODIFIED, fetcher);
370 service.OnURLFetchComplete(fetcher); 374 service.OnURLFetchComplete(fetcher);
371 EXPECT_FALSE( 375 EXPECT_FALSE(
372 prefs.FindPreference(prefs::kVariationsSeedDate)->IsDefaultValue()); 376 prefs.FindPreference(prefs::kVariationsSeedDate)->IsDefaultValue());
373 } 377 }
374 378
375 TEST_F(VariationsServiceTest, Observer) { 379 TEST_F(VariationsServiceTest, Observer) {
376 TestingPrefServiceSimple prefs; 380 TestingPrefServiceSimple prefs;
377 VariationsService::RegisterPrefs(prefs.registry()); 381 VariationsService::RegisterPrefs(prefs.registry());
378 VariationsService service(new TestRequestAllowedNotifier, &prefs, NULL); 382 VariationsService service(new TestRequestAllowedNotifier(&prefs), &prefs,
383 NULL);
379 384
380 struct { 385 struct {
381 int normal_count; 386 int normal_count;
382 int best_effort_count; 387 int best_effort_count;
383 int critical_count; 388 int critical_count;
384 int expected_best_effort_notifications; 389 int expected_best_effort_notifications;
385 int expected_crtical_notifications; 390 int expected_crtical_notifications;
386 } cases[] = { 391 } cases[] = {
387 {0, 0, 0, 0, 0}, 392 {0, 0, 0, 0, 0},
388 {1, 0, 0, 0, 0}, 393 {1, 0, 0, 0, 0},
(...skipping 21 matching lines...) Expand all
410 EXPECT_EQ(cases[i].expected_best_effort_notifications, 415 EXPECT_EQ(cases[i].expected_best_effort_notifications,
411 observer.best_effort_changes_notified()) << i; 416 observer.best_effort_changes_notified()) << i;
412 EXPECT_EQ(cases[i].expected_crtical_notifications, 417 EXPECT_EQ(cases[i].expected_crtical_notifications,
413 observer.crticial_changes_notified()) << i; 418 observer.crticial_changes_notified()) << i;
414 419
415 service.RemoveObserver(&observer); 420 service.RemoveObserver(&observer);
416 } 421 }
417 } 422 }
418 423
419 } // namespace chrome_variations 424 } // namespace chrome_variations
OLDNEW
« no previous file with comments | « chrome/browser/metrics/variations/variations_service.cc ('k') | chrome/browser/translate/translate_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698