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