Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / chromeos / login / captive_portal_window_browsertest.cc
blob3dc117b5fdc11fc4cf11ff4d1ffb3acb9689d254
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"
15 namespace chromeos {
17 namespace {
19 // Stub implementation of CaptivePortalWindowProxyDelegate, does
20 // nothing and used to instantiate CaptivePortalWindowProxy.
21 class CaptivePortalWindowProxyStubDelegate
22 : public CaptivePortalWindowProxyDelegate {
23 public:
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_; }
36 private:
37 int num_portal_notifications_;
40 } // namespace
42 class CaptivePortalWindowTest : public InProcessBrowserTest {
43 protected:
44 void ShowIfRedirected() {
45 captive_portal_window_proxy_->ShowIfRedirected();
48 void Show() {
49 captive_portal_window_proxy_->Show();
52 void Close() {
53 captive_portal_window_proxy_->Close();
56 void OnRedirected() {
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()->
80 GetWebContents();
81 captive_portal_window_proxy_.reset(
82 new CaptivePortalWindowProxy(&delegate_, web_contents));
85 private:
86 scoped_ptr<CaptivePortalWindowProxy> captive_portal_window_proxy_;
87 CaptivePortalWindowProxyStubDelegate delegate_;
90 IN_PROC_BROWSER_TEST_F(CaptivePortalWindowTest, ShowClose) {
91 CheckState(false, 0);
93 Show();
94 CheckState(true, 0);
96 Close();
97 CheckState(false, 0);
100 IN_PROC_BROWSER_TEST_F(CaptivePortalWindowTest, OnRedirected) {
101 CheckState(false, 0);
103 ShowIfRedirected();
104 CheckState(false, 0);
106 OnRedirected();
107 CheckState(true, 1);
109 Close();
110 CheckState(false, 1);
113 IN_PROC_BROWSER_TEST_F(CaptivePortalWindowTest, OnOriginalURLLoaded) {
114 CheckState(false, 0);
116 ShowIfRedirected();
117 CheckState(false, 0);
119 OnRedirected();
120 CheckState(true, 1);
122 OnOriginalURLLoaded();
123 CheckState(false, 1);
126 IN_PROC_BROWSER_TEST_F(CaptivePortalWindowTest, MultipleCalls) {
127 CheckState(false, 0);
129 ShowIfRedirected();
130 CheckState(false, 0);
132 Show();
133 CheckState(true, 0);
135 Close();
136 CheckState(false, 0);
138 OnRedirected();
139 CheckState(false, 1);
141 OnOriginalURLLoaded();
142 CheckState(false, 1);
144 Show();
145 CheckState(true, 1);
147 OnRedirected();
148 CheckState(true, 2);
150 Close();
151 CheckState(false, 2);
153 OnOriginalURLLoaded();
154 CheckState(false, 2);
157 } // namespace chromeos