Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
|
Peter Kasting
2010/06/02 02:57:19
Nit: 2010
| |
| 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 "chrome/browser/autocomplete/autocomplete.h" | 5 #include "chrome/browser/autocomplete/autocomplete.h" |
| 6 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 6 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
| 7 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" | 7 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" |
| 8 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 8 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
| 9 #include "chrome/browser/browser.h" | 9 #include "chrome/browser/browser.h" |
| 10 #include "chrome/browser/browser_window.h" | 10 #include "chrome/browser/browser_window.h" |
| 11 #include "chrome/browser/extensions/extension_apitest.h" | 11 #include "chrome/browser/extensions/extension_apitest.h" |
| 12 #include "chrome/browser/history/history.h" | |
| 13 #include "chrome/browser/location_bar.h" | 12 #include "chrome/browser/location_bar.h" |
| 14 #include "chrome/browser/profile.h" | 13 #include "chrome/browser/profile.h" |
| 14 #include "chrome/browser/search_engines/template_url_model.h" | |
| 15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/common/notification_type.h" | 16 #include "chrome/common/notification_type.h" |
| 17 #include "chrome/common/url_constants.h" | 17 #include "chrome/common/url_constants.h" |
| 18 #include "chrome/test/ui_test_utils.h" | 18 #include "chrome/test/ui_test_utils.h" |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 std::wstring AutocompleteResultAsString(const AutocompleteResult& result) { | 22 std::wstring AutocompleteResultAsString(const AutocompleteResult& result) { |
| 23 std::wstring output(StringPrintf(L"{%d} ", result.size())); | 23 std::wstring output(StringPrintf(L"{%d} ", result.size())); |
| 24 for (size_t i = 0; i < result.size(); ++i) { | 24 for (size_t i = 0; i < result.size(); ++i) { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 37 protected: | 37 protected: |
| 38 LocationBar* GetLocationBar() const { | 38 LocationBar* GetLocationBar() const { |
| 39 return browser()->window()->GetLocationBar(); | 39 return browser()->window()->GetLocationBar(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 AutocompleteController* GetAutocompleteController() const { | 42 AutocompleteController* GetAutocompleteController() const { |
| 43 return GetLocationBar()->location_entry()->model()->popup_model()-> | 43 return GetLocationBar()->location_entry()->model()->popup_model()-> |
| 44 autocomplete_controller(); | 44 autocomplete_controller(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void WaitForHistoryBackendToLoad() { | 47 void WaitForTemplateURLModelToLoad() { |
| 48 HistoryService* history_service = | 48 TemplateURLModel* model = |
| 49 browser()->profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); | 49 browser()->profile()->GetTemplateURLModel(); |
| 50 if (!history_service->BackendLoaded()) | 50 model->Load(); |
| 51 ui_test_utils::WaitForNotification(NotificationType::HISTORY_LOADED); | 51 if (!model->loaded()) { |
| 52 ui_test_utils::WaitForNotification( | |
| 53 NotificationType::TEMPLATE_URL_MODEL_LOADED); | |
| 54 } | |
| 52 } | 55 } |
| 53 | 56 |
| 54 void WaitForAutocompleteDone(AutocompleteController* controller) { | 57 void WaitForAutocompleteDone(AutocompleteController* controller) { |
| 55 while (!controller->done()) { | 58 while (!controller->done()) { |
| 56 ui_test_utils::WaitForNotification( | 59 ui_test_utils::WaitForNotification( |
| 57 NotificationType::AUTOCOMPLETE_CONTROLLER_DEFAULT_MATCH_UPDATED); | 60 NotificationType::AUTOCOMPLETE_CONTROLLER_DEFAULT_MATCH_UPDATED); |
| 58 } | 61 } |
| 59 } | 62 } |
| 60 }; | 63 }; |
| 61 | 64 |
| 62 IN_PROC_BROWSER_TEST_F(OmniboxApiTest, Basic) { | 65 IN_PROC_BROWSER_TEST_F(OmniboxApiTest, Basic) { |
| 63 CommandLine::ForCurrentProcess()->AppendSwitch( | 66 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 64 switches::kEnableExperimentalExtensionApis); | 67 switches::kEnableExperimentalExtensionApis); |
| 65 | 68 |
| 66 ASSERT_TRUE(StartHTTPServer()); | 69 ASSERT_TRUE(StartHTTPServer()); |
| 67 ASSERT_TRUE(RunExtensionTest("omnibox")) << message_; | 70 ASSERT_TRUE(RunExtensionTest("omnibox")) << message_; |
| 68 | 71 |
| 69 // The results depend on the history backend being loaded. Make sure it is | 72 // The results depend on the TemplateURLModel being loaded. Make sure it is |
| 70 // loaded so that the autocomplete results are consistent. | 73 // loaded so that the autocomplete results are consistent. |
| 71 WaitForHistoryBackendToLoad(); | 74 WaitForTemplateURLModelToLoad(); |
| 72 | 75 |
| 73 LocationBar* location_bar = GetLocationBar(); | 76 LocationBar* location_bar = GetLocationBar(); |
| 74 AutocompleteController* autocomplete_controller = GetAutocompleteController(); | 77 AutocompleteController* autocomplete_controller = GetAutocompleteController(); |
| 75 | 78 |
| 76 // Test that our extension's keyword is suggested to us when we partially type | 79 // Test that our extension's keyword is suggested to us when we partially type |
| 77 // it. | 80 // it. |
| 78 { | 81 { |
| 79 autocomplete_controller->Start(L"keywor", std::wstring(), | 82 autocomplete_controller->Start(L"keywor", std::wstring(), |
| 80 true, false, false); | 83 true, false, false); |
| 81 | 84 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 } | 128 } |
| 126 | 129 |
| 127 { | 130 { |
| 128 ResultCatcher catcher; | 131 ResultCatcher catcher; |
| 129 autocomplete_controller->Start(L"keyword command", std::wstring(), | 132 autocomplete_controller->Start(L"keyword command", std::wstring(), |
| 130 true, false, false); | 133 true, false, false); |
| 131 location_bar->AcceptInput(); | 134 location_bar->AcceptInput(); |
| 132 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 135 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 133 } | 136 } |
| 134 } | 137 } |
| OLD | NEW |