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

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

Issue 2881028: GTTF: test server cleanup: (Closed)
Patch Set: final Created 10 years, 5 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"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 = 54 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot));
55 HTTPTestServer::CreateServer(kDocRoot, NULL);
56 ASSERT_TRUE(NULL != server.get()); 55 ASSERT_TRUE(NULL != server.get());
57 scoped_refptr<TabProxy> tab(GetActiveTab()); 56 scoped_refptr<TabProxy> tab(GetActiveTab());
58 ASSERT_TRUE(tab.get()); 57 ASSERT_TRUE(tab.get());
59 ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-basic"))); 58 ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-basic")));
60 59
61 EXPECT_TRUE(tab->NeedsAuth()); 60 EXPECT_TRUE(tab->NeedsAuth());
62 EXPECT_FALSE(tab->SetAuth(username_basic_, password_bad_)); 61 EXPECT_FALSE(tab->SetAuth(username_basic_, password_bad_));
63 EXPECT_TRUE(tab->NeedsAuth()); 62 EXPECT_TRUE(tab->NeedsAuth());
64 EXPECT_TRUE(tab->CancelAuth()); 63 EXPECT_TRUE(tab->CancelAuth());
65 EXPECT_EQ(L"Denied: wrong password", GetActiveTabTitle()); 64 EXPECT_EQ(L"Denied: wrong password", GetActiveTabTitle());
66 65
67 ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-basic"))); 66 ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-basic")));
68 67
69 EXPECT_TRUE(tab->NeedsAuth()); 68 EXPECT_TRUE(tab->NeedsAuth());
70 EXPECT_TRUE(tab->SetAuth(username_basic_, password_)); 69 EXPECT_TRUE(tab->SetAuth(username_basic_, password_));
71 EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_), 70 EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_),
72 GetActiveTabTitle()); 71 GetActiveTabTitle());
73 } 72 }
74 73
75 // Test that "Digest" HTTP authentication works. 74 // Test that "Digest" HTTP authentication works.
76 TEST_F(LoginPromptTest, TestDigestAuth) { 75 TEST_F(LoginPromptTest, TestDigestAuth) {
77 scoped_refptr<HTTPTestServer> server = 76 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot));
78 HTTPTestServer::CreateServer(kDocRoot, NULL);
79 ASSERT_TRUE(NULL != server.get()); 77 ASSERT_TRUE(NULL != server.get());
80 scoped_refptr<TabProxy> tab(GetActiveTab()); 78 scoped_refptr<TabProxy> tab(GetActiveTab());
81 ASSERT_TRUE(tab.get()); 79 ASSERT_TRUE(tab.get());
82 ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-digest"))); 80 ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-digest")));
83 81
84 EXPECT_TRUE(tab->NeedsAuth()); 82 EXPECT_TRUE(tab->NeedsAuth());
85 EXPECT_FALSE(tab->SetAuth(username_digest_, password_bad_)); 83 EXPECT_FALSE(tab->SetAuth(username_digest_, password_bad_));
86 EXPECT_TRUE(tab->CancelAuth()); 84 EXPECT_TRUE(tab->CancelAuth());
87 EXPECT_EQ(L"Denied: wrong password", GetActiveTabTitle()); 85 EXPECT_EQ(L"Denied: wrong password", GetActiveTabTitle());
88 86
89 ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-digest"))); 87 ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-digest")));
90 88
91 EXPECT_TRUE(tab->NeedsAuth()); 89 EXPECT_TRUE(tab->NeedsAuth());
92 EXPECT_TRUE(tab->SetAuth(username_digest_, password_)); 90 EXPECT_TRUE(tab->SetAuth(username_digest_, password_));
93 EXPECT_EQ(ExpectedTitleFromAuth(username_digest_, password_), 91 EXPECT_EQ(ExpectedTitleFromAuth(username_digest_, password_),
94 GetActiveTabTitle()); 92 GetActiveTabTitle());
95 } 93 }
96 94
97 // Test that logging in on 2 tabs at once works. 95 // Test that logging in on 2 tabs at once works.
98 TEST_F(LoginPromptTest, TestTwoAuths) { 96 TEST_F(LoginPromptTest, TestTwoAuths) {
99 scoped_refptr<HTTPTestServer> server = 97 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot));
100 HTTPTestServer::CreateServer(kDocRoot, NULL);
101 ASSERT_TRUE(NULL != server.get()); 98 ASSERT_TRUE(NULL != server.get());
102 99
103 scoped_refptr<TabProxy> basic_tab(GetActiveTab()); 100 scoped_refptr<TabProxy> basic_tab(GetActiveTab());
104 ASSERT_TRUE(basic_tab.get()); 101 ASSERT_TRUE(basic_tab.get());
105 ASSERT_TRUE(basic_tab->NavigateToURL(server->TestServerPage("auth-basic"))); 102 ASSERT_TRUE(basic_tab->NavigateToURL(server->TestServerPage("auth-basic")));
106 103
107 AppendTab(GURL(chrome::kAboutBlankURL)); 104 AppendTab(GURL(chrome::kAboutBlankURL));
108 scoped_refptr<TabProxy> digest_tab(GetActiveTab()); 105 scoped_refptr<TabProxy> digest_tab(GetActiveTab());
109 ASSERT_TRUE(digest_tab.get()); 106 ASSERT_TRUE(digest_tab.get());
110 ASSERT_TRUE( 107 ASSERT_TRUE(
111 digest_tab->NavigateToURL(server->TestServerPage("auth-digest"))); 108 digest_tab->NavigateToURL(server->TestServerPage("auth-digest")));
112 109
113 EXPECT_TRUE(basic_tab->NeedsAuth()); 110 EXPECT_TRUE(basic_tab->NeedsAuth());
114 EXPECT_TRUE(basic_tab->SetAuth(username_basic_, password_)); 111 EXPECT_TRUE(basic_tab->SetAuth(username_basic_, password_));
115 EXPECT_TRUE(digest_tab->NeedsAuth()); 112 EXPECT_TRUE(digest_tab->NeedsAuth());
116 EXPECT_TRUE(digest_tab->SetAuth(username_digest_, password_)); 113 EXPECT_TRUE(digest_tab->SetAuth(username_digest_, password_));
117 114
118 wstring title; 115 wstring title;
119 EXPECT_TRUE(basic_tab->GetTabTitle(&title)); 116 EXPECT_TRUE(basic_tab->GetTabTitle(&title));
120 EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_), title); 117 EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_), title);
121 118
122 EXPECT_TRUE(digest_tab->GetTabTitle(&title)); 119 EXPECT_TRUE(digest_tab->GetTabTitle(&title));
123 EXPECT_EQ(ExpectedTitleFromAuth(username_digest_, password_), title); 120 EXPECT_EQ(ExpectedTitleFromAuth(username_digest_, password_), title);
124 } 121 }
125 122
126 // Test that cancelling authentication works. 123 // Test that cancelling authentication works.
127 TEST_F(LoginPromptTest, TestCancelAuth) { 124 TEST_F(LoginPromptTest, TestCancelAuth) {
128 scoped_refptr<HTTPTestServer> server = 125 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot));
129 HTTPTestServer::CreateServer(kDocRoot, NULL);
130 ASSERT_TRUE(NULL != server.get()); 126 ASSERT_TRUE(NULL != server.get());
131 scoped_refptr<TabProxy> tab(GetActiveTab()); 127 scoped_refptr<TabProxy> tab(GetActiveTab());
132 ASSERT_TRUE(tab.get()); 128 ASSERT_TRUE(tab.get());
133 129
134 // First navigate to a test server page so we have something to go back to. 130 // First navigate to a test server page so we have something to go back to.
135 ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("a"))); 131 ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("a")));
136 132
137 // Navigating while auth is requested is the same as cancelling. 133 // Navigating while auth is requested is the same as cancelling.
138 ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-basic"))); 134 ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-basic")));
139 EXPECT_TRUE(tab->NeedsAuth()); 135 EXPECT_TRUE(tab->NeedsAuth());
(...skipping 18 matching lines...) Expand all
158 ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-basic"))); 154 ASSERT_TRUE(tab->NavigateToURL(server->TestServerPage("auth-basic")));
159 EXPECT_TRUE(tab->NeedsAuth()); 155 EXPECT_TRUE(tab->NeedsAuth());
160 EXPECT_TRUE(tab->CancelAuth()); 156 EXPECT_TRUE(tab->CancelAuth());
161 EXPECT_FALSE(tab->NeedsAuth()); 157 EXPECT_FALSE(tab->NeedsAuth());
162 EXPECT_EQ(L"Denied: no auth", GetActiveTabTitle()); 158 EXPECT_EQ(L"Denied: no auth", GetActiveTabTitle());
163 } 159 }
164 160
165 // If multiple tabs are looking for the same auth, the user should only have to 161 // If multiple tabs are looking for the same auth, the user should only have to
166 // enter it once (http://crbug.com/8914). 162 // enter it once (http://crbug.com/8914).
167 TEST_F(LoginPromptTest, SupplyRedundantAuths) { 163 TEST_F(LoginPromptTest, SupplyRedundantAuths) {
168 scoped_refptr<HTTPTestServer> server = 164 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot));
169 HTTPTestServer::CreateServer(kDocRoot, NULL);
170 ASSERT_TRUE(NULL != server.get()); 165 ASSERT_TRUE(NULL != server.get());
171 166
172 scoped_refptr<TabProxy> basic_tab1(GetActiveTab()); 167 scoped_refptr<TabProxy> basic_tab1(GetActiveTab());
173 ASSERT_TRUE(basic_tab1.get()); 168 ASSERT_TRUE(basic_tab1.get());
174 ASSERT_TRUE( 169 ASSERT_TRUE(
175 basic_tab1->NavigateToURL(server->TestServerPage("auth-basic/1"))); 170 basic_tab1->NavigateToURL(server->TestServerPage("auth-basic/1")));
176 EXPECT_TRUE(basic_tab1->NeedsAuth()); 171 EXPECT_TRUE(basic_tab1->NeedsAuth());
177 172
178 AppendTab(GURL(chrome::kAboutBlankURL)); 173 AppendTab(GURL(chrome::kAboutBlankURL));
179 scoped_refptr<TabProxy> basic_tab2(GetActiveTab()); 174 scoped_refptr<TabProxy> basic_tab2(GetActiveTab());
(...skipping 13 matching lines...) Expand all
193 EXPECT_TRUE(basic_tab1->GetTabTitle(&title1)); 188 EXPECT_TRUE(basic_tab1->GetTabTitle(&title1));
194 EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_), title1); 189 EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_), title1);
195 wstring title2; 190 wstring title2;
196 EXPECT_TRUE(basic_tab2->GetTabTitle(&title2)); 191 EXPECT_TRUE(basic_tab2->GetTabTitle(&title2));
197 EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_), title2); 192 EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_), title2);
198 } 193 }
199 194
200 // If multiple tabs are looking for the same auth, and one is cancelled, the 195 // If multiple tabs are looking for the same auth, and one is cancelled, the
201 // other should be cancelled as well. 196 // other should be cancelled as well.
202 TEST_F(LoginPromptTest, CancelRedundantAuths) { 197 TEST_F(LoginPromptTest, CancelRedundantAuths) {
203 scoped_refptr<HTTPTestServer> server = 198 scoped_refptr<HTTPTestServer> server(HTTPTestServer::CreateServer(kDocRoot));
204 HTTPTestServer::CreateServer(kDocRoot, NULL);
205 ASSERT_TRUE(NULL != server.get()); 199 ASSERT_TRUE(NULL != server.get());
206 200
207 scoped_refptr<TabProxy> basic_tab1(GetActiveTab()); 201 scoped_refptr<TabProxy> basic_tab1(GetActiveTab());
208 ASSERT_TRUE(basic_tab1.get()); 202 ASSERT_TRUE(basic_tab1.get());
209 ASSERT_TRUE( 203 ASSERT_TRUE(
210 basic_tab1->NavigateToURL(server->TestServerPage("auth-basic/1"))); 204 basic_tab1->NavigateToURL(server->TestServerPage("auth-basic/1")));
211 EXPECT_TRUE(basic_tab1->NeedsAuth()); 205 EXPECT_TRUE(basic_tab1->NeedsAuth());
212 206
213 AppendTab(GURL(chrome::kAboutBlankURL)); 207 AppendTab(GURL(chrome::kAboutBlankURL));
214 scoped_refptr<TabProxy> basic_tab2(GetActiveTab()); 208 scoped_refptr<TabProxy> basic_tab2(GetActiveTab());
215 ASSERT_TRUE(basic_tab2.get()); 209 ASSERT_TRUE(basic_tab2.get());
216 ASSERT_TRUE( 210 ASSERT_TRUE(
217 basic_tab2->NavigateToURL(server->TestServerPage("auth-basic/2"))); 211 basic_tab2->NavigateToURL(server->TestServerPage("auth-basic/2")));
218 EXPECT_TRUE(basic_tab2->NeedsAuth()); 212 EXPECT_TRUE(basic_tab2->NeedsAuth());
219 213
220 // Cancel the auth in only one of the tabs (but wait for the other to load). 214 // Cancel the auth in only one of the tabs (but wait for the other to load).
221 int64 last_navigation_time; 215 int64 last_navigation_time;
222 ASSERT_TRUE(basic_tab2->GetLastNavigationTime(&last_navigation_time)); 216 ASSERT_TRUE(basic_tab2->GetLastNavigationTime(&last_navigation_time));
223 EXPECT_TRUE(basic_tab1->CancelAuth()); 217 EXPECT_TRUE(basic_tab1->CancelAuth());
224 EXPECT_TRUE(basic_tab2->WaitForNavigation(last_navigation_time)); 218 EXPECT_TRUE(basic_tab2->WaitForNavigation(last_navigation_time));
225 219
226 // Now both tabs have been denied. 220 // Now both tabs have been denied.
227 wstring title1; 221 wstring title1;
228 EXPECT_TRUE(basic_tab1->GetTabTitle(&title1)); 222 EXPECT_TRUE(basic_tab1->GetTabTitle(&title1));
229 EXPECT_EQ(L"Denied: no auth", title1); 223 EXPECT_EQ(L"Denied: no auth", title1);
230 wstring title2; 224 wstring title2;
231 EXPECT_TRUE(basic_tab2->GetTabTitle(&title2)); 225 EXPECT_TRUE(basic_tab2->GetTabTitle(&title2));
232 EXPECT_EQ(L"Denied: no auth", title2); 226 EXPECT_EQ(L"Denied: no auth", title2);
233 } 227 }
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