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 "base/command_line.h"
6 #include "base/compiler_specific.h"
7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "chrome/browser/chromeos/login/captive_portal_window_proxy.h"
10 #include "chrome/browser/chromeos/login/login_display_host_impl.h"
11 #include "chrome/browser/chromeos/login/webui_login_view.h"
12 #include "chrome/test/base/in_process_browser_test.h"
13 #include "chromeos/chromeos_switches.h"
19 // Stub implementation of CaptivePortalWindowProxyDelegate, does
20 // nothing and used to instantiate CaptivePortalWindowProxy.
21 class CaptivePortalWindowProxyStubDelegate
22 : public CaptivePortalWindowProxyDelegate
{
24 CaptivePortalWindowProxyStubDelegate(): num_portal_notifications_(0) {
27 virtual ~CaptivePortalWindowProxyStubDelegate() {
30 virtual void OnPortalDetected() OVERRIDE
{
31 ++num_portal_notifications_
;
34 int num_portal_notifications() const { return num_portal_notifications_
; }
37 int num_portal_notifications_
;
42 class CaptivePortalWindowTest
: public InProcessBrowserTest
{
44 void ShowIfRedirected() {
45 captive_portal_window_proxy_
->ShowIfRedirected();
49 captive_portal_window_proxy_
->Show();
53 captive_portal_window_proxy_
->Close();
57 captive_portal_window_proxy_
->OnRedirected();
60 void OnOriginalURLLoaded() {
61 captive_portal_window_proxy_
->OnOriginalURLLoaded();
64 void CheckState(bool is_shown
, int num_portal_notifications
) {
65 bool actual_is_shown
= (CaptivePortalWindowProxy::STATE_DISPLAYED
==
66 captive_portal_window_proxy_
->GetState());
67 ASSERT_EQ(is_shown
, actual_is_shown
);
68 ASSERT_EQ(num_portal_notifications
, delegate_
.num_portal_notifications());
71 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
72 command_line
->AppendSwitch(chromeos::switches::kForceLoginManagerInTests
);
73 command_line
->AppendSwitch(chromeos::switches::kLoginManager
);
76 virtual void SetUpOnMainThread() OVERRIDE
{
77 CHECK(LoginDisplayHostImpl::default_host());
78 content::WebContents
* web_contents
=
79 LoginDisplayHostImpl::default_host()->GetWebUILoginView()->
81 captive_portal_window_proxy_
.reset(
82 new CaptivePortalWindowProxy(&delegate_
, web_contents
));
86 scoped_ptr
<CaptivePortalWindowProxy
> captive_portal_window_proxy_
;
87 CaptivePortalWindowProxyStubDelegate delegate_
;
90 IN_PROC_BROWSER_TEST_F(CaptivePortalWindowTest
, ShowClose
) {
100 IN_PROC_BROWSER_TEST_F(CaptivePortalWindowTest
, OnRedirected
) {
101 CheckState(false, 0);
104 CheckState(false, 0);
110 CheckState(false, 1);
113 IN_PROC_BROWSER_TEST_F(CaptivePortalWindowTest
, OnOriginalURLLoaded
) {
114 CheckState(false, 0);
117 CheckState(false, 0);
122 OnOriginalURLLoaded();
123 CheckState(false, 1);
126 IN_PROC_BROWSER_TEST_F(CaptivePortalWindowTest
, MultipleCalls
) {
127 CheckState(false, 0);
130 CheckState(false, 0);
136 CheckState(false, 0);
139 CheckState(false, 1);
141 OnOriginalURLLoaded();
142 CheckState(false, 1);
151 CheckState(false, 2);
153 OnOriginalURLLoaded();
154 CheckState(false, 2);
157 } // namespace chromeos