| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdio.h> | 6 #include <stdio.h> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/memory/ptr_util.h" |
| 10 #include "base/scoped_observer.h" | 11 #include "base/scoped_observer.h" |
| 11 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 15 #include "build/build_config.h" | 16 #include "build/build_config.h" |
| 16 #include "chrome/app/chrome_command_ids.h" | 17 #include "chrome/app/chrome_command_ids.h" |
| 17 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 18 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 18 #include "chrome/browser/chrome_notification_types.h" | 19 #include "chrome/browser/chrome_notification_types.h" |
| 19 #include "chrome/browser/history/history_service_factory.h" | 20 #include "chrome/browser/history/history_service_factory.h" |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 ASSERT_TRUE(model); | 269 ASSERT_TRUE(model); |
| 269 | 270 |
| 270 search_test_utils::WaitForTemplateURLServiceToLoad(model); | 271 search_test_utils::WaitForTemplateURLServiceToLoad(model); |
| 271 | 272 |
| 272 ASSERT_TRUE(model->loaded()); | 273 ASSERT_TRUE(model->loaded()); |
| 273 | 274 |
| 274 TemplateURLData data; | 275 TemplateURLData data; |
| 275 data.SetShortName(ASCIIToUTF16(kSearchShortName)); | 276 data.SetShortName(ASCIIToUTF16(kSearchShortName)); |
| 276 data.SetKeyword(ASCIIToUTF16(kSearchKeyword)); | 277 data.SetKeyword(ASCIIToUTF16(kSearchKeyword)); |
| 277 data.SetURL(kSearchURL); | 278 data.SetURL(kSearchURL); |
| 278 TemplateURL* template_url = new TemplateURL(data); | 279 TemplateURL* template_url = model->Add(base::MakeUnique<TemplateURL>(data)); |
| 279 model->Add(template_url); | |
| 280 model->SetUserSelectedDefaultSearchProvider(template_url); | 280 model->SetUserSelectedDefaultSearchProvider(template_url); |
| 281 | 281 |
| 282 data.SetKeyword(ASCIIToUTF16(kSearchKeyword2)); | 282 data.SetKeyword(ASCIIToUTF16(kSearchKeyword2)); |
| 283 model->Add(new TemplateURL(data)); | 283 model->Add(base::MakeUnique<TemplateURL>(data)); |
| 284 | 284 |
| 285 // Remove built-in template urls, like google.com, bing.com etc., as they | 285 // Remove built-in template urls, like google.com, bing.com etc., as they |
| 286 // may appear as autocomplete suggests and interfere with our tests. | 286 // may appear as autocomplete suggests and interfere with our tests. |
| 287 TemplateURLService::TemplateURLVector urls = model->GetTemplateURLs(); | 287 TemplateURLService::TemplateURLVector urls = model->GetTemplateURLs(); |
| 288 for (TemplateURLService::TemplateURLVector::const_iterator i = urls.begin(); | 288 for (TemplateURLService::TemplateURLVector::const_iterator i = urls.begin(); |
| 289 i != urls.end(); | 289 i != urls.end(); |
| 290 ++i) { | 290 ++i) { |
| 291 if ((*i)->prepopulate_id() != 0) | 291 if ((*i)->prepopulate_id() != 0) |
| 292 model->Remove(*i); | 292 model->Remove(*i); |
| 293 } | 293 } |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 TemplateURLService* template_url_service = | 631 TemplateURLService* template_url_service = |
| 632 TemplateURLServiceFactory::GetForProfile(profile); | 632 TemplateURLServiceFactory::GetForProfile(profile); |
| 633 | 633 |
| 634 // Add a non-substituting keyword. This ensures the popup will have a | 634 // Add a non-substituting keyword. This ensures the popup will have a |
| 635 // non-verbatim entry with "ab" as a prefix. This way, by arrowing down, we | 635 // non-verbatim entry with "ab" as a prefix. This way, by arrowing down, we |
| 636 // can set "abc" as temporary text in the omnibox. | 636 // can set "abc" as temporary text in the omnibox. |
| 637 TemplateURLData data; | 637 TemplateURLData data; |
| 638 data.SetShortName(ASCIIToUTF16("abc")); | 638 data.SetShortName(ASCIIToUTF16("abc")); |
| 639 data.SetKeyword(ASCIIToUTF16(kSearchText)); | 639 data.SetKeyword(ASCIIToUTF16(kSearchText)); |
| 640 data.SetURL("http://abc.com/"); | 640 data.SetURL("http://abc.com/"); |
| 641 template_url_service->Add(new TemplateURL(data)); | 641 template_url_service->Add(base::MakeUnique<TemplateURL>(data)); |
| 642 | 642 |
| 643 // Send "ab", so that an "abc" entry appears in the popup. | 643 // Send "ab", so that an "abc" entry appears in the popup. |
| 644 const ui::KeyboardCode kSearchTextPrefixKeys[] = { | 644 const ui::KeyboardCode kSearchTextPrefixKeys[] = { |
| 645 ui::VKEY_A, ui::VKEY_B, ui::VKEY_UNKNOWN | 645 ui::VKEY_A, ui::VKEY_B, ui::VKEY_UNKNOWN |
| 646 }; | 646 }; |
| 647 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextPrefixKeys)); | 647 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextPrefixKeys)); |
| 648 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | 648 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); |
| 649 ASSERT_TRUE(popup_model->IsOpen()); | 649 ASSERT_TRUE(popup_model->IsOpen()); |
| 650 | 650 |
| 651 // Arrow down to the "abc" entry in the popup. | 651 // Arrow down to the "abc" entry in the popup. |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1106 | 1106 |
| 1107 Profile* profile = browser()->profile(); | 1107 Profile* profile = browser()->profile(); |
| 1108 TemplateURLService* template_url_service = | 1108 TemplateURLService* template_url_service = |
| 1109 TemplateURLServiceFactory::GetForProfile(profile); | 1109 TemplateURLServiceFactory::GetForProfile(profile); |
| 1110 | 1110 |
| 1111 // Add a non-default substituting keyword. | 1111 // Add a non-default substituting keyword. |
| 1112 TemplateURLData data; | 1112 TemplateURLData data; |
| 1113 data.SetShortName(ASCIIToUTF16("Search abc")); | 1113 data.SetShortName(ASCIIToUTF16("Search abc")); |
| 1114 data.SetKeyword(ASCIIToUTF16(kSearchText)); | 1114 data.SetKeyword(ASCIIToUTF16(kSearchText)); |
| 1115 data.SetURL("http://abc.com/{searchTerms}"); | 1115 data.SetURL("http://abc.com/{searchTerms}"); |
| 1116 TemplateURL* template_url = new TemplateURL(data); | 1116 TemplateURL* template_url = |
| 1117 template_url_service->Add(template_url); | 1117 template_url_service->Add(base::MakeUnique<TemplateURL>(data)); |
| 1118 | 1118 |
| 1119 omnibox_view->SetUserText(base::string16()); | 1119 omnibox_view->SetUserText(base::string16()); |
| 1120 | 1120 |
| 1121 // Non-default substituting keyword shouldn't be matched by default. | 1121 // Non-default substituting keyword shouldn't be matched by default. |
| 1122 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); | 1122 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); |
| 1123 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | 1123 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); |
| 1124 ASSERT_TRUE(popup_model->IsOpen()); | 1124 ASSERT_TRUE(popup_model->IsOpen()); |
| 1125 | 1125 |
| 1126 // Check if the default match result is Search Primary Provider. | 1126 // Check if the default match result is Search Primary Provider. |
| 1127 ASSERT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, | 1127 ASSERT_EQ(AutocompleteMatchType::SEARCH_WHAT_YOU_TYPED, |
| 1128 popup_model->result().default_match()->type); | 1128 popup_model->result().default_match()->type); |
| 1129 ASSERT_EQ(kSearchTextURL, | 1129 ASSERT_EQ(kSearchTextURL, |
| 1130 popup_model->result().default_match()->destination_url.spec()); | 1130 popup_model->result().default_match()->destination_url.spec()); |
| 1131 | 1131 |
| 1132 omnibox_view->SetUserText(base::string16()); | 1132 omnibox_view->SetUserText(base::string16()); |
| 1133 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | 1133 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); |
| 1134 ASSERT_FALSE(popup_model->IsOpen()); | 1134 ASSERT_FALSE(popup_model->IsOpen()); |
| 1135 | 1135 |
| 1136 // Try a non-substituting keyword. | 1136 // Try a non-substituting keyword. |
| 1137 template_url_service->Remove(template_url); | 1137 template_url_service->Remove(template_url); |
| 1138 data.SetShortName(ASCIIToUTF16("abc")); | 1138 data.SetShortName(ASCIIToUTF16("abc")); |
| 1139 data.SetURL("http://abc.com/"); | 1139 data.SetURL("http://abc.com/"); |
| 1140 template_url_service->Add(new TemplateURL(data)); | 1140 template_url_service->Add(base::MakeUnique<TemplateURL>(data)); |
| 1141 | 1141 |
| 1142 // We always allow exact matches for non-substituting keywords. | 1142 // We always allow exact matches for non-substituting keywords. |
| 1143 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); | 1143 ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextKeys)); |
| 1144 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); | 1144 ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone()); |
| 1145 ASSERT_TRUE(popup_model->IsOpen()); | 1145 ASSERT_TRUE(popup_model->IsOpen()); |
| 1146 ASSERT_EQ(AutocompleteMatchType::HISTORY_KEYWORD, | 1146 ASSERT_EQ(AutocompleteMatchType::HISTORY_KEYWORD, |
| 1147 popup_model->result().default_match()->type); | 1147 popup_model->result().default_match()->type); |
| 1148 ASSERT_EQ("http://abc.com/", | 1148 ASSERT_EQ("http://abc.com/", |
| 1149 popup_model->result().default_match()->destination_url.spec()); | 1149 popup_model->result().default_match()->destination_url.spec()); |
| 1150 } | 1150 } |
| (...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1988 | 1988 |
| 1989 // Now Shift+Right should do nothing, and Shift+Left should reduce. | 1989 // Now Shift+Right should do nothing, and Shift+Left should reduce. |
| 1990 // At the end, so Shift+Right should do nothing. | 1990 // At the end, so Shift+Right should do nothing. |
| 1991 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RIGHT, ui::EF_SHIFT_DOWN)); | 1991 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_RIGHT, ui::EF_SHIFT_DOWN)); |
| 1992 EXPECT_EQ(2u, GetSelectionSize(omnibox_view)); | 1992 EXPECT_EQ(2u, GetSelectionSize(omnibox_view)); |
| 1993 | 1993 |
| 1994 // And Left should reduce by one character. | 1994 // And Left should reduce by one character. |
| 1995 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, ui::EF_SHIFT_DOWN)); | 1995 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_LEFT, ui::EF_SHIFT_DOWN)); |
| 1996 EXPECT_EQ(1u, GetSelectionSize(omnibox_view)); | 1996 EXPECT_EQ(1u, GetSelectionSize(omnibox_view)); |
| 1997 } | 1997 } |
| OLD | NEW |