Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: chrome/browser/ui/search/local_ntp_browsertest.cc

Issue 2691033004: [Local NTP] Add an integration test for the fakebox (Closed)
Patch Set: . Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/test/data/local_ntp_browsertest.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/strings/utf_string_conversions.h" 5 #include "base/strings/utf_string_conversions.h"
6 #include "chrome/browser/browser_process.h" 6 #include "chrome/browser/browser_process.h"
7 #include "chrome/browser/chrome_notification_types.h"
7 #include "chrome/browser/search/search.h" 8 #include "chrome/browser/search/search.h"
8 #include "chrome/browser/ui/search/instant_test_utils.h" 9 #include "chrome/browser/ui/search/instant_test_utils.h"
9 #include "chrome/browser/ui/tabs/tab_strip_model.h" 10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
10 #include "chrome/common/pref_names.h" 11 #include "chrome/common/pref_names.h"
11 #include "chrome/common/url_constants.h" 12 #include "chrome/common/url_constants.h"
12 #include "chrome/test/base/in_process_browser_test.h" 13 #include "chrome/test/base/in_process_browser_test.h"
14 #include "chrome/test/base/interactive_test_utils.h"
13 #include "chrome/test/base/ui_test_utils.h" 15 #include "chrome/test/base/ui_test_utils.h"
16 #include "components/omnibox/browser/omnibox_edit_model.h"
17 #include "components/omnibox/browser/omnibox_view.h"
18 #include "components/omnibox/common/omnibox_focus_state.h"
14 #include "components/prefs/pref_service.h" 19 #include "components/prefs/pref_service.h"
20 #include "content/public/browser/notification_service.h"
15 #include "content/public/browser/web_contents.h" 21 #include "content/public/browser/web_contents.h"
22 #include "content/public/test/test_utils.h"
16 #include "net/test/embedded_test_server/embedded_test_server.h" 23 #include "net/test/embedded_test_server/embedded_test_server.h"
17 #include "ui/base/resource/resource_bundle.h" 24 #include "ui/base/resource/resource_bundle.h"
18 25
19 class LocalNTPTest : public InProcessBrowserTest, 26 class LocalNTPTest : public InProcessBrowserTest,
20 public InstantTestBase { 27 public InstantTestBase {
21 public: 28 public:
22 LocalNTPTest() {} 29 LocalNTPTest() {}
23 30
24 protected: 31 protected:
25 void SetUpInProcessBrowserTestFixture() override { 32 void SetUpInProcessBrowserTestFixture() override {
26 ASSERT_TRUE(https_test_server().Start()); 33 ASSERT_TRUE(https_test_server().Start());
27 GURL instant_url = 34 GURL instant_url =
28 https_test_server().GetURL("/instant_extended.html?strk=1&"); 35 https_test_server().GetURL("/instant_extended.html?strk=1&");
29 GURL ntp_url = 36 GURL ntp_url =
30 https_test_server().GetURL("/local_ntp_browsertest.html?strk=1&"); 37 https_test_server().GetURL("/local_ntp_browsertest.html?strk=1&");
31 InstantTestBase::Init(instant_url, ntp_url, false); 38 InstantTestBase::Init(instant_url, ntp_url, false);
32 } 39 }
33 }; 40 };
34 41
35 IN_PROC_BROWSER_TEST_F(LocalNTPTest, LocalNTPJavascriptTest) { 42 // This runs a bunch of pure JS-side tests, i.e. those that don't require any
43 // interaction from the native side.
44 IN_PROC_BROWSER_TEST_F(LocalNTPTest, SimpleJavascriptTests) {
36 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 45 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
37 FocusOmnibox(); 46 FocusOmnibox();
38 47
39 ui_test_utils::NavigateToURLWithDisposition( 48 ui_test_utils::NavigateToURLWithDisposition(
40 browser(), ntp_url(), WindowOpenDisposition::NEW_FOREGROUND_TAB, 49 browser(), ntp_url(), WindowOpenDisposition::NEW_FOREGROUND_TAB,
41 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB | 50 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB |
42 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 51 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
43 content::WebContents* active_tab = 52 content::WebContents* active_tab =
44 browser()->tab_strip_model()->GetActiveWebContents(); 53 browser()->tab_strip_model()->GetActiveWebContents();
45 ASSERT_TRUE(search::IsInstantNTP(active_tab)); 54 ASSERT_TRUE(search::IsInstantNTP(active_tab));
55
46 bool success = false; 56 bool success = false;
47 ASSERT_TRUE(GetBoolFromJS(active_tab, "!!runTests()", &success)); 57 ASSERT_TRUE(GetBoolFromJS(active_tab, "!!runSimpleTests()", &success));
48 EXPECT_TRUE(success); 58 EXPECT_TRUE(success);
49 } 59 }
50 60
61 IN_PROC_BROWSER_TEST_F(LocalNTPTest, FakeboxRedirectsToOmnibox) {
62 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
63 FocusOmnibox();
64
65 ui_test_utils::NavigateToURLWithDisposition(
66 browser(), ntp_url(), WindowOpenDisposition::NEW_FOREGROUND_TAB,
67 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB |
68 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
69 content::WebContents* active_tab =
70 browser()->tab_strip_model()->GetActiveWebContents();
71 ASSERT_TRUE(search::IsInstantNTP(active_tab));
72
73 bool result = false;
74 ASSERT_TRUE(GetBoolFromJS(active_tab, "!!setupAdvancedTest()", &result));
75 ASSERT_TRUE(result);
76
77 // Simulate a click on the fakebox. This should result in an invisible focus
78 // on the Omnibox.
79 content::WindowedNotificationObserver focus_observer(
80 chrome::NOTIFICATION_OMNIBOX_FOCUS_CHANGED,
81 content::NotificationService::AllSources());
82 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
83 ASSERT_TRUE(result);
84 focus_observer.Wait();
85 EXPECT_EQ(OMNIBOX_FOCUS_INVISIBLE, omnibox()->model()->focus_state());
86
87 // The fakebox should now also have focus.
88 ASSERT_TRUE(GetBoolFromJS(active_tab, "!!fakeboxIsFocused()", &result));
89 EXPECT_TRUE(result);
90
91 // Type "a".
92 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
93 browser(), ui::KeyboardCode::VKEY_A,
94 /*control=*/false, /*shift=*/false, /*alt=*/false, /*command=*/false));
95
96 // The omnibox should have received visible focus.
97 EXPECT_EQ(OMNIBOX_FOCUS_VISIBLE, omnibox()->model()->focus_state());
98 // ...and the typed text should have arrived there.
99 EXPECT_EQ("a", GetOmniboxText());
100
101 // On the JS side, the fakebox should have been hidden.
102 ASSERT_TRUE(GetBoolFromJS(active_tab, "!!fakeboxIsVisible()", &result));
103 EXPECT_FALSE(result);
104 }
105
51 IN_PROC_BROWSER_TEST_F(LocalNTPTest, 106 IN_PROC_BROWSER_TEST_F(LocalNTPTest,
52 NTPRespectsBrowserLanguageSetting) { 107 NTPRespectsBrowserLanguageSetting) {
53 // Make sure the default language is not French. 108 // Make sure the default language is not French.
54 std::string default_locale = g_browser_process->GetApplicationLocale(); 109 std::string default_locale = g_browser_process->GetApplicationLocale();
55 EXPECT_NE("fr", default_locale); 110 EXPECT_NE("fr", default_locale);
56 111
57 // Switch browser language to French. 112 // Switch browser language to French.
58 std::string loaded_locale = 113 std::string loaded_locale =
59 ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources("fr"); 114 ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources("fr");
60 115
(...skipping 16 matching lines...) Expand all
77 browser(), GURL(chrome::kChromeUINewTabURL), 132 browser(), GURL(chrome::kChromeUINewTabURL),
78 WindowOpenDisposition::NEW_FOREGROUND_TAB, 133 WindowOpenDisposition::NEW_FOREGROUND_TAB,
79 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB | 134 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB |
80 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 135 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
81 136
82 // Verify that the NTP is in French. 137 // Verify that the NTP is in French.
83 content::WebContents* active_tab = 138 content::WebContents* active_tab =
84 browser()->tab_strip_model()->GetActiveWebContents(); 139 browser()->tab_strip_model()->GetActiveWebContents();
85 EXPECT_EQ(base::ASCIIToUTF16("Nouvel onglet"), active_tab->GetTitle()); 140 EXPECT_EQ(base::ASCIIToUTF16("Nouvel onglet"), active_tab->GetTitle());
86 } 141 }
OLDNEW
« no previous file with comments | « no previous file | chrome/test/data/local_ntp_browsertest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698