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

Unified Diff: chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos_unittest.cc

Issue 2599833003: ChromeOS: Fix NewWindow's bug with browser on other user's desktop and no browser on current's (Closed)
Patch Set: add test coverage Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/ash/chrome_new_window_client.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos_unittest.cc
diff --git a/chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos_unittest.cc b/chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos_unittest.cc
index aa7d11f77ccf03f108bb0e3afdeb224b9653102d..2114633bfbcbeba414b34e38ea904bdb625068cc 100644
--- a/chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos_unittest.cc
+++ b/chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos_unittest.cc
@@ -34,11 +34,15 @@
#include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h"
#include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
+#include "chrome/browser/ui/ash/chrome_new_window_client.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h"
#include "chrome/browser/ui/ash/multi_user/user_switch_animator_chromeos.h"
#include "chrome/browser/ui/ash/session_util.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_list.h"
+#include "chrome/test/base/test_browser_window_aura.h"
#include "chrome/test/base/testing_browser_process.h"
#include "chrome/test/base/testing_profile.h"
#include "chrome/test/base/testing_profile_manager.h"
@@ -123,6 +127,17 @@ class TestShellDelegateChromeOS : public ash::test::TestShellDelegate {
DISALLOW_COPY_AND_ASSIGN(TestShellDelegateChromeOS);
};
+std::unique_ptr<Browser> CreateTestBrowser(aura::Window* window,
+ const gfx::Rect& bounds,
+ Browser::CreateParams* params) {
+ if (!bounds.IsEmpty())
+ window->SetBounds(bounds);
+ std::unique_ptr<Browser> browser =
+ chrome::CreateBrowserWithAuraTestWindowForParams(base::WrapUnique(window),
+ params);
+ return browser;
+}
+
} // namespace
namespace ash {
@@ -1528,5 +1543,42 @@ TEST_F(MultiUserWindowManagerChromeOSTest, WindowsOrderPreservedTests) {
EXPECT_EQ(mru_list[2], window(2));
}
+// Tests that ChromeNewWindowClient::GetActiveBrowser works properly in
+// multi-user scenario, that is it should return the browser with active window
+// associated with it (crbug.com/675265).
+TEST_F(MultiUserWindowManagerChromeOSTest, GetActiveBrowserTest) {
+ SetUpForThisManyWindows(1);
+
+ const AccountId account_id_A(AccountId::FromUserEmail("A"));
+ const AccountId account_id_B(AccountId::FromUserEmail("B"));
+ AddTestUser(account_id_A);
+ AddTestUser(account_id_B);
+ session_state_delegate()->set_logged_in_users(2);
+ user_manager()->SwitchActiveUser(account_id_A);
+ multi_user_window_manager()->ActiveUserChanged(account_id_A);
+
+ aura::client::ActivationClient* activation_client =
+ aura::client::GetActivationClient(window(0)->GetRootWindow());
+ multi_user_window_manager()->SetWindowOwner(window(0), account_id_A);
+ Profile* profile = multi_user_util::GetProfileFromAccountId(account_id_A);
+ Browser::CreateParams params(profile);
+ std::unique_ptr<Browser> browser(CreateTestBrowser(
+ CreateTestWindowInShellWithId(0), gfx::Rect(16, 32, 640, 320), &params));
+ aura::Window* browser_native_window = browser->window()->GetNativeWindow();
+ activation_client->ActivateWindow(browser_native_window);
+ // Manually set last active browser in BrowserList for testing.
+ BrowserList::GetInstance()->SetLastActive(browser.get());
+ EXPECT_EQ(browser.get(), BrowserList::GetInstance()->GetLastActive());
+ EXPECT_EQ(browser_native_window, wm::GetActiveWindow());
+ EXPECT_EQ(browser.get(), ChromeNewWindowClient::GetActiveBrowser());
+
+ // Switch to another user's desktop with no active window.
+ user_manager()->SwitchActiveUser(account_id_B);
+ multi_user_window_manager()->ActiveUserChanged(account_id_B);
+ EXPECT_EQ(browser.get(), BrowserList::GetInstance()->GetLastActive());
+ EXPECT_EQ(nullptr, wm::GetActiveWindow());
+ EXPECT_EQ(nullptr, ChromeNewWindowClient::GetActiveBrowser());
+}
+
} // namespace test
} // namespace ash
« no previous file with comments | « chrome/browser/ui/ash/chrome_new_window_client.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698