Chromium Code Reviews| Index: chrome/browser/ui/search/local_ntp_browsertest.cc |
| diff --git a/chrome/browser/ui/search/local_ntp_browsertest.cc b/chrome/browser/ui/search/local_ntp_browsertest.cc |
| index 61fcae0550489c09558452814c90bca7d0c28d69..8745e36140d0634c6be8e333fd009995a30f50ad 100644 |
| --- a/chrome/browser/ui/search/local_ntp_browsertest.cc |
| +++ b/chrome/browser/ui/search/local_ntp_browsertest.cc |
| @@ -4,15 +4,22 @@ |
| #include "base/strings/utf_string_conversions.h" |
| #include "chrome/browser/browser_process.h" |
| +#include "chrome/browser/chrome_notification_types.h" |
| #include "chrome/browser/search/search.h" |
| #include "chrome/browser/ui/search/instant_test_utils.h" |
| #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| #include "chrome/common/pref_names.h" |
| #include "chrome/common/url_constants.h" |
| #include "chrome/test/base/in_process_browser_test.h" |
| +#include "chrome/test/base/interactive_test_utils.h" |
| #include "chrome/test/base/ui_test_utils.h" |
| +#include "components/omnibox/browser/omnibox_edit_model.h" |
| +#include "components/omnibox/browser/omnibox_view.h" |
| +#include "components/omnibox/common/omnibox_focus_state.h" |
| #include "components/prefs/pref_service.h" |
| +#include "content/public/browser/notification_service.h" |
| #include "content/public/browser/web_contents.h" |
| +#include "content/public/test/test_utils.h" |
| #include "net/test/embedded_test_server/embedded_test_server.h" |
| #include "ui/base/resource/resource_bundle.h" |
| @@ -32,7 +39,9 @@ class LocalNTPTest : public InProcessBrowserTest, |
| } |
| }; |
| -IN_PROC_BROWSER_TEST_F(LocalNTPTest, LocalNTPJavascriptTest) { |
| +// This runs a bunch of pure JS-side tests, i.e. those that don't require any |
| +// interaction from the native side. |
| +IN_PROC_BROWSER_TEST_F(LocalNTPTest, SimpleJavascriptTests) { |
| ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| FocusOmnibox(); |
| @@ -43,11 +52,57 @@ IN_PROC_BROWSER_TEST_F(LocalNTPTest, LocalNTPJavascriptTest) { |
| content::WebContents* active_tab = |
| browser()->tab_strip_model()->GetActiveWebContents(); |
| ASSERT_TRUE(search::IsInstantNTP(active_tab)); |
| + |
| bool success = false; |
| - ASSERT_TRUE(GetBoolFromJS(active_tab, "!!runTests()", &success)); |
| + ASSERT_TRUE(GetBoolFromJS(active_tab, "!!runSimpleTests()", &success)); |
| EXPECT_TRUE(success); |
| } |
| +IN_PROC_BROWSER_TEST_F(LocalNTPTest, FakeboxRedirectsToOmnibox) { |
| + ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| + FocusOmnibox(); |
| + |
| + ui_test_utils::NavigateToURLWithDisposition( |
| + browser(), ntp_url(), WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| + ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB | |
| + ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| + content::WebContents* active_tab = |
| + browser()->tab_strip_model()->GetActiveWebContents(); |
| + ASSERT_TRUE(search::IsInstantNTP(active_tab)); |
| + |
| + bool result = false; |
| + ASSERT_TRUE(GetBoolFromJS(active_tab, "!!setupAdvancedTest()", &result)); |
| + ASSERT_TRUE(result); |
| + |
| + // Simulate a click on the fakebox. This should result in an invisible focus |
| + // on the Omnibox. |
| + content::WindowedNotificationObserver focus_observer( |
| + chrome::NOTIFICATION_OMNIBOX_FOCUS_CHANGED, |
| + content::NotificationService::AllSources()); |
| + ASSERT_TRUE(GetBoolFromJS(active_tab, "!!clickOnFakebox()", &result)); |
|
sfiera
2017/02/14 14:05:44
Is it not also possible to send a "real" mouse eve
Marc Treib
2017/02/14 14:32:05
Artifact of the order in which I wrote this stuff
|
| + ASSERT_TRUE(result); |
| + focus_observer.Wait(); |
| + EXPECT_EQ(OMNIBOX_FOCUS_INVISIBLE, omnibox()->model()->focus_state()); |
| + |
| + // The fakebox should now also have focus. |
| + ASSERT_TRUE(GetBoolFromJS(active_tab, "!!fakeboxIsFocused()", &result)); |
| + EXPECT_TRUE(result); |
| + |
| + // Type "a". |
| + ASSERT_TRUE(ui_test_utils::SendKeyPressSync( |
| + browser(), ui::KeyboardCode::VKEY_A, |
| + /*control=*/false, /*shift=*/false, /*alt=*/false, /*command=*/false)); |
| + |
| + // The omnibox should have received visible focus. |
| + EXPECT_EQ(OMNIBOX_FOCUS_VISIBLE, omnibox()->model()->focus_state()); |
| + // ...and the typed text should have arrived there. |
| + EXPECT_EQ("a", GetOmniboxText()); |
| + |
| + // On the JS side, the fakebox should have been hidden. |
| + ASSERT_TRUE(GetBoolFromJS(active_tab, "!!fakeboxIsVisible()", &result)); |
| + EXPECT_FALSE(result); |
| +} |
| + |
| IN_PROC_BROWSER_TEST_F(LocalNTPTest, |
| NTPRespectsBrowserLanguageSetting) { |
| // Make sure the default language is not French. |