| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
| 8 #include "chrome/browser/chrome_notification_types.h" | 8 #include "chrome/browser/chrome_notification_types.h" |
| 9 #include "chrome/browser/search/instant_service.h" | 9 #include "chrome/browser/search/instant_service.h" |
| 10 #include "chrome/browser/search/instant_service_factory.h" | 10 #include "chrome/browser/search/instant_service_factory.h" |
| 11 #include "chrome/browser/search/search.h" | 11 #include "chrome/browser/search/search.h" |
| 12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/browser_commands.h" | 13 #include "chrome/browser/ui/browser_commands.h" |
| 14 #include "chrome/browser/ui/search/instant_test_utils.h" | 14 #include "chrome/browser/ui/search/instant_test_utils.h" |
| 15 #include "chrome/browser/ui/search/instant_uitest_base.h" |
| 15 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 16 #include "chrome/common/search/search_types.h" | 17 #include "chrome/common/search/search_types.h" |
| 17 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
| 18 #include "chrome/test/base/in_process_browser_test.h" | 19 #include "chrome/test/base/in_process_browser_test.h" |
| 19 #include "chrome/test/base/interactive_test_utils.h" | 20 #include "chrome/test/base/interactive_test_utils.h" |
| 20 #include "chrome/test/base/ui_test_utils.h" | 21 #include "chrome/test/base/ui_test_utils.h" |
| 21 #include "components/omnibox/browser/omnibox_edit_model.h" | 22 #include "components/omnibox/browser/omnibox_edit_model.h" |
| 22 #include "components/omnibox/common/omnibox_focus_state.h" | 23 #include "components/omnibox/common/omnibox_focus_state.h" |
| 23 #include "components/search/search.h" | 24 #include "components/search/search.h" |
| 24 #include "content/public/browser/navigation_controller.h" | 25 #include "content/public/browser/navigation_controller.h" |
| 25 #include "content/public/browser/navigation_entry.h" | 26 #include "content/public/browser/navigation_entry.h" |
| 26 #include "content/public/browser/notification_service.h" | 27 #include "content/public/browser/notification_service.h" |
| 27 #include "content/public/browser/render_process_host.h" | 28 #include "content/public/browser/render_process_host.h" |
| 28 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
| 29 #include "content/public/test/browser_test_utils.h" | 30 #include "content/public/test/browser_test_utils.h" |
| 30 #include "net/base/network_change_notifier.h" | 31 #include "net/base/network_change_notifier.h" |
| 31 #include "net/dns/mock_host_resolver.h" | 32 #include "net/dns/mock_host_resolver.h" |
| 32 #include "url/gurl.h" | 33 #include "url/gurl.h" |
| 33 | 34 |
| 34 // !!! IMPORTANT !!! | 35 // !!! IMPORTANT !!! |
| 35 // These tests are run against a mock GWS using the web-page-replay system. | 36 // These tests are run against a mock GWS using the web-page-replay system. |
| 36 // If you change a test, you MUST re-record the mock GWS session. | 37 // If you change a test, you MUST re-record the mock GWS session. |
| 37 // See: src/chrome/test/data/search/tools/instant_extended_manual_tests.py | 38 // See: src/chrome/test/data/search/tools/instant_extended_manual_tests.py |
| 38 // for details. | 39 // for details. |
| 39 | 40 |
| 40 // Instant extended tests that need to be run manually because they need to | 41 // Instant extended tests that need to be run manually because they need to |
| 41 // talk to the external network. All tests in this file should be marked as | 42 // talk to the external network. All tests in this file should be marked as |
| 42 // "MANUAL_" unless they are disabled. | 43 // "MANUAL_" unless they are disabled. |
| 43 class InstantExtendedManualTest : public InProcessBrowserTest, | 44 class InstantExtendedManualTest : public InProcessBrowserTest, |
| 44 public InstantTestBase { | 45 public InstantUITestBase { |
| 45 public: | 46 public: |
| 46 InstantExtendedManualTest() { | 47 InstantExtendedManualTest() { |
| 47 host_resolver_proc_ = new net::RuleBasedHostResolverProc(NULL); | 48 host_resolver_proc_ = new net::RuleBasedHostResolverProc(NULL); |
| 48 host_resolver_proc_->AllowDirectLookup("*"); | 49 host_resolver_proc_->AllowDirectLookup("*"); |
| 49 scoped_host_resolver_proc_.reset( | 50 scoped_host_resolver_proc_.reset( |
| 50 new net::ScopedDefaultHostResolverProc(host_resolver_proc_.get())); | 51 new net::ScopedDefaultHostResolverProc(host_resolver_proc_.get())); |
| 51 } | 52 } |
| 52 | 53 |
| 53 ~InstantExtendedManualTest() override { | 54 ~InstantExtendedManualTest() override { |
| 54 scoped_host_resolver_proc_.reset(); | 55 scoped_host_resolver_proc_.reset(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 71 disable_network_change_notifier_.reset(); | 72 disable_network_change_notifier_.reset(); |
| 72 } | 73 } |
| 73 | 74 |
| 74 protected: | 75 protected: |
| 75 content::WebContents* active_tab() { | 76 content::WebContents* active_tab() { |
| 76 return browser()->tab_strip_model()->GetActiveWebContents(); | 77 return browser()->tab_strip_model()->GetActiveWebContents(); |
| 77 } | 78 } |
| 78 | 79 |
| 79 bool IsGooglePage(content::WebContents* contents) { | 80 bool IsGooglePage(content::WebContents* contents) { |
| 80 bool is_google = false; | 81 bool is_google = false; |
| 81 if (!GetBoolFromJS(contents, "!!window.google", &is_google)) | 82 if (!instant_test_utils::GetBoolFromJS(contents, "!!window.google", |
| 83 &is_google)) |
| 82 return false; | 84 return false; |
| 83 return is_google; | 85 return is_google; |
| 84 } | 86 } |
| 85 | 87 |
| 86 private: | 88 private: |
| 87 scoped_refptr<net::RuleBasedHostResolverProc> host_resolver_proc_; | 89 scoped_refptr<net::RuleBasedHostResolverProc> host_resolver_proc_; |
| 88 std::unique_ptr<net::ScopedDefaultHostResolverProc> | 90 std::unique_ptr<net::ScopedDefaultHostResolverProc> |
| 89 scoped_host_resolver_proc_; | 91 scoped_host_resolver_proc_; |
| 90 std::unique_ptr<net::NetworkChangeNotifier::DisableForTest> | 92 std::unique_ptr<net::NetworkChangeNotifier::DisableForTest> |
| 91 disable_network_change_notifier_; | 93 disable_network_change_notifier_; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 106 content::WebContents* active_tab = | 108 content::WebContents* active_tab = |
| 107 browser()->tab_strip_model()->GetActiveWebContents(); | 109 browser()->tab_strip_model()->GetActiveWebContents(); |
| 108 ASSERT_TRUE(IsGooglePage(active_tab)); | 110 ASSERT_TRUE(IsGooglePage(active_tab)); |
| 109 | 111 |
| 110 // Click in the fakebox and expect invisible focus. | 112 // Click in the fakebox and expect invisible focus. |
| 111 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); | 113 ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); |
| 112 bool fakebox_is_present = false; | 114 bool fakebox_is_present = false; |
| 113 content::WindowedNotificationObserver focus_observer( | 115 content::WindowedNotificationObserver focus_observer( |
| 114 chrome::NOTIFICATION_OMNIBOX_FOCUS_CHANGED, | 116 chrome::NOTIFICATION_OMNIBOX_FOCUS_CHANGED, |
| 115 content::NotificationService::AllSources()); | 117 content::NotificationService::AllSources()); |
| 116 ASSERT_TRUE(GetBoolFromJS(active_tab, "!!document.querySelector('#fkbx')", | 118 ASSERT_TRUE(instant_test_utils::GetBoolFromJS( |
| 117 &fakebox_is_present)); | 119 active_tab, "!!document.querySelector('#fkbx')", &fakebox_is_present)); |
| 118 ASSERT_TRUE(fakebox_is_present); | 120 ASSERT_TRUE(fakebox_is_present); |
| 119 ASSERT_TRUE(content::ExecuteScript( | 121 ASSERT_TRUE(content::ExecuteScript( |
| 120 active_tab, "document.querySelector('#fkbx').click()")); | 122 active_tab, "document.querySelector('#fkbx').click()")); |
| 121 focus_observer.Wait(); | 123 focus_observer.Wait(); |
| 122 EXPECT_EQ(OMNIBOX_FOCUS_INVISIBLE, omnibox()->model()->focus_state()); | 124 EXPECT_EQ(OMNIBOX_FOCUS_INVISIBLE, omnibox()->model()->focus_state()); |
| 123 | 125 |
| 124 // Type "test". | 126 // Type "test". |
| 125 const ui::KeyboardCode query[] = { | 127 const ui::KeyboardCode query[] = { |
| 126 ui::VKEY_T, ui::VKEY_E, ui::VKEY_S, ui::VKEY_T, | 128 ui::VKEY_T, ui::VKEY_E, ui::VKEY_S, ui::VKEY_T, |
| 127 ui::VKEY_UNKNOWN | 129 ui::VKEY_UNKNOWN |
| 128 }; | 130 }; |
| 129 for (size_t i = 0; query[i] != ui::VKEY_UNKNOWN; i++) { | 131 for (size_t i = 0; query[i] != ui::VKEY_UNKNOWN; i++) { |
| 130 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), query[i], | 132 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(browser(), query[i], |
| 131 false, false, false, false)); | 133 false, false, false, false)); |
| 132 } | 134 } |
| 133 | 135 |
| 134 // The omnibox should say "test" and have visible focus. | 136 // The omnibox should say "test" and have visible focus. |
| 135 EXPECT_EQ("test", GetOmniboxText()); | 137 EXPECT_EQ("test", GetOmniboxText()); |
| 136 EXPECT_EQ(OMNIBOX_FOCUS_VISIBLE, omnibox()->model()->focus_state()); | 138 EXPECT_EQ(OMNIBOX_FOCUS_VISIBLE, omnibox()->model()->focus_state()); |
| 137 | 139 |
| 138 // Pressing enter should search for [test]. | 140 // Pressing enter should search for [test]. |
| 139 const base::string16& search_title = | 141 const base::string16& search_title = |
| 140 base::ASCIIToUTF16("test - Google Search"); | 142 base::ASCIIToUTF16("test - Google Search"); |
| 141 content::TitleWatcher title_watcher(active_tab, search_title); | 143 content::TitleWatcher title_watcher(active_tab, search_title); |
| 142 PressEnterAndWaitForNavigation(); | 144 PressEnterAndWaitForNavigation(); |
| 143 EXPECT_EQ(search_title, title_watcher.WaitAndGetTitle()); | 145 EXPECT_EQ(search_title, title_watcher.WaitAndGetTitle()); |
| 144 } | 146 } |
| OLD | NEW |