Elim cr-checkbox
[chromium-blink-merge.git] / chrome / browser / chromeos / policy / variations_service_policy_browsertest.cc
blob9969b9b48392a625c5f3659ef15a471bcd6033f6
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/memory/scoped_ptr.h"
6 #include "base/strings/string_util.h"
7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/chromeos/policy/device_policy_builder.h"
9 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
10 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
11 #include "chrome/browser/metrics/variations/chrome_variations_service_client.h"
12 #include "chrome/test/base/testing_browser_process.h"
13 #include "components/variations/service/variations_service.h"
14 #include "net/base/url_util.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 namespace policy {
19 class VariationsServiceDevicePolicyTest : public DevicePolicyCrosBrowserTest {
20 protected:
21 VariationsServiceDevicePolicyTest() {}
23 void SetUpInProcessBrowserTestFixture() override {
24 DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture();
26 InstallOwnerKey();
27 SetSpecificDevicePolicies();
28 RefreshDevicePolicy();
31 void SetSpecificDevicePolicies() {
32 // Setup the device policy DeviceVariationsRestrictParameter.
33 enterprise_management::ChromeDeviceSettingsProto& proto(
34 device_policy()->payload());
35 proto.mutable_variations_parameter()->set_parameter("restricted");
38 private:
39 DISALLOW_COPY_AND_ASSIGN(VariationsServiceDevicePolicyTest);
42 IN_PROC_BROWSER_TEST_F(VariationsServiceDevicePolicyTest, VariationsURLValid) {
43 const std::string default_variations_url =
44 variations::VariationsService::GetDefaultVariationsServerURLForTesting();
46 // g_browser_process->variations_service() is null by default in Chromium
47 // builds, so construct a VariationsService locally instead.
48 scoped_ptr<variations::VariationsService> service =
49 variations::VariationsService::CreateForTesting(
50 make_scoped_ptr(new ChromeVariationsServiceClient()),
51 g_browser_process->local_state());
53 // Device policy has updated the cros settings.
54 const GURL url = service->GetVariationsServerURL(
55 g_browser_process->local_state(), std::string());
56 EXPECT_TRUE(base::StartsWith(url.spec(), default_variations_url,
57 base::CompareCase::SENSITIVE));
58 std::string value;
59 EXPECT_TRUE(net::GetValueForKeyInQuery(url, "restrict", &value));
60 EXPECT_EQ("restricted", value);
63 } // namespace policy