Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / login / screens / network_screen_browsertest.cc
blob6ecde46a78d21b5fdc1eeef5e47e5a8551247e5f
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/mock_screen_observer.h"
8 #include "chrome/browser/chromeos/login/screens/network_screen.h"
9 #include "chrome/browser/chromeos/login/screens/wizard_screen.h"
10 #include "chrome/browser/chromeos/login/wizard_controller.h"
11 #include "chrome/browser/chromeos/login/wizard_in_process_browser_test.h"
12 #include "chrome/test/base/ui_test_utils.h"
13 #include "chromeos/dbus/fake_dbus_thread_manager.h"
14 #include "chromeos/dbus/fake_session_manager_client.h"
15 #include "content/public/test/test_utils.h"
16 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "third_party/cros_system_api/dbus/service_constants.h"
19 #include "ui/views/controls/button/button.h"
21 using ::testing::_;
22 using ::testing::AnyNumber;
23 using ::testing::Return;
24 using ::testing::ReturnRef;
25 using views::Button;
27 namespace chromeos {
29 class DummyButtonListener : public views::ButtonListener {
30 public:
31 virtual void ButtonPressed(views::Button* sender,
32 const ui::Event& event) OVERRIDE {}
35 namespace login {
37 class MockNetworkStateHelper : public NetworkStateHelper {
38 public:
39 MOCK_CONST_METHOD0(GetCurrentNetworkName, base::string16(void));
40 MOCK_CONST_METHOD0(IsConnected, bool(void));
41 MOCK_CONST_METHOD0(IsConnecting, bool(void));
44 } // namespace login
46 class NetworkScreenTest : public WizardInProcessBrowserTest {
47 public:
48 NetworkScreenTest(): WizardInProcessBrowserTest("network"),
49 fake_session_manager_client_(NULL) {
52 protected:
53 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
54 WizardInProcessBrowserTest::SetUpInProcessBrowserTestFixture();
56 FakeDBusThreadManager* fake_dbus_thread_manager = new FakeDBusThreadManager;
57 fake_dbus_thread_manager->SetFakeClients();
58 fake_session_manager_client_ = new FakeSessionManagerClient;
59 fake_dbus_thread_manager->SetSessionManagerClient(
60 scoped_ptr<SessionManagerClient>(fake_session_manager_client_));
61 DBusThreadManager::SetInstanceForTesting(fake_dbus_thread_manager);
64 virtual void SetUpOnMainThread() OVERRIDE {
65 WizardInProcessBrowserTest::SetUpOnMainThread();
66 mock_screen_observer_.reset(new MockScreenObserver());
67 ASSERT_TRUE(WizardController::default_controller() != NULL);
68 network_screen_ =
69 WizardController::default_controller()->GetNetworkScreen();
70 ASSERT_TRUE(network_screen_ != NULL);
71 ASSERT_EQ(WizardController::default_controller()->current_screen(),
72 network_screen_);
73 network_screen_->screen_observer_ = mock_screen_observer_.get();
74 ASSERT_TRUE(network_screen_->actor() != NULL);
76 mock_network_state_helper_ = new login::MockNetworkStateHelper;
77 SetDefaultNetworkStateHelperExpectations();
78 network_screen_->SetNetworkStateHelperForTest(mock_network_state_helper_);
81 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE {
82 InProcessBrowserTest::TearDownInProcessBrowserTestFixture();
85 void EmulateContinueButtonExit(NetworkScreen* network_screen) {
86 EXPECT_CALL(*mock_screen_observer_,
87 OnExit(ScreenObserver::NETWORK_CONNECTED))
88 .Times(1);
89 EXPECT_CALL(*mock_network_state_helper_, IsConnected())
90 .WillOnce(Return(true));
91 network_screen->OnContinuePressed();
92 content::RunAllPendingInMessageLoop();
95 void SetDefaultNetworkStateHelperExpectations() {
96 EXPECT_CALL(*mock_network_state_helper_, GetCurrentNetworkName())
97 .Times(AnyNumber())
98 .WillRepeatedly((Return(base::string16())));
99 EXPECT_CALL(*mock_network_state_helper_, IsConnected())
100 .Times(AnyNumber())
101 .WillRepeatedly((Return(false)));
102 EXPECT_CALL(*mock_network_state_helper_, IsConnecting())
103 .Times(AnyNumber())
104 .WillRepeatedly((Return(false)));
107 scoped_ptr<MockScreenObserver> mock_screen_observer_;
108 login::MockNetworkStateHelper* mock_network_state_helper_;
109 NetworkScreen* network_screen_;
110 FakeSessionManagerClient* fake_session_manager_client_;
112 private:
113 DISALLOW_COPY_AND_ASSIGN(NetworkScreenTest);
116 IN_PROC_BROWSER_TEST_F(NetworkScreenTest, CanConnect) {
117 EXPECT_CALL(*mock_network_state_helper_, IsConnecting())
118 .WillOnce((Return(true)));
119 // EXPECT_FALSE(actor_->IsContinueEnabled());
120 network_screen_->UpdateStatus();
122 EXPECT_CALL(*mock_network_state_helper_, IsConnected())
123 .Times(2)
124 .WillRepeatedly(Return(true));
125 // TODO(nkostylev): Add integration with WebUI actor http://crosbug.com/22570
126 // EXPECT_FALSE(actor_->IsContinueEnabled());
127 // EXPECT_FALSE(actor_->IsConnecting());
128 network_screen_->UpdateStatus();
130 // EXPECT_TRUE(actor_->IsContinueEnabled());
131 EmulateContinueButtonExit(network_screen_);
132 EXPECT_EQ(
133 1, fake_session_manager_client_->emit_login_prompt_ready_call_count());
136 IN_PROC_BROWSER_TEST_F(NetworkScreenTest, Timeout) {
137 EXPECT_CALL(*mock_network_state_helper_, IsConnecting())
138 .WillOnce((Return(true)));
139 // EXPECT_FALSE(actor_->IsContinueEnabled());
140 network_screen_->UpdateStatus();
142 EXPECT_CALL(*mock_network_state_helper_, IsConnected())
143 .Times(2)
144 .WillRepeatedly(Return(false));
145 // TODO(nkostylev): Add integration with WebUI actor http://crosbug.com/22570
146 // EXPECT_FALSE(actor_->IsContinueEnabled());
147 // EXPECT_FALSE(actor_->IsConnecting());
148 network_screen_->OnConnectionTimeout();
150 // Close infobubble with error message - it makes the test stable.
151 // EXPECT_FALSE(actor_->IsContinueEnabled());
152 // EXPECT_FALSE(actor_->IsConnecting());
153 // actor_->ClearErrors();
154 EXPECT_EQ(
155 1, fake_session_manager_client_->emit_login_prompt_ready_call_count());
158 } // namespace chromeos