OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2015 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. | |
4 | |
5 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | |
6 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" | |
7 #include "chrome/browser/chromeos/policy/stub_enterprise_install_attributes.h" | |
8 #include "chrome/browser/extensions/api/enterprise_device_attributes/enterprise_ device_attributes_api.h" | |
9 #include "chrome/browser/extensions/extension_apitest.h" | |
10 #include "chromeos/dbus/fake_session_manager_client.h" | |
11 #include "chromeos/login/user_names.h" | |
12 #include "extensions/browser/api_test_utils.h" | |
13 #include "extensions/common/manifest_constants.h" | |
pneubeck (no reviews)
2015/08/05 12:19:20
this and the includes below may not be required an
Polina Bondarenko
2015/08/05 14:15:12
Done.
| |
14 #include "extensions/common/permissions/permissions_data.h" | |
15 #include "extensions/common/permissions/permissions_info.h" | |
16 | |
17 namespace { | |
18 const std::string kDeviceId = "device_id"; | |
19 } // namespace | |
20 | |
21 namespace extensions { | |
22 class EnterpriseDeviceAttributesTest : public ExtensionApiTest { | |
pneubeck (no reviews)
2015/08/05 12:19:20
nit: empty line before this one
Polina Bondarenko
2015/08/05 14:15:11
Done.
| |
23 public: | |
24 explicit EnterpriseDeviceAttributesTest(const std::string& domain) | |
25 : fake_session_manager_client_(new chromeos::FakeSessionManagerClient), | |
26 test_domain_(domain), | |
27 get_device_id_function_( | |
28 new EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction()) {} | |
29 | |
30 protected: | |
31 void SetUpInProcessBrowserTestFixture() override { | |
32 chromeos::DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( | |
33 scoped_ptr<chromeos::SessionManagerClient>( | |
pneubeck (no reviews)
2015/08/05 12:19:20
does make_scoped_ptr work here? (you would not hav
Polina Bondarenko
2015/08/05 14:15:12
Sure, done.
| |
34 fake_session_manager_client_)); | |
35 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | |
36 InitTest(); | |
37 } | |
38 | |
39 // Inits the device policy and install attributes, should be invoked before | |
pneubeck (no reviews)
2015/08/05 12:19:20
you could inline this function into SetUpInProcess
Polina Bondarenko
2015/08/05 14:15:12
Done.
| |
40 // browser init. | |
41 void InitTest() { | |
42 // Set up fake install attributes. | |
43 scoped_ptr<policy::StubEnterpriseInstallAttributes> attributes( | |
44 new policy::StubEnterpriseInstallAttributes()); | |
45 | |
46 attributes->SetDomain(test_domain_); | |
47 attributes->SetRegistrationUser(chromeos::login::kStubUser); | |
48 policy::BrowserPolicyConnectorChromeOS::SetInstallAttributesForTesting( | |
49 attributes.release()); | |
50 | |
51 test_helper_.InstallOwnerKey(); | |
52 // Init the device policy. | |
53 policy::DevicePolicyBuilder* device_policy = test_helper_.device_policy(); | |
54 device_policy->SetDefaultSigningKey(); | |
55 device_policy->policy_data().set_directory_api_id(kDeviceId); | |
56 device_policy->Build(); | |
57 | |
58 fake_session_manager_client_->set_device_policy(device_policy->GetBlob()); | |
59 fake_session_manager_client_->OnPropertyChangeComplete(true); | |
60 } | |
61 | |
62 void RunAffiliationTest(const std::string& expect_value) { | |
63 scoped_ptr<base::Value> result( | |
64 api_test_utils::RunFunctionAndReturnSingleResult( | |
65 get_device_id_function_.get(), "[]", browser()->profile())); | |
66 | |
67 std::string value; | |
68 EXPECT_TRUE(result->GetAsString(&value)); | |
69 | |
70 EXPECT_EQ(expect_value, value); | |
71 } | |
72 | |
73 private: | |
74 chromeos::FakeSessionManagerClient* fake_session_manager_client_; | |
pneubeck (no reviews)
2015/08/05 12:19:20
nit: const
Polina Bondarenko
2015/08/05 14:15:11
Some non-const methods are invoked from this insta
| |
75 policy::DevicePolicyCrosTestHelper test_helper_; | |
76 std::string test_domain_; | |
pneubeck (no reviews)
2015/08/05 12:19:20
nit: const
Polina Bondarenko
2015/08/05 14:15:12
Done.
| |
77 scoped_refptr<EnterpriseDeviceAttributesGetDirectoryDeviceIdFunction> | |
78 get_device_id_function_; | |
79 }; | |
80 | |
81 // Creates affiliated user before browser initializes. | |
82 class EnterpriseDeviceAttributesAffiliatedTest | |
83 : public EnterpriseDeviceAttributesTest { | |
84 public: | |
85 EnterpriseDeviceAttributesAffiliatedTest() | |
86 : EnterpriseDeviceAttributesTest("gmail.com") {} | |
87 }; | |
88 | |
89 // Creates non-affiliated user before browser init. | |
90 class EnterpriseDeviceAttributesNonAffiliatedTest | |
91 : public EnterpriseDeviceAttributesTest { | |
92 public: | |
93 EnterpriseDeviceAttributesNonAffiliatedTest() | |
94 : EnterpriseDeviceAttributesTest("example.com") {} | |
95 }; | |
96 | |
97 // Tests the case when the user is affiliated. | |
98 // Expected result: successful device id fetch. | |
99 IN_PROC_BROWSER_TEST_F(EnterpriseDeviceAttributesAffiliatedTest, Success) { | |
100 RunAffiliationTest(kDeviceId); | |
101 } | |
102 | |
103 // Tests the case when the user is not affiliated Expected result: fetch empty | |
104 // string as a device id.. | |
105 IN_PROC_BROWSER_TEST_F(EnterpriseDeviceAttributesNonAffiliatedTest, | |
106 EmptyString) { | |
107 RunAffiliationTest(""); | |
108 } | |
109 | |
110 } // namespace extensions | |
OLD | NEW |