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