| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/browser_finder.h" | 5 #include "chrome/browser/ui/browser_finder.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/test/ash_test_helper.h" | 8 #include "ash/test/ash_test_helper.h" |
| 9 #include "ash/test/test_session_state_delegate.h" | 9 #include "ash/test/test_session_state_delegate.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" | |
| 12 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 11 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
| 13 #include "chrome/browser/chromeos/profiles/profile_helper.h" | |
| 14 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" | 12 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" |
| 15 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h" | 13 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h" |
| 16 #include "chrome/test/base/browser_with_test_window_test.h" | 14 #include "chrome/test/base/browser_with_test_window_test.h" |
| 17 #include "chrome/test/base/test_browser_window_aura.h" | 15 #include "chrome/test/base/test_browser_window_aura.h" |
| 18 #include "chrome/test/base/testing_browser_process.h" | 16 #include "chrome/test/base/testing_browser_process.h" |
| 19 #include "chrome/test/base/testing_profile_manager.h" | 17 #include "chrome/test/base/testing_profile_manager.h" |
| 20 #include "components/signin/core/account_id/account_id.h" | 18 #include "components/signin/core/account_id/account_id.h" |
| 21 #include "components/user_manager/fake_user_manager.h" | |
| 22 #include "components/user_manager/user.h" | |
| 23 | 19 |
| 24 namespace test { | 20 namespace test { |
| 25 | 21 |
| 26 namespace { | 22 namespace { |
| 27 | 23 |
| 28 const char kTestAccount1[] = "user1@test.com"; | 24 const char kTestAccount1[] = "user1@test.com"; |
| 29 const char kTestAccount2[] = "user2@test.com"; | 25 const char kTestAccount2[] = "user2@test.com"; |
| 30 | 26 |
| 31 } // namespace | 27 } // namespace |
| 32 | 28 |
| 33 class BrowserFinderChromeOSTest : public BrowserWithTestWindowTest { | 29 class BrowserFinderChromeOSTest : public BrowserWithTestWindowTest { |
| 34 protected: | 30 protected: |
| 35 BrowserFinderChromeOSTest() | 31 BrowserFinderChromeOSTest() : multi_user_window_manager_(nullptr) {} |
| 36 : multi_user_window_manager_(nullptr), | |
| 37 fake_user_manager_(new user_manager::FakeUserManager), | |
| 38 user_manager_enabler_(fake_user_manager_) {} | |
| 39 | 32 |
| 40 TestingProfile* CreateMultiUserProfile(const AccountId& account_id) { | 33 TestingProfile* CreateMultiUserProfile(const AccountId& account_id) { |
| 41 TestingProfile* profile = | 34 TestingProfile* profile = |
| 42 profile_manager_->CreateTestingProfile(account_id.GetUserEmail()); | 35 profile_manager_->CreateTestingProfile(account_id.GetUserEmail()); |
| 43 GetUserWindowManager()->AddUser(profile); | 36 GetUserWindowManager()->AddUser(profile); |
| 44 const user_manager::User* user = fake_user_manager_->AddUser(account_id); | |
| 45 chromeos::ProfileHelper::Get()->SetProfileToUserMappingForTesting( | |
| 46 const_cast<user_manager::User*>(user)); | |
| 47 ash::test::AshTestHelper::GetTestSessionStateDelegate()->AddUser( | 37 ash::test::AshTestHelper::GetTestSessionStateDelegate()->AddUser( |
| 48 account_id); | 38 account_id); |
| 49 return profile; | 39 return profile; |
| 50 } | 40 } |
| 51 | 41 |
| 52 chrome::MultiUserWindowManagerChromeOS* GetUserWindowManager() { | 42 chrome::MultiUserWindowManagerChromeOS* GetUserWindowManager() { |
| 53 if (!multi_user_window_manager_) { | 43 if (!multi_user_window_manager_) { |
| 54 multi_user_window_manager_ = | 44 multi_user_window_manager_ = |
| 55 new chrome::MultiUserWindowManagerChromeOS(test_account_id1_); | 45 new chrome::MultiUserWindowManagerChromeOS(test_account_id1_); |
| 56 multi_user_window_manager_->Init(); | 46 multi_user_window_manager_->Init(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 return CreateMultiUserProfile(test_account_id1_); | 81 return CreateMultiUserProfile(test_account_id1_); |
| 92 } | 82 } |
| 93 | 83 |
| 94 void DestroyProfile(TestingProfile* test_profile) override { | 84 void DestroyProfile(TestingProfile* test_profile) override { |
| 95 profile_manager_->DeleteTestingProfile(test_profile->GetProfileUserName()); | 85 profile_manager_->DeleteTestingProfile(test_profile->GetProfileUserName()); |
| 96 } | 86 } |
| 97 | 87 |
| 98 TestingProfile* second_profile_; | 88 TestingProfile* second_profile_; |
| 99 std::unique_ptr<TestingProfileManager> profile_manager_; | 89 std::unique_ptr<TestingProfileManager> profile_manager_; |
| 100 chrome::MultiUserWindowManagerChromeOS* multi_user_window_manager_; | 90 chrome::MultiUserWindowManagerChromeOS* multi_user_window_manager_; |
| 101 user_manager::FakeUserManager* fake_user_manager_; // Not owned. | |
| 102 chromeos::ScopedUserManagerEnabler user_manager_enabler_; | |
| 103 | 91 |
| 104 DISALLOW_COPY_AND_ASSIGN(BrowserFinderChromeOSTest); | 92 DISALLOW_COPY_AND_ASSIGN(BrowserFinderChromeOSTest); |
| 105 }; | 93 }; |
| 106 | 94 |
| 107 TEST_F(BrowserFinderChromeOSTest, IncognitoBrowserMatchTest) { | 95 TEST_F(BrowserFinderChromeOSTest, IncognitoBrowserMatchTest) { |
| 108 // GetBrowserCount() use kMatchAll to find all browser windows for profile(). | 96 // GetBrowserCount() use kMatchAll to find all browser windows for profile(). |
| 109 EXPECT_EQ(1u, chrome::GetBrowserCount(profile())); | 97 EXPECT_EQ(1u, chrome::GetBrowserCount(profile())); |
| 110 EXPECT_TRUE(chrome::FindAnyBrowser(profile(), true)); | 98 EXPECT_TRUE(chrome::FindAnyBrowser(profile(), true)); |
| 111 EXPECT_TRUE(chrome::FindAnyBrowser(profile(), false)); | 99 EXPECT_TRUE(chrome::FindAnyBrowser(profile(), false)); |
| 112 set_browser(nullptr); | 100 set_browser(nullptr); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 137 // Move the browser window to another user's desktop. Then no window should | 125 // Move the browser window to another user's desktop. Then no window should |
| 138 // be available for the current profile. | 126 // be available for the current profile. |
| 139 GetUserWindowManager()->ShowWindowForUser( | 127 GetUserWindowManager()->ShowWindowForUser( |
| 140 browser->window()->GetNativeWindow(), test_account_id2_); | 128 browser->window()->GetNativeWindow(), test_account_id2_); |
| 141 EXPECT_EQ(0u, chrome::GetBrowserCount(profile())); | 129 EXPECT_EQ(0u, chrome::GetBrowserCount(profile())); |
| 142 EXPECT_FALSE(chrome::FindAnyBrowser(profile(), true)); | 130 EXPECT_FALSE(chrome::FindAnyBrowser(profile(), true)); |
| 143 EXPECT_FALSE(chrome::FindAnyBrowser(profile(), false)); | 131 EXPECT_FALSE(chrome::FindAnyBrowser(profile(), false)); |
| 144 } | 132 } |
| 145 | 133 |
| 146 } // namespace test | 134 } // namespace test |
| OLD | NEW |