Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(94)

Side by Side Diff: chrome/browser/chromeos/login/captive_portal_window_browsertest.cc

Issue 15780006: Added bowser test for Captive Portal Window. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/chromeos/login/captive_portal_window_proxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 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.
4
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/cros/cros_in_process_browser_test.h"
10 #include "chrome/browser/chromeos/login/captive_portal_window_proxy.h"
11 #include "chrome/browser/chromeos/login/login_display_host_impl.h"
12 #include "chromeos/chromeos_switches.h"
13
14 namespace chromeos {
15
16 namespace {
17
18 // Stub implementation of CaptivePortalWindowProxyDelegate, does
19 // nothing and used to instantiate CaptivePortalWindowProxy.
20 class CaptivePortalWindowProxyStubDelegate
21 : public CaptivePortalWindowProxyDelegate {
22 public:
23 CaptivePortalWindowProxyStubDelegate(): num_portal_notifications_(0) {
24 }
25
26 virtual ~CaptivePortalWindowProxyStubDelegate() {
27 }
28
29 virtual void OnPortalDetected() OVERRIDE {
30 ++num_portal_notifications_;
31 }
32
33 int num_portal_notifications() const { return num_portal_notifications_; }
34
35 private:
36 int num_portal_notifications_;
37 };
38
39 } // namespace
40
41 class CaptivePortalWindowTest : public CrosInProcessBrowserTest {
42 protected:
43 void ShowIfRedirected() {
44 captive_portal_window_proxy_->ShowIfRedirected();
45 }
46
47 void Show() {
48 captive_portal_window_proxy_->Show();
49 }
50
51 void Close() {
52 captive_portal_window_proxy_->Close();
53 }
54
55 void OnRedirected() {
56 captive_portal_window_proxy_->OnRedirected();
57 }
58
59 void OnOriginalURLLoaded() {
60 captive_portal_window_proxy_->OnOriginalURLLoaded();
61 }
62
63 void CheckState(bool is_shown, int num_portal_notifications) {
64 bool actual_is_shown = (CaptivePortalWindowProxy::STATE_DISPLAYED ==
65 captive_portal_window_proxy_->GetState());
66 ASSERT_EQ(is_shown, actual_is_shown);
67 ASSERT_EQ(num_portal_notifications, delegate_.num_portal_notifications());
68 }
69
70 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
71 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
72 command_line->AppendSwitch(chromeos::switches::kLoginManager);
73 }
74
75 virtual void SetUpOnMainThread() OVERRIDE {
76 CHECK(LoginDisplayHostImpl::default_host());
77 gfx::NativeWindow native_window =
78 LoginDisplayHostImpl::default_host()->GetNativeWindow();
79 captive_portal_window_proxy_.reset(
80 new CaptivePortalWindowProxy(&delegate_, native_window));
81 }
82
83 private:
84 scoped_ptr<CaptivePortalWindowProxy> captive_portal_window_proxy_;
85 CaptivePortalWindowProxyStubDelegate delegate_;
86 };
87
88 IN_PROC_BROWSER_TEST_F(CaptivePortalWindowTest, ShowClose) {
89 CheckState(false, 0);
90
91 Show();
92 CheckState(true, 0);
93
94 Close();
95 CheckState(false, 0);
96 }
97
98 IN_PROC_BROWSER_TEST_F(CaptivePortalWindowTest, OnRedirected) {
99 CheckState(false, 0);
100
101 ShowIfRedirected();
102 CheckState(false, 0);
103
104 OnRedirected();
105 CheckState(true, 1);
106
107 Close();
108 CheckState(false, 1);
109 }
110
111 IN_PROC_BROWSER_TEST_F(CaptivePortalWindowTest, OnOriginalURLLoaded) {
112 CheckState(false, 0);
113
114 ShowIfRedirected();
115 CheckState(false, 0);
116
117 OnRedirected();
118 CheckState(true, 1);
119
120 OnOriginalURLLoaded();
121 CheckState(false, 1);
122 }
123
124 IN_PROC_BROWSER_TEST_F(CaptivePortalWindowTest, MultipleCalls) {
125 CheckState(false, 0);
126
127 ShowIfRedirected();
128 CheckState(false, 0);
129
130 Show();
131 CheckState(true, 0);
132
133 Close();
134 CheckState(false, 0);
135
136 OnRedirected();
137 CheckState(false, 1);
138
139 OnOriginalURLLoaded();
140 CheckState(false, 1);
141
142 Show();
143 CheckState(true, 1);
144
145 OnRedirected();
146 CheckState(true, 2);
147
148 Close();
149 CheckState(false, 2);
150
151 OnOriginalURLLoaded();
152 CheckState(false, 2);
153 }
154
155 } // namespace chromeos
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/login/captive_portal_window_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698