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

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

Issue 1984733002: [Reland] GetAccountIdFromProfile() should not return an empty account id if a valid profile is prov… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/browser_finder.h" 5 #include "chrome/browser/ui/browser_finder.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/test/ash_test_helper.h" 8 #include "ash/test/ash_test_helper.h"
9 #include "ash/test/test_session_state_delegate.h" 9 #include "ash/test/test_session_state_delegate.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
11 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" 12 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
13 #include "chrome/browser/chromeos/profiles/profile_helper.h"
12 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" 14 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
13 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h" 15 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h"
14 #include "chrome/test/base/browser_with_test_window_test.h" 16 #include "chrome/test/base/browser_with_test_window_test.h"
15 #include "chrome/test/base/test_browser_window_aura.h" 17 #include "chrome/test/base/test_browser_window_aura.h"
16 #include "chrome/test/base/testing_browser_process.h" 18 #include "chrome/test/base/testing_browser_process.h"
17 #include "chrome/test/base/testing_profile_manager.h" 19 #include "chrome/test/base/testing_profile_manager.h"
18 #include "components/signin/core/account_id/account_id.h" 20 #include "components/signin/core/account_id/account_id.h"
21 #include "components/user_manager/fake_user_manager.h"
22 #include "components/user_manager/user.h"
19 23
20 namespace test { 24 namespace test {
21 25
22 namespace { 26 namespace {
23 27
24 const char kTestAccount1[] = "user1@test.com"; 28 const char kTestAccount1[] = "user1@test.com";
25 const char kTestAccount2[] = "user2@test.com"; 29 const char kTestAccount2[] = "user2@test.com";
26 30
27 } // namespace 31 } // namespace
28 32
29 class BrowserFinderChromeOSTest : public BrowserWithTestWindowTest { 33 class BrowserFinderChromeOSTest : public BrowserWithTestWindowTest {
30 protected: 34 protected:
31 BrowserFinderChromeOSTest() : multi_user_window_manager_(nullptr) {} 35 BrowserFinderChromeOSTest()
36 : multi_user_window_manager_(nullptr),
37 fake_user_manager_(new user_manager::FakeUserManager),
38 user_manager_enabler_(fake_user_manager_) {}
32 39
33 TestingProfile* CreateMultiUserProfile(const AccountId& account_id) { 40 TestingProfile* CreateMultiUserProfile(const AccountId& account_id) {
34 TestingProfile* profile = 41 TestingProfile* profile =
35 profile_manager_->CreateTestingProfile(account_id.GetUserEmail()); 42 profile_manager_->CreateTestingProfile(account_id.GetUserEmail());
36 GetUserWindowManager()->AddUser(profile); 43 const user_manager::User* user = fake_user_manager_->AddUser(account_id);
44 chromeos::ProfileHelper::Get()->SetUserToProfileMappingForTesting(
45 const_cast<user_manager::User*>(user), profile);
46 chromeos::ProfileHelper::Get()->SetProfileToUserMappingForTesting(
47 const_cast<user_manager::User*>(user));
37 ash::test::AshTestHelper::GetTestSessionStateDelegate()->AddUser( 48 ash::test::AshTestHelper::GetTestSessionStateDelegate()->AddUser(
38 account_id); 49 account_id);
50 GetUserWindowManager()->AddUser(profile);
39 return profile; 51 return profile;
40 } 52 }
41 53
42 chrome::MultiUserWindowManagerChromeOS* GetUserWindowManager() { 54 chrome::MultiUserWindowManagerChromeOS* GetUserWindowManager() {
43 if (!multi_user_window_manager_) { 55 if (!multi_user_window_manager_) {
44 multi_user_window_manager_ = 56 multi_user_window_manager_ =
45 new chrome::MultiUserWindowManagerChromeOS(test_account_id1_); 57 new chrome::MultiUserWindowManagerChromeOS(test_account_id1_);
46 multi_user_window_manager_->Init(); 58 multi_user_window_manager_->Init();
47 chrome::MultiUserWindowManager::SetInstanceForTest( 59 chrome::MultiUserWindowManager::SetInstanceForTest(
48 multi_user_window_manager_, 60 multi_user_window_manager_,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 return CreateMultiUserProfile(test_account_id1_); 93 return CreateMultiUserProfile(test_account_id1_);
82 } 94 }
83 95
84 void DestroyProfile(TestingProfile* test_profile) override { 96 void DestroyProfile(TestingProfile* test_profile) override {
85 profile_manager_->DeleteTestingProfile(test_profile->GetProfileUserName()); 97 profile_manager_->DeleteTestingProfile(test_profile->GetProfileUserName());
86 } 98 }
87 99
88 TestingProfile* second_profile_; 100 TestingProfile* second_profile_;
89 std::unique_ptr<TestingProfileManager> profile_manager_; 101 std::unique_ptr<TestingProfileManager> profile_manager_;
90 chrome::MultiUserWindowManagerChromeOS* multi_user_window_manager_; 102 chrome::MultiUserWindowManagerChromeOS* multi_user_window_manager_;
103 user_manager::FakeUserManager* fake_user_manager_; // Not owned.
104 chromeos::ScopedUserManagerEnabler user_manager_enabler_;
91 105
92 DISALLOW_COPY_AND_ASSIGN(BrowserFinderChromeOSTest); 106 DISALLOW_COPY_AND_ASSIGN(BrowserFinderChromeOSTest);
93 }; 107 };
94 108
95 TEST_F(BrowserFinderChromeOSTest, IncognitoBrowserMatchTest) { 109 TEST_F(BrowserFinderChromeOSTest, IncognitoBrowserMatchTest) {
96 // GetBrowserCount() use kMatchAll to find all browser windows for profile(). 110 // GetBrowserCount() use kMatchAll to find all browser windows for profile().
97 EXPECT_EQ(1u, chrome::GetBrowserCount(profile())); 111 EXPECT_EQ(1u, chrome::GetBrowserCount(profile()));
98 EXPECT_TRUE(chrome::FindAnyBrowser(profile(), true)); 112 EXPECT_TRUE(chrome::FindAnyBrowser(profile(), true));
99 EXPECT_TRUE(chrome::FindAnyBrowser(profile(), false)); 113 EXPECT_TRUE(chrome::FindAnyBrowser(profile(), false));
100 set_browser(nullptr); 114 set_browser(nullptr);
(...skipping 24 matching lines...) Expand all
125 // Move the browser window to another user's desktop. Then no window should 139 // Move the browser window to another user's desktop. Then no window should
126 // be available for the current profile. 140 // be available for the current profile.
127 GetUserWindowManager()->ShowWindowForUser( 141 GetUserWindowManager()->ShowWindowForUser(
128 browser->window()->GetNativeWindow(), test_account_id2_); 142 browser->window()->GetNativeWindow(), test_account_id2_);
129 EXPECT_EQ(0u, chrome::GetBrowserCount(profile())); 143 EXPECT_EQ(0u, chrome::GetBrowserCount(profile()));
130 EXPECT_FALSE(chrome::FindAnyBrowser(profile(), true)); 144 EXPECT_FALSE(chrome::FindAnyBrowser(profile(), true));
131 EXPECT_FALSE(chrome::FindAnyBrowser(profile(), false)); 145 EXPECT_FALSE(chrome::FindAnyBrowser(profile(), false));
132 } 146 }
133 147
134 } // namespace test 148 } // namespace test
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/multi_user/multi_user_util_chromeos_unittest.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698