Chromium Code Reviews| 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 scoped_ptr<TestBrowserWindowAura> CreateBrowserWindowWithProfile( | |
| 35 Profile* profile, | |
| 36 bool is_incognito) { | |
| 37 if (is_incognito) { | |
| 38 Browser::CreateParams params(profile->GetOffTheRecordProfile(), | |
| 39 chrome::HOST_DESKTOP_TYPE_ASH); | |
| 40 return CreateBrowserWithNativeWindowForParams(params); | |
| 41 } else { | |
|
msw
2015/07/07 18:11:54
nit: no else after return
xdai1
2015/07/08 00:26:21
Done.
| |
| 42 Browser::CreateParams params(profile->GetOriginalProfile(), | |
| 43 chrome::HOST_DESKTOP_TYPE_ASH); | |
| 44 return CreateBrowserWithNativeWindowForParams(params); | |
| 45 } | |
| 46 } | |
| 47 | |
| 48 chrome::MultiUserWindowManagerChromeOS* GetUserWindowManager() { | |
| 49 if (!multi_user_window_manager_) { | |
| 50 multi_user_window_manager_ = | |
| 51 new chrome::MultiUserWindowManagerChromeOS(kTestAccount1); | |
| 52 multi_user_window_manager_->Init(); | |
| 53 chrome::MultiUserWindowManager::SetInstanceForTest( | |
| 54 multi_user_window_manager_, | |
| 55 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED); | |
| 56 } | |
| 57 return multi_user_window_manager_; | |
| 58 } | |
| 59 | |
| 60 private: | |
| 61 void SetUp() override { | |
| 62 profile_manager_.reset( | |
| 63 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); | |
| 64 ASSERT_TRUE(profile_manager_->SetUp()); | |
| 65 profile_manager_->SetLoggedIn(true); | |
| 66 chromeos::WallpaperManager::Initialize(); | |
| 67 BrowserWithTestWindowTest::SetUp(); | |
| 68 // Create a second profile. | |
| 69 second_profile_ = CreateMultiUserProfile(kTestAccount2); | |
| 70 } | |
| 71 | |
| 72 void TearDown() override { | |
| 73 chrome::MultiUserWindowManager::DeleteInstance(); | |
| 74 BrowserWithTestWindowTest::TearDown(); | |
| 75 chromeos::WallpaperManager::Shutdown(); | |
| 76 if (second_profile_) { | |
| 77 DestroyProfile(second_profile_); | |
| 78 second_profile_ = nullptr; | |
| 79 } | |
| 80 } | |
| 81 | |
| 82 TestingProfile* CreateProfile() override { | |
| 83 return CreateMultiUserProfile(kTestAccount1); | |
| 84 } | |
| 85 | |
| 86 void DestroyProfile(TestingProfile* test_profile) override { | |
| 87 profile_manager_->DeleteTestingProfile(test_profile->GetProfileUserName()); | |
| 88 } | |
| 89 | |
| 90 TestingProfile* second_profile_; | |
| 91 scoped_ptr<TestingProfileManager> profile_manager_; | |
| 92 chrome::MultiUserWindowManagerChromeOS* multi_user_window_manager_; | |
| 93 | |
| 94 DISALLOW_COPY_AND_ASSIGN(BrowserFinderChromeOSTest); | |
| 95 }; | |
| 96 | |
| 97 TEST_F(BrowserFinderChromeOSTest, IncognitoBrowserMatchTest) { | |
| 98 // GetBrowserCount() use kMatchAll to find all browser windows for profile(). | |
| 99 EXPECT_EQ(1u, | |
| 100 chrome::GetBrowserCount(profile(), chrome::HOST_DESKTOP_TYPE_ASH)); | |
| 101 EXPECT_TRUE( | |
| 102 chrome::FindAnyBrowser(profile(), true, chrome::HOST_DESKTOP_TYPE_ASH)); | |
| 103 EXPECT_TRUE( | |
| 104 chrome::FindAnyBrowser(profile(), false, chrome::HOST_DESKTOP_TYPE_ASH)); | |
| 105 set_browser(nullptr); | |
| 106 | |
| 107 scoped_ptr<TestBrowserWindowAura> incognito_browser_window = | |
| 108 CreateBrowserWindowWithProfile(profile(), true); | |
| 109 // Incognito windows are excluded in GetBrowserCount() because kMatchAll | |
| 110 // doesn't match original profile of the browser with the given profile. | |
| 111 EXPECT_EQ(0u, | |
| 112 chrome::GetBrowserCount(profile(), chrome::HOST_DESKTOP_TYPE_ASH)); | |
| 113 EXPECT_TRUE( | |
| 114 chrome::FindAnyBrowser(profile(), true, chrome::HOST_DESKTOP_TYPE_ASH)); | |
| 115 EXPECT_FALSE( | |
| 116 chrome::FindAnyBrowser(profile(), false, chrome::HOST_DESKTOP_TYPE_ASH)); | |
| 117 } | |
| 118 | |
| 119 TEST_F(BrowserFinderChromeOSTest, FindBrowserOwnedByAnotherProfile) { | |
| 120 set_browser(nullptr); | |
| 121 | |
| 122 scoped_ptr<TestBrowserWindowAura> browser_window = | |
| 123 CreateBrowserWindowWithProfile(profile(), false); | |
| 124 GetUserWindowManager()->SetWindowOwner(browser_window->GetNativeWindow(), | |
| 125 kTestAccount1); | |
| 126 EXPECT_EQ(1u, | |
| 127 chrome::GetBrowserCount(profile(), chrome::HOST_DESKTOP_TYPE_ASH)); | |
| 128 EXPECT_TRUE( | |
| 129 chrome::FindAnyBrowser(profile(), true, chrome::HOST_DESKTOP_TYPE_ASH)); | |
| 130 EXPECT_TRUE( | |
| 131 chrome::FindAnyBrowser(profile(), false, chrome::HOST_DESKTOP_TYPE_ASH)); | |
| 132 | |
| 133 // Move the browser window to another user's desktop. Then no window should | |
| 134 // be available for the current profile. | |
| 135 GetUserWindowManager()->ShowWindowForUser(browser_window->GetNativeWindow(), | |
| 136 kTestAccount2); | |
| 137 EXPECT_EQ(0u, | |
| 138 chrome::GetBrowserCount(profile(), chrome::HOST_DESKTOP_TYPE_ASH)); | |
| 139 EXPECT_FALSE( | |
| 140 chrome::FindAnyBrowser(profile(), true, chrome::HOST_DESKTOP_TYPE_ASH)); | |
| 141 EXPECT_FALSE( | |
| 142 chrome::FindAnyBrowser(profile(), false, chrome::HOST_DESKTOP_TYPE_ASH)); | |
| 143 } | |
| 144 | |
| 145 } // namespace test | |
| OLD | NEW |