Upstream version 5.34.92.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / ash / multi_user / multi_user_context_menu_chromeos_unittest.cc
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.
4
5 #include "ash/shell.h"
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"
18
19 namespace ash {
20 namespace test {
21
22 // A test class for preparing the chrome::MultiUserContextMenu.
23 class MultiUserContextMenuChromeOSTest : public AshTestBase {
24  public:
25   MultiUserContextMenuChromeOSTest() : multi_user_window_manager_(NULL) {}
26
27   virtual void SetUp() OVERRIDE;
28   virtual void TearDown() OVERRIDE;
29
30  protected:
31   // Set up the test environment for this many windows.
32   void SetUpForThisManyWindows(int windows);
33
34   aura::Window* window() { return window_; }
35   chrome::MultiUserWindowManagerChromeOS* multi_user_window_manager() {
36     return multi_user_window_manager_;
37   }
38
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);
44   }
45
46  private:
47   // A window which can be used for testing.
48   aura::Window* window_;
49
50   // The instance of the MultiUserWindowManager.
51   chrome::MultiUserWindowManagerChromeOS* multi_user_window_manager_;
52
53   DISALLOW_COPY_AND_ASSIGN(MultiUserContextMenuChromeOSTest);
54 };
55
56 void MultiUserContextMenuChromeOSTest::SetUp() {
57   CommandLine::ForCurrentProcess()->AppendSwitch(switches::kMultiProfiles);
58   AshTestBase::SetUp();
59
60   window_ = CreateTestWindowInShellWithId(0);
61   window_->Show();
62
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_);
67 }
68
69 void MultiUserContextMenuChromeOSTest::TearDown() {
70   delete window_;
71
72   chrome::MultiUserWindowManager::DeleteInstance();
73   AshTestBase::TearDown();
74 }
75
76 // Check that an unowned window will never create a menu.
77 TEST_F(MultiUserContextMenuChromeOSTest, UnownedWindow) {
78   EXPECT_EQ(NULL, CreateMultiUserContextMenu(window()).get());
79
80   // Add more users.
81   SetNumberOfUsers(2);
82   EXPECT_EQ(NULL, CreateMultiUserContextMenu(window()).get());
83 }
84
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
88   // user exists).
89   multi_user_window_manager()->SetWindowOwner(window(), "A");
90   EXPECT_EQ(NULL, CreateMultiUserContextMenu(window()).get());
91
92   // After adding another user a menu should get created.
93   {
94     SetNumberOfUsers(2);
95     scoped_ptr<ui::MenuModel> menu = CreateMultiUserContextMenu(window());
96     ASSERT_TRUE(menu.get());
97     EXPECT_EQ(1, menu.get()->GetItemCount());
98   }
99   {
100     SetNumberOfUsers(3);
101     scoped_ptr<ui::MenuModel> menu = CreateMultiUserContextMenu(window());
102     ASSERT_TRUE(menu.get());
103     EXPECT_EQ(2, menu.get()->GetItemCount());
104   }
105 }
106
107 }  // namespace test
108 }  // namespace ash