OLD | NEW |
(Empty) | |
| 1 // Copyright 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 "base/memory/scoped_ptr.h" |
| 6 #include "chrome/browser/chromeos/policy/affiliation_test_helper.h" |
| 7 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" |
| 8 #include "chromeos/dbus/dbus_thread_manager.h" |
| 9 #include "chromeos/dbus/fake_session_manager_client.h" |
| 10 #include "chromeos/dbus/session_manager_client.h" |
| 11 #include "components/user_manager/user.h" |
| 12 #include "components/user_manager/user_manager.h" |
| 13 #include "content/public/test/test_utils.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 |
| 16 namespace policy { |
| 17 |
| 18 namespace { |
| 19 |
| 20 const char kAffiliatedUser[] = "affiliated-user@example.com"; |
| 21 const char kAffiliationID[] = "some-affiliation-id"; |
| 22 const char kAnotherAffiliationID[] = "another-affiliation-id"; |
| 23 struct Params { |
| 24 explicit Params(bool affiliated) : affiliated_(affiliated) {} |
| 25 bool affiliated_; |
| 26 }; |
| 27 |
| 28 } // namespace |
| 29 |
| 30 class UserAffiliationBrowserTest |
| 31 : public InProcessBrowserTest, |
| 32 public ::testing::WithParamInterface<Params> { |
| 33 public: |
| 34 UserAffiliationBrowserTest() { set_exit_when_last_browser_closes(false); } |
| 35 |
| 36 protected: |
| 37 // InProcessBrowserTest |
| 38 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 39 InProcessBrowserTest::SetUpCommandLine(command_line); |
| 40 affiliation_test_helper::AppendCommandLineSwitchesForLoginManager( |
| 41 command_line); |
| 42 } |
| 43 |
| 44 // InProcessBrowserTest |
| 45 void SetUpInProcessBrowserTestFixture() override { |
| 46 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); |
| 47 |
| 48 chromeos::FakeSessionManagerClient* fake_session_manager_client = |
| 49 new chromeos::FakeSessionManagerClient; |
| 50 chromeos::DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( |
| 51 make_scoped_ptr<chromeos::SessionManagerClient>( |
| 52 fake_session_manager_client)); |
| 53 |
| 54 UserPolicyBuilder user_policy; |
| 55 DevicePolicyCrosTestHelper test_helper; |
| 56 |
| 57 std::set<std::string> device_affiliation_ids; |
| 58 device_affiliation_ids.insert(kAffiliationID); |
| 59 affiliation_test_helper::SetDeviceAffiliationID( |
| 60 &test_helper, fake_session_manager_client, device_affiliation_ids); |
| 61 |
| 62 std::set<std::string> user_affiliation_ids; |
| 63 if (GetParam().affiliated_) { |
| 64 user_affiliation_ids.insert(kAffiliationID); |
| 65 } else { |
| 66 user_affiliation_ids.insert(kAnotherAffiliationID); |
| 67 } |
| 68 affiliation_test_helper::SetUserAffiliationIDs( |
| 69 &user_policy, fake_session_manager_client, kAffiliatedUser, |
| 70 user_affiliation_ids); |
| 71 } |
| 72 |
| 73 private: |
| 74 DISALLOW_COPY_AND_ASSIGN(UserAffiliationBrowserTest); |
| 75 }; |
| 76 |
| 77 IN_PROC_BROWSER_TEST_P(UserAffiliationBrowserTest, PRE_Affiliated) { |
| 78 affiliation_test_helper::PreLoginUser(kAffiliatedUser); |
| 79 } |
| 80 |
| 81 IN_PROC_BROWSER_TEST_P(UserAffiliationBrowserTest, Affiliated) { |
| 82 affiliation_test_helper::LoginUser(kAffiliatedUser); |
| 83 EXPECT_EQ(GetParam().affiliated_, |
| 84 user_manager::UserManager::Get() |
| 85 ->FindUser(AccountId::FromUserEmail(kAffiliatedUser)) |
| 86 ->is_affiliated()); |
| 87 } |
| 88 |
| 89 INSTANTIATE_TEST_CASE_P(AffiliationCheck, |
| 90 UserAffiliationBrowserTest, |
| 91 ::testing::Values(Params(true), Params(false))); |
| 92 |
| 93 } // namespace policy |
OLD | NEW |