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/fake_chrome_user_manager.h" | |
|
msw
2015/06/30 18:42:33
This doesn't appear to be used/needed.
xdai1
2015/07/01 01:06:20
Removed.
| |
| 8 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | |
| 9 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" | |
| 10 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h" | |
| 11 #include "chrome/browser/ui/browser.h" | |
| 12 #include "chrome/browser/ui/browser_list.h" | |
|
msw
2015/06/30 18:42:33
This doesn't appear to be used/needed.
xdai1
2015/07/01 01:06:20
Removed.
| |
| 13 #include "chrome/browser/ui/browser_window.h" | |
| 14 #include "chrome/test/base/browser_with_test_window_test.h" | |
| 15 #include "chrome/test/base/testing_browser_process.h" | |
| 16 #include "chrome/test/base/testing_profile_manager.h" | |
| 17 | |
| 18 namespace test { | |
| 19 | |
| 20 namespace { | |
| 21 | |
| 22 const char kTestAccount1[] = "user1@test.com"; | |
| 23 const char kTestAccount2[] = "user2@test.com"; | |
| 24 | |
| 25 class TestBrowserWindowAura : public TestBrowserWindow { | |
|
msw
2015/06/30 18:42:33
Should this file include chrome/test/base/test_bro
xdai1
2015/07/01 01:06:20
It has been included in "chrome/test/base/browser_
| |
| 26 public: | |
| 27 // |native_window| is owned by the caller. | |
| 28 explicit TestBrowserWindowAura(aura::Window* native_window) | |
| 29 : native_window_(native_window) {} | |
| 30 ~TestBrowserWindowAura() override {} | |
| 31 | |
| 32 // TestBrowserWindow override. | |
| 33 aura::Window* GetNativeWindow() const override { | |
| 34 return native_window_.get(); | |
| 35 } | |
| 36 | |
| 37 Browser* browser() { return browser_.get(); } | |
| 38 | |
| 39 void CreateBrowser(const Browser::CreateParams& params) { | |
| 40 Browser::CreateParams create_params = params; | |
| 41 create_params.window = this; | |
| 42 browser_.reset(new Browser(create_params)); | |
| 43 } | |
| 44 | |
| 45 private: | |
| 46 scoped_ptr<Browser> browser_; | |
| 47 scoped_ptr<aura::Window> native_window_; | |
| 48 | |
| 49 DISALLOW_COPY_AND_ASSIGN(TestBrowserWindowAura); | |
| 50 }; | |
| 51 | |
| 52 } // namespace | |
| 53 | |
| 54 class BrowserFinderChromeOSTest : public BrowserWithTestWindowTest { | |
| 55 protected: | |
| 56 BrowserFinderChromeOSTest() : multi_user_window_manager_(NULL) {} | |
|
msw
2015/06/30 18:42:34
nit: nullptr
xdai1
2015/07/01 01:06:20
Done.
| |
| 57 | |
| 58 TestingProfile* CreateMultiUserProfile(const std::string& user_email) { | |
|
msw
2015/06/30 18:42:33
Why not inline this in the CreateProfile override
xdai1
2015/07/01 01:06:20
CreateProfile() is override from BrowserWithTestWi
| |
| 59 TestingProfile* profile = | |
| 60 profile_manager()->CreateTestingProfile(user_email); | |
|
msw
2015/06/30 18:42:34
nit: use profile_manager_ and remove the accessor.
xdai1
2015/07/01 01:06:20
Done.
| |
| 61 created_profiles_[profile] = user_email; | |
| 62 GetUserWindowManager()->AddUser(profile); | |
| 63 return profile; | |
| 64 } | |
| 65 | |
| 66 scoped_ptr<TestBrowserWindowAura> CreateBrowserWindowWithProfile( | |
|
msw
2015/06/30 18:42:33
This and TestBrowserWindowAura seem very odd to me
xdai1
2015/07/01 01:06:21
In BrowserWithTestWindowTest, the |window_| is usu
| |
| 67 Profile* profile, | |
| 68 bool is_incognito) { | |
| 69 // Create a window. | |
| 70 aura::Window* window = new aura::Window(NULL); | |
| 71 window->set_id(0); | |
| 72 window->SetType(ui::wm::WINDOW_TYPE_NORMAL); | |
| 73 window->Init(ui::LAYER_TEXTURED); | |
| 74 window->Show(); | |
| 75 | |
| 76 scoped_ptr<TestBrowserWindowAura> browser_window( | |
| 77 new TestBrowserWindowAura(window)); | |
| 78 if (is_incognito) { | |
| 79 Browser::CreateParams params(profile->GetOffTheRecordProfile(), | |
| 80 chrome::HOST_DESKTOP_TYPE_ASH); | |
| 81 browser_window->CreateBrowser(params); | |
| 82 } else { | |
| 83 Browser::CreateParams params(profile->GetOriginalProfile(), | |
| 84 chrome::HOST_DESKTOP_TYPE_ASH); | |
| 85 browser_window->CreateBrowser(params); | |
| 86 } | |
| 87 return browser_window.Pass(); | |
| 88 } | |
| 89 | |
| 90 chrome::MultiUserWindowManagerChromeOS* GetUserWindowManager() { | |
| 91 if (!multi_user_window_manager_) { | |
| 92 multi_user_window_manager_ = | |
| 93 new chrome::MultiUserWindowManagerChromeOS(kTestAccount1); | |
| 94 multi_user_window_manager_->Init(); | |
| 95 chrome::MultiUserWindowManager::SetInstanceForTest( | |
| 96 multi_user_window_manager_, | |
| 97 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED); | |
| 98 } | |
| 99 return multi_user_window_manager_; | |
| 100 } | |
| 101 | |
| 102 private: | |
| 103 void SetUp() override { | |
| 104 profile_manager_.reset( | |
| 105 new TestingProfileManager(TestingBrowserProcess::GetGlobal())); | |
| 106 ASSERT_TRUE(profile_manager_->SetUp()); | |
| 107 profile_manager_->SetLoggedIn(true); | |
| 108 chromeos::WallpaperManager::Initialize(); | |
|
msw
2015/06/30 18:42:33
q: why do we need this?
xdai1
2015/07/01 01:06:20
This will be used in CreateMultiUserProfile() func
| |
| 109 BrowserWithTestWindowTest::SetUp(); | |
| 110 } | |
| 111 | |
| 112 void TearDown() override { | |
| 113 chrome::MultiUserWindowManager::DeleteInstance(); | |
| 114 BrowserWithTestWindowTest::TearDown(); | |
| 115 chromeos::WallpaperManager::Shutdown(); | |
| 116 for (ProfileToNameMap::iterator it = created_profiles_.begin(); | |
| 117 it != created_profiles_.end(); ++it) { | |
| 118 profile_manager_->DeleteTestingProfile(it->second); | |
| 119 } | |
| 120 } | |
| 121 | |
| 122 TestingProfileManager* profile_manager() { return profile_manager_.get(); } | |
| 123 | |
| 124 // Override BrowserWithTestWindowTest. | |
| 125 TestingProfile* CreateProfile() override { | |
| 126 return CreateMultiUserProfile(kTestAccount1); | |
| 127 } | |
| 128 void DestroyProfile(TestingProfile* profile) override { | |
| 129 ProfileToNameMap::iterator it = created_profiles_.find(profile); | |
| 130 DCHECK(it != created_profiles_.end()); | |
| 131 profile_manager_->DeleteTestingProfile(it->second); | |
| 132 created_profiles_.erase(it); | |
| 133 } | |
| 134 | |
| 135 scoped_ptr<TestingProfileManager> profile_manager_; | |
| 136 chrome::MultiUserWindowManagerChromeOS* multi_user_window_manager_; | |
| 137 | |
| 138 typedef std::map<Profile*, std::string> ProfileToNameMap; | |
|
msw
2015/06/30 18:42:33
Why is this needed? Can't you just use GetProfileU
xdai1
2015/07/01 01:06:20
Removed this and maintained a raw pointer of the s
| |
| 139 ProfileToNameMap created_profiles_; | |
| 140 }; | |
| 141 | |
| 142 // Test the matching rules for incognito browser. | |
|
msw
2015/06/30 18:42:33
nit: this comment doesn't add much value, remove i
xdai1
2015/07/01 01:06:21
Done.
| |
| 143 TEST_F(BrowserFinderChromeOSTest, IncognitoBrowserMatchTest) { | |
| 144 // GetBrowserCount() use kMatchAll to find all browser windows for profile(). | |
| 145 EXPECT_EQ(1u, | |
| 146 chrome::GetBrowserCount(profile(), chrome::HOST_DESKTOP_TYPE_ASH)); | |
| 147 EXPECT_TRUE( | |
| 148 chrome::FindAnyBrowser(profile(), true, chrome::HOST_DESKTOP_TYPE_ASH)); | |
| 149 EXPECT_TRUE( | |
| 150 chrome::FindAnyBrowser(profile(), false, chrome::HOST_DESKTOP_TYPE_ASH)); | |
| 151 set_browser(nullptr); | |
| 152 | |
| 153 scoped_ptr<TestBrowserWindowAura> incognito_browser_window = | |
| 154 CreateBrowserWindowWithProfile(profile(), true); | |
| 155 // Incognito windows are excluded in GetBrowserCount() because kMatchAll | |
| 156 // doesn't match original profile of the browser with the given profile. | |
| 157 EXPECT_EQ(0u, | |
| 158 chrome::GetBrowserCount(profile(), chrome::HOST_DESKTOP_TYPE_ASH)); | |
| 159 EXPECT_TRUE( | |
| 160 chrome::FindAnyBrowser(profile(), true, chrome::HOST_DESKTOP_TYPE_ASH)); | |
| 161 EXPECT_FALSE( | |
| 162 chrome::FindAnyBrowser(profile(), false, chrome::HOST_DESKTOP_TYPE_ASH)); | |
| 163 } | |
| 164 | |
| 165 TEST_F(BrowserFinderChromeOSTest, MultiProfileBrowserMatchTest) { | |
|
msw
2015/06/30 18:42:33
nit: name this test something like "FindBrowserOwn
xdai1
2015/07/01 01:06:20
Done.
| |
| 166 set_browser(nullptr); | |
| 167 | |
| 168 // Add another profile. | |
| 169 CreateMultiUserProfile(kTestAccount2); | |
| 170 | |
| 171 scoped_ptr<TestBrowserWindowAura> browser_window = | |
| 172 CreateBrowserWindowWithProfile(profile(), false); | |
| 173 GetUserWindowManager()->SetWindowOwner(browser_window->GetNativeWindow(), | |
| 174 kTestAccount1); | |
| 175 EXPECT_EQ(1u, | |
| 176 chrome::GetBrowserCount(profile(), chrome::HOST_DESKTOP_TYPE_ASH)); | |
| 177 EXPECT_TRUE( | |
| 178 chrome::FindAnyBrowser(profile(), true, chrome::HOST_DESKTOP_TYPE_ASH)); | |
| 179 EXPECT_TRUE( | |
| 180 chrome::FindAnyBrowser(profile(), false, chrome::HOST_DESKTOP_TYPE_ASH)); | |
| 181 | |
| 182 // Move the browser window to another user's desktop. Then no window should | |
| 183 // be avaiable for the current profile. | |
|
msw
2015/06/30 18:42:33
nit: available
xdai1
2015/07/01 01:06:21
Done.
| |
| 184 GetUserWindowManager()->ShowWindowForUser(browser_window->GetNativeWindow(), | |
| 185 kTestAccount2); | |
| 186 EXPECT_EQ(0u, | |
| 187 chrome::GetBrowserCount(profile(), chrome::HOST_DESKTOP_TYPE_ASH)); | |
| 188 EXPECT_FALSE( | |
| 189 chrome::FindAnyBrowser(profile(), true, chrome::HOST_DESKTOP_TYPE_ASH)); | |
| 190 EXPECT_FALSE( | |
| 191 chrome::FindAnyBrowser(profile(), false, chrome::HOST_DESKTOP_TYPE_ASH)); | |
| 192 } | |
| 193 | |
| 194 } // namespace test | |
| OLD | NEW |