Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(339)

Side by Side Diff: chrome/browser/ui/browser_finder_chromeos_unittest.cc

Issue 1198313003: Fix the browser match rules. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address msw@'s comments. Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 chrome::MultiUserWindowManagerChromeOS* GetUserWindowManager() {
35 if (!multi_user_window_manager_) {
36 multi_user_window_manager_ =
37 new chrome::MultiUserWindowManagerChromeOS(kTestAccount1);
38 multi_user_window_manager_->Init();
39 chrome::MultiUserWindowManager::SetInstanceForTest(
40 multi_user_window_manager_,
41 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED);
42 }
43 return multi_user_window_manager_;
44 }
45
46 private:
47 void SetUp() override {
48 profile_manager_.reset(
49 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
50 ASSERT_TRUE(profile_manager_->SetUp());
51 profile_manager_->SetLoggedIn(true);
52 chromeos::WallpaperManager::Initialize();
53 BrowserWithTestWindowTest::SetUp();
54 second_profile_ = CreateMultiUserProfile(kTestAccount2);
55 }
56
57 void TearDown() override {
58 chrome::MultiUserWindowManager::DeleteInstance();
59 BrowserWithTestWindowTest::TearDown();
60 chromeos::WallpaperManager::Shutdown();
61 if (second_profile_) {
62 DestroyProfile(second_profile_);
63 second_profile_ = nullptr;
64 }
65 }
66
67 TestingProfile* CreateProfile() override {
68 return CreateMultiUserProfile(kTestAccount1);
69 }
70
71 void DestroyProfile(TestingProfile* test_profile) override {
72 profile_manager_->DeleteTestingProfile(test_profile->GetProfileUserName());
73 }
74
75 TestingProfile* second_profile_;
76 scoped_ptr<TestingProfileManager> profile_manager_;
77 chrome::MultiUserWindowManagerChromeOS* multi_user_window_manager_;
78
79 DISALLOW_COPY_AND_ASSIGN(BrowserFinderChromeOSTest);
80 };
81
82 TEST_F(BrowserFinderChromeOSTest, IncognitoBrowserMatchTest) {
83 // GetBrowserCount() use kMatchAll to find all browser windows for profile().
84 EXPECT_EQ(1u,
85 chrome::GetBrowserCount(profile(), chrome::HOST_DESKTOP_TYPE_ASH));
86 EXPECT_TRUE(
87 chrome::FindAnyBrowser(profile(), true, chrome::HOST_DESKTOP_TYPE_ASH));
88 EXPECT_TRUE(
89 chrome::FindAnyBrowser(profile(), false, chrome::HOST_DESKTOP_TYPE_ASH));
90 set_browser(nullptr);
91
92 // Create an incognito browser.
93 Browser::CreateParams params(profile()->GetOffTheRecordProfile(),
94 chrome::HOST_DESKTOP_TYPE_ASH);
95 scoped_ptr<Browser> incognito_browser(
96 chrome::CreateBrowserWithAuraTestWindowForParams(nullptr, &params));
97 // Incognito windows are excluded in GetBrowserCount() because kMatchAll
98 // doesn't match original profile of the browser with the given profile.
99 EXPECT_EQ(0u,
100 chrome::GetBrowserCount(profile(), chrome::HOST_DESKTOP_TYPE_ASH));
101 EXPECT_TRUE(
102 chrome::FindAnyBrowser(profile(), true, chrome::HOST_DESKTOP_TYPE_ASH));
103 EXPECT_FALSE(
104 chrome::FindAnyBrowser(profile(), false, chrome::HOST_DESKTOP_TYPE_ASH));
105 }
106
107 TEST_F(BrowserFinderChromeOSTest, FindBrowserOwnedByAnotherProfile) {
108 set_browser(nullptr);
109
110 Browser::CreateParams params(profile()->GetOriginalProfile(),
111 chrome::HOST_DESKTOP_TYPE_ASH);
112 scoped_ptr<Browser> browser(
113 chrome::CreateBrowserWithAuraTestWindowForParams(nullptr, &params));
114 GetUserWindowManager()->SetWindowOwner(browser->window()->GetNativeWindow(),
115 kTestAccount1);
116 EXPECT_EQ(1u,
117 chrome::GetBrowserCount(profile(), chrome::HOST_DESKTOP_TYPE_ASH));
118 EXPECT_TRUE(
119 chrome::FindAnyBrowser(profile(), true, chrome::HOST_DESKTOP_TYPE_ASH));
120 EXPECT_TRUE(
121 chrome::FindAnyBrowser(profile(), false, chrome::HOST_DESKTOP_TYPE_ASH));
122
123 // Move the browser window to another user's desktop. Then no window should
124 // be available for the current profile.
125 GetUserWindowManager()->ShowWindowForUser(
126 browser->window()->GetNativeWindow(), kTestAccount2);
127 EXPECT_EQ(0u,
128 chrome::GetBrowserCount(profile(), chrome::HOST_DESKTOP_TYPE_ASH));
129 EXPECT_FALSE(
130 chrome::FindAnyBrowser(profile(), true, chrome::HOST_DESKTOP_TYPE_ASH));
131 EXPECT_FALSE(
132 chrome::FindAnyBrowser(profile(), false, chrome::HOST_DESKTOP_TYPE_ASH));
133 }
134
135 } // namespace test
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698