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 chromeos { |
| 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 } // namespace |
| 28 |
| 29 class UserAffiliationBrowserTest |
| 30 : public InProcessBrowserTest, |
| 31 public ::testing::WithParamInterface<Params> { |
| 32 public: |
| 33 UserAffiliationBrowserTest() { set_exit_when_last_browser_closes(false); } |
| 34 |
| 35 protected: |
| 36 // InProcessBrowserTest |
| 37 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 38 InProcessBrowserTest::SetUpCommandLine(command_line); |
| 39 affiliation_test_helper::AppendCommandLineSwitchesForLoginManager( |
| 40 command_line); |
| 41 } |
| 42 |
| 43 // InProcessBrowserTest |
| 44 void SetUpInProcessBrowserTestFixture() override { |
| 45 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); |
| 46 |
| 47 FakeSessionManagerClient* fake_session_manager_client = |
| 48 new chromeos::FakeSessionManagerClient; |
| 49 DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( |
| 50 scoped_ptr<SessionManagerClient>(fake_session_manager_client)); |
| 51 |
| 52 policy::UserPolicyBuilder user_policy; |
| 53 policy::DevicePolicyCrosTestHelper test_helper; |
| 54 |
| 55 std::set<std::string> device_affiliation_ids; |
| 56 device_affiliation_ids.insert(kAffiliationID); |
| 57 affiliation_test_helper::SetDeviceAffiliationID( |
| 58 &test_helper, fake_session_manager_client, device_affiliation_ids); |
| 59 |
| 60 std::set<std::string> user_affiliation_ids; |
| 61 if (GetParam().affiliated_) { |
| 62 user_affiliation_ids.insert(kAffiliationID); |
| 63 } else { |
| 64 user_affiliation_ids.insert(kAnotherAffiliationID); |
| 65 } |
| 66 affiliation_test_helper::SetUserAffiliationIDs( |
| 67 &user_policy, fake_session_manager_client, kAffiliatedUser, |
| 68 user_affiliation_ids); |
| 69 } |
| 70 |
| 71 private: |
| 72 DISALLOW_COPY_AND_ASSIGN(UserAffiliationBrowserTest); |
| 73 }; |
| 74 |
| 75 IN_PROC_BROWSER_TEST_P(UserAffiliationBrowserTest, PRE_Affiliated) { |
| 76 affiliation_test_helper::PreLoginUser(kAffiliatedUser); |
| 77 } |
| 78 |
| 79 IN_PROC_BROWSER_TEST_P(UserAffiliationBrowserTest, Affiliated) { |
| 80 affiliation_test_helper::LoginUser(kAffiliatedUser); |
| 81 EXPECT_EQ(GetParam().affiliated_, user_manager::UserManager::Get() |
| 82 ->FindUser(kAffiliatedUser) |
| 83 ->is_affiliated()); |
| 84 } |
| 85 |
| 86 INSTANTIATE_TEST_CASE_P(AffiliationCheck, |
| 87 UserAffiliationBrowserTest, |
| 88 ::testing::Values(Params(true), Params(false))); |
| 89 |
| 90 } // namespace chromeos |
OLD | NEW |