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