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

Side by Side Diff: chrome/browser/login_prompt_uitest.cc

Issue 5606002: Move:... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years 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 | « chrome/browser/login_prompt_mac.mm ('k') | chrome/browser/login_prompt_unittest.cc » ('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) 2006-2008 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 <string>
6
7 #include "chrome/browser/net/url_fixer_upper.h"
8 #include "chrome/common/chrome_switches.h"
9 #include "chrome/common/url_constants.h"
10 #include "chrome/test/automation/tab_proxy.h"
11 #include "chrome/test/automation/browser_proxy.h"
12 #include "chrome/test/ui/ui_test.h"
13 #include "net/test/test_server.h"
14
15 using std::wstring;
16
17 namespace {
18
19 const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data");
20
21 } // namespace
22
23 class LoginPromptTest : public UITest {
24 protected:
25 LoginPromptTest()
26 : username_basic_(L"basicuser"),
27 username_digest_(L"digestuser"),
28 password_(L"secret"),
29 password_bad_(L"denyme"),
30 test_server_(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)) {
31 }
32
33 void AppendTab(const GURL& url) {
34 scoped_refptr<BrowserProxy> window_proxy(automation()->GetBrowserWindow(0));
35 ASSERT_TRUE(window_proxy.get());
36 ASSERT_TRUE(window_proxy->AppendTab(url));
37 }
38
39 protected:
40 wstring username_basic_;
41 wstring username_digest_;
42 wstring password_;
43 wstring password_bad_;
44
45 net::TestServer test_server_;
46 };
47
48 wstring ExpectedTitleFromAuth(const wstring& username,
49 const wstring& password) {
50 // The TestServer sets the title to username/password on successful login.
51 return username + L"/" + password;
52 }
53
54 #if defined(OS_WIN)
55 // Probably related to test server flakiness in http://crbug.com/60937
56 #define MAYBE_TestBasicAuth FLAKY_TestBasicAuth
57 #else
58 #define MAYBE_TestBasicAuth TestBasicAuth
59 #endif
60
61 // Test that "Basic" HTTP authentication works.
62 TEST_F(LoginPromptTest, MAYBE_TestBasicAuth) {
63 ASSERT_TRUE(test_server_.Start());
64
65 scoped_refptr<TabProxy> tab(GetActiveTab());
66 ASSERT_TRUE(tab.get());
67 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED,
68 tab->NavigateToURL(test_server_.GetURL("auth-basic")));
69
70 EXPECT_TRUE(tab->NeedsAuth());
71 EXPECT_FALSE(tab->SetAuth(username_basic_, password_bad_));
72 EXPECT_TRUE(tab->NeedsAuth());
73 EXPECT_TRUE(tab->CancelAuth());
74 EXPECT_EQ(L"Denied: wrong password", GetActiveTabTitle());
75
76 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED,
77 tab->NavigateToURL(test_server_.GetURL("auth-basic")));
78
79 EXPECT_TRUE(tab->NeedsAuth());
80 EXPECT_TRUE(tab->SetAuth(username_basic_, password_));
81 EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_),
82 GetActiveTabTitle());
83 }
84
85 #if defined(OS_WIN)
86 // Probably related to test server flakiness in http://crbug.com/60937
87 #define MAYBE_TestDigestAuth FLAKY_TestDigestAuth
88 #else
89 #define MAYBE_TestDigestAuth TestDigestAuth
90 #endif
91
92 // Test that "Digest" HTTP authentication works.
93 TEST_F(LoginPromptTest, MAYBE_TestDigestAuth) {
94 ASSERT_TRUE(test_server_.Start());
95
96 scoped_refptr<TabProxy> tab(GetActiveTab());
97 ASSERT_TRUE(tab.get());
98 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED,
99 tab->NavigateToURL(test_server_.GetURL("auth-digest")));
100
101 EXPECT_TRUE(tab->NeedsAuth());
102 EXPECT_FALSE(tab->SetAuth(username_digest_, password_bad_));
103 EXPECT_TRUE(tab->CancelAuth());
104 EXPECT_EQ(L"Denied: wrong password", GetActiveTabTitle());
105
106 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED,
107 tab->NavigateToURL(test_server_.GetURL("auth-digest")));
108
109 EXPECT_TRUE(tab->NeedsAuth());
110 EXPECT_TRUE(tab->SetAuth(username_digest_, password_));
111 EXPECT_EQ(ExpectedTitleFromAuth(username_digest_, password_),
112 GetActiveTabTitle());
113 }
114
115 #if defined(OS_WIN)
116 // Probably related to test server flakiness in http://crbug.com/60937
117 #define MAYBE_TestTwoAuths FLAKY_TestTwoAuths
118 #else
119 #define MAYBE_TestTwoAuths TestTwoAuths
120 #endif
121
122 // Test that logging in on 2 tabs at once works.
123 TEST_F(LoginPromptTest, MAYBE_TestTwoAuths) {
124 ASSERT_TRUE(test_server_.Start());
125
126 scoped_refptr<TabProxy> basic_tab(GetActiveTab());
127 ASSERT_TRUE(basic_tab.get());
128 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED,
129 basic_tab->NavigateToURL(test_server_.GetURL("auth-basic")));
130
131 AppendTab(GURL(chrome::kAboutBlankURL));
132 scoped_refptr<TabProxy> digest_tab(GetActiveTab());
133 ASSERT_TRUE(digest_tab.get());
134 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED,
135 digest_tab->NavigateToURL(test_server_.GetURL("auth-digest")));
136
137 EXPECT_TRUE(basic_tab->NeedsAuth());
138 EXPECT_TRUE(basic_tab->SetAuth(username_basic_, password_));
139 EXPECT_TRUE(digest_tab->NeedsAuth());
140 EXPECT_TRUE(digest_tab->SetAuth(username_digest_, password_));
141
142 wstring title;
143 EXPECT_TRUE(basic_tab->GetTabTitle(&title));
144 EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_), title);
145
146 EXPECT_TRUE(digest_tab->GetTabTitle(&title));
147 EXPECT_EQ(ExpectedTitleFromAuth(username_digest_, password_), title);
148 }
149
150 #if defined(OS_WIN)
151 // Probably related to test server flakiness in http://crbug.com/60937
152 #define MAYBE_TestCancelAuth FLAKY_TestCancelAuth
153 #else
154 #define MAYBE_TestCancelAuth TestCancelAuth
155 #endif
156
157 // Test that cancelling authentication works.
158 TEST_F(LoginPromptTest, MAYBE_TestCancelAuth) {
159 ASSERT_TRUE(test_server_.Start());
160
161 scoped_refptr<TabProxy> tab(GetActiveTab());
162 ASSERT_TRUE(tab.get());
163
164 // First navigate to a test server page so we have something to go back to.
165 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS,
166 tab->NavigateToURL(test_server_.GetURL("a")));
167
168 // Navigating while auth is requested is the same as cancelling.
169 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED,
170 tab->NavigateToURL(test_server_.GetURL("auth-basic")));
171 EXPECT_TRUE(tab->NeedsAuth());
172 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS,
173 tab->NavigateToURL(test_server_.GetURL("b")));
174 EXPECT_FALSE(tab->NeedsAuth());
175
176 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED,
177 tab->NavigateToURL(test_server_.GetURL("auth-basic")));
178 EXPECT_TRUE(tab->NeedsAuth());
179 EXPECT_TRUE(tab->GoBack()); // should bring us back to 'a'
180 EXPECT_FALSE(tab->NeedsAuth());
181
182 // Now add a page and go back, so we have something to go forward to.
183 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS,
184 tab->NavigateToURL(test_server_.GetURL("c")));
185 EXPECT_TRUE(tab->GoBack()); // should bring us back to 'a'
186
187 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED,
188 tab->NavigateToURL(test_server_.GetURL("auth-basic")));
189 EXPECT_TRUE(tab->NeedsAuth());
190 EXPECT_TRUE(tab->GoForward()); // should bring us to 'c'
191 EXPECT_FALSE(tab->NeedsAuth());
192
193 // Now test that cancelling works as expected.
194 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED,
195 tab->NavigateToURL(test_server_.GetURL("auth-basic")));
196 EXPECT_TRUE(tab->NeedsAuth());
197 EXPECT_TRUE(tab->CancelAuth());
198 EXPECT_FALSE(tab->NeedsAuth());
199 EXPECT_EQ(L"Denied: no auth", GetActiveTabTitle());
200 }
201
202 #if defined(OS_WIN)
203 // Probably related to test server flakiness in http://crbug.com/60937
204 #define MAYBE_SupplyRedundantAuths FLAKY_SupplyRedundantAuths
205 #else
206 #define MAYBE_SupplyRedundantAuths SupplyRedundantAuths
207 #endif
208
209 // If multiple tabs are looking for the same auth, the user should only have to
210 // enter it once.
211 TEST_F(LoginPromptTest, MAYBE_SupplyRedundantAuths) {
212 ASSERT_TRUE(test_server_.Start());
213
214 scoped_refptr<TabProxy> basic_tab1(GetActiveTab());
215 ASSERT_TRUE(basic_tab1.get());
216 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED,
217 basic_tab1->NavigateToURL(test_server_.GetURL("auth-basic/1")));
218 EXPECT_TRUE(basic_tab1->NeedsAuth());
219
220 AppendTab(GURL(chrome::kAboutBlankURL));
221 scoped_refptr<TabProxy> basic_tab2(GetActiveTab());
222 ASSERT_TRUE(basic_tab2.get());
223 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED,
224 basic_tab2->NavigateToURL(test_server_.GetURL("auth-basic/2")));
225 EXPECT_TRUE(basic_tab2->NeedsAuth());
226
227 // Set the auth in only one of the tabs (but wait for the other to load).
228 int64 last_navigation_time;
229 ASSERT_TRUE(basic_tab2->GetLastNavigationTime(&last_navigation_time));
230 EXPECT_TRUE(basic_tab1->SetAuth(username_basic_, password_));
231 EXPECT_TRUE(basic_tab2->WaitForNavigation(last_navigation_time));
232
233 // Now both tabs have loaded.
234 wstring title1;
235 EXPECT_TRUE(basic_tab1->GetTabTitle(&title1));
236 EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_), title1);
237 wstring title2;
238 EXPECT_TRUE(basic_tab2->GetTabTitle(&title2));
239 EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_), title2);
240 }
241
242 #if defined(OS_WIN)
243 // Probably related to test server flakiness in http://crbug.com/60937
244 #define MAYBE_CancelRedundantAuths FLAKY_CancelRedundantAuths
245 #else
246 #define MAYBE_CancelRedundantAuths CancelRedundantAuths
247 #endif
248
249 // If multiple tabs are looking for the same auth, and one is cancelled, the
250 // other should be cancelled as well.
251 TEST_F(LoginPromptTest, MAYBE_CancelRedundantAuths) {
252 ASSERT_TRUE(test_server_.Start());
253
254 scoped_refptr<TabProxy> basic_tab1(GetActiveTab());
255 ASSERT_TRUE(basic_tab1.get());
256 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED,
257 basic_tab1->NavigateToURL(test_server_.GetURL("auth-basic/1")));
258 EXPECT_TRUE(basic_tab1->NeedsAuth());
259
260 AppendTab(GURL(chrome::kAboutBlankURL));
261 scoped_refptr<TabProxy> basic_tab2(GetActiveTab());
262 ASSERT_TRUE(basic_tab2.get());
263 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED,
264 basic_tab2->NavigateToURL(test_server_.GetURL("auth-basic/2")));
265 EXPECT_TRUE(basic_tab2->NeedsAuth());
266
267 // Cancel the auth in only one of the tabs (but wait for the other to load).
268 int64 last_navigation_time;
269 ASSERT_TRUE(basic_tab2->GetLastNavigationTime(&last_navigation_time));
270 EXPECT_TRUE(basic_tab1->CancelAuth());
271 EXPECT_TRUE(basic_tab2->WaitForNavigation(last_navigation_time));
272
273 // Now both tabs have been denied.
274 wstring title1;
275 EXPECT_TRUE(basic_tab1->GetTabTitle(&title1));
276 EXPECT_EQ(L"Denied: no auth", title1);
277 wstring title2;
278 EXPECT_TRUE(basic_tab2->GetTabTitle(&title2));
279 EXPECT_EQ(L"Denied: no auth", title2);
280 }
OLDNEW
« no previous file with comments | « chrome/browser/login_prompt_mac.mm ('k') | chrome/browser/login_prompt_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698