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

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

Issue 1880923003: GetAccountIdFromProfile() should not return an empty account id if a valid profile is provided. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address rogerta@'s comments. Rebase 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 GetUserWindowManager()->AddUser(profile);
44 const user_manager::User* user = fake_user_manager_->AddUser(account_id);
45 chromeos::ProfileHelper::Get()->SetProfileToUserMappingForTesting(
46 const_cast<user_manager::User*>(user));
37 ash::test::AshTestHelper::GetTestSessionStateDelegate()->AddUser( 47 ash::test::AshTestHelper::GetTestSessionStateDelegate()->AddUser(
38 account_id); 48 account_id);
39 return profile; 49 return profile;
40 } 50 }
41 51
42 chrome::MultiUserWindowManagerChromeOS* GetUserWindowManager() { 52 chrome::MultiUserWindowManagerChromeOS* GetUserWindowManager() {
43 if (!multi_user_window_manager_) { 53 if (!multi_user_window_manager_) {
44 multi_user_window_manager_ = 54 multi_user_window_manager_ =
45 new chrome::MultiUserWindowManagerChromeOS(test_account_id1_); 55 new chrome::MultiUserWindowManagerChromeOS(test_account_id1_);
46 multi_user_window_manager_->Init(); 56 multi_user_window_manager_->Init();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 return CreateMultiUserProfile(test_account_id1_); 91 return CreateMultiUserProfile(test_account_id1_);
82 } 92 }
83 93
84 void DestroyProfile(TestingProfile* test_profile) override { 94 void DestroyProfile(TestingProfile* test_profile) override {
85 profile_manager_->DeleteTestingProfile(test_profile->GetProfileUserName()); 95 profile_manager_->DeleteTestingProfile(test_profile->GetProfileUserName());
86 } 96 }
87 97
88 TestingProfile* second_profile_; 98 TestingProfile* second_profile_;
89 std::unique_ptr<TestingProfileManager> profile_manager_; 99 std::unique_ptr<TestingProfileManager> profile_manager_;
90 chrome::MultiUserWindowManagerChromeOS* multi_user_window_manager_; 100 chrome::MultiUserWindowManagerChromeOS* multi_user_window_manager_;
101 user_manager::FakeUserManager* fake_user_manager_; // Not owned.
102 chromeos::ScopedUserManagerEnabler user_manager_enabler_;
91 103
92 DISALLOW_COPY_AND_ASSIGN(BrowserFinderChromeOSTest); 104 DISALLOW_COPY_AND_ASSIGN(BrowserFinderChromeOSTest);
93 }; 105 };
94 106
95 TEST_F(BrowserFinderChromeOSTest, IncognitoBrowserMatchTest) { 107 TEST_F(BrowserFinderChromeOSTest, IncognitoBrowserMatchTest) {
96 // GetBrowserCount() use kMatchAll to find all browser windows for profile(). 108 // GetBrowserCount() use kMatchAll to find all browser windows for profile().
97 EXPECT_EQ(1u, chrome::GetBrowserCount(profile())); 109 EXPECT_EQ(1u, chrome::GetBrowserCount(profile()));
98 EXPECT_TRUE(chrome::FindAnyBrowser(profile(), true)); 110 EXPECT_TRUE(chrome::FindAnyBrowser(profile(), true));
99 EXPECT_TRUE(chrome::FindAnyBrowser(profile(), false)); 111 EXPECT_TRUE(chrome::FindAnyBrowser(profile(), false));
100 set_browser(nullptr); 112 set_browser(nullptr);
(...skipping 24 matching lines...) Expand all
125 // Move the browser window to another user's desktop. Then no window should 137 // Move the browser window to another user's desktop. Then no window should
126 // be available for the current profile. 138 // be available for the current profile.
127 GetUserWindowManager()->ShowWindowForUser( 139 GetUserWindowManager()->ShowWindowForUser(
128 browser->window()->GetNativeWindow(), test_account_id2_); 140 browser->window()->GetNativeWindow(), test_account_id2_);
129 EXPECT_EQ(0u, chrome::GetBrowserCount(profile())); 141 EXPECT_EQ(0u, chrome::GetBrowserCount(profile()));
130 EXPECT_FALSE(chrome::FindAnyBrowser(profile(), true)); 142 EXPECT_FALSE(chrome::FindAnyBrowser(profile(), true));
131 EXPECT_FALSE(chrome::FindAnyBrowser(profile(), false)); 143 EXPECT_FALSE(chrome::FindAnyBrowser(profile(), false));
132 } 144 }
133 145
134 } // namespace test 146 } // 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