1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_OMNIBOX_OMNIBOX_API_TESTBASE_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_OMNIBOX_OMNIBOX_API_TESTBASE_H_
8 #include "base/format_macros.h"
9 #include "base/strings/stringprintf.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "chrome/browser/chrome_notification_types.h"
12 #include "chrome/browser/extensions/extension_apitest.h"
13 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_window.h"
15 #include "chrome/browser/ui/location_bar/location_bar.h"
16 #include "components/omnibox/browser/autocomplete_match.h"
17 #include "components/omnibox/browser/autocomplete_result.h"
18 #include "components/omnibox/browser/omnibox_popup_model.h"
19 #include "components/omnibox/browser/omnibox_view.h"
20 #include "content/public/test/test_utils.h"
23 class AutocompleteController
;
25 class OmniboxApiTest
: public ExtensionApiTest
{
27 LocationBar
* GetLocationBar(Browser
* browser
) const {
28 return browser
->window()->GetLocationBar();
31 AutocompleteController
* GetAutocompleteController(Browser
* browser
) const {
32 return GetLocationBar(browser
)->GetOmniboxView()->model()->popup_model()->
33 autocomplete_controller();
36 // TODO(phajdan.jr): Get rid of this wait-in-a-loop pattern.
37 void WaitForAutocompleteDone(AutocompleteController
* controller
) {
38 while (!controller
->done()) {
39 content::WindowedNotificationObserver
ready_observer(
40 chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY
,
41 content::Source
<AutocompleteController
>(controller
));
42 ready_observer
.Wait();
46 static base::string16
AutocompleteResultAsString(
47 const AutocompleteResult
& result
) {
48 std::string
output(base::StringPrintf("{%" PRIuS
"} ", result
.size()));
49 for (size_t i
= 0; i
< result
.size(); ++i
) {
50 AutocompleteMatch match
= result
.match_at(i
);
51 std::string provider_name
= match
.provider
->GetName();
53 base::StringPrintf("[\"%s\" by \"%s\"] ",
54 base::UTF16ToUTF8(match
.contents
).c_str(),
55 provider_name
.c_str()));
57 return base::UTF8ToUTF16(output
);
61 #endif // CHROME_BROWSER_EXTENSIONS_API_OMNIBOX_OMNIBOX_API_TESTBASE_H_