| 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 "base/format_macros.h" | 5 #include "base/format_macros.h" |
| 6 #include "base/string_util.h" | 6 #include "base/string_util.h" |
| 7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/autocomplete/autocomplete_input.h" | 9 #include "chrome/browser/autocomplete/autocomplete_input.h" |
| 10 #include "chrome/browser/autocomplete/autocomplete_match.h" | 10 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 void WaitForAutocompleteDone(AutocompleteController* controller) { | 56 void WaitForAutocompleteDone(AutocompleteController* controller) { |
| 57 while (!controller->done()) { | 57 while (!controller->done()) { |
| 58 content::WindowedNotificationObserver ready_observer( | 58 content::WindowedNotificationObserver ready_observer( |
| 59 chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY, | 59 chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY, |
| 60 content::Source<AutocompleteController>(controller)); | 60 content::Source<AutocompleteController>(controller)); |
| 61 ready_observer.Wait(); | 61 ready_observer.Wait(); |
| 62 } | 62 } |
| 63 } | 63 } |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 // Flaky, http://crbug.com/167158 . | 66 IN_PROC_BROWSER_TEST_F(OmniboxApiTest, Basic) { |
| 67 IN_PROC_BROWSER_TEST_F(OmniboxApiTest, DISABLED_Basic) { | |
| 68 ASSERT_TRUE(RunExtensionTest("omnibox")) << message_; | 67 ASSERT_TRUE(RunExtensionTest("omnibox")) << message_; |
| 69 | 68 |
| 70 // The results depend on the TemplateURLService being loaded. Make sure it is | 69 // The results depend on the TemplateURLService being loaded. Make sure it is |
| 71 // loaded so that the autocomplete results are consistent. | 70 // loaded so that the autocomplete results are consistent. |
| 72 ui_test_utils::WaitForTemplateURLServiceToLoad( | 71 ui_test_utils::WaitForTemplateURLServiceToLoad( |
| 73 TemplateURLServiceFactory::GetForProfile(browser()->profile())); | 72 TemplateURLServiceFactory::GetForProfile(browser()->profile())); |
| 74 | 73 |
| 75 LocationBar* location_bar = GetLocationBar(browser()); | |
| 76 AutocompleteController* autocomplete_controller = | 74 AutocompleteController* autocomplete_controller = |
| 77 GetAutocompleteController(browser()); | 75 GetAutocompleteController(browser()); |
| 78 | 76 |
| 79 // Test that our extension's keyword is suggested to us when we partially type | 77 // Test that our extension's keyword is suggested to us when we partially type |
| 80 // it. | 78 // it. |
| 81 { | 79 { |
| 82 autocomplete_controller->Start( | 80 autocomplete_controller->Start( |
| 83 AutocompleteInput(ASCIIToUTF16("keywor"), string16::npos, string16(), | 81 AutocompleteInput(ASCIIToUTF16("keywor"), string16::npos, string16(), |
| 84 true, false, true, AutocompleteInput::ALL_MATCHES)); | 82 true, false, true, AutocompleteInput::ALL_MATCHES)); |
| 85 WaitForAutocompleteDone(autocomplete_controller); | 83 WaitForAutocompleteDone(autocomplete_controller); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 107 WaitForAutocompleteDone(autocomplete_controller); | 105 WaitForAutocompleteDone(autocomplete_controller); |
| 108 EXPECT_TRUE(autocomplete_controller->done()); | 106 EXPECT_TRUE(autocomplete_controller->done()); |
| 109 | 107 |
| 110 // Now, peek into the controller to see if it has the results we expect. | 108 // Now, peek into the controller to see if it has the results we expect. |
| 111 // First result should be to invoke the keyword with what we typed, 2-4 | 109 // First result should be to invoke the keyword with what we typed, 2-4 |
| 112 // should be to invoke with suggestions from the extension, and the last | 110 // should be to invoke with suggestions from the extension, and the last |
| 113 // should be to search for what we typed. | 111 // should be to search for what we typed. |
| 114 const AutocompleteResult& result = autocomplete_controller->result(); | 112 const AutocompleteResult& result = autocomplete_controller->result(); |
| 115 ASSERT_EQ(5U, result.size()) << AutocompleteResultAsString(result); | 113 ASSERT_EQ(5U, result.size()) << AutocompleteResultAsString(result); |
| 116 | 114 |
| 117 ASSERT_FALSE(result.match_at(0).keyword.empty()); | 115 EXPECT_EQ(ASCIIToUTF16("keyword"), result.match_at(0).keyword); |
| 118 EXPECT_EQ(ASCIIToUTF16("keyword suggestio"), | 116 EXPECT_EQ(ASCIIToUTF16("keyword suggestio"), |
| 119 result.match_at(0).fill_into_edit); | 117 result.match_at(0).fill_into_edit); |
| 118 EXPECT_EQ(ASCIIToUTF16("keyword"), result.match_at(1).keyword); |
| 120 EXPECT_EQ(ASCIIToUTF16("keyword suggestion1"), | 119 EXPECT_EQ(ASCIIToUTF16("keyword suggestion1"), |
| 121 result.match_at(1).fill_into_edit); | 120 result.match_at(1).fill_into_edit); |
| 121 EXPECT_EQ(ASCIIToUTF16("keyword"), result.match_at(2).keyword); |
| 122 EXPECT_EQ(ASCIIToUTF16("keyword suggestion2"), | 122 EXPECT_EQ(ASCIIToUTF16("keyword suggestion2"), |
| 123 result.match_at(2).fill_into_edit); | 123 result.match_at(2).fill_into_edit); |
| 124 EXPECT_EQ(ASCIIToUTF16("keyword"), result.match_at(3).keyword); |
| 124 EXPECT_EQ(ASCIIToUTF16("keyword suggestion3"), | 125 EXPECT_EQ(ASCIIToUTF16("keyword suggestion3"), |
| 125 result.match_at(3).fill_into_edit); | 126 result.match_at(3).fill_into_edit); |
| 126 | 127 |
| 127 string16 description = | 128 string16 description = |
| 128 ASCIIToUTF16("Description with style: <match>, [dim], (url till end)"); | 129 ASCIIToUTF16("Description with style: <match>, [dim], (url till end)"); |
| 129 EXPECT_EQ(description, result.match_at(1).contents); | 130 EXPECT_EQ(description, result.match_at(1).contents); |
| 130 ASSERT_EQ(6u, result.match_at(1).contents_class.size()); | 131 ASSERT_EQ(6u, result.match_at(1).contents_class.size()); |
| 131 | 132 |
| 132 EXPECT_EQ(0u, | 133 EXPECT_EQ(0u, |
| 133 result.match_at(1).contents_class[0].offset); | 134 result.match_at(1).contents_class[0].offset); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 157 EXPECT_EQ(description.find('('), | 158 EXPECT_EQ(description.find('('), |
| 158 result.match_at(1).contents_class[5].offset); | 159 result.match_at(1).contents_class[5].offset); |
| 159 EXPECT_EQ(ACMatchClassification::URL, | 160 EXPECT_EQ(ACMatchClassification::URL, |
| 160 result.match_at(1).contents_class[5].style); | 161 result.match_at(1).contents_class[5].style); |
| 161 | 162 |
| 162 AutocompleteMatch match = result.match_at(4); | 163 AutocompleteMatch match = result.match_at(4); |
| 163 EXPECT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, match.type); | 164 EXPECT_EQ(AutocompleteMatch::SEARCH_WHAT_YOU_TYPED, match.type); |
| 164 EXPECT_FALSE(match.deletable); | 165 EXPECT_FALSE(match.deletable); |
| 165 } | 166 } |
| 166 | 167 |
| 168 // Flaky, see http://crbug.com/167158 |
| 169 /* |
| 167 { | 170 { |
| 171 LocationBar* location_bar = GetLocationBar(browser()); |
| 168 ResultCatcher catcher; | 172 ResultCatcher catcher; |
| 169 OmniboxView* omnibox_view = location_bar->GetLocationEntry(); | 173 OmniboxView* omnibox_view = location_bar->GetLocationEntry(); |
| 170 omnibox_view->OnBeforePossibleChange(); | 174 omnibox_view->OnBeforePossibleChange(); |
| 171 omnibox_view->SetUserText( ASCIIToUTF16("keyword command")); | 175 omnibox_view->SetUserText(ASCIIToUTF16("keyword command")); |
| 172 omnibox_view->OnAfterPossibleChange(); | 176 omnibox_view->OnAfterPossibleChange(); |
| 173 location_bar->AcceptInput(); | 177 location_bar->AcceptInput(); |
| 174 // This checks that the keyword provider (via javascript) | 178 // This checks that the keyword provider (via javascript) |
| 175 // gets told to navigate to the string "command". | 179 // gets told to navigate to the string "command". |
| 176 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 180 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 177 } | 181 } |
| 182 */ |
| 178 } | 183 } |
| 179 | 184 |
| 180 // Tests that the autocomplete popup doesn't reopen after accepting input for | 185 // Tests that the autocomplete popup doesn't reopen after accepting input for |
| 181 // a given query. | 186 // a given query. |
| 182 // http://crbug.com/88552 | 187 // http://crbug.com/88552 |
| 183 IN_PROC_BROWSER_TEST_F(OmniboxApiTest, PopupStaysClosed) { | 188 IN_PROC_BROWSER_TEST_F(OmniboxApiTest, PopupStaysClosed) { |
| 184 ASSERT_TRUE(RunExtensionTest("omnibox")) << message_; | 189 ASSERT_TRUE(RunExtensionTest("omnibox")) << message_; |
| 185 | 190 |
| 186 // The results depend on the TemplateURLService being loaded. Make sure it is | 191 // The results depend on the TemplateURLService being loaded. Make sure it is |
| 187 // loaded so that the autocomplete results are consistent. | 192 // loaded so that the autocomplete results are consistent. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 { | 278 { |
| 274 ResultCatcher catcher; | 279 ResultCatcher catcher; |
| 275 autocomplete_controller->Start( | 280 autocomplete_controller->Start( |
| 276 AutocompleteInput(ASCIIToUTF16("keyword command incognito"), | 281 AutocompleteInput(ASCIIToUTF16("keyword command incognito"), |
| 277 string16::npos, string16(), true, false, true, | 282 string16::npos, string16(), true, false, true, |
| 278 AutocompleteInput::ALL_MATCHES)); | 283 AutocompleteInput::ALL_MATCHES)); |
| 279 location_bar->AcceptInput(); | 284 location_bar->AcceptInput(); |
| 280 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 285 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 281 } | 286 } |
| 282 } | 287 } |
| OLD | NEW |