Chromium Code Reviews| 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/search/instant_test_utils.h" | 9 #include "chrome/browser/ui/search/instant_test_utils.h" |
| 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 10 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
| 26 #include "ui/gfx/geometry/point.h" | 26 #include "ui/gfx/geometry/point.h" |
| 27 #include "ui/gfx/geometry/rect.h" | 27 #include "ui/gfx/geometry/rect.h" |
| 28 #include "ui/gfx/geometry/vector2d.h" | 28 #include "ui/gfx/geometry/vector2d.h" |
| 29 | 29 |
| 30 class LocalNTPTest : public InProcessBrowserTest, | 30 class LocalNTPTest : public InProcessBrowserTest, |
| 31 public InstantTestBase { | 31 public InstantTestBase { |
| 32 public: | 32 public: |
| 33 LocalNTPTest() {} | 33 LocalNTPTest() {} |
| 34 | 34 |
| 35 GURL other_url() { return https_test_server().GetURL("/simple.html"); } | |
| 36 | |
| 35 protected: | 37 protected: |
| 36 void SetUpInProcessBrowserTestFixture() override { | 38 void SetUpInProcessBrowserTestFixture() override { |
| 37 ASSERT_TRUE(https_test_server().Start()); | 39 ASSERT_TRUE(https_test_server().Start()); |
| 38 GURL instant_url = | 40 GURL instant_url = |
| 39 https_test_server().GetURL("/instant_extended.html?strk=1&"); | 41 https_test_server().GetURL("/instant_extended.html?strk=1&"); |
| 40 GURL ntp_url = | 42 GURL ntp_url = |
| 41 https_test_server().GetURL("/local_ntp_browsertest.html?strk=1&"); | 43 https_test_server().GetURL("/local_ntp_browsertest.html?strk=1&"); |
| 42 InstantTestBase::Init(instant_url, ntp_url, false); | 44 InstantTestBase::Init(instant_url, ntp_url, false); |
| 43 } | 45 } |
| 44 }; | 46 }; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 55 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 57 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 56 content::WebContents* active_tab = | 58 content::WebContents* active_tab = |
| 57 browser()->tab_strip_model()->GetActiveWebContents(); | 59 browser()->tab_strip_model()->GetActiveWebContents(); |
| 58 ASSERT_TRUE(search::IsInstantNTP(active_tab)); | 60 ASSERT_TRUE(search::IsInstantNTP(active_tab)); |
| 59 | 61 |
| 60 bool success = false; | 62 bool success = false; |
| 61 ASSERT_TRUE(GetBoolFromJS(active_tab, "!!runSimpleTests()", &success)); | 63 ASSERT_TRUE(GetBoolFromJS(active_tab, "!!runSimpleTests()", &success)); |
| 62 EXPECT_TRUE(success); | 64 EXPECT_TRUE(success); |
| 63 } | 65 } |
| 64 | 66 |
| 67 IN_PROC_BROWSER_TEST_F(LocalNTPTest, EmbeddedSearchAPIOnlyAvailableOnNTP) { | |
| 68 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | |
| 69 FocusOmnibox(); | |
| 70 | |
| 71 // Open an NTP. | |
| 72 ui_test_utils::NavigateToURLWithDisposition( | |
| 73 browser(), ntp_url(), WindowOpenDisposition::NEW_FOREGROUND_TAB, | |
| 74 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB | | |
| 75 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
| 76 content::WebContents* active_tab = | |
| 77 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 78 ASSERT_TRUE(search::IsInstantNTP(active_tab)); | |
| 79 | |
| 80 // Check that the embeddedSearch API is available. | |
| 81 bool result = false; | |
| 82 ASSERT_TRUE( | |
| 83 GetBoolFromJS(active_tab, "!!window.chrome.embeddedSearch", &result)); | |
| 84 EXPECT_TRUE(result); | |
| 85 | |
| 86 // Navigate somewhere else in the same tab. | |
| 87 ui_test_utils::NavigateToURLWithDisposition( | |
| 88 browser(), other_url(), WindowOpenDisposition::CURRENT_TAB, | |
| 89 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
| 90 ASSERT_FALSE(search::IsInstantNTP(active_tab)); | |
| 91 | |
| 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 an NTP. | |
|
sfiera
2017/02/21 11:49:46
You're not actually navigating "back", right?
(th
Marc Treib
2017/02/21 12:13:08
Right, the formulation was misleading. Changed.
| |
| 98 ui_test_utils::NavigateToURLWithDisposition( | |
| 99 browser(), ntp_url(), WindowOpenDisposition::CURRENT_TAB, | |
| 100 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | |
| 101 ASSERT_TRUE(search::IsInstantNTP(active_tab)); | |
| 102 | |
| 103 // Now the API should be available again. | |
| 104 ASSERT_TRUE( | |
| 105 GetBoolFromJS(active_tab, "!!window.chrome.embeddedSearch", &result)); | |
| 106 EXPECT_TRUE(result); | |
| 107 } | |
| 108 | |
| 65 IN_PROC_BROWSER_TEST_F(LocalNTPTest, FakeboxRedirectsToOmnibox) { | 109 IN_PROC_BROWSER_TEST_F(LocalNTPTest, FakeboxRedirectsToOmnibox) { |
| 66 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); | 110 ASSERT_NO_FATAL_FAILURE(SetupInstant(browser())); |
| 67 FocusOmnibox(); | 111 FocusOmnibox(); |
| 68 | 112 |
| 69 ui_test_utils::NavigateToURLWithDisposition( | 113 ui_test_utils::NavigateToURLWithDisposition( |
| 70 browser(), ntp_url(), WindowOpenDisposition::NEW_FOREGROUND_TAB, | 114 browser(), ntp_url(), WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 71 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB | | 115 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB | |
| 72 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 116 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 73 content::WebContents* active_tab = | 117 content::WebContents* active_tab = |
| 74 browser()->tab_strip_model()->GetActiveWebContents(); | 118 browser()->tab_strip_model()->GetActiveWebContents(); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 240 browser(), GURL(chrome::kChromeUINewTabURL), | 284 browser(), GURL(chrome::kChromeUINewTabURL), |
| 241 WindowOpenDisposition::NEW_FOREGROUND_TAB, | 285 WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 242 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB | | 286 ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB | |
| 243 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); | 287 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 244 | 288 |
| 245 // Verify that the NTP is in French. | 289 // Verify that the NTP is in French. |
| 246 content::WebContents* active_tab = | 290 content::WebContents* active_tab = |
| 247 browser()->tab_strip_model()->GetActiveWebContents(); | 291 browser()->tab_strip_model()->GetActiveWebContents(); |
| 248 EXPECT_EQ(base::ASCIIToUTF16("Nouvel onglet"), active_tab->GetTitle()); | 292 EXPECT_EQ(base::ASCIIToUTF16("Nouvel onglet"), active_tab->GetTitle()); |
| 249 } | 293 } |
| OLD | NEW |