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