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

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
« no previous file with comments | « chrome/browser/ui/browser_finder.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_window.h"
12 #include "chrome/test/base/browser_with_test_window_test.h"
13 #include "chrome/test/base/testing_browser_process.h"
14 #include "chrome/test/base/testing_profile_manager.h"
15
16 namespace test {
17
18 namespace {
19
20 const char kTestAccount1[] = "user1@test.com";
21 const char kTestAccount2[] = "user2@test.com";
22
23 class TestBrowserWindowAura : public TestBrowserWindow {
msw 2015/07/01 19:55:16 I now see that three other files define TestBrowse
xdai1 2015/07/07 00:33:42 Extracted the class TestBrowserWindowAura into tes
24 public:
25 // |native_window| is owned by the caller.
26 explicit TestBrowserWindowAura(aura::Window* native_window)
27 : native_window_(native_window) {}
28 ~TestBrowserWindowAura() override {}
29
30 // TestBrowserWindow override.
31 aura::Window* GetNativeWindow() const override {
32 return native_window_.get();
33 }
34
35 Browser* browser() { return browser_.get(); }
36
37 void CreateBrowser(const Browser::CreateParams& params) {
38 Browser::CreateParams create_params = params;
39 create_params.window = this;
40 browser_.reset(new Browser(create_params));
41 }
42
43 private:
44 scoped_ptr<Browser> browser_;
45 scoped_ptr<aura::Window> native_window_;
46
47 DISALLOW_COPY_AND_ASSIGN(TestBrowserWindowAura);
48 };
49
50 } // namespace
51
52 class BrowserFinderChromeOSTest : public BrowserWithTestWindowTest {
53 protected:
54 BrowserFinderChromeOSTest() : multi_user_window_manager_(nullptr) {}
55
56 TestingProfile* CreateMultiUserProfile(const std::string& user_email) {
57 TestingProfile* profile =
58 profile_manager_->CreateTestingProfile(user_email);
59 GetUserWindowManager()->AddUser(profile);
60 return profile;
61 }
62
63 scoped_ptr<TestBrowserWindowAura> CreateBrowserWindowWithProfile(
64 Profile* profile,
65 bool is_incognito) {
66 // Create a window.
67 aura::Window* window = new aura::Window(NULL);
msw 2015/07/01 19:55:16 nit: nullptr
xdai1 2015/07/07 00:33:42 Done.
68 window->set_id(0);
69 window->SetType(ui::wm::WINDOW_TYPE_NORMAL);
70 window->Init(ui::LAYER_TEXTURED);
71 window->Show();
72
73 scoped_ptr<TestBrowserWindowAura> browser_window(
74 new TestBrowserWindowAura(window));
75 if (is_incognito) {
76 Browser::CreateParams params(profile->GetOffTheRecordProfile(),
77 chrome::HOST_DESKTOP_TYPE_ASH);
78 browser_window->CreateBrowser(params);
79 } else {
80 Browser::CreateParams params(profile->GetOriginalProfile(),
81 chrome::HOST_DESKTOP_TYPE_ASH);
82 browser_window->CreateBrowser(params);
83 }
84 return browser_window.Pass();
85 }
86
87 chrome::MultiUserWindowManagerChromeOS* GetUserWindowManager() {
88 if (!multi_user_window_manager_) {
89 multi_user_window_manager_ =
90 new chrome::MultiUserWindowManagerChromeOS(kTestAccount1);
91 multi_user_window_manager_->Init();
92 chrome::MultiUserWindowManager::SetInstanceForTest(
93 multi_user_window_manager_,
94 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED);
95 }
96 return multi_user_window_manager_;
97 }
98
99 private:
100 void SetUp() override {
101 profile_manager_.reset(
102 new TestingProfileManager(TestingBrowserProcess::GetGlobal()));
103 ASSERT_TRUE(profile_manager_->SetUp());
104 profile_manager_->SetLoggedIn(true);
105 chromeos::WallpaperManager::Initialize();
106 BrowserWithTestWindowTest::SetUp();
107 // Create a second profile.
msw 2015/07/01 19:55:16 TearDown should probably explicitly destroy this p
xdai1 2015/07/07 00:33:42 Done.
108 CreateMultiUserProfile(kTestAccount2);
109 }
110
111 void TearDown() override {
112 chrome::MultiUserWindowManager::DeleteInstance();
113 BrowserWithTestWindowTest::TearDown();
114 chromeos::WallpaperManager::Shutdown();
115 }
116
117 // Override BrowserWithTestWindowTest.
msw 2015/07/01 19:55:16 nit: SetUp and TearDown also override BrowserWithT
xdai1 2015/07/07 00:33:42 Removed it.
118 TestingProfile* CreateProfile() override {
119 return CreateMultiUserProfile(kTestAccount1);
120 }
121
122 void DestroyProfile(TestingProfile* test_profile) override {
123 profile_manager_->DeleteAllTestingProfiles();
msw 2015/07/01 19:55:16 Deleting all testing profiles doesn't seem like th
xdai1 2015/07/07 00:33:42 Done.
124 }
125
126 TestingProfile* second_profile_;
127 scoped_ptr<TestingProfileManager> profile_manager_;
128 chrome::MultiUserWindowManagerChromeOS* multi_user_window_manager_;
129
130 DISALLOW_COPY_AND_ASSIGN(BrowserFinderChromeOSTest);
131 };
132
133 TEST_F(BrowserFinderChromeOSTest, IncognitoBrowserMatchTest) {
134 // GetBrowserCount() use kMatchAll to find all browser windows for profile().
135 EXPECT_EQ(1u,
136 chrome::GetBrowserCount(profile(), chrome::HOST_DESKTOP_TYPE_ASH));
137 EXPECT_TRUE(
138 chrome::FindAnyBrowser(profile(), true, chrome::HOST_DESKTOP_TYPE_ASH));
139 EXPECT_TRUE(
140 chrome::FindAnyBrowser(profile(), false, chrome::HOST_DESKTOP_TYPE_ASH));
141 set_browser(nullptr);
142
143 scoped_ptr<TestBrowserWindowAura> incognito_browser_window =
144 CreateBrowserWindowWithProfile(profile(), true);
145 // Incognito windows are excluded in GetBrowserCount() because kMatchAll
146 // doesn't match original profile of the browser with the given profile.
147 EXPECT_EQ(0u,
148 chrome::GetBrowserCount(profile(), chrome::HOST_DESKTOP_TYPE_ASH));
149 EXPECT_TRUE(
150 chrome::FindAnyBrowser(profile(), true, chrome::HOST_DESKTOP_TYPE_ASH));
151 EXPECT_FALSE(
152 chrome::FindAnyBrowser(profile(), false, chrome::HOST_DESKTOP_TYPE_ASH));
153 }
154
155 TEST_F(BrowserFinderChromeOSTest, FindBrowserOwnedByAnotherProfile) {
156 set_browser(nullptr);
157
158 scoped_ptr<TestBrowserWindowAura> browser_window =
159 CreateBrowserWindowWithProfile(profile(), false);
160 GetUserWindowManager()->SetWindowOwner(browser_window->GetNativeWindow(),
161 kTestAccount1);
162 EXPECT_EQ(1u,
163 chrome::GetBrowserCount(profile(), chrome::HOST_DESKTOP_TYPE_ASH));
164 EXPECT_TRUE(
165 chrome::FindAnyBrowser(profile(), true, chrome::HOST_DESKTOP_TYPE_ASH));
166 EXPECT_TRUE(
167 chrome::FindAnyBrowser(profile(), false, chrome::HOST_DESKTOP_TYPE_ASH));
168
169 // Move the browser window to another user's desktop. Then no window should
170 // be available for the current profile.
171 GetUserWindowManager()->ShowWindowForUser(browser_window->GetNativeWindow(),
172 kTestAccount2);
173 EXPECT_EQ(0u,
174 chrome::GetBrowserCount(profile(), chrome::HOST_DESKTOP_TYPE_ASH));
175 EXPECT_FALSE(
176 chrome::FindAnyBrowser(profile(), true, chrome::HOST_DESKTOP_TYPE_ASH));
177 EXPECT_FALSE(
178 chrome::FindAnyBrowser(profile(), false, chrome::HOST_DESKTOP_TYPE_ASH));
179 }
180
181 } // namespace test
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_finder.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698