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

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

Issue 3034038: GTTF: Move more test server code from net/url_request/url_request_unittest.h (Closed)
Patch Set: hopefully final Created 10 years, 4 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
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 6
7 #include "chrome/browser/net/url_fixer_upper.h" 7 #include "chrome/browser/net/url_fixer_upper.h"
8 #include "chrome/common/chrome_switches.h" 8 #include "chrome/common/chrome_switches.h"
9 #include "chrome/common/url_constants.h" 9 #include "chrome/common/url_constants.h"
10 #include "chrome/test/automation/tab_proxy.h" 10 #include "chrome/test/automation/tab_proxy.h"
11 #include "chrome/test/automation/browser_proxy.h" 11 #include "chrome/test/automation/browser_proxy.h"
12 #include "chrome/test/ui/ui_test.h" 12 #include "chrome/test/ui/ui_test.h"
13 #include "net/url_request/url_request_unittest.h" 13 #include "net/test/test_server.h"
14 14
15 using std::wstring; 15 using std::wstring;
16 16
17 namespace { 17 namespace {
18 18
19 const wchar_t kDocRoot[] = L"chrome/test/data"; 19 const wchar_t kDocRoot[] = L"chrome/test/data";
20 20
21 } // namespace 21 } // namespace
22 22
23 class LoginPromptTest : public UITest { 23 class LoginPromptTest : public UITest {
(...skipping 20 matching lines...) Expand all
44 }; 44 };
45 45
46 wstring ExpectedTitleFromAuth(const wstring& username, 46 wstring ExpectedTitleFromAuth(const wstring& username,
47 const wstring& password) { 47 const wstring& password) {
48 // The TestServer sets the title to username/password on successful login. 48 // The TestServer sets the title to username/password on successful login.
49 return username + L"/" + password; 49 return username + L"/" + password;
50 } 50 }
51 51
52 // Test that "Basic" HTTP authentication works. 52 // Test that "Basic" HTTP authentication works.
53 TEST_F(LoginPromptTest, TestBasicAuth) { 53 TEST_F(LoginPromptTest, TestBasicAuth) {
54 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); 54 scoped_refptr<net::HTTPTestServer> server(
55 net::HTTPTestServer::CreateServer(kDocRoot));
55 ASSERT_TRUE(NULL != server.get()); 56 ASSERT_TRUE(NULL != server.get());
56 scoped_refptr<TabProxy> tab(GetActiveTab()); 57 scoped_refptr<TabProxy> tab(GetActiveTab());
57 ASSERT_TRUE(tab.get()); 58 ASSERT_TRUE(tab.get());
58 ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-basic"))); 59 ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-basic")));
59 60
60 EXPECT_TRUE(tab->NeedsAuth()); 61 EXPECT_TRUE(tab->NeedsAuth());
61 EXPECT_FALSE(tab->SetAuth(username_basic_, password_bad_)); 62 EXPECT_FALSE(tab->SetAuth(username_basic_, password_bad_));
62 EXPECT_TRUE(tab->NeedsAuth()); 63 EXPECT_TRUE(tab->NeedsAuth());
63 EXPECT_TRUE(tab->CancelAuth()); 64 EXPECT_TRUE(tab->CancelAuth());
64 EXPECT_EQ(L"Denied: wrong password", GetActiveTabTitle()); 65 EXPECT_EQ(L"Denied: wrong password", GetActiveTabTitle());
65 66
66 ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-basic"))); 67 ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-basic")));
67 68
68 EXPECT_TRUE(tab->NeedsAuth()); 69 EXPECT_TRUE(tab->NeedsAuth());
69 EXPECT_TRUE(tab->SetAuth(username_basic_, password_)); 70 EXPECT_TRUE(tab->SetAuth(username_basic_, password_));
70 EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_), 71 EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_),
71 GetActiveTabTitle()); 72 GetActiveTabTitle());
72 } 73 }
73 74
74 // Test that "Digest" HTTP authentication works. 75 // Test that "Digest" HTTP authentication works.
75 TEST_F(LoginPromptTest, TestDigestAuth) { 76 TEST_F(LoginPromptTest, TestDigestAuth) {
76 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); 77 scoped_refptr<net::HTTPTestServer> server(
78 net::HTTPTestServer::CreateServer(kDocRoot));
77 ASSERT_TRUE(NULL != server.get()); 79 ASSERT_TRUE(NULL != server.get());
78 scoped_refptr<TabProxy> tab(GetActiveTab()); 80 scoped_refptr<TabProxy> tab(GetActiveTab());
79 ASSERT_TRUE(tab.get()); 81 ASSERT_TRUE(tab.get());
80 ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-digest"))); 82 ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-digest")));
81 83
82 EXPECT_TRUE(tab->NeedsAuth()); 84 EXPECT_TRUE(tab->NeedsAuth());
83 EXPECT_FALSE(tab->SetAuth(username_digest_, password_bad_)); 85 EXPECT_FALSE(tab->SetAuth(username_digest_, password_bad_));
84 EXPECT_TRUE(tab->CancelAuth()); 86 EXPECT_TRUE(tab->CancelAuth());
85 EXPECT_EQ(L"Denied: wrong password", GetActiveTabTitle()); 87 EXPECT_EQ(L"Denied: wrong password", GetActiveTabTitle());
86 88
87 ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-digest"))); 89 ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-digest")));
88 90
89 EXPECT_TRUE(tab->NeedsAuth()); 91 EXPECT_TRUE(tab->NeedsAuth());
90 EXPECT_TRUE(tab->SetAuth(username_digest_, password_)); 92 EXPECT_TRUE(tab->SetAuth(username_digest_, password_));
91 EXPECT_EQ(ExpectedTitleFromAuth(username_digest_, password_), 93 EXPECT_EQ(ExpectedTitleFromAuth(username_digest_, password_),
92 GetActiveTabTitle()); 94 GetActiveTabTitle());
93 } 95 }
94 96
95 // Test that logging in on 2 tabs at once works. 97 // Test that logging in on 2 tabs at once works.
96 TEST_F(LoginPromptTest, TestTwoAuths) { 98 TEST_F(LoginPromptTest, TestTwoAuths) {
97 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); 99 scoped_refptr<net::HTTPTestServer> server(
100 net::HTTPTestServer::CreateServer(kDocRoot));
98 ASSERT_TRUE(NULL != server.get()); 101 ASSERT_TRUE(NULL != server.get());
99 102
100 scoped_refptr<TabProxy> basic_tab(GetActiveTab()); 103 scoped_refptr<TabProxy> basic_tab(GetActiveTab());
101 ASSERT_TRUE(basic_tab.get()); 104 ASSERT_TRUE(basic_tab.get());
102 ASSERT_TRUE(basic_tab->NavigateToURL(server->TestServerPage("auth-basic"))); 105 ASSERT_TRUE(basic_tab->NavigateToURL(server->TestServerPage("auth-basic")));
103 106
104 AppendTab(GURL(chrome::kAboutBlankURL)); 107 AppendTab(GURL(chrome::kAboutBlankURL));
105 scoped_refptr<TabProxy> digest_tab(GetActiveTab()); 108 scoped_refptr<TabProxy> digest_tab(GetActiveTab());
106 ASSERT_TRUE(digest_tab.get()); 109 ASSERT_TRUE(digest_tab.get());
107 ASSERT_TRUE( 110 ASSERT_TRUE(
108 digest_tab->NavigateToURL(server->TestServerPage("auth-digest"))); 111 digest_tab->NavigateToURL(server->TestServerPage("auth-digest")));
109 112
110 EXPECT_TRUE(basic_tab->NeedsAuth()); 113 EXPECT_TRUE(basic_tab->NeedsAuth());
111 EXPECT_TRUE(basic_tab->SetAuth(username_basic_, password_)); 114 EXPECT_TRUE(basic_tab->SetAuth(username_basic_, password_));
112 EXPECT_TRUE(digest_tab->NeedsAuth()); 115 EXPECT_TRUE(digest_tab->NeedsAuth());
113 EXPECT_TRUE(digest_tab->SetAuth(username_digest_, password_)); 116 EXPECT_TRUE(digest_tab->SetAuth(username_digest_, password_));
114 117
115 wstring title; 118 wstring title;
116 EXPECT_TRUE(basic_tab->GetTabTitle(&title)); 119 EXPECT_TRUE(basic_tab->GetTabTitle(&title));
117 EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_), title); 120 EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_), title);
118 121
119 EXPECT_TRUE(digest_tab->GetTabTitle(&title)); 122 EXPECT_TRUE(digest_tab->GetTabTitle(&title));
120 EXPECT_EQ(ExpectedTitleFromAuth(username_digest_, password_), title); 123 EXPECT_EQ(ExpectedTitleFromAuth(username_digest_, password_), title);
121 } 124 }
122 125
123 // Test that cancelling authentication works. 126 // Test that cancelling authentication works.
124 TEST_F(LoginPromptTest, TestCancelAuth) { 127 TEST_F(LoginPromptTest, TestCancelAuth) {
125 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); 128 scoped_refptr<net::HTTPTestServer> server(
129 net::HTTPTestServer::CreateServer(kDocRoot));
126 ASSERT_TRUE(NULL != server.get()); 130 ASSERT_TRUE(NULL != server.get());
127 scoped_refptr<TabProxy> tab(GetActiveTab()); 131 scoped_refptr<TabProxy> tab(GetActiveTab());
128 ASSERT_TRUE(tab.get()); 132 ASSERT_TRUE(tab.get());
129 133
130 // First navigate to a test server page so we have something to go back to. 134 // First navigate to a test server page so we have something to go back to.
131 ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("a"))); 135 ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("a")));
132 136
133 // Navigating while auth is requested is the same as cancelling. 137 // Navigating while auth is requested is the same as cancelling.
134 ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-basic"))); 138 ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-basic")));
135 EXPECT_TRUE(tab->NeedsAuth()); 139 EXPECT_TRUE(tab->NeedsAuth());
(...skipping 18 matching lines...) Expand all
154 ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-basic"))); 158 ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-basic")));
155 EXPECT_TRUE(tab->NeedsAuth()); 159 EXPECT_TRUE(tab->NeedsAuth());
156 EXPECT_TRUE(tab->CancelAuth()); 160 EXPECT_TRUE(tab->CancelAuth());
157 EXPECT_FALSE(tab->NeedsAuth()); 161 EXPECT_FALSE(tab->NeedsAuth());
158 EXPECT_EQ(L"Denied: no auth", GetActiveTabTitle()); 162 EXPECT_EQ(L"Denied: no auth", GetActiveTabTitle());
159 } 163 }
160 164
161 // If multiple tabs are looking for the same auth, the user should only have to 165 // If multiple tabs are looking for the same auth, the user should only have to
162 // enter it once (http://crbug.com/8914). 166 // enter it once (http://crbug.com/8914).
163 TEST_F(LoginPromptTest, SupplyRedundantAuths) { 167 TEST_F(LoginPromptTest, SupplyRedundantAuths) {
164 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); 168 scoped_refptr<net::HTTPTestServer> server(
169 net::HTTPTestServer::CreateServer(kDocRoot));
165 ASSERT_TRUE(NULL != server.get()); 170 ASSERT_TRUE(NULL != server.get());
166 171
167 scoped_refptr<TabProxy> basic_tab1(GetActiveTab()); 172 scoped_refptr<TabProxy> basic_tab1(GetActiveTab());
168 ASSERT_TRUE(basic_tab1.get()); 173 ASSERT_TRUE(basic_tab1.get());
169 ASSERT_TRUE( 174 ASSERT_TRUE(
170 basic_tab1->NavigateToURL(server->TestServerPage("auth-basic/1"))); 175 basic_tab1->NavigateToURL(server->TestServerPage("auth-basic/1")));
171 EXPECT_TRUE(basic_tab1->NeedsAuth()); 176 EXPECT_TRUE(basic_tab1->NeedsAuth());
172 177
173 AppendTab(GURL(chrome::kAboutBlankURL)); 178 AppendTab(GURL(chrome::kAboutBlankURL));
174 scoped_refptr<TabProxy> basic_tab2(GetActiveTab()); 179 scoped_refptr<TabProxy> basic_tab2(GetActiveTab());
(...skipping 13 matching lines...) Expand all
188 EXPECT_TRUE(basic_tab1->GetTabTitle(&title1)); 193 EXPECT_TRUE(basic_tab1->GetTabTitle(&title1));
189 EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_), title1); 194 EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_), title1);
190 wstring title2; 195 wstring title2;
191 EXPECT_TRUE(basic_tab2->GetTabTitle(&title2)); 196 EXPECT_TRUE(basic_tab2->GetTabTitle(&title2));
192 EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_), title2); 197 EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_), title2);
193 } 198 }
194 199
195 // If multiple tabs are looking for the same auth, and one is cancelled, the 200 // If multiple tabs are looking for the same auth, and one is cancelled, the
196 // other should be cancelled as well. 201 // other should be cancelled as well.
197 TEST_F(LoginPromptTest, CancelRedundantAuths) { 202 TEST_F(LoginPromptTest, CancelRedundantAuths) {
198 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot)); 203 scoped_refptr<net::HTTPTestServer> server(
204 net::HTTPTestServer::CreateServer(kDocRoot));
199 ASSERT_TRUE(NULL != server.get()); 205 ASSERT_TRUE(NULL != server.get());
200 206
201 scoped_refptr<TabProxy> basic_tab1(GetActiveTab()); 207 scoped_refptr<TabProxy> basic_tab1(GetActiveTab());
202 ASSERT_TRUE(basic_tab1.get()); 208 ASSERT_TRUE(basic_tab1.get());
203 ASSERT_TRUE( 209 ASSERT_TRUE(
204 basic_tab1->NavigateToURL(server->TestServerPage("auth-basic/1"))); 210 basic_tab1->NavigateToURL(server->TestServerPage("auth-basic/1")));
205 EXPECT_TRUE(basic_tab1->NeedsAuth()); 211 EXPECT_TRUE(basic_tab1->NeedsAuth());
206 212
207 AppendTab(GURL(chrome::kAboutBlankURL)); 213 AppendTab(GURL(chrome::kAboutBlankURL));
208 scoped_refptr<TabProxy> basic_tab2(GetActiveTab()); 214 scoped_refptr<TabProxy> basic_tab2(GetActiveTab());
209 ASSERT_TRUE(basic_tab2.get()); 215 ASSERT_TRUE(basic_tab2.get());
210 ASSERT_TRUE( 216 ASSERT_TRUE(
211 basic_tab2->NavigateToURL(server->TestServerPage("auth-basic/2"))); 217 basic_tab2->NavigateToURL(server->TestServerPage("auth-basic/2")));
212 EXPECT_TRUE(basic_tab2->NeedsAuth()); 218 EXPECT_TRUE(basic_tab2->NeedsAuth());
213 219
214 // Cancel the auth in only one of the tabs (but wait for the other to load). 220 // Cancel the auth in only one of the tabs (but wait for the other to load).
215 int64 last_navigation_time; 221 int64 last_navigation_time;
216 ASSERT_TRUE(basic_tab2->GetLastNavigationTime(&last_navigation_time)); 222 ASSERT_TRUE(basic_tab2->GetLastNavigationTime(&last_navigation_time));
217 EXPECT_TRUE(basic_tab1->CancelAuth()); 223 EXPECT_TRUE(basic_tab1->CancelAuth());
218 EXPECT_TRUE(basic_tab2->WaitForNavigation(last_navigation_time)); 224 EXPECT_TRUE(basic_tab2->WaitForNavigation(last_navigation_time));
219 225
220 // Now both tabs have been denied. 226 // Now both tabs have been denied.
221 wstring title1; 227 wstring title1;
222 EXPECT_TRUE(basic_tab1->GetTabTitle(&title1)); 228 EXPECT_TRUE(basic_tab1->GetTabTitle(&title1));
223 EXPECT_EQ(L"Denied: no auth", title1); 229 EXPECT_EQ(L"Denied: no auth", title1);
224 wstring title2; 230 wstring title2;
225 EXPECT_TRUE(basic_tab2->GetTabTitle(&title2)); 231 EXPECT_TRUE(basic_tab2->GetTabTitle(&title2));
226 EXPECT_EQ(L"Denied: no auth", title2); 232 EXPECT_EQ(L"Denied: no auth", title2);
227 } 233 }
OLDNEW
« no previous file with comments | « chrome/browser/history/redirect_uitest.cc ('k') | chrome/browser/net/connection_tester_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698