Home | History | Annotate | Download | only in omnibox
      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.
      4 
      5 #ifndef CHROME_BROWSER_EXTENSIONS_API_OMNIBOX_OMNIBOX_API_TESTBASE_H_
      6 #define CHROME_BROWSER_EXTENSIONS_API_OMNIBOX_OMNIBOX_API_TESTBASE_H_
      7 
      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 "chrome/browser/ui/omnibox/omnibox_popup_model.h"
     17 #include "chrome/browser/ui/omnibox/omnibox_view.h"
     18 #include "components/omnibox/autocomplete_match.h"
     19 #include "components/omnibox/autocomplete_result.h"
     20 #include "content/public/test/test_utils.h"
     21 
     22 
     23 class AutocompleteController;
     24 
     25 class OmniboxApiTest : public ExtensionApiTest {
     26  protected:
     27   LocationBar* GetLocationBar(Browser* browser) const {
     28     return browser->window()->GetLocationBar();
     29   }
     30 
     31   AutocompleteController* GetAutocompleteController(Browser* browser) const {
     32     return GetLocationBar(browser)->GetOmniboxView()->model()->popup_model()->
     33         autocomplete_controller();
     34   }
     35 
     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();
     43     }
     44   }
     45 
     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();
     52       output.append(
     53           base::StringPrintf("[\"%s\" by \"%s\"] ",
     54                              base::UTF16ToUTF8(match.contents).c_str(),
     55                              provider_name.c_str()));
     56     }
     57     return base::UTF8ToUTF16(output);
     58   }
     59 };
     60 
     61 #endif  // CHROME_BROWSER_EXTENSIONS_API_OMNIBOX_OMNIBOX_API_TESTBASE_H_
     62