| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/string_util.h" | 5 #include "base/string_util.h" |
| 6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
| 7 #include "chrome/browser/autocomplete/autocomplete.h" | 7 #include "chrome/browser/autocomplete/autocomplete.h" |
| 8 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 8 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
| 9 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" | 9 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" |
| 10 #include "chrome/browser/autocomplete/autocomplete_match.h" | 10 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 // http://crbug.com/52928 | 25 // http://crbug.com/52928 |
| 26 #if defined(OS_CHROMEOS) | 26 #if defined(OS_CHROMEOS) |
| 27 #define MAYBE_Autocomplete FLAKY_Autocomplete | 27 #define MAYBE_Autocomplete FLAKY_Autocomplete |
| 28 #else | 28 #else |
| 29 #define MAYBE_Autocomplete Autocomplete | 29 #define MAYBE_Autocomplete Autocomplete |
| 30 #endif | 30 #endif |
| 31 | 31 |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 std::wstring AutocompleteResultAsString(const AutocompleteResult& result) { | 35 string16 AutocompleteResultAsString(const AutocompleteResult& result) { |
| 36 std::wstring output(StringPrintf(L"{%d} ", result.size())); | 36 std::string output(base::StringPrintf("{%lu} ", result.size())); |
| 37 for (size_t i = 0; i < result.size(); ++i) { | 37 for (size_t i = 0; i < result.size(); ++i) { |
| 38 AutocompleteMatch match = result.match_at(i); | 38 AutocompleteMatch match = result.match_at(i); |
| 39 std::wstring provider_name(ASCIIToWide(match.provider->name())); | 39 std::string provider_name = match.provider->name(); |
| 40 output.append(StringPrintf(L"[\"%ls\" by \"%ls\"] ", | 40 output.append(base::StringPrintf("[\"%s\" by \"%s\"] ", |
| 41 match.contents.c_str(), | 41 UTF16ToUTF8(match.contents).c_str(), |
| 42 provider_name.c_str())); | 42 provider_name.c_str())); |
| 43 } | 43 } |
| 44 return output; | 44 return UTF8ToUTF16(output); |
| 45 } | 45 } |
| 46 | 46 |
| 47 } // namespace | 47 } // namespace |
| 48 | 48 |
| 49 class AutocompleteBrowserTest : public InProcessBrowserTest { | 49 class AutocompleteBrowserTest : public InProcessBrowserTest { |
| 50 protected: | 50 protected: |
| 51 LocationBar* GetLocationBar() const { | 51 LocationBar* GetLocationBar() const { |
| 52 return browser()->window()->GetLocationBar(); | 52 return browser()->window()->GetLocationBar(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 AutocompleteController* GetAutocompleteController() const { | 55 AutocompleteController* GetAutocompleteController() const { |
| 56 return GetLocationBar()->location_entry()->model()->popup_model()-> | 56 return GetLocationBar()->location_entry()->model()->popup_model()-> |
| 57 autocomplete_controller(); | 57 autocomplete_controller(); |
| 58 } | 58 } |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, Basic) { | 61 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, Basic) { |
| 62 LocationBar* location_bar = GetLocationBar(); | 62 LocationBar* location_bar = GetLocationBar(); |
| 63 | 63 |
| 64 EXPECT_TRUE(location_bar->GetInputString().empty()); | 64 EXPECT_TRUE(location_bar->GetInputString().empty()); |
| 65 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), | 65 EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), |
| 66 location_bar->location_entry()->GetText()); | 66 location_bar->location_entry()->GetText()); |
| 67 // TODO(phajdan.jr): check state of IsSelectAll when it's consistent across | 67 // TODO(phajdan.jr): check state of IsSelectAll when it's consistent across |
| 68 // platforms. | 68 // platforms. |
| 69 | 69 |
| 70 location_bar->FocusLocation(true); | 70 location_bar->FocusLocation(true); |
| 71 | 71 |
| 72 EXPECT_TRUE(location_bar->GetInputString().empty()); | 72 EXPECT_TRUE(location_bar->GetInputString().empty()); |
| 73 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), | 73 EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), |
| 74 location_bar->location_entry()->GetText()); | 74 location_bar->location_entry()->GetText()); |
| 75 EXPECT_TRUE(location_bar->location_entry()->IsSelectAll()); | 75 EXPECT_TRUE(location_bar->location_entry()->IsSelectAll()); |
| 76 | 76 |
| 77 location_bar->location_entry()->SetUserText(L"chrome"); | 77 location_bar->location_entry()->SetUserText(ASCIIToUTF16("chrome")); |
| 78 | 78 |
| 79 EXPECT_TRUE(location_bar->GetInputString().empty()); | 79 EXPECT_TRUE(location_bar->GetInputString().empty()); |
| 80 EXPECT_EQ(L"chrome", location_bar->location_entry()->GetText()); | 80 EXPECT_EQ(ASCIIToUTF16("chrome"), location_bar->location_entry()->GetText()); |
| 81 EXPECT_FALSE(location_bar->location_entry()->IsSelectAll()); | 81 EXPECT_FALSE(location_bar->location_entry()->IsSelectAll()); |
| 82 | 82 |
| 83 location_bar->location_entry()->RevertAll(); | 83 location_bar->location_entry()->RevertAll(); |
| 84 | 84 |
| 85 EXPECT_TRUE(location_bar->GetInputString().empty()); | 85 EXPECT_TRUE(location_bar->GetInputString().empty()); |
| 86 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), | 86 EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), |
| 87 location_bar->location_entry()->GetText()); | 87 location_bar->location_entry()->GetText()); |
| 88 EXPECT_FALSE(location_bar->location_entry()->IsSelectAll()); | 88 EXPECT_FALSE(location_bar->location_entry()->IsSelectAll()); |
| 89 | 89 |
| 90 location_bar->location_entry()->SetUserText(L"chrome"); | 90 location_bar->location_entry()->SetUserText(ASCIIToUTF16("chrome")); |
| 91 location_bar->Revert(); | 91 location_bar->Revert(); |
| 92 | 92 |
| 93 EXPECT_TRUE(location_bar->GetInputString().empty()); | 93 EXPECT_TRUE(location_bar->GetInputString().empty()); |
| 94 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), | 94 EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), |
| 95 location_bar->location_entry()->GetText()); | 95 location_bar->location_entry()->GetText()); |
| 96 EXPECT_FALSE(location_bar->location_entry()->IsSelectAll()); | 96 EXPECT_FALSE(location_bar->location_entry()->IsSelectAll()); |
| 97 } | 97 } |
| 98 | 98 |
| 99 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, MAYBE_Autocomplete) { | 99 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, MAYBE_Autocomplete) { |
| 100 // The results depend on the history backend being loaded. Make sure it is | 100 // The results depend on the history backend being loaded. Make sure it is |
| 101 // loaded so that the autocomplete results are consistent. | 101 // loaded so that the autocomplete results are consistent. |
| 102 ui_test_utils::WaitForHistoryToLoad(browser()); | 102 ui_test_utils::WaitForHistoryToLoad(browser()); |
| 103 | 103 |
| 104 LocationBar* location_bar = GetLocationBar(); | 104 LocationBar* location_bar = GetLocationBar(); |
| 105 AutocompleteController* autocomplete_controller = GetAutocompleteController(); | 105 AutocompleteController* autocomplete_controller = GetAutocompleteController(); |
| 106 | 106 |
| 107 { | 107 { |
| 108 autocomplete_controller->Start(L"chrome", std::wstring(), | 108 autocomplete_controller->Start(ASCIIToUTF16("chrome"), string16(), |
| 109 true, false, true, true); | 109 true, false, true, true); |
| 110 | 110 |
| 111 EXPECT_TRUE(autocomplete_controller->done()); | 111 EXPECT_TRUE(autocomplete_controller->done()); |
| 112 EXPECT_TRUE(location_bar->GetInputString().empty()); | 112 EXPECT_TRUE(location_bar->GetInputString().empty()); |
| 113 EXPECT_TRUE(location_bar->location_entry()->GetText().empty()); | 113 EXPECT_TRUE(location_bar->location_entry()->GetText().empty()); |
| 114 EXPECT_TRUE(location_bar->location_entry()->IsSelectAll()); | 114 EXPECT_TRUE(location_bar->location_entry()->IsSelectAll()); |
| 115 const AutocompleteResult& result = autocomplete_controller->result(); | 115 const AutocompleteResult& result = autocomplete_controller->result(); |
| 116 ASSERT_EQ(1U, result.size()) << AutocompleteResultAsString(result); | 116 ASSERT_EQ(1U, result.size()) << AutocompleteResultAsString(result); |
| 117 AutocompleteMatch match = result.match_at(0); | 117 AutocompleteMatch match = result.match_at(0); |
| 118 EXPECT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, match.type); | 118 EXPECT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, match.type); |
| 119 EXPECT_FALSE(match.deletable); | 119 EXPECT_FALSE(match.deletable); |
| 120 } | 120 } |
| 121 | 121 |
| 122 { | 122 { |
| 123 location_bar->Revert(); | 123 location_bar->Revert(); |
| 124 | 124 |
| 125 EXPECT_TRUE(location_bar->GetInputString().empty()); | 125 EXPECT_TRUE(location_bar->GetInputString().empty()); |
| 126 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), | 126 EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), |
| 127 location_bar->location_entry()->GetText()); | 127 location_bar->location_entry()->GetText()); |
| 128 EXPECT_FALSE(location_bar->location_entry()->IsSelectAll()); | 128 EXPECT_FALSE(location_bar->location_entry()->IsSelectAll()); |
| 129 const AutocompleteResult& result = autocomplete_controller->result(); | 129 const AutocompleteResult& result = autocomplete_controller->result(); |
| 130 EXPECT_TRUE(result.empty()) << AutocompleteResultAsString(result); | 130 EXPECT_TRUE(result.empty()) << AutocompleteResultAsString(result); |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 | 133 |
| 134 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, TabAwayRevertSelect) { | 134 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, TabAwayRevertSelect) { |
| 135 // http://code.google.com/p/chromium/issues/detail?id=38385 | 135 // http://code.google.com/p/chromium/issues/detail?id=38385 |
| 136 // Make sure that tabbing away from an empty omnibar causes a revert | 136 // Make sure that tabbing away from an empty omnibar causes a revert |
| 137 // and select all. | 137 // and select all. |
| 138 LocationBar* location_bar = GetLocationBar(); | 138 LocationBar* location_bar = GetLocationBar(); |
| 139 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), | 139 EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), |
| 140 location_bar->location_entry()->GetText()); | 140 location_bar->location_entry()->GetText()); |
| 141 location_bar->location_entry()->SetUserText(L""); | 141 location_bar->location_entry()->SetUserText(string16()); |
| 142 browser()->AddSelectedTabWithURL(GURL(chrome::kAboutBlankURL), | 142 browser()->AddSelectedTabWithURL(GURL(chrome::kAboutBlankURL), |
| 143 PageTransition::START_PAGE); | 143 PageTransition::START_PAGE); |
| 144 ui_test_utils::WaitForNavigation( | 144 ui_test_utils::WaitForNavigation( |
| 145 &browser()->GetSelectedTabContents()->controller()); | 145 &browser()->GetSelectedTabContents()->controller()); |
| 146 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), | 146 EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), |
| 147 location_bar->location_entry()->GetText()); | 147 location_bar->location_entry()->GetText()); |
| 148 browser()->CloseTab(); | 148 browser()->CloseTab(); |
| 149 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), | 149 EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), |
| 150 location_bar->location_entry()->GetText()); | 150 location_bar->location_entry()->GetText()); |
| 151 EXPECT_TRUE(location_bar->location_entry()->IsSelectAll()); | 151 EXPECT_TRUE(location_bar->location_entry()->IsSelectAll()); |
| 152 } | 152 } |
| 153 | 153 |
| 154 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, FocusSearch) { | 154 IN_PROC_BROWSER_TEST_F(AutocompleteBrowserTest, FocusSearch) { |
| 155 LocationBar* location_bar = GetLocationBar(); | 155 LocationBar* location_bar = GetLocationBar(); |
| 156 | 156 |
| 157 // Focus search when omnibox is blank | 157 // Focus search when omnibox is blank |
| 158 { | 158 { |
| 159 EXPECT_TRUE(location_bar->GetInputString().empty()); | 159 EXPECT_TRUE(location_bar->GetInputString().empty()); |
| 160 EXPECT_EQ(UTF8ToWide(chrome::kAboutBlankURL), | 160 EXPECT_EQ(UTF8ToUTF16(chrome::kAboutBlankURL), |
| 161 location_bar->location_entry()->GetText()); | 161 location_bar->location_entry()->GetText()); |
| 162 | 162 |
| 163 location_bar->FocusSearch(); | 163 location_bar->FocusSearch(); |
| 164 EXPECT_TRUE(location_bar->GetInputString().empty()); | 164 EXPECT_TRUE(location_bar->GetInputString().empty()); |
| 165 EXPECT_EQ(L"?", location_bar->location_entry()->GetText()); | 165 EXPECT_EQ(ASCIIToUTF16("?"), location_bar->location_entry()->GetText()); |
| 166 | 166 |
| 167 size_t selection_start, selection_end; | 167 size_t selection_start, selection_end; |
| 168 location_bar->location_entry()->GetSelectionBounds(&selection_start, | 168 location_bar->location_entry()->GetSelectionBounds(&selection_start, |
| 169 &selection_end); | 169 &selection_end); |
| 170 EXPECT_EQ(1U, selection_start); | 170 EXPECT_EQ(1U, selection_start); |
| 171 EXPECT_EQ(1U, selection_end); | 171 EXPECT_EQ(1U, selection_end); |
| 172 } | 172 } |
| 173 | 173 |
| 174 // Focus search when omnibox is _not_ alread in forced query mode. | 174 // Focus search when omnibox is _not_ alread in forced query mode. |
| 175 { | 175 { |
| 176 location_bar->location_entry()->SetUserText(L"foo"); | 176 location_bar->location_entry()->SetUserText(ASCIIToUTF16("foo")); |
| 177 EXPECT_TRUE(location_bar->GetInputString().empty()); | 177 EXPECT_TRUE(location_bar->GetInputString().empty()); |
| 178 EXPECT_EQ(L"foo", location_bar->location_entry()->GetText()); | 178 EXPECT_EQ(ASCIIToUTF16("foo"), location_bar->location_entry()->GetText()); |
| 179 | 179 |
| 180 location_bar->FocusSearch(); | 180 location_bar->FocusSearch(); |
| 181 EXPECT_TRUE(location_bar->GetInputString().empty()); | 181 EXPECT_TRUE(location_bar->GetInputString().empty()); |
| 182 EXPECT_EQ(L"?", location_bar->location_entry()->GetText()); | 182 EXPECT_EQ(ASCIIToUTF16("?"), location_bar->location_entry()->GetText()); |
| 183 | 183 |
| 184 size_t selection_start, selection_end; | 184 size_t selection_start, selection_end; |
| 185 location_bar->location_entry()->GetSelectionBounds(&selection_start, | 185 location_bar->location_entry()->GetSelectionBounds(&selection_start, |
| 186 &selection_end); | 186 &selection_end); |
| 187 EXPECT_EQ(1U, selection_start); | 187 EXPECT_EQ(1U, selection_start); |
| 188 EXPECT_EQ(1U, selection_end); | 188 EXPECT_EQ(1U, selection_end); |
| 189 } | 189 } |
| 190 | 190 |
| 191 // Focus search when omnibox _is_ already in forced query mode, but no query | 191 // Focus search when omnibox _is_ already in forced query mode, but no query |
| 192 // has been typed. | 192 // has been typed. |
| 193 { | 193 { |
| 194 location_bar->location_entry()->SetUserText(L"?"); | 194 location_bar->location_entry()->SetUserText(ASCIIToUTF16("?")); |
| 195 EXPECT_TRUE(location_bar->GetInputString().empty()); | 195 EXPECT_TRUE(location_bar->GetInputString().empty()); |
| 196 EXPECT_EQ(L"?", location_bar->location_entry()->GetText()); | 196 EXPECT_EQ(ASCIIToUTF16("?"), location_bar->location_entry()->GetText()); |
| 197 | 197 |
| 198 location_bar->FocusSearch(); | 198 location_bar->FocusSearch(); |
| 199 EXPECT_TRUE(location_bar->GetInputString().empty()); | 199 EXPECT_TRUE(location_bar->GetInputString().empty()); |
| 200 EXPECT_EQ(L"?", location_bar->location_entry()->GetText()); | 200 EXPECT_EQ(ASCIIToUTF16("?"), location_bar->location_entry()->GetText()); |
| 201 | 201 |
| 202 size_t selection_start, selection_end; | 202 size_t selection_start, selection_end; |
| 203 location_bar->location_entry()->GetSelectionBounds(&selection_start, | 203 location_bar->location_entry()->GetSelectionBounds(&selection_start, |
| 204 &selection_end); | 204 &selection_end); |
| 205 EXPECT_EQ(1U, selection_start); | 205 EXPECT_EQ(1U, selection_start); |
| 206 EXPECT_EQ(1U, selection_end); | 206 EXPECT_EQ(1U, selection_end); |
| 207 } | 207 } |
| 208 | 208 |
| 209 // Focus search when omnibox _is_ already in forced query mode, and some query | 209 // Focus search when omnibox _is_ already in forced query mode, and some query |
| 210 // has been typed. | 210 // has been typed. |
| 211 { | 211 { |
| 212 location_bar->location_entry()->SetUserText(L"?foo"); | 212 location_bar->location_entry()->SetUserText(ASCIIToUTF16("?foo")); |
| 213 EXPECT_TRUE(location_bar->GetInputString().empty()); | 213 EXPECT_TRUE(location_bar->GetInputString().empty()); |
| 214 EXPECT_EQ(L"?foo", location_bar->location_entry()->GetText()); | 214 EXPECT_EQ(ASCIIToUTF16("?foo"), location_bar->location_entry()->GetText()); |
| 215 | 215 |
| 216 location_bar->FocusSearch(); | 216 location_bar->FocusSearch(); |
| 217 EXPECT_TRUE(location_bar->GetInputString().empty()); | 217 EXPECT_TRUE(location_bar->GetInputString().empty()); |
| 218 EXPECT_EQ(L"?foo", location_bar->location_entry()->GetText()); | 218 EXPECT_EQ(ASCIIToUTF16("?foo"), location_bar->location_entry()->GetText()); |
| 219 | 219 |
| 220 size_t selection_start, selection_end; | 220 size_t selection_start, selection_end; |
| 221 location_bar->location_entry()->GetSelectionBounds(&selection_start, | 221 location_bar->location_entry()->GetSelectionBounds(&selection_start, |
| 222 &selection_end); | 222 &selection_end); |
| 223 EXPECT_EQ(1U, std::min(selection_start, selection_end)); | 223 EXPECT_EQ(1U, std::min(selection_start, selection_end)); |
| 224 EXPECT_EQ(4U, std::max(selection_start, selection_end)); | 224 EXPECT_EQ(4U, std::max(selection_start, selection_end)); |
| 225 } | 225 } |
| 226 | 226 |
| 227 // Focus search when omnibox is in forced query mode with leading whitespace. | 227 // Focus search when omnibox is in forced query mode with leading whitespace. |
| 228 { | 228 { |
| 229 location_bar->location_entry()->SetUserText(L" ?foo"); | 229 location_bar->location_entry()->SetUserText(ASCIIToUTF16(" ?foo")); |
| 230 EXPECT_TRUE(location_bar->GetInputString().empty()); | 230 EXPECT_TRUE(location_bar->GetInputString().empty()); |
| 231 EXPECT_EQ(L" ?foo", location_bar->location_entry()->GetText()); | 231 EXPECT_EQ(ASCIIToUTF16(" ?foo"), |
| 232 location_bar->location_entry()->GetText()); |
| 232 | 233 |
| 233 location_bar->FocusSearch(); | 234 location_bar->FocusSearch(); |
| 234 EXPECT_TRUE(location_bar->GetInputString().empty()); | 235 EXPECT_TRUE(location_bar->GetInputString().empty()); |
| 235 EXPECT_EQ(L" ?foo", location_bar->location_entry()->GetText()); | 236 EXPECT_EQ(ASCIIToUTF16(" ?foo"), |
| 237 location_bar->location_entry()->GetText()); |
| 236 | 238 |
| 237 size_t selection_start, selection_end; | 239 size_t selection_start, selection_end; |
| 238 location_bar->location_entry()->GetSelectionBounds(&selection_start, | 240 location_bar->location_entry()->GetSelectionBounds(&selection_start, |
| 239 &selection_end); | 241 &selection_end); |
| 240 EXPECT_EQ(4U, std::min(selection_start, selection_end)); | 242 EXPECT_EQ(4U, std::min(selection_start, selection_end)); |
| 241 EXPECT_EQ(7U, std::max(selection_start, selection_end)); | 243 EXPECT_EQ(7U, std::max(selection_start, selection_end)); |
| 242 } | 244 } |
| 243 } | 245 } |
| OLD | NEW |