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 #include "chrome/browser/autocomplete/chrome_autocomplete_scheme_classifier.h"
      6 #include "chrome/browser/extensions/api/omnibox/omnibox_api_testbase.h"
      7 #include "chrome/browser/search_engines/template_url_service_factory.h"
      8 #include "chrome/test/base/ui_test_utils.h"
      9 #include "components/metrics/proto/omnibox_event.pb.h"
     10 #include "extensions/test/result_catcher.h"
     11 
     12 // Tests that the autocomplete popup doesn't reopen after accepting input for
     13 // a given query.
     14 // http://crbug.com/88552
     15 IN_PROC_BROWSER_TEST_F(OmniboxApiTest, PopupStaysClosed) {
     16   ASSERT_TRUE(RunExtensionTest("omnibox")) << message_;
     17 
     18   // The results depend on the TemplateURLService being loaded. Make sure it is
     19   // loaded so that the autocomplete results are consistent.
     20   Profile* profile = browser()->profile();
     21   ui_test_utils::WaitForTemplateURLServiceToLoad(
     22       TemplateURLServiceFactory::GetForProfile(profile));
     23 
     24   LocationBar* location_bar = GetLocationBar(browser());
     25   OmniboxView* omnibox_view = location_bar->GetOmniboxView();
     26   AutocompleteController* autocomplete_controller =
     27       GetAutocompleteController(browser());
     28   OmniboxPopupModel* popup_model = omnibox_view->model()->popup_model();
     29 
     30   // Input a keyword query and wait for suggestions from the extension.
     31   omnibox_view->OnBeforePossibleChange();
     32   omnibox_view->SetUserText(base::ASCIIToUTF16("keyword comman"));
     33   omnibox_view->OnAfterPossibleChange();
     34   WaitForAutocompleteDone(autocomplete_controller);
     35   EXPECT_TRUE(autocomplete_controller->done());
     36   EXPECT_TRUE(popup_model->IsOpen());
     37 
     38   // Quickly type another query and accept it before getting suggestions back
     39   // for the query. The popup will close after accepting input - ensure that it
     40   // does not reopen when the extension returns its suggestions.
     41   extensions::ResultCatcher catcher;
     42 
     43   // TODO: Rather than send this second request by talking to the controller
     44   // directly, figure out how to send it via the proper calls to
     45   // location_bar or location_bar->().
     46   autocomplete_controller->Start(AutocompleteInput(
     47       base::ASCIIToUTF16("keyword command"), base::string16::npos,
     48       base::string16(), GURL(), metrics::OmniboxEventProto::NTP, true, false,
     49       true, true, ChromeAutocompleteSchemeClassifier(profile)));
     50   location_bar->AcceptInput();
     51   WaitForAutocompleteDone(autocomplete_controller);
     52   EXPECT_TRUE(autocomplete_controller->done());
     53   // This checks that the keyword provider (via javascript)
     54   // gets told to navigate to the string "command".
     55   EXPECT_TRUE(catcher.GetNextResult()) << catcher.message();
     56   EXPECT_FALSE(popup_model->IsOpen());
     57 }
     58