Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / omnibox / omnibox_view_browsertest.cc
index 68348c6..f5ae22f 100644 (file)
 #include "base/strings/utf_string_conversions.h"
 #include "base/time/time.h"
 #include "chrome/app/chrome_command_ids.h"
-#include "chrome/browser/autocomplete/autocomplete_input.h"
-#include "chrome/browser/autocomplete/autocomplete_match.h"
 #include "chrome/browser/autocomplete/history_quick_provider.h"
 #include "chrome/browser/bookmarks/bookmark_model_factory.h"
 #include "chrome/browser/chrome_notification_types.h"
 #include "chrome/browser/history/history_service.h"
 #include "chrome/browser/history/history_service_factory.h"
 #include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/search_engines/template_url.h"
-#include "chrome/browser/search_engines/template_url_service.h"
 #include "chrome/browser/search_engines/template_url_service_factory.h"
 #include "chrome/browser/ui/browser.h"
 #include "chrome/browser/ui/browser_commands.h"
 #include "chrome/browser/ui/browser_window.h"
-#include "chrome/browser/ui/omnibox/location_bar.h"
+#include "chrome/browser/ui/location_bar/location_bar.h"
 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h"
 #include "chrome/browser/ui/omnibox/omnibox_view.h"
 #include "chrome/browser/ui/tabs/tab_strip_model.h"
 #include "components/bookmarks/browser/bookmark_model.h"
 #include "components/bookmarks/browser/bookmark_utils.h"
 #include "components/bookmarks/test/bookmark_test_helpers.h"
+#include "components/omnibox/autocomplete_input.h"
+#include "components/omnibox/autocomplete_match.h"
+#include "components/search_engines/template_url.h"
+#include "components/search_engines/template_url_service.h"
 #include "content/public/browser/notification_service.h"
 #include "content/public/browser/web_contents.h"
 #include "net/dns/mock_host_resolver.h"
@@ -56,16 +56,26 @@ namespace {
 
 const char kSearchKeyword[] = "foo";
 const char kSearchKeyword2[] = "footest.com";
-const wchar_t kSearchKeywordKeys[] = { ui::VKEY_F, ui::VKEY_O, ui::VKEY_O, 0 };
+const ui::KeyboardCode kSearchKeywordKeys[] = {
+  ui::VKEY_F, ui::VKEY_O, ui::VKEY_O, ui::VKEY_UNKNOWN
+};
+const ui::KeyboardCode kSearchKeywordPrefixKeys[] = {
+  ui::VKEY_F, ui::VKEY_O, ui::VKEY_UNKNOWN
+};
+const ui::KeyboardCode kSearchKeywordCompletionKeys[] = {
+  ui::VKEY_O, ui::VKEY_UNKNOWN
+};
 const char kSearchURL[] = "http://www.foo.com/search?q={searchTerms}";
 const char kSearchShortName[] = "foo";
 const char kSearchText[] = "abc";
-const wchar_t kSearchTextKeys[] = { ui::VKEY_A, ui::VKEY_B, ui::VKEY_C, 0 };
+const ui::KeyboardCode kSearchTextKeys[] = {
+  ui::VKEY_A, ui::VKEY_B, ui::VKEY_C, ui::VKEY_UNKNOWN
+};
 const char kSearchTextURL[] = "http://www.foo.com/search?q=abc";
 
 const char kInlineAutocompleteText[] = "def";
-const wchar_t kInlineAutocompleteTextKeys[] = {
-  ui::VKEY_D, ui::VKEY_E, ui::VKEY_F, 0
+const ui::KeyboardCode kInlineAutocompleteTextKeys[] = {
+  ui::VKEY_D, ui::VKEY_E, ui::VKEY_F, ui::VKEY_UNKNOWN
 };
 
 // Hostnames that shall be blocked by host resolver.
@@ -167,9 +177,9 @@ class OmniboxViewTest : public InProcessBrowserTest,
     SendKeyForBrowser(browser(), key, modifiers);
   }
 
-  void SendKeySequence(const wchar_t* keys) {
-    for (; *keys; ++keys)
-      ASSERT_NO_FATAL_FAILURE(SendKey(static_cast<ui::KeyboardCode>(*keys), 0));
+  void SendKeySequence(const ui::KeyboardCode* keys) {
+    for (; *keys != ui::VKEY_UNKNOWN; ++keys)
+      ASSERT_NO_FATAL_FAILURE(SendKey(*keys, 0));
   }
 
   bool SendKeyAndWait(const Browser* browser,
@@ -292,7 +302,7 @@ class OmniboxViewTest : public InProcessBrowserTest,
                                         entry.typed_count, time, false,
                                         history::SOURCE_BROWSED);
     if (entry.starred)
-      bookmark_utils::AddIfNotBookmarked(bookmark_model, url, base::string16());
+      bookmarks::AddIfNotBookmarked(bookmark_model, url, base::string16());
     // Wait at least for the AddPageWithDetails() call to finish.
     {
       content::NotificationRegistrar registrar;
@@ -563,7 +573,9 @@ IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DesiredTLD) {
   ASSERT_TRUE(popup_model);
 
   // Test ctrl-Enter.
-  const wchar_t kKeys[] = { ui::VKEY_B, ui::VKEY_A, ui::VKEY_R, 0 };
+  const ui::KeyboardCode kKeys[] = {
+    ui::VKEY_B, ui::VKEY_A, ui::VKEY_R, ui::VKEY_UNKNOWN
+  };
   ASSERT_NO_FATAL_FAILURE(SendKeySequence(kKeys));
   ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
   ASSERT_TRUE(popup_model->IsOpen());
@@ -600,7 +612,9 @@ IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DesiredTLDWithTemporaryText) {
   template_url_service->Add(new TemplateURL(data));
 
   // Send "ab", so that an "abc" entry appears in the popup.
-  const wchar_t kSearchTextPrefixKeys[] = { ui::VKEY_A, ui::VKEY_B, 0 };
+  const ui::KeyboardCode kSearchTextPrefixKeys[] = {
+    ui::VKEY_A, ui::VKEY_B, ui::VKEY_UNKNOWN
+  };
   ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchTextPrefixKeys));
   ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
   ASSERT_TRUE(popup_model->IsOpen());
@@ -665,7 +679,9 @@ IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DISABLED_EnterToSearch) {
   EXPECT_EQ(kSearchTextURL, url.spec());
 
   // Test that entering a single character then Enter performs a search.
-  const wchar_t kSearchSingleCharKeys[] = { ui::VKEY_Z, 0 };
+  const ui::KeyboardCode kSearchSingleCharKeys[] = {
+    ui::VKEY_Z, ui::VKEY_UNKNOWN
+  };
   chrome::FocusLocationBar(browser());
   EXPECT_TRUE(omnibox_view->IsSelectAll());
   ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchSingleCharKeys));
