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.
5 #include "ash/session/session_state_delegate.h"
7 #include "base/command_line.h"
8 #include "chrome/browser/chromeos/login/login_manager_test.h"
9 #include "chrome/browser/chromeos/login/startup_utils.h"
10 #include "chrome/browser/profiles/profile_manager.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/browser_finder.h"
13 #include "chrome/browser/ui/browser_window.h"
14 #include "chrome/browser/ui/view_ids.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "ui/views/focus/focus_manager.h"
18 #include "ui/views/view.h"
19 #include "ui/views/widget/widget.h"
25 const char kTestUser
[] = "test-user@gmail.com";
29 class BrowserLoginTest
: public chromeos::LoginManagerTest
{
31 BrowserLoginTest() : LoginManagerTest(true) {}
32 ~BrowserLoginTest() override
{}
34 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
35 LoginManagerTest::SetUpCommandLine(command_line
);
36 command_line
->AppendSwitch(::switches::kCreateBrowserOnStartupForTests
);
40 IN_PROC_BROWSER_TEST_F(BrowserLoginTest
, PRE_BrowserActive
) {
41 RegisterUser(kTestUser
);
42 EXPECT_EQ(ash::SessionStateDelegate::SESSION_STATE_LOGIN_PRIMARY
,
43 ash::Shell::GetInstance()->session_state_delegate()->
45 chromeos::StartupUtils::MarkOobeCompleted();
48 IN_PROC_BROWSER_TEST_F(BrowserLoginTest
, BrowserActive
) {
49 EXPECT_EQ(ash::SessionStateDelegate::SESSION_STATE_LOGIN_PRIMARY
,
50 ash::Shell::GetInstance()->session_state_delegate()->
53 EXPECT_EQ(ash::SessionStateDelegate::SESSION_STATE_ACTIVE
,
54 ash::Shell::GetInstance()->session_state_delegate()->
57 Browser
* browser
= FindAnyBrowser(ProfileManager::GetActiveUserProfile(),
59 chrome::HOST_DESKTOP_TYPE_ASH
);
60 EXPECT_TRUE(browser
!= NULL
);
61 EXPECT_TRUE(browser
->window()->IsActive());
63 gfx::NativeWindow window
= browser
->window()->GetNativeWindow();
64 views::Widget
* widget
= views::Widget::GetWidgetForNativeWindow(window
);
65 views::FocusManager
* focus_manager
= widget
->GetFocusManager();
66 EXPECT_TRUE(focus_manager
!= NULL
);
68 const views::View
* focused_view
= focus_manager
->GetFocusedView();
69 EXPECT_TRUE(focused_view
!= NULL
);
70 EXPECT_EQ(VIEW_ID_OMNIBOX
, focused_view
->id());
73 } // namespace chromeos