| 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 "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" |
| 11 #include "base/sha1.h" | 11 #include "base/sha1.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "chrome/browser/web_resource/resource_request_allowed_notifier_test_uti
l.h" | 14 #include "chrome/browser/web_resource/resource_request_allowed_notifier_test_uti
l.h" |
| 15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
| 16 #include "chrome/test/base/testing_browser_process.h" | 16 #include "chrome/test/base/testing_browser_process.h" |
| 17 #include "chrome/test/base/testing_pref_service_syncable.h" |
| 17 #include "components/variations/proto/study.pb.h" | 18 #include "components/variations/proto/study.pb.h" |
| 18 #include "components/variations/proto/variations_seed.pb.h" | 19 #include "components/variations/proto/variations_seed.pb.h" |
| 19 #include "content/public/test/test_browser_thread.h" | 20 #include "content/public/test/test_browser_thread.h" |
| 20 #include "net/base/url_util.h" | 21 #include "net/base/url_util.h" |
| 21 #include "net/http/http_response_headers.h" | 22 #include "net/http/http_response_headers.h" |
| 22 #include "net/http/http_status_code.h" | 23 #include "net/http/http_status_code.h" |
| 23 #include "net/url_request/test_url_fetcher_factory.h" | 24 #include "net/url_request/test_url_fetcher_factory.h" |
| 24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
| 25 | 26 |
| 26 #if defined(OS_CHROMEOS) | 27 #if defined(OS_CHROMEOS) |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 // Not used directly. Initializes CrosSettings for testing. | 117 // Not used directly. Initializes CrosSettings for testing. |
| 117 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 118 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
| 118 chromeos::ScopedTestCrosSettings test_cros_settings_; | 119 chromeos::ScopedTestCrosSettings test_cros_settings_; |
| 119 #endif | 120 #endif |
| 120 | 121 |
| 121 DISALLOW_COPY_AND_ASSIGN(VariationsServiceTest); | 122 DISALLOW_COPY_AND_ASSIGN(VariationsServiceTest); |
| 122 }; | 123 }; |
| 123 | 124 |
| 124 #if !defined(OS_CHROMEOS) | 125 #if !defined(OS_CHROMEOS) |
| 125 TEST_F(VariationsServiceTest, VariationsURLIsValid) { | 126 TEST_F(VariationsServiceTest, VariationsURLIsValid) { |
| 127 #if defined(OS_ANDROID) |
| 128 // Android uses profile prefs as the PrefService to generate the URL. |
| 129 TestingPrefServiceSyncable prefs; |
| 130 VariationsService::RegisterProfilePrefs(prefs.registry()); |
| 131 #else |
| 126 TestingPrefServiceSimple prefs; | 132 TestingPrefServiceSimple prefs; |
| 127 VariationsService::RegisterPrefs(prefs.registry()); | 133 VariationsService::RegisterPrefs(prefs.registry()); |
| 134 #endif |
| 128 const std::string default_variations_url = | 135 const std::string default_variations_url = |
| 129 VariationsService::GetDefaultVariationsServerURLForTesting(); | 136 VariationsService::GetDefaultVariationsServerURLForTesting(); |
| 130 | 137 |
| 131 std::string value; | 138 std::string value; |
| 132 GURL url = VariationsService::GetVariationsServerURL(&prefs); | 139 GURL url = VariationsService::GetVariationsServerURL(&prefs); |
| 133 EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true)); | 140 EXPECT_TRUE(StartsWithASCII(url.spec(), default_variations_url, true)); |
| 134 EXPECT_FALSE(net::GetValueForKeyInQuery(url, "restrict", &value)); | 141 EXPECT_FALSE(net::GetValueForKeyInQuery(url, "restrict", &value)); |
| 135 | 142 |
| 136 prefs.SetString(prefs::kVariationsRestrictParameter, "restricted"); | 143 prefs.SetString(prefs::kVariationsRestrictParameter, "restricted"); |
| 137 url = VariationsService::GetVariationsServerURL(&prefs); | 144 url = VariationsService::GetVariationsServerURL(&prefs); |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 prefs.FindPreference(prefs::kVariationsSeedDate)->IsDefaultValue()); | 317 prefs.FindPreference(prefs::kVariationsSeedDate)->IsDefaultValue()); |
| 311 | 318 |
| 312 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 319 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
| 313 SimulateServerResponse(net::HTTP_NOT_MODIFIED, fetcher); | 320 SimulateServerResponse(net::HTTP_NOT_MODIFIED, fetcher); |
| 314 variations_service.OnURLFetchComplete(fetcher); | 321 variations_service.OnURLFetchComplete(fetcher); |
| 315 EXPECT_FALSE( | 322 EXPECT_FALSE( |
| 316 prefs.FindPreference(prefs::kVariationsSeedDate)->IsDefaultValue()); | 323 prefs.FindPreference(prefs::kVariationsSeedDate)->IsDefaultValue()); |
| 317 } | 324 } |
| 318 | 325 |
| 319 } // namespace chrome_variations | 326 } // namespace chrome_variations |
| OLD | NEW |