OLD | NEW |
---|---|
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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/prefs/testing_pref_service.h" | 8 #include "base/prefs/testing_pref_service.h" |
9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
10 #include "chrome/browser/metrics/proto/study.pb.h" | 10 #include "chrome/browser/metrics/proto/study.pb.h" |
11 #include "chrome/browser/metrics/variations/resource_request_allowed_notifier_te st_util.h" | 11 #include "chrome/browser/metrics/variations/resource_request_allowed_notifier_te st_util.h" |
12 #include "chrome/browser/metrics/variations/variations_service.h" | 12 #include "chrome/browser/metrics/variations/variations_service.h" |
13 #include "chrome/common/chrome_version_info.h" | 13 #include "chrome/common/chrome_version_info.h" |
14 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
15 #include "chrome/test/base/testing_browser_process.h" | 15 #include "chrome/test/base/testing_browser_process.h" |
16 #include "content/public/test/test_browser_thread.h" | 16 #include "content/public/test/test_browser_thread.h" |
17 #include "net/http/http_response_headers.h" | 17 #include "net/http/http_response_headers.h" |
18 #include "net/http/http_status_code.h" | 18 #include "net/http/http_status_code.h" |
19 #include "net/url_request/test_url_fetcher_factory.h" | 19 #include "net/url_request/test_url_fetcher_factory.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
21 | 21 |
22 #if defined(OS_CHROMEOS) | |
23 #include "chrome/browser/chromeos/settings/cros_settings.h" | |
24 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" | |
25 #endif | |
26 | |
22 namespace chrome_variations { | 27 namespace chrome_variations { |
23 | 28 |
24 namespace { | 29 namespace { |
25 | 30 |
26 // A test class used to validate expected functionality in VariationsService. | 31 // A test class used to validate expected functionality in VariationsService. |
27 class TestVariationsService : public VariationsService { | 32 class TestVariationsService : public VariationsService { |
28 public: | 33 public: |
29 TestVariationsService(TestRequestAllowedNotifier* test_notifier, | 34 TestVariationsService(TestRequestAllowedNotifier* test_notifier, |
30 PrefService* local_state) | 35 PrefService* local_state) |
31 : VariationsService(test_notifier, local_state), | 36 : VariationsService(test_notifier, local_state), |
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
371 | 376 |
372 TEST(VariationsServiceTest, VariationsURLIsValid) { | 377 TEST(VariationsServiceTest, VariationsURLIsValid) { |
373 TestingPrefServiceSimple prefs; | 378 TestingPrefServiceSimple prefs; |
374 VariationsService::RegisterPrefs(prefs.registry()); | 379 VariationsService::RegisterPrefs(prefs.registry()); |
375 const std::string default_variations_url = | 380 const std::string default_variations_url = |
376 VariationsService::GetDefaultVariationsServerURLForTesting(); | 381 VariationsService::GetDefaultVariationsServerURLForTesting(); |
377 | 382 |
378 EXPECT_EQ(default_variations_url, | 383 EXPECT_EQ(default_variations_url, |
379 VariationsService::GetVariationsServerURL(&prefs).spec()); | 384 VariationsService::GetVariationsServerURL(&prefs).spec()); |
380 | 385 |
386 #if defined(OS_CHROMEOS) | |
387 chromeos::StubCrosSettingsProvider stub_settings_provider; | |
Alexei Svitkine (slow)
2013/04/17 21:24:36
I think it would be cleaner to do this in a separa
Mathieu
2013/04/18 19:17:19
Done.
| |
388 chromeos::CrosSettings* cros_settings = chromeos::CrosSettings::Get(); | |
Mattias Nissler (ping if slow)
2013/04/18 10:39:39
Sigh, CrosSettings mocking still sucks. Sorry abou
Mathieu
2013/04/18 19:17:19
Hey at least it works ;)
| |
389 // Remove the real DeviceSettingsProvider and replace it with a stub that | |
390 // allows modifications in a test. | |
391 chromeos::CrosSettingsProvider* device_settings_provider = | |
392 cros_settings->GetProvider(chromeos::kReportDeviceVersionInfo); | |
Alexei Svitkine (slow)
2013/04/17 21:24:36
Indent 2 more.
Mathieu
2013/04/18 19:17:19
Done.
| |
393 EXPECT_TRUE(device_settings_provider != NULL); | |
394 EXPECT_TRUE(cros_settings->RemoveSettingsProvider(device_settings_provider)); | |
395 cros_settings->AddSettingsProvider(&stub_settings_provider); | |
396 | |
397 cros_settings->SetString(chromeos::kVariationsRestrictParameter, | |
398 "restricted"); | |
399 #else | |
381 prefs.SetString(prefs::kVariationsRestrictParameter, "restricted"); | 400 prefs.SetString(prefs::kVariationsRestrictParameter, "restricted"); |
401 #endif | |
402 | |
382 EXPECT_EQ(default_variations_url + "?restrict=restricted", | 403 EXPECT_EQ(default_variations_url + "?restrict=restricted", |
383 VariationsService::GetVariationsServerURL(&prefs).spec()); | 404 VariationsService::GetVariationsServerURL(&prefs).spec()); |
405 | |
406 #if defined(OS_CHROMEOS) | |
407 // Restore the real DeviceSettingsProvider. | |
408 EXPECT_TRUE( | |
409 cros_settings->RemoveSettingsProvider(&stub_settings_provider)); | |
Alexei Svitkine (slow)
2013/04/17 21:24:36
Indent 2 more.
Mathieu
2013/04/18 19:17:19
Done.
| |
410 cros_settings->AddSettingsProvider(device_settings_provider); | |
411 #endif | |
384 } | 412 } |
385 | 413 |
386 TEST(VariationsServiceTest, LoadSeed) { | 414 TEST(VariationsServiceTest, LoadSeed) { |
387 // Store good seed data to test if loading from prefs works. | 415 // Store good seed data to test if loading from prefs works. |
388 const TrialsSeed seed = CreateTestSeed(); | 416 const TrialsSeed seed = CreateTestSeed(); |
389 const std::string base64_seed = SerializeSeedBase64(seed); | 417 const std::string base64_seed = SerializeSeedBase64(seed); |
390 | 418 |
391 TestingPrefServiceSimple prefs; | 419 TestingPrefServiceSimple prefs; |
392 VariationsService::RegisterPrefs(prefs.registry()); | 420 VariationsService::RegisterPrefs(prefs.registry()); |
393 prefs.SetString(prefs::kVariationsSeed, base64_seed); | 421 prefs.SetString(prefs::kVariationsSeed, base64_seed); |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
601 | 629 |
602 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 630 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
603 SimulateServerResponse(non_ok_status_codes[i], fetcher); | 631 SimulateServerResponse(non_ok_status_codes[i], fetcher); |
604 variations_service.OnURLFetchComplete(fetcher); | 632 variations_service.OnURLFetchComplete(fetcher); |
605 | 633 |
606 EXPECT_TRUE(prefs.FindPreference(prefs::kVariationsSeed)->IsDefaultValue()); | 634 EXPECT_TRUE(prefs.FindPreference(prefs::kVariationsSeed)->IsDefaultValue()); |
607 } | 635 } |
608 } | 636 } |
609 | 637 |
610 } // namespace chrome_variations | 638 } // namespace chrome_variations |
OLD | NEW |