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

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: Added captive_portal_window_borwsertest.cc to git index. Created 7 years, 7 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
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 ASSERT_EQ(is_shown, captive_portal_window_proxy_->IsShown());
65 ASSERT_EQ(num_portal_notifications, delegate_.num_portal_notifications());
66 }
67
68 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
69 command_line->AppendSwitch(chromeos::switches::kForceLoginManagerInTests);
70 command_line->AppendSwitch(chromeos::switches::kLoginManager);
71 }
72
73 virtual void SetUpOnMainThread() OVERRIDE {
74 CHECK(LoginDisplayHostImpl::default_host());
75 gfx::NativeWindow native_window =
76 LoginDisplayHostImpl::default_host()->GetNativeWindow();
77 captive_portal_window_proxy_.reset(
78 new CaptivePortalWindowProxy(&delegate_, native_window));
79 }
80
81 private:
82 scoped_ptr<CaptivePortalWindowProxy> captive_portal_window_proxy_;
83 CaptivePortalWindowProxyStubDelegate delegate_;
84 };
85
86 IN_PROC_BROWSER_TEST_F(CaptivePortalWindowTest, ShowClose) {
87 CheckState(false, 0);
88
89 Show();
90 CheckState(true, 0);
91
92 Close();
93 CheckState(false, 0);
94 }
95
96 IN_PROC_BROWSER_TEST_F(CaptivePortalWindowTest, OnRedirected) {
97 CheckState(false, 0);
98
99 ShowIfRedirected();
100 CheckState(false, 0);
101
102 OnRedirected();
103 CheckState(true, 1);
104
105 Close();
106 CheckState(false, 1);
107 }
108
109 IN_PROC_BROWSER_TEST_F(CaptivePortalWindowTest, OnOriginalURLLoaded) {
110 CheckState(false, 0);
111
112 ShowIfRedirected();
113 CheckState(false, 0);
114
115 OnRedirected();
116 CheckState(true, 1);
117
118 OnOriginalURLLoaded();
119 CheckState(false, 1);
120 }
121
122 IN_PROC_BROWSER_TEST_F(CaptivePortalWindowTest, MultipleCalls) {
123 CheckState(false, 0);
124
125 ShowIfRedirected();
126 CheckState(false, 0);
127
128 Show();
129 CheckState(true, 0);
130
131 Close();
132 CheckState(false, 0);
133
134 OnRedirected();
135 CheckState(true, 1);
Nikita (slow) 2013/05/27 16:55:35 It makes sense to improve UX which this test shows
ygorshenin1 2013/05/28 10:04:14 Done.
136
137 OnOriginalURLLoaded();
138 CheckState(false, 1);
139
140 Show();
141 CheckState(true, 1);
142
143 OnRedirected();
144 CheckState(true, 2);
145
146 Close();
147 CheckState(false, 2);
148
149 OnOriginalURLLoaded();
150 CheckState(false, 2);
151 }
152
153 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698