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

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: fix Mac 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
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"
25 #include "ui/gfx/geometry/point.h"
26 #include "ui/gfx/geometry/rect.h"
27 #include "ui/gfx/geometry/vector2d.h"
18 28
19 class LocalNTPTest : public InProcessBrowserTest, 29 class LocalNTPTest : public InProcessBrowserTest,
20 public InstantTestBase { 30 public InstantTestBase {
21 public: 31 public:
22 LocalNTPTest() {} 32 LocalNTPTest() {}
23 33
24 protected: 34 protected:
25 void SetUpInProcessBrowserTestFixture() override { 35 void SetUpInProcessBrowserTestFixture() override {
26 ASSERT_TRUE(https_test_server().Start()); 36 ASSERT_TRUE(https_test_server().Start());
27 GURL instant_url = 37 GURL instant_url =
28 https_test_server().GetURL("/instant_extended.html?strk=1&"); 38 https_test_server().GetURL("/instant_extended.html?strk=1&");
29 GURL ntp_url = 39 GURL ntp_url =
30 https_test_server().GetURL("/local_ntp_browsertest.html?strk=1&"); 40 https_test_server().GetURL("/local_ntp_browsertest.html?strk=1&");
31 InstantTestBase::Init(instant_url, ntp_url, false); 41 InstantTestBase::Init(instant_url, ntp_url, false);
32 } 42 }
33 }; 43 };
34 44
35 IN_PROC_BROWSER_TEST_F(LocalNTPTest, LocalNTPJavascriptTest) { 45 // This runs a bunch of pure JS-side tests, i.e. those that don't require any
46 // interaction from the native side.
47 IN_PROC_BROWSER_TEST_F(LocalNTPTest, SimpleJavascriptTests) {
36 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); 48 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
37 FocusOmnibox(); 49 FocusOmnibox();
38 50
39 ui_test_utils::NavigateToURLWithDisposition( 51 ui_test_utils::NavigateToURLWithDisposition(
40 browser(), ntp_url(), WindowOpenDisposition::NEW_FOREGROUND_TAB, 52 browser(), ntp_url(), WindowOpenDisposition::NEW_FOREGROUND_TAB,
41 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB | 53 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB |
42 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 54 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
43 content::WebContents* active_tab = 55 content::WebContents* active_tab =
44 browser()->tab_strip_model()->GetActiveWebContents(); 56 browser()->tab_strip_model()->GetActiveWebContents();
45 ASSERT_TRUE(search::IsInstantNTP(active_tab)); 57 ASSERT_TRUE(search::IsInstantNTP(active_tab));
58
46 bool success = false; 59 bool success = false;
47 ASSERT_TRUE(GetBoolFromJS(active_tab, "!!runTests()", &success)); 60 ASSERT_TRUE(GetBoolFromJS(active_tab, "!!runSimpleTests()", &success));
48 EXPECT_TRUE(success); 61 EXPECT_TRUE(success);
49 } 62 }
50 63
64 IN_PROC_BROWSER_TEST_F(LocalNTPTest, FakeboxRedirectsToOmnibox) {
65 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
66 FocusOmnibox();
67
68 ui_test_utils::NavigateToURLWithDisposition(
69 browser(), ntp_url(), WindowOpenDisposition::NEW_FOREGROUND_TAB,
70 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB |
71 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
72 content::WebContents* active_tab =
73 browser()->tab_strip_model()->GetActiveWebContents();
74 ASSERT_TRUE(search::IsInstantNTP(active_tab));
75
76 // This is required to make the mouse events we send below arrive at the right
77 // place. It *should* be the default for all interactive_ui_tests anyway, but
78 // on Mac it isn't; see crbug.com/641969.
79 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
80
81 bool result = false;
82 ASSERT_TRUE(GetBoolFromJS(active_tab, "!!setupAdvancedTest()", &result));
83 ASSERT_TRUE(result);
84
85 // Get the position of the fakebox on the page.
86 double fakebox_x = 0;
87 ASSERT_TRUE(GetDoubleFromJS(active_tab, "getFakeboxPositionX()", &fakebox_x));
88 double fakebox_y = 0;
89 ASSERT_TRUE(GetDoubleFromJS(active_tab, "getFakeboxPositionY()", &fakebox_y));
90
91 // Move the mouse over the fakebox.
92 gfx::Vector2d fakebox_pos(static_cast<int>(std::ceil(fakebox_x)),
93 static_cast<int>(std::ceil(fakebox_y)));
94 gfx::Point origin = active_tab->GetContainerBounds().origin();
95 ASSERT_TRUE(ui_test_utils::SendMouseMoveSync(origin + fakebox_pos +
96 gfx::Vector2d(1, 1)));
97
98 // Click on the fakebox, and wait for the omnibox to receive invisible focus.
99 // Note that simply waiting for the first OMNIBOX_FOCUS_CHANGED notification
100 // is not sufficient: If the omnibox had focus before, it will first lose the
101 // focus before gaining invisible focus.
102 ASSERT_NE(OMNIBOX_FOCUS_INVISIBLE, omnibox()->model()->focus_state());
103 content::WindowedNotificationObserver focus_observer(
104 chrome::NOTIFICATION_OMNIBOX_FOCUS_CHANGED,
105 base::Bind(
106 [](const OmniboxEditModel* omnibox_model) {
107 return omnibox_model->focus_state() == OMNIBOX_FOCUS_INVISIBLE;
108 },
109 omnibox()->model()));
110
111 ASSERT_TRUE(
112 ui_test_utils::SendMouseEventsSync(ui_controls::LEFT, ui_controls::DOWN));
113 ASSERT_TRUE(
114 ui_test_utils::SendMouseEventsSync(ui_controls::LEFT, ui_controls::UP));
115
116 focus_observer.Wait();
117 EXPECT_EQ(OMNIBOX_FOCUS_INVISIBLE, omnibox()->model()->focus_state());
118
119 // The fakebox should now also have focus.
120 ASSERT_TRUE(GetBoolFromJS(active_tab, "!!fakeboxIsFocused()", &result));
121 EXPECT_TRUE(result);
122
123 // Type "a".
124 ASSERT_TRUE(ui_test_utils::SendKeyPressSync(
125 browser(), ui::KeyboardCode::VKEY_A,
126 /*control=*/false, /*shift=*/false, /*alt=*/false, /*command=*/false));
127
128 // The omnibox should have received visible focus.
129 EXPECT_EQ(OMNIBOX_FOCUS_VISIBLE, omnibox()->model()->focus_state());
130 // ...and the typed text should have arrived there.
131 EXPECT_EQ("a", GetOmniboxText());
132
133 // On the JS side, the fakebox should have been hidden.
134 ASSERT_TRUE(GetBoolFromJS(active_tab, "!!fakeboxIsVisible()", &result));
135 EXPECT_FALSE(result);
136 }
137
51 IN_PROC_BROWSER_TEST_F(LocalNTPTest, 138 IN_PROC_BROWSER_TEST_F(LocalNTPTest,
52 NTPRespectsBrowserLanguageSetting) { 139 NTPRespectsBrowserLanguageSetting) {
53 // Make sure the default language is not French. 140 // Make sure the default language is not French.
54 std::string default_locale = g_browser_process->GetApplicationLocale(); 141 std::string default_locale = g_browser_process->GetApplicationLocale();
55 EXPECT_NE("fr", default_locale); 142 EXPECT_NE("fr", default_locale);
56 143
57 // Switch browser language to French. 144 // Switch browser language to French.
58 std::string loaded_locale = 145 std::string loaded_locale =
59 ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources("fr"); 146 ui::ResourceBundle::GetSharedInstance().ReloadLocaleResources("fr");
60 147
(...skipping 16 matching lines...) Expand all
77 browser(), GURL(chrome::kChromeUINewTabURL), 164 browser(), GURL(chrome::kChromeUINewTabURL),
78 WindowOpenDisposition::NEW_FOREGROUND_TAB, 165 WindowOpenDisposition::NEW_FOREGROUND_TAB,
79 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB | 166 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB |
80 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 167 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
81 168
82 // Verify that the NTP is in French. 169 // Verify that the NTP is in French.
83 content::WebContents* active_tab = 170 content::WebContents* active_tab =
84 browser()->tab_strip_model()->GetActiveWebContents(); 171 browser()->tab_strip_model()->GetActiveWebContents();
85 EXPECT_EQ(base::ASCIIToUTF16("Nouvel onglet"), active_tab->GetTitle()); 172 EXPECT_EQ(base::ASCIIToUTF16("Nouvel onglet"), active_tab->GetTitle());
86 } 173 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/instant_test_utils.cc ('k') | chrome/test/data/local_ntp_browsertest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698