Chromium Code Reviews| 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/common/new_window_delegate.h" | |
| 6 #include "ash/common/wm_shell.h" | 5 #include "ash/common/wm_shell.h" |
| 6 #include "ash/public/interfaces/new_window.mojom.h" | |
| 7 #include "ash/wm/window_util.h" | 7 #include "ash/wm/window_util.h" |
| 8 #include "chrome/browser/profiles/profile_manager.h" | 8 #include "chrome/browser/profiles/profile_manager.h" |
| 9 #include "chrome/browser/ui/browser_finder.h" | 9 #include "chrome/browser/ui/browser_finder.h" |
| 10 #include "chrome/browser/ui/browser_window.h" | 10 #include "chrome/browser/ui/browser_window.h" |
| 11 #include "chrome/test/base/in_process_browser_test.h" | 11 #include "chrome/test/base/in_process_browser_test.h" |
| 12 #include "components/signin/core/account_id/account_id.h" | 12 #include "components/signin/core/account_id/account_id.h" |
| 13 #include "components/user_manager/user_manager.h" | 13 #include "components/user_manager/user_manager.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 const char kTestUserName1[] = "test1@test.com"; | 19 const char kTestUserName1[] = "test1@test.com"; |
| 20 const char kTestUserName2[] = "test2@test.com"; | 20 const char kTestUserName2[] = "test2@test.com"; |
| 21 | 21 |
| 22 } // namespace | 22 } // namespace |
| 23 | 23 |
| 24 typedef InProcessBrowserTest ChromeNewWindowDelegateBrowserTest; | 24 typedef InProcessBrowserTest ChromeNewWindowClientBrowserTest; |
|
James Cook
2016/10/21 22:22:30
nit: if you're touching it anyway, using foo = bar
Elliot Glaysher
2016/10/21 22:45:56
Done.
| |
| 25 | 25 |
| 26 // Tests that when we open a new window by pressing 'Ctrl-N', we should use the | 26 // 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 | 27 // current active window's profile to determine on which profile's desktop we |
| 28 // should open a new window. | 28 // should open a new window. |
| 29 IN_PROC_BROWSER_TEST_F(ChromeNewWindowDelegateBrowserTest, | 29 IN_PROC_BROWSER_TEST_F(ChromeNewWindowClientBrowserTest, |
| 30 NewWindowForActiveWindowProfileTest) { | 30 NewWindowForActiveWindowProfileTest) { |
| 31 user_manager::UserManager::Get()->UserLoggedIn( | 31 user_manager::UserManager::Get()->UserLoggedIn( |
| 32 AccountId::FromUserEmail(kTestUserName1), kTestUserName1, false); | 32 AccountId::FromUserEmail(kTestUserName1), kTestUserName1, false); |
| 33 Profile* profile1 = ProfileManager::GetActiveUserProfile(); | 33 Profile* profile1 = ProfileManager::GetActiveUserProfile(); |
| 34 Browser* browser1 = CreateBrowser(profile1); | 34 Browser* browser1 = CreateBrowser(profile1); |
| 35 // The newly created window should be created for the current active profile. | 35 // The newly created window should be created for the current active profile. |
| 36 ash::WmShell::Get()->new_window_delegate()->NewWindow(false); | 36 ash::WmShell::Get()->new_window_client()->NewWindow(false); |
| 37 EXPECT_EQ( | 37 EXPECT_EQ( |
| 38 chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow())->profile(), | 38 chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow())->profile(), |
| 39 profile1); | 39 profile1); |
| 40 | 40 |
| 41 // Login another user and make sure the current active user changes. | 41 // Login another user and make sure the current active user changes. |
| 42 user_manager::UserManager::Get()->UserLoggedIn( | 42 user_manager::UserManager::Get()->UserLoggedIn( |
| 43 AccountId::FromUserEmail(kTestUserName2), kTestUserName2, false); | 43 AccountId::FromUserEmail(kTestUserName2), kTestUserName2, false); |
| 44 Profile* profile2 = ProfileManager::GetActiveUserProfile(); | 44 Profile* profile2 = ProfileManager::GetActiveUserProfile(); |
| 45 EXPECT_NE(profile1, profile2); | 45 EXPECT_NE(profile1, profile2); |
| 46 | 46 |
| 47 Browser* browser2 = CreateBrowser(profile2); | 47 Browser* browser2 = CreateBrowser(profile2); |
| 48 // The newly created window should be created for the current active window's | 48 // The newly created window should be created for the current active window's |
| 49 // profile, which is |profile2|. | 49 // profile, which is |profile2|. |
| 50 ash::WmShell::Get()->new_window_delegate()->NewWindow(false); | 50 ash::WmShell::Get()->new_window_client()->NewWindow(false); |
| 51 EXPECT_EQ( | 51 EXPECT_EQ( |
| 52 chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow())->profile(), | 52 chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow())->profile(), |
| 53 profile2); | 53 profile2); |
| 54 | 54 |
| 55 // After activating |browser1|, the newly created window should be created | 55 // After activating |browser1|, the newly created window should be created |
| 56 // against |browser1|'s profile. | 56 // against |browser1|'s profile. |
| 57 browser1->window()->Show(); | 57 browser1->window()->Show(); |
| 58 ash::WmShell::Get()->new_window_delegate()->NewWindow(false); | 58 ash::WmShell::Get()->new_window_client()->NewWindow(false); |
| 59 EXPECT_EQ( | 59 EXPECT_EQ( |
| 60 chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow())->profile(), | 60 chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow())->profile(), |
| 61 profile1); | 61 profile1); |
| 62 | 62 |
| 63 // Test for incognito windows. | 63 // Test for incognito windows. |
| 64 // The newly created incoginito window should be created against the current | 64 // The newly created incoginito window should be created against the current |
| 65 // active |browser1|'s profile. | 65 // active |browser1|'s profile. |
| 66 browser1->window()->Show(); | 66 browser1->window()->Show(); |
| 67 ash::WmShell::Get()->new_window_delegate()->NewWindow(true); | 67 ash::WmShell::Get()->new_window_client()->NewWindow(true); |
| 68 EXPECT_EQ(chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()) | 68 EXPECT_EQ(chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()) |
| 69 ->profile() | 69 ->profile() |
| 70 ->GetOriginalProfile(), | 70 ->GetOriginalProfile(), |
| 71 profile1); | 71 profile1); |
| 72 | 72 |
| 73 // The newly created incoginito window should be created against the current | 73 // The newly created incoginito window should be created against the current |
| 74 // active |browser2|'s profile. | 74 // active |browser2|'s profile. |
| 75 browser2->window()->Show(); | 75 browser2->window()->Show(); |
| 76 ash::WmShell::Get()->new_window_delegate()->NewWindow(true); | 76 ash::WmShell::Get()->new_window_client()->NewWindow(true); |
| 77 EXPECT_EQ(chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()) | 77 EXPECT_EQ(chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()) |
| 78 ->profile() | 78 ->profile() |
| 79 ->GetOriginalProfile(), | 79 ->GetOriginalProfile(), |
| 80 profile2); | 80 profile2); |
| 81 } | 81 } |
| OLD | NEW |