| 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 "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 7 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
| 8 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" | 8 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" |
| 9 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h" | 9 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h" |
| 10 #include "chrome/test/base/browser_with_test_window_test.h" | 10 #include "chrome/test/base/browser_with_test_window_test.h" |
| 11 #include "chrome/test/base/test_browser_window_aura.h" | 11 #include "chrome/test/base/test_browser_window_aura.h" |
| 12 #include "chrome/test/base/testing_browser_process.h" | 12 #include "chrome/test/base/testing_browser_process.h" |
| 13 #include "chrome/test/base/testing_profile_manager.h" | 13 #include "chrome/test/base/testing_profile_manager.h" |
| 14 #include "components/signin/core/account_id/account_id.h" |
| 14 | 15 |
| 15 namespace test { | 16 namespace test { |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 const char kTestAccount1[] = "user1@test.com"; | 20 const char kTestAccount1[] = "user1@test.com"; |
| 20 const char kTestAccount2[] = "user2@test.com"; | 21 const char kTestAccount2[] = "user2@test.com"; |
| 21 | 22 |
| 22 } // namespace | 23 } // namespace |
| 23 | 24 |
| 24 class BrowserFinderChromeOSTest : public BrowserWithTestWindowTest { | 25 class BrowserFinderChromeOSTest : public BrowserWithTestWindowTest { |
| 25 protected: | 26 protected: |
| 26 BrowserFinderChromeOSTest() : multi_user_window_manager_(nullptr) {} | 27 BrowserFinderChromeOSTest() : multi_user_window_manager_(nullptr) {} |
| 27 | 28 |
| 28 TestingProfile* CreateMultiUserProfile(const std::string& user_email) { | 29 TestingProfile* CreateMultiUserProfile(const std::string& user_email) { |
| 29 TestingProfile* profile = | 30 TestingProfile* profile = |
| 30 profile_manager_->CreateTestingProfile(user_email); | 31 profile_manager_->CreateTestingProfile(user_email); |
| 31 GetUserWindowManager()->AddUser(profile); | 32 GetUserWindowManager()->AddUser(profile); |
| 32 return profile; | 33 return profile; |
| 33 } | 34 } |
| 34 | 35 |
| 35 chrome::MultiUserWindowManagerChromeOS* GetUserWindowManager() { | 36 chrome::MultiUserWindowManagerChromeOS* GetUserWindowManager() { |
| 36 if (!multi_user_window_manager_) { | 37 if (!multi_user_window_manager_) { |
| 37 multi_user_window_manager_ = | 38 multi_user_window_manager_ = |
| 38 new chrome::MultiUserWindowManagerChromeOS(kTestAccount1); | 39 new chrome::MultiUserWindowManagerChromeOS(test_account_id1_); |
| 39 multi_user_window_manager_->Init(); | 40 multi_user_window_manager_->Init(); |
| 40 chrome::MultiUserWindowManager::SetInstanceForTest( | 41 chrome::MultiUserWindowManager::SetInstanceForTest( |
| 41 multi_user_window_manager_, | 42 multi_user_window_manager_, |
| 42 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED); | 43 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED); |
| 43 } | 44 } |
| 44 return multi_user_window_manager_; | 45 return multi_user_window_manager_; |
| 45 } | 46 } |
| 46 | 47 |
| 48 AccountId test_account_id1_ = EmptyAccountId(); |
| 49 AccountId test_account_id2_ = EmptyAccountId(); |
| 50 |
| 47 private: | 51 private: |
| 48 void SetUp() override { | 52 void SetUp() override { |
| 49 profile_manager_.reset( | 53 profile_manager_.reset( |
| 50 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); | 54 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); |
| 51 ASSERT_TRUE(profile_manager_->SetUp()); | 55 ASSERT_TRUE(profile_manager_->SetUp()); |
| 56 test_account_id1_ = AccountId::FromUserEmail(kTestAccount1); |
| 57 test_account_id2_ = AccountId::FromUserEmail(kTestAccount2); |
| 52 profile_manager_->SetLoggedIn(true); | 58 profile_manager_->SetLoggedIn(true); |
| 53 chromeos::WallpaperManager::Initialize(); | 59 chromeos::WallpaperManager::Initialize(); |
| 54 BrowserWithTestWindowTest::SetUp(); | 60 BrowserWithTestWindowTest::SetUp(); |
| 55 second_profile_ = CreateMultiUserProfile(kTestAccount2); | 61 second_profile_ = CreateMultiUserProfile(test_account_id2_.GetUserEmail()); |
| 56 } | 62 } |
| 57 | 63 |
| 58 void TearDown() override { | 64 void TearDown() override { |
| 59 chrome::MultiUserWindowManager::DeleteInstance(); | 65 chrome::MultiUserWindowManager::DeleteInstance(); |
| 60 BrowserWithTestWindowTest::TearDown(); | 66 BrowserWithTestWindowTest::TearDown(); |
| 61 chromeos::WallpaperManager::Shutdown(); | 67 chromeos::WallpaperManager::Shutdown(); |
| 62 if (second_profile_) { | 68 if (second_profile_) { |
| 63 DestroyProfile(second_profile_); | 69 DestroyProfile(second_profile_); |
| 64 second_profile_ = nullptr; | 70 second_profile_ = nullptr; |
| 65 } | 71 } |
| 66 } | 72 } |
| 67 | 73 |
| 68 TestingProfile* CreateProfile() override { | 74 TestingProfile* CreateProfile() override { |
| 69 return CreateMultiUserProfile(kTestAccount1); | 75 return CreateMultiUserProfile(test_account_id1_.GetUserEmail()); |
| 70 } | 76 } |
| 71 | 77 |
| 72 void DestroyProfile(TestingProfile* test_profile) override { | 78 void DestroyProfile(TestingProfile* test_profile) override { |
| 73 profile_manager_->DeleteTestingProfile(test_profile->GetProfileUserName()); | 79 profile_manager_->DeleteTestingProfile(test_profile->GetProfileUserName()); |
| 74 } | 80 } |
| 75 | 81 |
| 76 TestingProfile* second_profile_; | 82 TestingProfile* second_profile_; |
| 77 scoped_ptr<TestingProfileManager> profile_manager_; | 83 scoped_ptr<TestingProfileManager> profile_manager_; |
| 78 chrome::MultiUserWindowManagerChromeOS* multi_user_window_manager_; | 84 chrome::MultiUserWindowManagerChromeOS* multi_user_window_manager_; |
| 79 | 85 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 106 } | 112 } |
| 107 | 113 |
| 108 TEST_F(BrowserFinderChromeOSTest, FindBrowserOwnedByAnotherProfile) { | 114 TEST_F(BrowserFinderChromeOSTest, FindBrowserOwnedByAnotherProfile) { |
| 109 set_browser(nullptr); | 115 set_browser(nullptr); |
| 110 | 116 |
| 111 Browser::CreateParams params(profile()->GetOriginalProfile(), | 117 Browser::CreateParams params(profile()->GetOriginalProfile(), |
| 112 chrome::HOST_DESKTOP_TYPE_ASH); | 118 chrome::HOST_DESKTOP_TYPE_ASH); |
| 113 scoped_ptr<Browser> browser( | 119 scoped_ptr<Browser> browser( |
| 114 chrome::CreateBrowserWithAuraTestWindowForParams(nullptr, ¶ms)); | 120 chrome::CreateBrowserWithAuraTestWindowForParams(nullptr, ¶ms)); |
| 115 GetUserWindowManager()->SetWindowOwner(browser->window()->GetNativeWindow(), | 121 GetUserWindowManager()->SetWindowOwner(browser->window()->GetNativeWindow(), |
| 116 kTestAccount1); | 122 test_account_id1_); |
| 117 EXPECT_EQ(1u, | 123 EXPECT_EQ(1u, |
| 118 chrome::GetBrowserCount(profile(), chrome::HOST_DESKTOP_TYPE_ASH)); | 124 chrome::GetBrowserCount(profile(), chrome::HOST_DESKTOP_TYPE_ASH)); |
| 119 EXPECT_TRUE( | 125 EXPECT_TRUE( |
| 120 chrome::FindAnyBrowser(profile(), true, chrome::HOST_DESKTOP_TYPE_ASH)); | 126 chrome::FindAnyBrowser(profile(), true, chrome::HOST_DESKTOP_TYPE_ASH)); |
| 121 EXPECT_TRUE( | 127 EXPECT_TRUE( |
| 122 chrome::FindAnyBrowser(profile(), false, chrome::HOST_DESKTOP_TYPE_ASH)); | 128 chrome::FindAnyBrowser(profile(), false, chrome::HOST_DESKTOP_TYPE_ASH)); |
| 123 | 129 |
| 124 // Move the browser window to another user's desktop. Then no window should | 130 // Move the browser window to another user's desktop. Then no window should |
| 125 // be available for the current profile. | 131 // be available for the current profile. |
| 126 GetUserWindowManager()->ShowWindowForUser( | 132 GetUserWindowManager()->ShowWindowForUser( |
| 127 browser->window()->GetNativeWindow(), kTestAccount2); | 133 browser->window()->GetNativeWindow(), test_account_id2_); |
| 128 EXPECT_EQ(0u, | 134 EXPECT_EQ(0u, |
| 129 chrome::GetBrowserCount(profile(), chrome::HOST_DESKTOP_TYPE_ASH)); | 135 chrome::GetBrowserCount(profile(), chrome::HOST_DESKTOP_TYPE_ASH)); |
| 130 EXPECT_FALSE( | 136 EXPECT_FALSE( |
| 131 chrome::FindAnyBrowser(profile(), true, chrome::HOST_DESKTOP_TYPE_ASH)); | 137 chrome::FindAnyBrowser(profile(), true, chrome::HOST_DESKTOP_TYPE_ASH)); |
| 132 EXPECT_FALSE( | 138 EXPECT_FALSE( |
| 133 chrome::FindAnyBrowser(profile(), false, chrome::HOST_DESKTOP_TYPE_ASH)); | 139 chrome::FindAnyBrowser(profile(), false, chrome::HOST_DESKTOP_TYPE_ASH)); |
| 134 } | 140 } |
| 135 | 141 |
| 136 } // namespace test | 142 } // namespace test |
| OLD | NEW |