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(
}
default:
if (observer_) {
observer_->OnAutofillDataAvailable(
UTF16ToWideHack(preferred_match->username_value),
UTF16ToWideHack(preferred_match->password_value));
observer_->OnAutofillDataAvailable(preferred_match->username_value,
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
// found in the LICENSE file.
......@@ -6,7 +6,7 @@
#define CHROME_BROWSER_UI_LOGIN_LOGIN_MODEL_H_
#pragma once
#include <string>
#include "base/string16.h"
// Simple Model & Observer interfaces for a LoginView to facilitate exchanging
// information.
......@@ -14,8 +14,8 @@ class LoginModelObserver {
public:
// Called by the model when a username,password pair has been identified
// as a match for the pending login prompt.
virtual void OnAutofillDataAvailable(const std::wstring& username,
const std::wstring& password) = 0;
virtual void OnAutofillDataAvailable(const string16& username,
const string16& password) = 0;
protected:
virtual ~LoginModelObserver() {}
......
......@@ -26,22 +26,22 @@ namespace {
class LoginPromptBrowserTest : public InProcessBrowserTest {
public:
LoginPromptBrowserTest()
: bad_password_(L"incorrect"), bad_username_(L"nouser") {
: bad_password_("incorrect"), bad_username_("nouser") {
set_show_window(true);
auth_map_["foo"] = AuthInfo(L"testuser", L"foopassword");
auth_map_["bar"] = AuthInfo(L"testuser", L"barpassword");
auth_map_["foo"] = AuthInfo("testuser", "foopassword");
auth_map_["bar"] = AuthInfo("testuser", "barpassword");
}
protected:
struct AuthInfo {
std::wstring username_;
std::wstring password_;
std::string username_;
std::string password_;
AuthInfo() {}
AuthInfo(const std::wstring username,
const std::wstring password)
AuthInfo(const std::string username,
const std::string password)
: username_(username), password_(password) {}
};
......@@ -50,8 +50,8 @@ class LoginPromptBrowserTest : public InProcessBrowserTest {
void SetAuthFor(LoginHandler* handler);
AuthMap auth_map_;
std::wstring bad_password_;
std::wstring bad_username_;
std::string bad_password_;
std::string bad_username_;
};
void LoginPromptBrowserTest::SetAuthFor(LoginHandler* handler) {
......@@ -62,8 +62,8 @@ void LoginPromptBrowserTest::SetAuthFor(LoginHandler* handler) {
EXPECT_TRUE(auth_map_.end() != i);
if (i != auth_map_.end()) {
const AuthInfo& info = i->second;
handler->SetAuth(WideToUTF16Hack(info.username_),
WideToUTF16Hack(info.password_));
handler->SetAuth(UTF8ToUTF16(info.username_),
UTF8ToUTF16(info.password_));
}
}
......@@ -491,8 +491,8 @@ IN_PROC_BROWSER_TEST_F(LoginPromptBrowserTest, IncorrectConfirmation) {
LoginHandler* handler = *observer.handlers_.begin();
ASSERT_TRUE(handler);
handler->SetAuth(WideToUTF16Hack(bad_username_),
WideToUTF16Hack(bad_password_));
handler->SetAuth(UTF8ToUTF16(bad_username_),
UTF8ToUTF16(bad_password_));
auth_supplied_waiter.Wait();
// The request should be retried after the incorrect password is
......
......@@ -6,6 +6,7 @@
#include <gtk/gtk.h>
#include "base/string16.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/password_manager/password_manager.h"
#include "chrome/browser/tab_contents/tab_contents_view_gtk.h"
......@@ -49,17 +50,17 @@ class LoginHandlerGtk : public LoginHandler,
}
// LoginModelObserver implementation.
virtual void OnAutofillDataAvailable(const std::wstring& username,
const std::wstring& password) {
virtual void OnAutofillDataAvailable(const string16& username,
const string16& password) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
// NOTE: Would be nice to use gtk_entry_get_text_length, but it is fairly
// new and not always in our GTK version.
if (strlen(gtk_entry_get_text(GTK_ENTRY(username_entry_))) == 0) {
gtk_entry_set_text(GTK_ENTRY(username_entry_),
WideToUTF8(username).c_str());
UTF16ToUTF8(username).c_str());
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);
}
}
......
......@@ -6,6 +6,7 @@
#import "chrome/browser/ui/login/login_prompt_mac.h"
#include "base/mac/mac_util.h"
#include "base/string16.h"
#include "base/string_util.h"
#include "base/sys_string_conversions.h"
#include "base/utf_string_conversions.h"
......@@ -44,12 +45,12 @@ class LoginHandlerMac : public LoginHandler,
}
// LoginModelObserver implementation.
virtual void OnAutofillDataAvailable(const std::wstring& username,
const std::wstring& password) {
virtual void OnAutofillDataAvailable(const string16& username,
const string16& password) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
[sheet_controller_ autofillLogin:base::SysWideToNSString(username)
password:base::SysWideToNSString(password)];
[sheet_controller_ autofillLogin:base::SysUTF16ToNSString(username)
password:base::SysUTF16ToNSString(password)];
}
// LoginHandler:
......
......@@ -9,6 +9,7 @@
#include "base/bind.h"
#include "base/bind_helpers.h"
#include "base/json/json_reader.h"
#include "base/string16.h"
#include "base/utf_string_conversions.h"
#include "base/values.h"
#include "chrome/browser/profiles/profile.h"
......@@ -127,8 +128,8 @@ class LoginHandlerHtmlDelegate : public HtmlDialogUIDelegate,
base::Unretained(this)));
}
void ShowAutofillData(const std::wstring& username,
const std::wstring& password);
void ShowAutofillData(const string16& username,
const string16& password);
private:
// Send autofill data to HTML once the dialog is ready and the data is
......@@ -147,8 +148,8 @@ class LoginHandlerHtmlDelegate : public HtmlDialogUIDelegate,
bool has_autofill_;
bool ready_for_autofill_;
std::string autofill_username_;
std::string autofill_password_;
string16 autofill_username_;
string16 autofill_password_;
static const int kDialogWidth = 400;
static const int kDialogHeight = 160;
......@@ -164,8 +165,8 @@ class LoginHandlerHtml : public LoginHandler {
}
// LoginModelObserver method:
virtual void OnAutofillDataAvailable(const std::wstring& username,
const std::wstring& password) OVERRIDE {
virtual void OnAutofillDataAvailable(const string16& username,
const string16& password) OVERRIDE {
if (delegate_)
delegate_->ShowAutofillData(username, password);
}
......@@ -218,10 +219,10 @@ void LoginHandlerHtmlDelegate::OnDialogClosed(const std::string& json_retval) {
// we've registered ourselves as a WebUIMessageHandler.
}
void LoginHandlerHtmlDelegate::ShowAutofillData(const std::wstring& username,
const std::wstring& password) {
autofill_username_ = WideToUTF8(username);
autofill_password_ = WideToUTF8(password);
void LoginHandlerHtmlDelegate::ShowAutofillData(const string16& username,
const string16& password) {
autofill_username_ = username;
autofill_password_ = password;
has_autofill_ = true;
SendAutofillData();
}
......
......@@ -4,6 +4,8 @@
#include <string>
#include "base/string16.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/net/url_fixer_upper.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/automation/automation_proxy.h"
......@@ -23,10 +25,10 @@ const FilePath::CharType kDocRoot[] = FILE_PATH_LITERAL("chrome/test/data");
class LoginPromptTest : public UITest {
protected:
LoginPromptTest()
: username_basic_(L"basicuser"),
username_digest_(L"digestuser"),
password_(L"secret"),
password_bad_(L"denyme"),
: username_basic_(UTF8ToUTF16("basicuser")),
username_digest_(UTF8ToUTF16("digestuser")),
password_(UTF8ToUTF16("secret")),
password_bad_(UTF8ToUTF16("denyme")),
test_server_(net::TestServer::TYPE_HTTP, FilePath(kDocRoot)) {
}
......@@ -37,18 +39,18 @@ class LoginPromptTest : public UITest {
}
protected:
wstring username_basic_;
wstring username_digest_;
wstring password_;
wstring password_bad_;
string16 username_basic_;
string16 username_digest_;
string16 password_;
string16 password_bad_;
net::TestServer test_server_;
};
wstring ExpectedTitleFromAuth(const wstring& username,
const wstring& password) {
string16 ExpectedTitleFromAuth(const string16& username,
const string16& password) {
// 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.
......@@ -61,7 +63,8 @@ TEST_F(LoginPromptTest, TestBasicAuth) {
tab->NavigateToURL(test_server_.GetURL("auth-basic")));
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->CancelAuth());
EXPECT_EQ(L"Denied: wrong password", GetActiveTabTitle());
......@@ -70,9 +73,10 @@ TEST_F(LoginPromptTest, TestBasicAuth) {
tab->NavigateToURL(test_server_.GetURL("auth-basic")));
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_),
GetActiveTabTitle());
WideToUTF16Hack(GetActiveTabTitle()));
}
// Test that "Digest" HTTP authentication works.
......@@ -85,7 +89,8 @@ TEST_F(LoginPromptTest, TestDigestAuth) {
tab->NavigateToURL(test_server_.GetURL("auth-digest")));
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_EQ(L"Denied: wrong password", GetActiveTabTitle());
......@@ -93,9 +98,10 @@ TEST_F(LoginPromptTest, TestDigestAuth) {
tab->NavigateToURL(test_server_.GetURL("auth-digest")));
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_),
GetActiveTabTitle());
WideToUTF16Hack(GetActiveTabTitle()));
}
// Test that logging in on 2 tabs at once works.
......@@ -114,16 +120,20 @@ TEST_F(LoginPromptTest, TestTwoAuths) {
digest_tab->NavigateToURL(test_server_.GetURL("auth-digest")));
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->SetAuth(username_digest_, password_));
EXPECT_TRUE(digest_tab->SetAuth(UTF16ToWideHack(username_digest_),
UTF16ToWideHack(password_)));
wstring 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_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
......@@ -147,16 +157,19 @@ TEST_F(LoginPromptTest, SupplyRedundantAuths) {
// Set the auth in only one of the tabs (but wait for the other to load).
int64 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));
// Now both tabs have loaded.
wstring title1;
EXPECT_TRUE(basic_tab1->GetTabTitle(&title1));
EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_), title1);
EXPECT_EQ(ExpectedTitleFromAuth(username_basic_, password_),
WideToUTF16Hack(title1));
wstring 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
......
......@@ -4,6 +4,7 @@
#include "chrome/browser/ui/login/login_prompt.h"
#include "base/string16.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/password_manager/password_manager.h"
#include "chrome/browser/tab_contents/tab_util.h"
......@@ -37,8 +38,8 @@ class LoginHandlerWin : public LoginHandler,
}
// LoginModelObserver implementation.
virtual void OnAutofillDataAvailable(const std::wstring& username,
const std::wstring& password) OVERRIDE {
virtual void OnAutofillDataAvailable(const string16& username,
const string16& password) OVERRIDE {
// 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