| 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 "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/chrome_notification_types.h" |
| 8 #include "chrome/browser/search/search.h" | 8 #include "chrome/browser/search/search.h" |
| 9 #include "chrome/browser/ui/browser_commands.h" |
| 9 #include "chrome/browser/ui/search/instant_test_utils.h" | 10 #include "chrome/browser/ui/search/instant_test_utils.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 11 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
| 12 #include "chrome/common/url_constants.h" | 13 #include "chrome/common/url_constants.h" |
| 13 #include "chrome/test/base/in_process_browser_test.h" | 14 #include "chrome/test/base/in_process_browser_test.h" |
| 14 #include "chrome/test/base/interactive_test_utils.h" | 15 #include "chrome/test/base/interactive_test_utils.h" |
| 15 #include "chrome/test/base/ui_test_utils.h" | 16 #include "chrome/test/base/ui_test_utils.h" |
| 16 #include "components/omnibox/browser/omnibox_edit_model.h" | 17 #include "components/omnibox/browser/omnibox_edit_model.h" |
| 17 #include "components/omnibox/browser/omnibox_view.h" | 18 #include "components/omnibox/browser/omnibox_view.h" |
| 18 #include "components/omnibox/common/omnibox_focus_state.h" | 19 #include "components/omnibox/common/omnibox_focus_state.h" |
| 19 #include "components/prefs/pref_service.h" | 20 #include "components/prefs/pref_service.h" |
| 20 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
| 21 #include "content/public/browser/web_contents.h" | 22 #include "content/public/browser/web_contents.h" |
| 22 #include "content/public/test/browser_test_utils.h" | 23 #include "content/public/test/browser_test_utils.h" |
| 24 #include "content/public/test/test_navigation_observer.h" |
| 23 #include "content/public/test/test_utils.h" | 25 #include "content/public/test/test_utils.h" |
| 24 #include "net/test/embedded_test_server/embedded_test_server.h" | 26 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 25 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
| 26 #include "ui/gfx/geometry/point.h" | 28 #include "ui/gfx/geometry/point.h" |
| 27 #include "ui/gfx/geometry/rect.h" | 29 #include "ui/gfx/geometry/rect.h" |
| 28 #include "ui/gfx/geometry/vector2d.h" | 30 #include "ui/gfx/geometry/vector2d.h" |
| 29 | 31 |
| 30 class LocalNTPTest : public InProcessBrowserTest, | 32 class LocalNTPTest : public InProcessBrowserTest, |
| 31 public InstantTestBase { | 33 public InstantTestBase { |
| 32 public: | 34 public: |
| 33 LocalNTPTest() {} | 35 LocalNTPTest() {} |
| 34 | 36 |
| 37 GURL other_url() { return https_test_server().GetURL("/simple.html"); } |
| 38 |
| 35 protected: | 39 protected: |
| 36 void SetUpInProcessBrowserTestFixture() override { | 40 void SetUpInProcessBrowserTestFixture() override { |
| 37 ASSERT_TRUE(https_test_server().Start()); | 41 ASSERT_TRUE(https_test_server().Start()); |
| 38 GURL instant_url = | 42 GURL instant_url = |
| 39 https_test_server().GetURL("/instant_extended.html?strk=1&"); | 43 https_test_server().GetURL("/instant_extended.html?strk=1&"); |
| 40 GURL ntp_url = | 44 GURL ntp_url = |
| 41 https_test_server().GetURL("/local_ntp_browsertest.html?strk=1&"); | 45 https_test_server().GetURL("/local_ntp_browsertest.html?strk=1&"); |
| 42 InstantTestBase::Init(instant_url, ntp_url, false); | 46 InstantTestBase::Init(instant_url, ntp_url, false); |
| 43 } | 47 } |
| 44 }; | 48 }; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 55 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 59 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 56 content::WebContents* active_tab = | 60 content::WebContents* active_tab = |
| 57 browser()->tab_strip_model()->GetActiveWebContents(); | 61 browser()->tab_strip_model()->GetActiveWebContents(); |
| 58 ASSERT_TRUE(search::IsInstantNTP(active_tab)); | 62 ASSERT_TRUE(search::IsInstantNTP(active_tab)); |
| 59 | 63 |
| 60 bool success = false; | 64 bool success = false; |
| 61 ASSERT_TRUE(GetBoolFromJS(active_tab, "!!runSimpleTests()", &success)); | 65 ASSERT_TRUE(GetBoolFromJS(active_tab, "!!runSimpleTests()", &success)); |
| 62 EXPECT_TRUE(success); | 66 EXPECT_TRUE(success); |
| 63 } | 67 } |
| 64 | 68 |
| 69 IN_PROC_BROWSER_TEST_F(LocalNTPTest, EmbeddedSearchAPIOnlyAvailableOnNTP) { |
| 70 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 71 FocusOmnibox(); |
| 72 |
| 73 // Open an NTP. |
| 74 ui_test_utils::NavigateToURLWithDisposition( |
| 75 browser(), ntp_url(), WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 76 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB | |
| 77 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 78 content::WebContents* active_tab = |
| 79 browser()->tab_strip_model()->GetActiveWebContents(); |
| 80 ASSERT_TRUE(search::IsInstantNTP(active_tab)); |
| 81 // Check that the embeddedSearch API is available. |
| 82 bool result = false; |
| 83 ASSERT_TRUE( |
| 84 GetBoolFromJS(active_tab, "!!window.chrome.embeddedSearch", &result)); |
| 85 EXPECT_TRUE(result); |
| 86 |
| 87 // Navigate somewhere else in the same tab. |
| 88 ui_test_utils::NavigateToURLWithDisposition( |
| 89 browser(), other_url(), WindowOpenDisposition::CURRENT_TAB, |
| 90 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 91 ASSERT_FALSE(search::IsInstantNTP(active_tab)); |
| 92 // Now the embeddedSearch API should have gone away. |
| 93 ASSERT_TRUE( |
| 94 GetBoolFromJS(active_tab, "!!window.chrome.embeddedSearch", &result)); |
| 95 EXPECT_FALSE(result); |
| 96 |
| 97 // Navigate back to the NTP. |
| 98 content::TestNavigationObserver back_observer(active_tab); |
| 99 chrome::GoBack(browser(), WindowOpenDisposition::CURRENT_TAB); |
| 100 back_observer.Wait(); |
| 101 // The API should be back. |
| 102 ASSERT_TRUE( |
| 103 GetBoolFromJS(active_tab, "!!window.chrome.embeddedSearch", &result)); |
| 104 EXPECT_TRUE(result); |
| 105 |
| 106 // Navigate forward to the non-NTP page. |
| 107 content::TestNavigationObserver fwd_observer(active_tab); |
| 108 chrome::GoForward(browser(), WindowOpenDisposition::CURRENT_TAB); |
| 109 fwd_observer.Wait(); |
| 110 // The API should be gone. |
| 111 ASSERT_TRUE( |
| 112 GetBoolFromJS(active_tab, "!!window.chrome.embeddedSearch", &result)); |
| 113 EXPECT_FALSE(result); |
| 114 |
| 115 // Navigate to a new NTP instance. |
| 116 ui_test_utils::NavigateToURLWithDisposition( |
| 117 browser(), ntp_url(), WindowOpenDisposition::CURRENT_TAB, |
| 118 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 119 ASSERT_TRUE(search::IsInstantNTP(active_tab)); |
| 120 // Now the API should be available again. |
| 121 ASSERT_TRUE( |
| 122 GetBoolFromJS(active_tab, "!!window.chrome.embeddedSearch", &result)); |
| 123 EXPECT_TRUE(result); |
| 124 } |
| 125 |
| 65 IN_PROC_BROWSER_TEST_F(LocalNTPTest, FakeboxRedirectsToOmnibox) { | 126 IN_PROC_BROWSER_TEST_F(LocalNTPTest, FakeboxRedirectsToOmnibox) { |
| 66 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 127 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 67 FocusOmnibox(); | 128 FocusOmnibox(); |
| 68 | 129 |
| 69 ui_test_utils::NavigateToURLWithDisposition( | 130 ui_test_utils::NavigateToURLWithDisposition( |
| 70 browser(), ntp_url(), WindowOpenDisposition::NEW_FOREGROUND_TAB, | 131 browser(), ntp_url(), WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 71 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB | | 132 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB | |
| 72 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 133 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 73 content::WebContents* active_tab = | 134 content::WebContents* active_tab = |
| 74 browser()->tab_strip_model()->GetActiveWebContents(); | 135 browser()->tab_strip_model()->GetActiveWebContents(); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 browser(), GURL(chrome::kChromeUINewTabURL), | 301 browser(), GURL(chrome::kChromeUINewTabURL), |
| 241 WindowOpenDisposition::NEW_FOREGROUND_TAB, | 302 WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 242 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB | | 303 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB | |
| 243 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 304 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 244 | 305 |
| 245 // Verify that the NTP is in French. | 306 // Verify that the NTP is in French. |
| 246 content::WebContents* active_tab = | 307 content::WebContents* active_tab = |
| 247 browser()->tab_strip_model()->GetActiveWebContents(); | 308 browser()->tab_strip_model()->GetActiveWebContents(); |
| 248 EXPECT_EQ(base::ASCIIToUTF16("Nouvel onglet"), active_tab->GetTitle()); | 309 EXPECT_EQ(base::ASCIIToUTF16("Nouvel onglet"), active_tab->GetTitle()); |
| 249 } | 310 } |
| OLD | NEW |