Commit 8950590b authored by tony@chromium.org's avatar tony@chromium.org

wstring removal/cleanup in browser/ui/login

BUG=23581
TEST=None


Review URL: http://codereview.chromium.org/8413022

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@108016 0039d316-1c4b-4281-b951-d872f2087c98
parent 1c424a95
...@@ -236,9 +236,8 @@ void PasswordManager::Autofill( ...@@ -236,9 +236,8 @@ void PasswordManager::Autofill(
} }
default: default:
if (observer_) { if (observer_) {
observer_->OnAutofillDataAvailable( observer_->OnAutofillDataAvailable(preferred_match->username_value,
UTF16ToWideHack(preferred_match->username_value), preferred_match->password_value);
UTF16ToWideHack(preferred_match->password_value));
} }
} }
} }
// Copyright (c) 2009 The Chromium Authors. All rights reserved. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#define CHROME_BROWSER_UI_LOGIN_LOGIN_MODEL_H_ #define CHROME_BROWSER_UI_LOGIN_LOGIN_MODEL_H_
#pragma once #pragma once
#include <string> #include "base/string16.h"
// Simple Model & Observer interfaces for a LoginView to facilitate exchanging // Simple Model & Observer interfaces for a LoginView to facilitate exchanging
// information. // information.
...@@ -14,8 +14,8 @@ class LoginModelObserver { ...@@ -14,8 +14,8 @@ class LoginModelObserver {
public: public:
// Called by the model when a username,password pair has been identified // Called by the model when a username,password pair has been identified
// as a match for the pending login prompt. // as a match for the pending login prompt.
virtual void OnAutofillDataAvailable(const std::wstring& username, virtual void OnAutofillDataAvailable(const string16& username,
const std::wstring& password) = 0; const string16& password) = 0;
protected: protected:
virtual ~LoginModelObserver() {} virtual ~LoginModelObserver() {}
......
...@@ -26,22 +26,22 @@ namespace { ...@@ -26,22 +26,22 @@ namespace {
class LoginPromptBrowserTest : public InProcessBrowserTest { class LoginPromptBrowserTest : public InProcessBrowserTest {
public: public:
LoginPromptBrowserTest() LoginPromptBrowserTest()
: bad_password_(L"incorrect"), bad_username_(L"nouser") { : bad_password_("incorrect"), bad_username_("nouser") {
set_show_window(true); set_show_window(true);
auth_map_["foo"] = AuthInfo(L"testuser", L"foopassword"); auth_map_["foo"] = AuthInfo("testuser", "foopassword");
auth_map_["bar"] = AuthInfo(L"testuser", L"barpassword"); auth_map_["bar"] = AuthInfo("testuser", "barpassword");
} }
protected: protected:
struct AuthInfo { struct AuthInfo {
std::wstring username_; std::string username_;
std::wstring password_; std::string password_;
AuthInfo() {} AuthInfo() {}
AuthInfo(const std::wstring username, AuthInfo(const std::string username,
const std::wstring password) const std::string password)
: username_(username), password_(password) {} : username_(username), password_(password) {}
}; };
...@@ -50,8 +50,8 @@ class LoginPromptBrowserTest : public InProcessBrowserTest { ...@@ -50,8 +50,8 @@ class LoginPromptBrowserTest : public InProcessBrowserTest {
void SetAuthFor(LoginHandler* handler); void SetAuthFor(LoginHandler* handler);
AuthMap auth_map_; AuthMap auth_map_;
std::wstring bad_password_; std::string bad_password_;
std::wstring bad_username_; std::string bad_username_;
}; };
void LoginPromptBrowserTest::SetAuthFor(LoginHandler* handler) { void LoginPromptBrowserTest::SetAuthFor(LoginHandler* handler) {
...@@ -62,8 +62,8 @@ void LoginPromptBrowserTest::SetAuthFor(LoginHandler* handler) { ...@@ -62,8 +62,8 @@ void LoginPromptBrowserTest::SetAuthFor(LoginHandler* handler) {
EXPECT_TRUE(auth_map_.end() != i); EXPECT_TRUE(auth_map_.end() != i);
if (i != auth_map_.end()) { if (i != auth_map_.end()) {
const AuthInfo& info = i->second; const AuthInfo& info = i->second;
handler->SetAuth(WideToUTF16Hack(info.username_), handler->SetAuth(UTF8ToUTF16(info.username_),
WideToUTF16Hack(info.password_)); UTF8ToUTF16(info.password_));
} }
} }
...@@ -491,8 +491,8 @@ IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, IncorrectConfirmation) { ...@@ -491,8 +491,8 @@ IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, IncorrectConfirmation) {
LoginHandler* handler = *observer.handlers_.begin(); LoginHandler* handler = *observer.handlers_.begin();
ASSERT_TRUE(handler); ASSERT_TRUE(handler);
handler->SetAuth(WideToUTF16Hack(bad_username_), handler->SetAuth(UTF8ToUTF16(bad_username_),
WideToUTF16Hack(bad_password_)); UTF8ToUTF16(bad_password_));
auth_supplied_waiter.Wait(); auth_supplied_waiter.Wait();
// The request should be retried after the incorrect password is // The request should be retried after the incorrect password is
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include "base/string16.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "chrome/browser/password_manager/password_manager.h" #include "chrome/browser/password_manager/password_manager.h"
#include "chrome/browser/tab_contents/tab_contents_view_gtk.h" #include "chrome/browser/tab_contents/tab_contents_view_gtk.h"
...@@ -49,17 +50,17 @@ class LoginHandlerGtk : public LoginHandler, ...@@ -49,17 +50,17 @@ class LoginHandlerGtk : public LoginHandler,
} }
// LoginModelObserver implementation. // LoginModelObserver implementation.
virtual void OnAutofillDataAvailable(const std::wstring& username, virtual void OnAutofillDataAvailable(const string16& username,
const std::wstring& password) { const string16& password) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// NOTE: Would be nice to use gtk_entry_get_text_length, but it is fairly // NOTE: Would be nice to use gtk_entry_get_text_length, but it is fairly
// new and not always in our GTK version. // new and not always in our GTK version.
if (strlen(gtk_entry_get_text(GTK_ENTRY(username_entry_))) == 0) { if (strlen(gtk_entry_get_text(GTK_ENTRY(username_entry_))) == 0) {
gtk_entry_set_text(GTK_ENTRY(username_entry_), gtk_entry_set_text(GTK_ENTRY(username_entry_),
WideToUTF8(username).c_str()); UTF16ToUTF8(username).c_str());
gtk_entry_set_text(GTK_ENTRY(password_entry_), gtk_entry_set_text(GTK_ENTRY(password_entry_),
WideToUTF8(password).c_str()); UTF16ToUTF8(password).c_str());
gtk_editable_select_region(GTK_EDITABLE(username_entry_), 0, -1); gtk_editable_select_region(GTK_EDITABLE(username_entry_), 0, -1);
} }
} }
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#import "chrome/browser/ui/login/login_prompt_mac.h" #import "chrome/browser/ui/login/login_prompt_mac.h"
#include "base/mac/mac_util.h" #include "base/mac/mac_util.h"
#include "base/string16.h"
#include "base/string_util.h" #include "base/string_util.h"
#include "base/sys_string_conversions.h" #include "base/sys_string_conversions.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
...@@ -44,12 +45,12 @@ class LoginHandlerMac : public LoginHandler, ...@@ -44,12 +45,12 @@ class LoginHandlerMac : public LoginHandler,
} }
// LoginModelObserver implementation. // LoginModelObserver implementation.
virtual void OnAutofillDataAvailable(const std::wstring& username, virtual void OnAutofillDataAvailable(const string16& username,
const std::wstring& password) { const string16& password) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[sheet_controller_ autofillLogin:base::SysWideToNSString(username) [sheet_controller_ autofillLogin:base::SysUTF16ToNSString(username)
password:base::SysWideToNSString(password)]; password:base::SysUTF16ToNSString(password)];
} }
// LoginHandler: // LoginHandler:
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/json/json_reader.h" #include "base/json/json_reader.h"
#include "base/string16.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile.h"
...@@ -127,8 +128,8 @@ class LoginHandlerHtmlDelegate : public HtmlDialogUIDelegate, ...@@ -127,8 +128,8 @@ class LoginHandlerHtmlDelegate : public HtmlDialogUIDelegate,
base::Unretained(this))); base::Unretained(this)));
} }
void ShowAutofillData(const std::wstring& username, void ShowAutofillData(const string16& username,
const std::wstring& password); const string16& password);
private: private:
// Send autofill data to HTML once the dialog is ready and the data is // Send autofill data to HTML once the dialog is ready and the data is
...@@ -147,8 +148,8 @@ class LoginHandlerHtmlDelegate : public HtmlDialogUIDelegate, ...@@ -147,8 +148,8 @@ class LoginHandlerHtmlDelegate : public HtmlDialogUIDelegate,
bool has_autofill_; bool has_autofill_;
bool ready_for_autofill_; bool ready_for_autofill_;
std::string autofill_username_; string16 autofill_username_;
std::string autofill_password_; string16 autofill_password_;
static const int kDialogWidth = 400; static const int kDialogWidth = 400;
static const int kDialogHeight = 160; static const int kDialogHeight = 160;
...@@ -164,8 +165,8 @@ class LoginHandlerHtml : public LoginHandler { ...@@ -164,8 +165,8 @@ class LoginHandlerHtml : public LoginHandler {
} }
// LoginModelObserver method: // LoginModelObserver method:
virtual void OnAutofillDataAvailable(const std::wstring& username, virtual void OnAutofillDataAvailable(const string16& username,
const std::wstring& password) OVERRIDE { const string16& password) OVERRIDE {
if (delegate_) if (delegate_)
delegate_->ShowAutofillData(username, password); delegate_->ShowAutofillData(username, password);
} }
...@@ -218,10 +219,10 @@ void LoginHandlerHtmlDelegate::OnDialogClosed(const std::string& json_retval) { ...@@ -218,10 +219,10 @@ void LoginHandlerHtmlDelegate::OnDialogClosed(const std::string& json_retval) {
// we've registered ourselves as a WebUIMessageHandler. // we've registered ourselves as a WebUIMessageHandler.
} }
void LoginHandlerHtmlDelegate::ShowAutofillData(const std::wstring& username, void LoginHandlerHtmlDelegate::ShowAutofillData(const string16& username,
const std::wstring& password) { const string16& password) {
autofill_username_ = WideToUTF8(username); autofill_username_ = username;
autofill_password_ = WideToUTF8(password); autofill_password_ = password;
has_autofill_ = true; has_autofill_ = true;
SendAutofillData(); SendAutofillData();
} }
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include <string> #include <string>
#include "base/string16.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/net/url_fixer_upper.h" #include "chrome/browser/net/url_fixer_upper.h"
#include "chrome/common/url_constants.h" #include "chrome/common/url_constants.h"
#include "chrome/test/automation/automation_proxy.h" #include "chrome/test/automation/automation_proxy.h"
...@@ -23,10 +25,10 @@ const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data"); ...@@ -23,10 +25,10 @@ const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data");
class LoginPromptTest : public UITest { class LoginPromptTest : public UITest {
protected: protected:
LoginPromptTest() LoginPromptTest()
: username_basic_(L"basicuser"), : username_basic_(UTF8ToUTF16("basicuser")),
username_digest_(L"digestuser"), username_digest_(UTF8ToUTF16("digestuser")),
password_(L"secret"), password_(UTF8ToUTF16("secret")),
password_bad_(L"denyme"), password_bad_(UTF8ToUTF16("denyme")),
test_server_(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)) { test_server_(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)) {
} }
...@@ -37,18 +39,18 @@ class LoginPromptTest : public UITest { ...@@ -37,18 +39,18 @@ class LoginPromptTest : public UITest {
} }
protected: protected:
wstring username_basic_; string16 username_basic_;
wstring username_digest_; string16 username_digest_;
wstring password_; string16 password_;
wstring password_bad_; string16 password_bad_;
net::TestServer test_server_; net::TestServer test_server_;
}; };
wstring ExpectedTitleFromAuth(const wstring& username, string16 ExpectedTitleFromAuth(const string16& username,
const wstring& password) { const string16& password) {
// The TestServer sets the title to username/password on successful login. // The TestServer sets the title to username/password on successful login.
return username + L"/" + password; return username + UTF8ToUTF16("/") + password;
} }
// Test that "Basic" HTTP authentication works. // Test that "Basic" HTTP authentication works.
...@@ -61,7 +63,8 @@ TEST_F(LoginPromptTest, TestBasicAuth) { ...@@ -61,7 +63,8 @@ TEST_F(LoginPromptTest, TestBasicAuth) {
tab->NavigateToURL(test_server_.GetURL("auth-basic"))); tab->NavigateToURL(test_server_.GetURL("auth-basic")));
EXPECT_TRUE(tab->NeedsAuth()); EXPECT_TRUE(tab->NeedsAuth());
EXPECT_FALSE(tab->SetAuth(username_basic_, password_bad_)); EXPECT_FALSE(tab->SetAuth(UTF16ToWideHack(username_basic_),
UTF16ToWideHack(password_bad_)));
EXPECT_TRUE(tab->NeedsAuth()); EXPECT_TRUE(tab->NeedsAuth());
EXPECT_TRUE(tab->CancelAuth()); EXPECT_TRUE(tab->CancelAuth());
EXPECT_EQ(L"Denied: wrong password", GetActiveTabTitle()); EXPECT_EQ(L"Denied: wrong password", GetActiveTabTitle());
...@@ -70,9 +73,10 @@ TEST_F(LoginPromptTest, TestBasicAuth) { ...@@ -70,9 +73,10 @@ TEST_F(LoginPromptTest, TestBasicAuth) {
tab->NavigateToURL(test_server_.GetURL("auth-basic"))); tab->NavigateToURL(test_server_.GetURL("auth-basic")));
EXPECT_TRUE(tab->NeedsAuth()); EXPECT_TRUE(tab->NeedsAuth());
EXPECT_TRUE(tab->SetAuth(username_basic_, password_)); EXPECT_TRUE(tab->SetAuth(UTF16ToWideHack(username_basic_),
UTF16ToWideHack(password_)));
EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_), EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_),
GetActiveTabTitle()); WideToUTF16Hack(GetActiveTabTitle()));
} }
// Test that "Digest" HTTP authentication works. // Test that "Digest" HTTP authentication works.
...@@ -85,7 +89,8 @@ TEST_F(LoginPromptTest, TestDigestAuth) { ...@@ -85,7 +89,8 @@ TEST_F(LoginPromptTest, TestDigestAuth) {
tab->NavigateToURL(test_server_.GetURL("auth-digest"))); tab->NavigateToURL(test_server_.GetURL("auth-digest")));
EXPECT_TRUE(tab->NeedsAuth()); EXPECT_TRUE(tab->NeedsAuth());
EXPECT_FALSE(tab->SetAuth(username_digest_, password_bad_)); EXPECT_FALSE(tab->SetAuth(UTF16ToWideHack(username_digest_),
UTF16ToWideHack(password_bad_)));
EXPECT_TRUE(tab->CancelAuth()); EXPECT_TRUE(tab->CancelAuth());
EXPECT_EQ(L"Denied: wrong password", GetActiveTabTitle()); EXPECT_EQ(L"Denied: wrong password", GetActiveTabTitle());
...@@ -93,9 +98,10 @@ TEST_F(LoginPromptTest, TestDigestAuth) { ...@@ -93,9 +98,10 @@ TEST_F(LoginPromptTest, TestDigestAuth) {
tab->NavigateToURL(test_server_.GetURL("auth-digest"))); tab->NavigateToURL(test_server_.GetURL("auth-digest")));
EXPECT_TRUE(tab->NeedsAuth()); EXPECT_TRUE(tab->NeedsAuth());
EXPECT_TRUE(tab->SetAuth(username_digest_, password_)); EXPECT_TRUE(tab->SetAuth(UTF16ToWideHack(username_digest_),
UTF16ToWideHack(password_)));
EXPECT_EQ(ExpectedTitleFromAuth(username_digest_, password_), EXPECT_EQ(ExpectedTitleFromAuth(username_digest_, password_),
GetActiveTabTitle()); WideToUTF16Hack(GetActiveTabTitle()));
} }
// Test that logging in on 2 tabs at once works. // Test that logging in on 2 tabs at once works.
...@@ -114,16 +120,20 @@ TEST_F(LoginPromptTest, TestTwoAuths) { ...@@ -114,16 +120,20 @@ TEST_F(LoginPromptTest, TestTwoAuths) {
digest_tab->NavigateToURL(test_server_.GetURL("auth-digest"))); digest_tab->NavigateToURL(test_server_.GetURL("auth-digest")));
EXPECT_TRUE(basic_tab->NeedsAuth()); EXPECT_TRUE(basic_tab->NeedsAuth());
EXPECT_TRUE(basic_tab->SetAuth(username_basic_, password_)); EXPECT_TRUE(basic_tab->SetAuth(UTF16ToWideHack(username_basic_),
UTF16ToWideHack(password_)));
EXPECT_TRUE(digest_tab->NeedsAuth()); EXPECT_TRUE(digest_tab->NeedsAuth());
EXPECT_TRUE(digest_tab->SetAuth(username_digest_, password_)); EXPECT_TRUE(digest_tab->SetAuth(UTF16ToWideHack(username_digest_),
UTF16ToWideHack(password_)));
wstring title; wstring title;
EXPECT_TRUE(basic_tab->GetTabTitle(&title)); EXPECT_TRUE(basic_tab->GetTabTitle(&title));
EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_), title); EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_),
WideToUTF16Hack(title));
EXPECT_TRUE(digest_tab->GetTabTitle(&title)); EXPECT_TRUE(digest_tab->GetTabTitle(&title));
EXPECT_EQ(ExpectedTitleFromAuth(username_digest_, password_), title); EXPECT_EQ(ExpectedTitleFromAuth(username_digest_, password_),
WideToUTF16Hack(title));
} }
// If multiple tabs are looking for the same auth, the user should only have to // If multiple tabs are looking for the same auth, the user should only have to
...@@ -147,16 +157,19 @@ TEST_F(LoginPromptTest, SupplyRedundantAuths) { ...@@ -147,16 +157,19 @@ TEST_F(LoginPromptTest, SupplyRedundantAuths) {
// Set the auth in only one of the tabs (but wait for the other to load). // Set the auth in only one of the tabs (but wait for the other to load).
int64 last_navigation_time; int64 last_navigation_time;
ASSERT_TRUE(basic_tab2->GetLastNavigationTime(&last_navigation_time)); ASSERT_TRUE(basic_tab2->GetLastNavigationTime(&last_navigation_time));
EXPECT_TRUE(basic_tab1->SetAuth(username_basic_, password_)); EXPECT_TRUE(basic_tab1->SetAuth(UTF16ToWideHack(username_basic_),
UTF16ToWideHack(password_)));
EXPECT_TRUE(basic_tab2->WaitForNavigation(last_navigation_time)); EXPECT_TRUE(basic_tab2->WaitForNavigation(last_navigation_time));
// Now both tabs have loaded. // Now both tabs have loaded.
wstring title1; wstring title1;
EXPECT_TRUE(basic_tab1->GetTabTitle(&title1)); EXPECT_TRUE(basic_tab1->GetTabTitle(&title1));
EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_), title1); EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_),
WideToUTF16Hack(title1));
wstring title2; wstring title2;
EXPECT_TRUE(basic_tab2->GetTabTitle(&title2)); EXPECT_TRUE(basic_tab2->GetTabTitle(&title2));
EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_), title2); EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_),
WideToUTF16Hack(title2));
} }
// If multiple tabs are looking for the same auth, and one is cancelled, the // If multiple tabs are looking for the same auth, and one is cancelled, the
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "chrome/browser/ui/login/login_prompt.h" #include "chrome/browser/ui/login/login_prompt.h"
#include "base/string16.h"
#include "base/utf_string_conversions.h" #include "base/utf_string_conversions.h"
#include "chrome/browser/password_manager/password_manager.h" #include "chrome/browser/password_manager/password_manager.h"
#include "chrome/browser/tab_contents/tab_util.h" #include "chrome/browser/tab_contents/tab_util.h"
...@@ -37,8 +38,8 @@ class LoginHandlerWin : public LoginHandler, ...@@ -37,8 +38,8 @@ class LoginHandlerWin : public LoginHandler,
} }
// LoginModelObserver implementation. // LoginModelObserver implementation.
virtual void OnAutofillDataAvailable(const std::wstring& username, virtual void OnAutofillDataAvailable(const string16& username,
const std::wstring& password) OVERRIDE { const string16& password) OVERRIDE {
// Nothing to do here since LoginView takes care of autofil for win. // Nothing to do here since LoginView takes care of autofil for win.
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment