Infobar material design refresh: layout
[chromium-blink-merge.git] / chrome / browser / ui / browser_finder_chromeos_unittest.cc
blob73018399bb35b4b1f859560f696fde3357c1f8f6
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.
5 #include "chrome/browser/ui/browser_finder.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"
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/test_browser_window_aura.h"
12 #include "chrome/test/base/testing_browser_process.h"
13 #include "chrome/test/base/testing_profile_manager.h"
15 namespace test {
17 namespace {
19 const char kTestAccount1[] = "user1@test.com";
20 const char kTestAccount2[] = "user2@test.com";
22 } // namespace
24 class BrowserFinderChromeOSTest : public BrowserWithTestWindowTest {
25 protected:
26 BrowserFinderChromeOSTest() : multi_user_window_manager_(nullptr) {}
28 TestingProfile* CreateMultiUserProfile(const std::string& user_email) {
29 TestingProfile* profile =
30 profile_manager_->CreateTestingProfile(user_email);
31 GetUserWindowManager()->AddUser(profile);
32 return profile;
35 chrome::MultiUserWindowManagerChromeOS* GetUserWindowManager() {
36 if (!multi_user_window_manager_) {
37 multi_user_window_manager_ =
38 new chrome::MultiUserWindowManagerChromeOS(kTestAccount1);
39 multi_user_window_manager_->Init();
40 chrome::MultiUserWindowManager::SetInstanceForTest(
41 multi_user_window_manager_,
42 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED);
44 return multi_user_window_manager_;
47 private:
48 void SetUp() override {
49 profile_manager_.reset(
50 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
51 ASSERT_TRUE(profile_manager_->SetUp());
52 profile_manager_->SetLoggedIn(true);
53 chromeos::WallpaperManager::Initialize();
54 BrowserWithTestWindowTest::SetUp();
55 second_profile_ = CreateMultiUserProfile(kTestAccount2);
58 void TearDown() override {
59 chrome::MultiUserWindowManager::DeleteInstance();
60 BrowserWithTestWindowTest::TearDown();
61 chromeos::WallpaperManager::Shutdown();
62 if (second_profile_) {
63 DestroyProfile(second_profile_);
64 second_profile_ = nullptr;
68 TestingProfile* CreateProfile() override {
69 return CreateMultiUserProfile(kTestAccount1);
72 void DestroyProfile(TestingProfile* test_profile) override {
73 profile_manager_->DeleteTestingProfile(test_profile->GetProfileUserName());
76 TestingProfile* second_profile_;
77 scoped_ptr<TestingProfileManager> profile_manager_;
78 chrome::MultiUserWindowManagerChromeOS* multi_user_window_manager_;
80 DISALLOW_COPY_AND_ASSIGN(BrowserFinderChromeOSTest);
83 TEST_F(BrowserFinderChromeOSTest, IncognitoBrowserMatchTest) {
84 // GetBrowserCount() use kMatchAll to find all browser windows for profile().
85 EXPECT_EQ(1u,
86 chrome::GetBrowserCount(profile(), chrome::HOST_DESKTOP_TYPE_ASH));
87 EXPECT_TRUE(
88 chrome::FindAnyBrowser(profile(), true, chrome::HOST_DESKTOP_TYPE_ASH));
89 EXPECT_TRUE(
90 chrome::FindAnyBrowser(profile(), false, chrome::HOST_DESKTOP_TYPE_ASH));
91 set_browser(nullptr);
93 // Create an incognito browser.
94 Browser::CreateParams params(profile()->GetOffTheRecordProfile(),
95 chrome::HOST_DESKTOP_TYPE_ASH);
96 scoped_ptr<Browser> incognito_browser(
97 chrome::CreateBrowserWithAuraTestWindowForParams(nullptr, &params));
98 // Incognito windows are excluded in GetBrowserCount() because kMatchAll
99 // doesn't match original profile of the browser with the given profile.
100 EXPECT_EQ(0u,
101 chrome::GetBrowserCount(profile(), chrome::HOST_DESKTOP_TYPE_ASH));
102 EXPECT_TRUE(
103 chrome::FindAnyBrowser(profile(), true, chrome::HOST_DESKTOP_TYPE_ASH));
104 EXPECT_FALSE(
105 chrome::FindAnyBrowser(profile(), false, chrome::HOST_DESKTOP_TYPE_ASH));
108 TEST_F(BrowserFinderChromeOSTest, FindBrowserOwnedByAnotherProfile) {
109 set_browser(nullptr);
111 Browser::CreateParams params(profile()->GetOriginalProfile(),
112 chrome::HOST_DESKTOP_TYPE_ASH);
113 scoped_ptr<Browser> browser(
114 chrome::CreateBrowserWithAuraTestWindowForParams(nullptr, &params));
115 GetUserWindowManager()->SetWindowOwner(browser->window()->GetNativeWindow(),
116 kTestAccount1);
117 EXPECT_EQ(1u,
118 chrome::GetBrowserCount(profile(), chrome::HOST_DESKTOP_TYPE_ASH));
119 EXPECT_TRUE(
120 chrome::FindAnyBrowser(profile(), true, chrome::HOST_DESKTOP_TYPE_ASH));
121 EXPECT_TRUE(
122 chrome::FindAnyBrowser(profile(), false, chrome::HOST_DESKTOP_TYPE_ASH));
124 // Move the browser window to another user's desktop. Then no window should
125 // be available for the current profile.
126 GetUserWindowManager()->ShowWindowForUser(
127 browser->window()->GetNativeWindow(), kTestAccount2);
128 EXPECT_EQ(0u,
129 chrome::GetBrowserCount(profile(), chrome::HOST_DESKTOP_TYPE_ASH));
130 EXPECT_FALSE(
131 chrome::FindAnyBrowser(profile(), true, chrome::HOST_DESKTOP_TYPE_ASH));
132 EXPECT_FALSE(
133 chrome::FindAnyBrowser(profile(), false, chrome::HOST_DESKTOP_TYPE_ASH));
136 } // namespace test