1 // Copyright (c) 2012 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 "base/memory/scoped_ptr.h"
6 #include "chrome/browser/chromeos/login/helper.h"
7 #include "chrome/browser/chromeos/login/screens/base_screen.h"
8 #include "chrome/browser/chromeos/login/screens/mock_base_screen_delegate.h"
9 #include "chrome/browser/chromeos/login/screens/network_screen.h"
10 #include "chrome/browser/chromeos/login/test/wizard_in_process_browser_test.h"
11 #include "chrome/browser/chromeos/login/wizard_controller.h"
12 #include "chromeos/dbus/dbus_thread_manager.h"
13 #include "chromeos/dbus/fake_session_manager_client.h"
14 #include "content/public/test/test_utils.h"
15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17 #include "third_party/cros_system_api/dbus/service_constants.h"
18 #include "ui/views/controls/button/button.h"
21 using ::testing::AnyNumber
;
22 using ::testing::Return
;
23 using ::testing::ReturnRef
;
28 class DummyButtonListener
: public views::ButtonListener
{
30 void ButtonPressed(views::Button
* sender
, const ui::Event
& event
) override
{}
35 class MockNetworkStateHelper
: public NetworkStateHelper
{
37 MOCK_CONST_METHOD0(GetCurrentNetworkName
, base::string16(void));
38 MOCK_CONST_METHOD0(IsConnected
, bool(void));
39 MOCK_CONST_METHOD0(IsConnecting
, bool(void));
44 class NetworkScreenTest
: public WizardInProcessBrowserTest
{
46 NetworkScreenTest(): WizardInProcessBrowserTest("network"),
47 fake_session_manager_client_(NULL
) {
51 void SetUpInProcessBrowserTestFixture() override
{
52 WizardInProcessBrowserTest::SetUpInProcessBrowserTestFixture();
54 fake_session_manager_client_
= new FakeSessionManagerClient
;
55 DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient(
56 scoped_ptr
<SessionManagerClient
>(fake_session_manager_client_
));
59 void SetUpOnMainThread() override
{
60 WizardInProcessBrowserTest::SetUpOnMainThread();
61 mock_base_screen_delegate_
.reset(new MockBaseScreenDelegate());
62 ASSERT_TRUE(WizardController::default_controller() != NULL
);
64 NetworkScreen::Get(WizardController::default_controller());
65 ASSERT_TRUE(network_screen_
!= NULL
);
66 ASSERT_EQ(WizardController::default_controller()->current_screen(),
68 network_screen_
->base_screen_delegate_
= mock_base_screen_delegate_
.get();
69 ASSERT_TRUE(network_screen_
->view_
!= nullptr);
71 mock_network_state_helper_
= new login::MockNetworkStateHelper
;
72 SetDefaultNetworkStateHelperExpectations();
73 network_screen_
->SetNetworkStateHelperForTest(mock_network_state_helper_
);
76 void TearDownInProcessBrowserTestFixture() override
{
77 InProcessBrowserTest::TearDownInProcessBrowserTestFixture();
80 void EmulateContinueButtonExit(NetworkScreen
* network_screen
) {
81 EXPECT_CALL(*mock_base_screen_delegate_
,
82 OnExit(_
, BaseScreenDelegate::NETWORK_CONNECTED
, _
)).Times(1);
83 EXPECT_CALL(*mock_network_state_helper_
, IsConnected())
84 .WillOnce(Return(true));
85 network_screen
->OnContinueButtonPressed();
86 content::RunAllPendingInMessageLoop();
89 void SetDefaultNetworkStateHelperExpectations() {
90 EXPECT_CALL(*mock_network_state_helper_
, GetCurrentNetworkName())
92 .WillRepeatedly((Return(base::string16())));
93 EXPECT_CALL(*mock_network_state_helper_
, IsConnected())
95 .WillRepeatedly((Return(false)));
96 EXPECT_CALL(*mock_network_state_helper_
, IsConnecting())
98 .WillRepeatedly((Return(false)));
101 scoped_ptr
<MockBaseScreenDelegate
> mock_base_screen_delegate_
;
102 login::MockNetworkStateHelper
* mock_network_state_helper_
;
103 NetworkScreen
* network_screen_
;
104 FakeSessionManagerClient
* fake_session_manager_client_
;
107 DISALLOW_COPY_AND_ASSIGN(NetworkScreenTest
);
110 IN_PROC_BROWSER_TEST_F(NetworkScreenTest
, CanConnect
) {
111 EXPECT_CALL(*mock_network_state_helper_
, IsConnecting())
112 .WillOnce((Return(true)));
113 // EXPECT_FALSE(actor_->IsContinueEnabled());
114 network_screen_
->UpdateStatus();
116 EXPECT_CALL(*mock_network_state_helper_
, IsConnected())
118 .WillRepeatedly(Return(true));
119 // TODO(nkostylev): Add integration with WebUI actor http://crosbug.com/22570
120 // EXPECT_FALSE(actor_->IsContinueEnabled());
121 // EXPECT_FALSE(actor_->IsConnecting());
122 network_screen_
->UpdateStatus();
124 // EXPECT_TRUE(actor_->IsContinueEnabled());
125 EmulateContinueButtonExit(network_screen_
);
128 IN_PROC_BROWSER_TEST_F(NetworkScreenTest
, Timeout
) {
129 EXPECT_CALL(*mock_network_state_helper_
, IsConnecting())
130 .WillOnce((Return(true)));
131 // EXPECT_FALSE(actor_->IsContinueEnabled());
132 network_screen_
->UpdateStatus();
134 EXPECT_CALL(*mock_network_state_helper_
, IsConnected())
136 .WillRepeatedly(Return(false));
137 // TODO(nkostylev): Add integration with WebUI actor http://crosbug.com/22570
138 // EXPECT_FALSE(actor_->IsContinueEnabled());
139 // EXPECT_FALSE(actor_->IsConnecting());
140 network_screen_
->OnConnectionTimeout();
142 // Close infobubble with error message - it makes the test stable.
143 // EXPECT_FALSE(actor_->IsContinueEnabled());
144 // EXPECT_FALSE(actor_->IsConnecting());
145 // actor_->ClearErrors();
148 } // namespace chromeos