| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ash/new_window_controller.h" | 5 #include "ash/new_window_controller.h" |
| 6 #include "ash/shell.h" | 6 #include "ash/shell.h" |
| 7 #include "ash/wm/window_util.h" | 7 #include "ash/wm/window_util.h" |
| 8 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 8 #include "chrome/browser/profiles/profile_manager.h" | 9 #include "chrome/browser/profiles/profile_manager.h" |
| 9 #include "chrome/browser/ui/browser_finder.h" | 10 #include "chrome/browser/ui/browser_finder.h" |
| 10 #include "chrome/browser/ui/browser_window.h" | 11 #include "chrome/browser/ui/browser_window.h" |
| 11 #include "chrome/test/base/in_process_browser_test.h" | 12 #include "chrome/test/base/in_process_browser_test.h" |
| 12 #include "components/session_manager/core/session_manager.h" | 13 #include "components/session_manager/core/session_manager.h" |
| 13 #include "components/signin/core/account_id/account_id.h" | 14 #include "components/signin/core/account_id/account_id.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 | 19 |
| 19 const char kTestUserName1[] = "test1@test.com"; | 20 const char kTestUserName1[] = "test1@test.com"; |
| 20 const char kTestUserName2[] = "test2@test.com"; | 21 const char kTestUserName2[] = "test2@test.com"; |
| 21 | 22 |
| 23 void CreateAndStartUserSession(const AccountId& account_id) { |
| 24 using chromeos::ProfileHelper; |
| 25 using session_manager::SessionManager; |
| 26 |
| 27 const std::string user_id_hash = |
| 28 ProfileHelper::GetUserIdHashByUserIdForTesting(account_id.GetUserEmail()); |
| 29 SessionManager::Get()->CreateSession(account_id, user_id_hash); |
| 30 ProfileHelper::GetProfileByUserIdHashForTest(user_id_hash); |
| 31 SessionManager::Get()->SessionStarted(); |
| 32 } |
| 33 |
| 22 } // namespace | 34 } // namespace |
| 23 | 35 |
| 24 using ChromeNewWindowClientBrowserTest = InProcessBrowserTest; | 36 using ChromeNewWindowClientBrowserTest = InProcessBrowserTest; |
| 25 | 37 |
| 26 // Tests that when we open a new window by pressing 'Ctrl-N', we should use the | 38 // Tests that when we open a new window by pressing 'Ctrl-N', we should use the |
| 27 // current active window's profile to determine on which profile's desktop we | 39 // current active window's profile to determine on which profile's desktop we |
| 28 // should open a new window. | 40 // should open a new window. |
| 29 IN_PROC_BROWSER_TEST_F(ChromeNewWindowClientBrowserTest, | 41 IN_PROC_BROWSER_TEST_F(ChromeNewWindowClientBrowserTest, |
| 30 NewWindowForActiveWindowProfileTest) { | 42 NewWindowForActiveWindowProfileTest) { |
| 31 session_manager::SessionManager::Get()->CreateSession( | 43 CreateAndStartUserSession(AccountId::FromUserEmail(kTestUserName1)); |
| 32 AccountId::FromUserEmail(kTestUserName1), kTestUserName1); | |
| 33 Profile* profile1 = ProfileManager::GetActiveUserProfile(); | 44 Profile* profile1 = ProfileManager::GetActiveUserProfile(); |
| 34 Browser* browser1 = CreateBrowser(profile1); | 45 Browser* browser1 = CreateBrowser(profile1); |
| 35 // The newly created window should be created for the current active profile. | 46 // The newly created window should be created for the current active profile. |
| 36 ash::Shell::Get()->new_window_controller()->NewWindow(false); | 47 ash::Shell::Get()->new_window_controller()->NewWindow(false); |
| 37 EXPECT_EQ( | 48 EXPECT_EQ( |
| 38 chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow())->profile(), | 49 chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow())->profile(), |
| 39 profile1); | 50 profile1); |
| 40 | 51 |
| 41 // Login another user and make sure the current active user changes. | 52 // Login another user and make sure the current active user changes. |
| 42 session_manager::SessionManager::Get()->CreateSession( | 53 CreateAndStartUserSession(AccountId::FromUserEmail(kTestUserName2)); |
| 43 AccountId::FromUserEmail(kTestUserName2), kTestUserName2); | |
| 44 Profile* profile2 = ProfileManager::GetActiveUserProfile(); | 54 Profile* profile2 = ProfileManager::GetActiveUserProfile(); |
| 45 EXPECT_NE(profile1, profile2); | 55 EXPECT_NE(profile1, profile2); |
| 46 | 56 |
| 47 Browser* browser2 = CreateBrowser(profile2); | 57 Browser* browser2 = CreateBrowser(profile2); |
| 48 // The newly created window should be created for the current active window's | 58 // The newly created window should be created for the current active window's |
| 49 // profile, which is |profile2|. | 59 // profile, which is |profile2|. |
| 50 ash::Shell::Get()->new_window_controller()->NewWindow(false); | 60 ash::Shell::Get()->new_window_controller()->NewWindow(false); |
| 51 EXPECT_EQ( | 61 EXPECT_EQ( |
| 52 chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow())->profile(), | 62 chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow())->profile(), |
| 53 profile2); | 63 profile2); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 72 | 82 |
| 73 // The newly created incoginito window should be created against the current | 83 // The newly created incoginito window should be created against the current |
| 74 // active |browser2|'s profile. | 84 // active |browser2|'s profile. |
| 75 browser2->window()->Show(); | 85 browser2->window()->Show(); |
| 76 ash::Shell::Get()->new_window_controller()->NewWindow(true); | 86 ash::Shell::Get()->new_window_controller()->NewWindow(true); |
| 77 EXPECT_EQ(chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()) | 87 EXPECT_EQ(chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()) |
| 78 ->profile() | 88 ->profile() |
| 79 ->GetOriginalProfile(), | 89 ->GetOriginalProfile(), |
| 80 profile2); | 90 profile2); |
| 81 } | 91 } |
| OLD | NEW |