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

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

Issue 74363004: Switching to the correct desktop when a system modal dialog gets shown (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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
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 7c83eb1950739e6560318104704b39ce051f5964..985dcd99cd5d2bf83d5e04b35abff8904c238fcd 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
@@ -2,8 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "ash/root_window_controller.h"
#include "ash/shell.h"
+#include "ash/shell_window_ids.h"
#include "ash/test/ash_test_base.h"
+#include "ash/test/test_session_state_delegate.h"
#include "ash/test/test_shell_delegate.h"
#include "ash/wm/window_state.h"
#include "base/command_line.h"
@@ -25,7 +28,9 @@ namespace test {
// various windows and instantiates the chrome::MultiUserWindowManager.
class MultiUserWindowManagerChromeOSTest : public AshTestBase {
public:
- MultiUserWindowManagerChromeOSTest() : multi_user_window_manager_(NULL) {}
+ MultiUserWindowManagerChromeOSTest()
+ : multi_user_window_manager_(NULL),
+ session_state_delegate_(NULL) {}
virtual void SetUp() OVERRIDE;
virtual void TearDown() OVERRIDE;
@@ -52,6 +57,20 @@ class MultiUserWindowManagerChromeOSTest : public AshTestBase {
// shown by A.
std::string GetStatus();
+ TestSessionStateDelegate* session_state_delegate() {
+ return session_state_delegate_;
+ }
+
+ // Make a window system modal.
+ void MakeWindowSystemModal(aura::Window* window) {
+ ash::internal::RootWindowController* controller =
+ ash::internal::GetRootWindowController(window->GetRootWindow());
+ aura::Window* system_modal_container =
+ controller->GetContainer(
+ ash::internal::kShellWindowId_SystemModalContainer);
+ system_modal_container->AddChild(window);
+ }
+
private:
// These get created for each session.
std::vector<aura::Window*> window_;
@@ -59,12 +78,18 @@ class MultiUserWindowManagerChromeOSTest : public AshTestBase {
// The instance of the MultiUserWindowManager.
chrome::MultiUserWindowManagerChromeOS* multi_user_window_manager_;
+ // The session state delegate.
+ ash::test::TestSessionStateDelegate* session_state_delegate_;
+
DISALLOW_COPY_AND_ASSIGN(MultiUserWindowManagerChromeOSTest);
};
void MultiUserWindowManagerChromeOSTest::SetUp() {
CommandLine::ForCurrentProcess()->AppendSwitch(switches::kMultiProfiles);
AshTestBase::SetUp();
+ session_state_delegate_ =
+ static_cast<TestSessionStateDelegate*> (
+ ash::Shell::GetInstance()->session_state_delegate());
}
void MultiUserWindowManagerChromeOSTest::SetUpForThisManyWindows(int windows) {
@@ -509,5 +534,67 @@ TEST_F(MultiUserWindowManagerChromeOSTest, PreserveInitialVisibility) {
EXPECT_EQ("H[A,B], H[A,B], S[B,A], H[B,A]", GetStatus());
}
+// Test that a system modal dialog will switch to the desktop of the owning
+// user.
+TEST_F(MultiUserWindowManagerChromeOSTest, SwitchUsersUponModalityChange) {
+ SetUpForThisManyWindows(1);
+ session_state_delegate()->SwitchActiveUser("a");
+
+ // Making the window system modal should not change anything.
+ MakeWindowSystemModal(window(0));
+ EXPECT_EQ("a", session_state_delegate()->get_activated_user());
+
+ // Making the window owned by user B should switch users.
+ multi_user_window_manager()->SetWindowOwner(window(0), "b");
+ EXPECT_EQ("b", session_state_delegate()->get_activated_user());
+}
+
+// Test that a system modal dialog will not switch desktop if active user has
+// shows window.
+TEST_F(MultiUserWindowManagerChromeOSTest, DontSwitchUsersUponModalityChange) {
+ SetUpForThisManyWindows(1);
+ session_state_delegate()->SwitchActiveUser("a");
+
+ // Making the window system modal should not change anything.
+ MakeWindowSystemModal(window(0));
+ EXPECT_EQ("a", session_state_delegate()->get_activated_user());
+
+ // Making the window owned by user a should not switch users.
+ multi_user_window_manager()->SetWindowOwner(window(0), "a");
+ EXPECT_EQ("a", session_state_delegate()->get_activated_user());
+}
+
+// Test that a system modal dialog will not switch if shown on correct desktop
+// but owned by another user.
+TEST_F(MultiUserWindowManagerChromeOSTest,
+ DontSwitchUsersUponModalityChangeWhenShownButNotOwned) {
+ SetUpForThisManyWindows(1);
+ session_state_delegate()->SwitchActiveUser("a");
+
+ window(0)->Hide();
+ multi_user_window_manager()->SetWindowOwner(window(0), "b");
+ multi_user_window_manager()->ShowWindowForUser(window(0), "a");
+ MakeWindowSystemModal(window(0));
+ // Showing the window should trigger no user switch.
+ window(0)->Show();
+ EXPECT_EQ("a", session_state_delegate()->get_activated_user());
+}
+
+// Test that a system modal dialog will switch if shown on incorrect desktop but
+// even if owned by current user.
+TEST_F(MultiUserWindowManagerChromeOSTest,
+ SwitchUsersUponModalityChangeWhenShownButNotOwned) {
+ SetUpForThisManyWindows(1);
+ session_state_delegate()->SwitchActiveUser("a");
+
+ window(0)->Hide();
+ multi_user_window_manager()->SetWindowOwner(window(0), "a");
+ multi_user_window_manager()->ShowWindowForUser(window(0), "b");
+ MakeWindowSystemModal(window(0));
+ // Showing the window should trigger a user switch.
+ window(0)->Show();
+ EXPECT_EQ("b", session_state_delegate()->get_activated_user());
+}
+
} // namespace test
} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698