1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
6 #include "ash/test/ash_test_base.h"
7 #include "ash/test/test_session_state_delegate.h"
8 #include "ash/test/test_shell_delegate.h"
9 #include "base/command_line.h"
10 #include "base/compiler_specific.h"
11 #include "base/logging.h"
12 #include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h"
13 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
14 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "ui/base/models/menu_model.h"
17 #include "ui/base/ui_base_types.h"
22 // A test class for preparing the chrome::MultiUserContextMenu.
23 class MultiUserContextMenuChromeOSTest : public AshTestBase {
25 MultiUserContextMenuChromeOSTest() : multi_user_window_manager_(NULL) {}
27 virtual void SetUp() OVERRIDE;
28 virtual void TearDown() OVERRIDE;
31 // Set up the test environment for this many windows.
32 void SetUpForThisManyWindows(int windows);
34 aura::Window* window() { return window_; }
35 chrome::MultiUserWindowManagerChromeOS* multi_user_window_manager() {
36 return multi_user_window_manager_;
39 void SetNumberOfUsers(int users) {
40 ash::test::TestSessionStateDelegate* delegate =
41 static_cast<ash::test::TestSessionStateDelegate*>(
42 ash::Shell::GetInstance()->session_state_delegate());
43 delegate->set_logged_in_users(users);
47 // A window which can be used for testing.
48 aura::Window* window_;
50 // The instance of the MultiUserWindowManager.
51 chrome::MultiUserWindowManagerChromeOS* multi_user_window_manager_;
53 DISALLOW_COPY_AND_ASSIGN(MultiUserContextMenuChromeOSTest);
56 void MultiUserContextMenuChromeOSTest::SetUp() {
57 CommandLine::ForCurrentProcess()->AppendSwitch(switches::kMultiProfiles);
60 window_ = CreateTestWindowInShellWithId(0);
63 multi_user_window_manager_ = new chrome::MultiUserWindowManagerChromeOS("A");
64 chrome::MultiUserWindowManager::SetInstanceForTest(multi_user_window_manager_,
65 chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED);
66 EXPECT_TRUE(multi_user_window_manager_);
69 void MultiUserContextMenuChromeOSTest::TearDown() {
72 chrome::MultiUserWindowManager::DeleteInstance();
73 AshTestBase::TearDown();
76 // Check that an unowned window will never create a menu.
77 TEST_F(MultiUserContextMenuChromeOSTest, UnownedWindow) {
78 EXPECT_EQ(NULL, CreateMultiUserContextMenu(window()).get());
82 EXPECT_EQ(NULL, CreateMultiUserContextMenu(window()).get());
85 // Check that an owned window will never create a menu.
86 TEST_F(MultiUserContextMenuChromeOSTest, OwnedWindow) {
87 // Make the window owned and check that there is no menu (since only a single
89 multi_user_window_manager()->SetWindowOwner(window(), "A");
90 EXPECT_EQ(NULL, CreateMultiUserContextMenu(window()).get());
92 // After adding another user a menu should get created.
95 scoped_ptr<ui::MenuModel> menu = CreateMultiUserContextMenu(window());
96 ASSERT_TRUE(menu.get());
97 EXPECT_EQ(1, menu.get()->GetItemCount());
101 scoped_ptr<ui::MenuModel> menu = CreateMultiUserContextMenu(window());
102 ASSERT_TRUE(menu.get());
103 EXPECT_EQ(2, menu.get()->GetItemCount());