diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-10 22:19:24 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-10 22:19:24 +0000 |
commit | a4db7e9ca2f12badff11a141fedbd9fca5385fe8 (patch) | |
tree | a82138495d41ff425c3b9d9993b7dd4206d91ab2 /chrome/browser/autocomplete | |
parent | 97bcdf233710049c2ae3ade31c97c8eacd450724 (diff) | |
download | chromium_src-a4db7e9ca2f12badff11a141fedbd9fca5385fe8.zip chromium_src-a4db7e9ca2f12badff11a141fedbd9fca5385fe8.tar.gz chromium_src-a4db7e9ca2f12badff11a141fedbd9fca5385fe8.tar.bz2 |
Changes autocomplete to only prefix with http if haven't modified
host.
BUG=43585
TEST=see bug
Review URL: http://codereview.chromium.org/1993006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46860 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete')
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit.cc | 15 | ||||
-rw-r--r-- | chrome/browser/autocomplete/autocomplete_edit_unittest.cc | 28 |
2 files changed, 29 insertions, 14 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_edit.cc b/chrome/browser/autocomplete/autocomplete_edit.cc index 04e1935..9060153 100644 --- a/chrome/browser/autocomplete/autocomplete_edit.cc +++ b/chrome/browser/autocomplete/autocomplete_edit.cc @@ -196,16 +196,17 @@ void AutocompleteEditModel::AdjustTextForCopy(int sel_start, // the text parses as a url with a scheme of http, the user selected the // entire host, and the user hasn't edited the host or manually removed the // scheme. - if (url->SchemeIs(chrome::kHttpScheme)) { + GURL perm_url; + if (GetURLForText(permanent_text_, &perm_url) && + perm_url.SchemeIs(chrome::kHttpScheme) && + url->SchemeIs(chrome::kHttpScheme) && + perm_url.host() == url->host()) { + *write_url = true; + std::wstring http = ASCIIToWide(chrome::kHttpScheme) + ASCIIToWide(chrome::kStandardSchemeSeparator); - std::wstring host = UTF8ToWide(url->host()); - if (text->compare(0, http.length(), http) != 0 && - text->length() >= host.length() && - permanent_text_.compare(0, host.length(), host) == 0) { + if (text->compare(0, http.length(), http) != 0) *text = http + *text; - *write_url = true; - } } } diff --git a/chrome/browser/autocomplete/autocomplete_edit_unittest.cc b/chrome/browser/autocomplete/autocomplete_edit_unittest.cc index 8affff1..bd48602 100644 --- a/chrome/browser/autocomplete/autocomplete_edit_unittest.cc +++ b/chrome/browser/autocomplete/autocomplete_edit_unittest.cc @@ -81,6 +81,7 @@ typedef testing::Test AutocompleteEditTest; // Tests various permutations of AutocompleteModel::AdjustTextForCopy. TEST(AutocompleteEditTest, AdjustTextForCopy) { struct Data { + const wchar_t* perm_text; const int sel_start; const bool is_all_selected; const wchar_t* input; @@ -89,28 +90,41 @@ TEST(AutocompleteEditTest, AdjustTextForCopy) { const char* expected_url; } input[] = { // Test that http:// is inserted if all text is selected. - { 0, true, L"a.b/c", L"http://a.b/c", true, "http://a.b/c" }, + { L"a.b/c", 0, true, L"a.b/c", L"http://a.b/c", true, "http://a.b/c" }, // Test that http:// is inserted if the host is selected. - { 0, false, L"a.b/", L"http://a.b/", true, "http://a.b/" }, + { L"a.b/c", 0, false, L"a.b/", L"http://a.b/", true, "http://a.b/" }, // Tests that http:// is inserted if the path is modified. - { 0, false, L"a.b/d", L"http://a.b/d", true, "http://a.b/d" }, + { L"a.b/c", 0, false, L"a.b/d", L"http://a.b/d", true, "http://a.b/d" }, // Tests that http:// isn't inserted if the host is modified. - { 0, false, L"a.c/", L"a.c/", false, "" }, + { L"a.b/c", 0, false, L"a.c/", L"a.c/", false, "" }, // Tests that http:// isn't inserted if the start of the selection is 1. - { 1, false, L"a.b/", L"a.b/", false, "" }, + { L"a.b/c", 1, false, L"a.b/", L"a.b/", false, "" }, + + // Tests that http:// isn't inserted if a portion of the host is selected. + { L"a.com/", 0, false, L"a.co", L"a.co", false, "" }, + + // Tests that http:// isn't inserted for an https url after the user nukes + // https. + { L"https://a.com/", 0, false, L"a.com/", L"a.com/", false, "" }, + + // Tests that http:// isn't inserted if the user adds to the host. + { L"a.b/", 0, false, L"a.bc/", L"a.bc/", false, "" }, + + // Tests that we don't get double http if the user manually inserts http. + { L"a.b/", 0, false, L"http://a.b/", L"http://a.b/", true, "http://a.b/" }, }; TestingAutocompleteEditView view; TestingAutocompleteEditController controller; TestingProfile profile; AutocompleteEditModel model(&view, &controller, &profile); - model.UpdatePermanentText(L"a.b/c"); - for (size_t i = 0; i < ARRAYSIZE_UNSAFE(input); ++i) { + model.UpdatePermanentText(input[i].perm_text); + std::wstring result(input[i].input); GURL url; bool write_url; |