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

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

Issue 8413022: wstring cleanup in browser/ui/login (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/url_constants.h" 8 #include "chrome/common/url_constants.h"
9 #include "chrome/test/automation/automation_proxy.h" 9 #include "chrome/test/automation/automation_proxy.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/test/test_server.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 FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); 19 const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data");
20 20
21 } // namespace 21 } // namespace
22 22
23 class LoginPromptTest : public UITest { 23 class LoginPromptTest : public UITest {
24 protected: 24 protected:
25 LoginPromptTest() 25 LoginPromptTest()
26 : username_basic_(L"basicuser"), 26 : username_basic_("basicuser"),
27 username_digest_(L"digestuser"), 27 username_digest_("digestuser"),
28 password_(L"secret"), 28 password_("secret"),
29 password_bad_(L"denyme"), 29 password_bad_("denyme"),
30 test_server_(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)) { 30 test_server_(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)) {
31 } 31 }
32 32
33 void AppendTab(const GURL& url) { 33 void AppendTab(const GURL& url) {
34 scoped_refptr<BrowserProxy> window_proxy(automation()->GetBrowserWindow(0)); 34 scoped_refptr<BrowserProxy> window_proxy(automation()->GetBrowserWindow(0));
35 ASSERT_TRUE(window_proxy.get()); 35 ASSERT_TRUE(window_proxy.get());
36 ASSERT_TRUE(window_proxy->AppendTab(url)); 36 ASSERT_TRUE(window_proxy->AppendTab(url));
37 } 37 }
38 38
39 protected: 39 protected:
40 wstring username_basic_; 40 std::string username_basic_;
41 wstring username_digest_; 41 std::string username_digest_;
42 wstring password_; 42 std::string password_;
43 wstring password_bad_; 43 std::string password_bad_;
44 44
45 net::TestServer test_server_; 45 net::TestServer test_server_;
46 }; 46 };
47 47
48 wstring ExpectedTitleFromAuth(const wstring& username, 48 std::string ExpectedTitleFromAuth(const std::string& username,
49 const wstring& password) { 49 const std::string& password) {
50 // The TestServer sets the title to username/password on successful login. 50 // The TestServer sets the title to username/password on successful login.
51 return username + L"/" + password; 51 return username + "/" + password;
52 } 52 }
53 53
54 // Test that "Basic" HTTP authentication works. 54 // Test that "Basic" HTTP authentication works.
55 TEST_F(LoginPromptTest, TestBasicAuth) { 55 TEST_F(LoginPromptTest, TestBasicAuth) {
56 ASSERT_TRUE(test_server_.Start()); 56 ASSERT_TRUE(test_server_.Start());
57 57
58 scoped_refptr<TabProxy> tab(GetActiveTab()); 58 scoped_refptr<TabProxy> tab(GetActiveTab());
59 ASSERT_TRUE(tab.get()); 59 ASSERT_TRUE(tab.get());
60 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED, 60 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED,
61 tab->NavigateToURL(test_server_.GetURL("auth-basic"))); 61 tab->NavigateToURL(test_server_.GetURL("auth-basic")));
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED, 113 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED,
114 digest_tab->NavigateToURL(test_server_.GetURL("auth-digest"))); 114 digest_tab->NavigateToURL(test_server_.GetURL("auth-digest")));
115 115
116 EXPECT_TRUE(basic_tab->NeedsAuth()); 116 EXPECT_TRUE(basic_tab->NeedsAuth());
117 EXPECT_TRUE(basic_tab->SetAuth(username_basic_, password_)); 117 EXPECT_TRUE(basic_tab->SetAuth(username_basic_, password_));
118 EXPECT_TRUE(digest_tab->NeedsAuth()); 118 EXPECT_TRUE(digest_tab->NeedsAuth());
119 EXPECT_TRUE(digest_tab->SetAuth(username_digest_, password_)); 119 EXPECT_TRUE(digest_tab->SetAuth(username_digest_, password_));
120 120
121 wstring title; 121 wstring title;
122 EXPECT_TRUE(basic_tab->GetTabTitle(&title)); 122 EXPECT_TRUE(basic_tab->GetTabTitle(&title));
123 EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_), title); 123 EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_),
124 WideToUTF8Hack(title));
124 125
125 EXPECT_TRUE(digest_tab->GetTabTitle(&title)); 126 EXPECT_TRUE(digest_tab->GetTabTitle(&title));
126 EXPECT_EQ(ExpectedTitleFromAuth(username_digest_, password_), title); 127 EXPECT_EQ(ExpectedTitleFromAuth(username_digest_, password_),
128 WideToUTF8Hack(title));
127 } 129 }
128 130
129 // If multiple tabs are looking for the same auth, the user should only have to 131 // If multiple tabs are looking for the same auth, the user should only have to
130 // enter it once. 132 // enter it once.
131 TEST_F(LoginPromptTest, SupplyRedundantAuths) { 133 TEST_F(LoginPromptTest, SupplyRedundantAuths) {
132 ASSERT_TRUE(test_server_.Start()); 134 ASSERT_TRUE(test_server_.Start());
133 135
134 scoped_refptr<TabProxy> basic_tab1(GetActiveTab()); 136 scoped_refptr<TabProxy> basic_tab1(GetActiveTab());
135 ASSERT_TRUE(basic_tab1.get()); 137 ASSERT_TRUE(basic_tab1.get());
136 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED, 138 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED,
137 basic_tab1->NavigateToURL(test_server_.GetURL("auth-basic/1"))); 139 basic_tab1->NavigateToURL(test_server_.GetURL("auth-basic/1")));
138 EXPECT_TRUE(basic_tab1->NeedsAuth()); 140 EXPECT_TRUE(basic_tab1->NeedsAuth());
139 141
140 AppendTab(GURL(chrome::kAboutBlankURL)); 142 AppendTab(GURL(chrome::kAboutBlankURL));
141 scoped_refptr<TabProxy> basic_tab2(GetActiveTab()); 143 scoped_refptr<TabProxy> basic_tab2(GetActiveTab());
142 ASSERT_TRUE(basic_tab2.get()); 144 ASSERT_TRUE(basic_tab2.get());
143 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED, 145 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED,
144 basic_tab2->NavigateToURL(test_server_.GetURL("auth-basic/2"))); 146 basic_tab2->NavigateToURL(test_server_.GetURL("auth-basic/2")));
145 EXPECT_TRUE(basic_tab2->NeedsAuth()); 147 EXPECT_TRUE(basic_tab2->NeedsAuth());
146 148
147 // Set the auth in only one of the tabs (but wait for the other to load). 149 // Set the auth in only one of the tabs (but wait for the other to load).
148 int64 last_navigation_time; 150 int64 last_navigation_time;
149 ASSERT_TRUE(basic_tab2->GetLastNavigationTime(&last_navigation_time)); 151 ASSERT_TRUE(basic_tab2->GetLastNavigationTime(&last_navigation_time));
150 EXPECT_TRUE(basic_tab1->SetAuth(username_basic_, password_)); 152 EXPECT_TRUE(basic_tab1->SetAuth(username_basic_, password_));
151 EXPECT_TRUE(basic_tab2->WaitForNavigation(last_navigation_time)); 153 EXPECT_TRUE(basic_tab2->WaitForNavigation(last_navigation_time));
152 154
153 // Now both tabs have loaded. 155 // Now both tabs have loaded.
154 wstring title1; 156 wstring title1;
155 EXPECT_TRUE(basic_tab1->GetTabTitle(&title1)); 157 EXPECT_TRUE(basic_tab1->GetTabTitle(&title1));
156 EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_), title1); 158 EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_),
159 WideToUTF8Hack(title1));
157 wstring title2; 160 wstring title2;
158 EXPECT_TRUE(basic_tab2->GetTabTitle(&title2)); 161 EXPECT_TRUE(basic_tab2->GetTabTitle(&title2));
159 EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_), title2); 162 EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_),
163 WideToUTF8Hack(title2));
160 } 164 }
161 165
162 // If multiple tabs are looking for the same auth, and one is cancelled, the 166 // If multiple tabs are looking for the same auth, and one is cancelled, the
163 // other should be cancelled as well. 167 // other should be cancelled as well.
164 TEST_F(LoginPromptTest, CancelRedundantAuths) { 168 TEST_F(LoginPromptTest, CancelRedundantAuths) {
165 ASSERT_TRUE(test_server_.Start()); 169 ASSERT_TRUE(test_server_.Start());
166 170
167 scoped_refptr<TabProxy> basic_tab1(GetActiveTab()); 171 scoped_refptr<TabProxy> basic_tab1(GetActiveTab());
168 ASSERT_TRUE(basic_tab1.get()); 172 ASSERT_TRUE(basic_tab1.get());
169 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED, 173 ASSERT_EQ(AUTOMATION_MSG_NAVIGATION_AUTH_NEEDED,
(...skipping 14 matching lines...) Expand all
184 EXPECT_TRUE(basic_tab2->WaitForNavigation(last_navigation_time)); 188 EXPECT_TRUE(basic_tab2->WaitForNavigation(last_navigation_time));
185 189
186 // Now both tabs have been denied. 190 // Now both tabs have been denied.
187 wstring title1; 191 wstring title1;
188 EXPECT_TRUE(basic_tab1->GetTabTitle(&title1)); 192 EXPECT_TRUE(basic_tab1->GetTabTitle(&title1));
189 EXPECT_EQ(L"Denied: no auth", title1); 193 EXPECT_EQ(L"Denied: no auth", title1);
190 wstring title2; 194 wstring title2;
191 EXPECT_TRUE(basic_tab2->GetTabTitle(&title2)); 195 EXPECT_TRUE(basic_tab2->GetTabTitle(&title2));
192 EXPECT_EQ(L"Denied: no auth", title2); 196 EXPECT_EQ(L"Denied: no auth", title2);
193 } 197 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698