| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/browser_finder.h" |
| 6 |
| 7 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_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" |
| 10 #include "chrome/test/base/browser_with_test_window_test.h" |
| 11 #include "chrome/test/base/testing_browser_process.h" |
| 12 #include "chrome/test/base/testing_profile_manager.h" |
| 13 |
| 14 namespace test { |
| 15 |
| 16 namespace { |
| 17 |
| 18 const char kTestAccount1[] = "user1@test.com"; |
| 19 const char kTestAccount2[] = "user2@test.com"; |
| 20 |
| 21 } // namespace |
| 22 |
| 23 class BrowserFinderChromeOSTest : public BrowserWithTestWindowTest { |
| 24 protected: |
| 25 BrowserFinderChromeOSTest() : multi_user_window_manager_(nullptr) {} |
| 26 |
| 27 TestingProfile* CreateMultiUserProfile(const std::string& user_email) { |
| 28 TestingProfile* profile = |
| 29 profile_manager_->CreateTestingProfile(user_email); |
| 30 GetUserWindowManager()->AddUser(profile); |
| 31 return profile; |
| 32 } |
| 33 |
| 34 Browser* CreateBrowserWithProfile(Profile* profile, bool is_incognito) { |
| 35 if (is_incognito) { |
| 36 Browser::CreateParams params(profile->GetOffTheRecordProfile(), |
| 37 chrome::HOST_DESKTOP_TYPE_ASH); |
| 38 return chrome::CreateBrowserWithAuraTestWindowForParams(params); |
| 39 } |
| 40 Browser::CreateParams params(profile->GetOriginalProfile(), |
| 41 chrome::HOST_DESKTOP_TYPE_ASH); |
| 42 return chrome::CreateBrowserWithAuraTestWindowForParams(params); |
| 43 } |
| 44 |
| 45 chrome::MultiUserWindowManagerChromeOS* GetUserWindowManager() { |
| 46 if (!multi_user_window_manager_) { |
| 47 multi_user_window_manager_ = |
| 48 new chrome::MultiUserWindowManagerChromeOS(kTestAccount1); |
| 49 multi_user_window_manager_->Init(); |
| 50 chrome::MultiUserWindowManager::SetInstanceForTest( |
| 51 multi_user_window_manager_, |
| 52 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED); |
| 53 } |
| 54 return multi_user_window_manager_; |
| 55 } |
| 56 |
| 57 private: |
| 58 void SetUp() override { |
| 59 profile_manager_.reset( |
| 60 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); |
| 61 ASSERT_TRUE(profile_manager_->SetUp()); |
| 62 profile_manager_->SetLoggedIn(true); |
| 63 chromeos::WallpaperManager::Initialize(); |
| 64 BrowserWithTestWindowTest::SetUp(); |
| 65 // Create a second profile. |
| 66 second_profile_ = CreateMultiUserProfile(kTestAccount2); |
| 67 } |
| 68 |
| 69 void TearDown() override { |
| 70 chrome::MultiUserWindowManager::DeleteInstance(); |
| 71 BrowserWithTestWindowTest::TearDown(); |
| 72 chromeos::WallpaperManager::Shutdown(); |
| 73 if (second_profile_) { |
| 74 DestroyProfile(second_profile_); |
| 75 second_profile_ = nullptr; |
| 76 } |
| 77 } |
| 78 |
| 79 TestingProfile* CreateProfile() override { |
| 80 return CreateMultiUserProfile(kTestAccount1); |
| 81 } |
| 82 |
| 83 void DestroyProfile(TestingProfile* test_profile) override { |
| 84 profile_manager_->DeleteTestingProfile(test_profile->GetProfileUserName()); |
| 85 } |
| 86 |
| 87 TestingProfile* second_profile_; |
| 88 scoped_ptr<TestingProfileManager> profile_manager_; |
| 89 chrome::MultiUserWindowManagerChromeOS* multi_user_window_manager_; |
| 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(BrowserFinderChromeOSTest); |
| 92 }; |
| 93 |
| 94 TEST_F(BrowserFinderChromeOSTest, IncognitoBrowserMatchTest) { |
| 95 // GetBrowserCount() use kMatchAll to find all browser windows for profile(). |
| 96 EXPECT_EQ(1u, |
| 97 chrome::GetBrowserCount(profile(), chrome::HOST_DESKTOP_TYPE_ASH)); |
| 98 EXPECT_TRUE( |
| 99 chrome::FindAnyBrowser(profile(), true, chrome::HOST_DESKTOP_TYPE_ASH)); |
| 100 EXPECT_TRUE( |
| 101 chrome::FindAnyBrowser(profile(), false, chrome::HOST_DESKTOP_TYPE_ASH)); |
| 102 set_browser(nullptr); |
| 103 |
| 104 scoped_ptr<Browser> incognito_browser( |
| 105 CreateBrowserWithProfile(profile(), true)); |
| 106 // Incognito windows are excluded in GetBrowserCount() because kMatchAll |
| 107 // doesn't match original profile of the browser with the given profile. |
| 108 EXPECT_EQ(0u, |
| 109 chrome::GetBrowserCount(profile(), chrome::HOST_DESKTOP_TYPE_ASH)); |
| 110 EXPECT_TRUE( |
| 111 chrome::FindAnyBrowser(profile(), true, chrome::HOST_DESKTOP_TYPE_ASH)); |
| 112 EXPECT_FALSE( |
| 113 chrome::FindAnyBrowser(profile(), false, chrome::HOST_DESKTOP_TYPE_ASH)); |
| 114 } |
| 115 |
| 116 TEST_F(BrowserFinderChromeOSTest, FindBrowserOwnedByAnotherProfile) { |
| 117 set_browser(nullptr); |
| 118 |
| 119 scoped_ptr<Browser> browser(CreateBrowserWithProfile(profile(), false)); |
| 120 GetUserWindowManager()->SetWindowOwner(browser->window()->GetNativeWindow(), |
| 121 kTestAccount1); |
| 122 EXPECT_EQ(1u, |
| 123 chrome::GetBrowserCount(profile(), chrome::HOST_DESKTOP_TYPE_ASH)); |
| 124 EXPECT_TRUE( |
| 125 chrome::FindAnyBrowser(profile(), true, chrome::HOST_DESKTOP_TYPE_ASH)); |
| 126 EXPECT_TRUE( |
| 127 chrome::FindAnyBrowser(profile(), false, chrome::HOST_DESKTOP_TYPE_ASH)); |
| 128 |
| 129 // Move the browser window to another user's desktop. Then no window should |
| 130 // be available for the current profile. |
| 131 GetUserWindowManager()->ShowWindowForUser( |
| 132 browser->window()->GetNativeWindow(), kTestAccount2); |
| 133 EXPECT_EQ(0u, |
| 134 chrome::GetBrowserCount(profile(), chrome::HOST_DESKTOP_TYPE_ASH)); |
| 135 EXPECT_FALSE( |
| 136 chrome::FindAnyBrowser(profile(), true, chrome::HOST_DESKTOP_TYPE_ASH)); |
| 137 EXPECT_FALSE( |
| 138 chrome::FindAnyBrowser(profile(), false, chrome::HOST_DESKTOP_TYPE_ASH)); |
| 139 } |
| 140 |
| 141 } // namespace test |
| OLD | NEW |