@@ -929,8 +945,8 @@ IN_PROC_BROWSER_TEST_F(OmniboxViewTest, MAYBE_AcceptKeywordBySpace) {
   ASSERT_NO_FATAL_FAILURE(
       AddHistoryEntry(kHistoryFoobar, Time::Now() - TimeDelta::FromHours(1)));
 
-  // Type "foo" to trigger inline autocomplete.
-  ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordKeys));
+  // Type "fo" to trigger inline autocomplete.
+  ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordPrefixKeys));
   ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
   ASSERT_TRUE(omnibox_view->model()->popup_model()->IsOpen());
   ASSERT_NE(search_keyword, omnibox_view->GetText());
@@ -939,6 +955,15 @@ IN_PROC_BROWSER_TEST_F(OmniboxViewTest, MAYBE_AcceptKeywordBySpace) {
   ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
   ASSERT_TRUE(omnibox_view->model()->keyword().empty());
 
+  // Add the "o".  Inline autocompletion should still happen, but now we
+  // should also get a keyword hint because we've typed a keyword exactly.
+  ASSERT_NO_FATAL_FAILURE(SendKeySequence(kSearchKeywordCompletionKeys));
+  ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
+  ASSERT_TRUE(omnibox_view->model()->popup_model()->IsOpen());
+  ASSERT_NE(search_keyword, omnibox_view->GetText());
+  ASSERT_TRUE(omnibox_view->model()->is_keyword_hint());
+  ASSERT_FALSE(omnibox_view->model()->keyword().empty());
+
   // Trigger keyword mode by space.
   ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_SPACE, 0));
   ASSERT_FALSE(omnibox_view->model()->is_keyword_hint());
@@ -1229,7 +1254,9 @@ IN_PROC_BROWSER_TEST_F(OmniboxViewTest, MAYBE_TabTraverseResultsTest) {
   ASSERT_TRUE(popup_model);
 
   // Input something to trigger results.
-  const wchar_t kKeys[] = { ui::VKEY_B, ui::VKEY_A, ui::VKEY_R, 0 };
+  const ui::KeyboardCode kKeys[] = {
+    ui::VKEY_B, ui::VKEY_A, ui::VKEY_R, ui::VKEY_UNKNOWN
+  };
   ASSERT_NO_FATAL_FAILURE(SendKeySequence(kKeys));
   ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
   ASSERT_TRUE(popup_model->IsOpen());
@@ -1700,7 +1727,9 @@ IN_PROC_BROWSER_TEST_F(OmniboxViewTest, CtrlArrowAfterArrowSuggestions) {
   ASSERT_TRUE(popup_model);
 
   // Input something to trigger results.
-  const wchar_t kKeys[] = { ui::VKEY_B, ui::VKEY_A, ui::VKEY_R, 0 };
+  const ui::KeyboardCode kKeys[] = {
+    ui::VKEY_B, ui::VKEY_A, ui::VKEY_R, ui::VKEY_UNKNOWN
+  };
   ASSERT_NO_FATAL_FAILURE(SendKeySequence(kKeys));
   ASSERT_NO_FATAL_FAILURE(WaitForAutocompleteControllerDone());
   ASSERT_TRUE(popup_model->IsOpen());