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

Unified Diff: chrome/browser/ui/search/local_ntp_browsertest.cc

Issue 2704373002: [Local NTP] Add a test for embeddedSearch API availability (Closed)
Patch Set: test back/fwd 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 c80828b124a92b567c87c4a9a4aa8d0898eda0db..5eb8f0df97039c98fb61eecab137cb3bdfe7130a 100644
--- a/chrome/browser/ui/search/local_ntp_browsertest.cc
+++ b/chrome/browser/ui/search/local_ntp_browsertest.cc
@@ -6,6 +6,7 @@
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/search/search.h"
+#include "chrome/browser/ui/browser_commands.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"
@@ -20,6 +21,7 @@
#include "content/public/browser/notification_service.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
+#include "content/public/test/test_navigation_observer.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,6 +34,8 @@ class LocalNTPTest : public InProcessBrowserTest,
public:
LocalNTPTest() {}
+ GURL other_url() { return https_test_server().GetURL("/simple.html"); }
+
protected:
void SetUpInProcessBrowserTestFixture() override {
ASSERT_TRUE(https_test_server().Start());
@@ -62,6 +66,63 @@ IN_PROC_BROWSER_TEST_F(LocalNTPTest, SimpleJavascriptTests) {
EXPECT_TRUE(success);
}
+IN_PROC_BROWSER_TEST_F(LocalNTPTest, EmbeddedSearchAPIOnlyAvailableOnNTP) {
+ ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
+ FocusOmnibox();
+
+ // Open an NTP.
+ 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));
+ // Check that the embeddedSearch API is available.
+ bool result = false;
+ ASSERT_TRUE(
+ GetBoolFromJS(active_tab, "!!window.chrome.embeddedSearch", &result));
+ EXPECT_TRUE(result);
+
+ // Navigate somewhere else in the same tab.
+ ui_test_utils::NavigateToURLWithDisposition(
+ browser(), other_url(), WindowOpenDisposition::CURRENT_TAB,
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
+ ASSERT_FALSE(search::IsInstantNTP(active_tab));
+ // Now the embeddedSearch API should have gone away.
+ ASSERT_TRUE(
+ GetBoolFromJS(active_tab, "!!window.chrome.embeddedSearch", &result));
+ EXPECT_FALSE(result);
+
+ // Navigate back to the NTP.
+ content::TestNavigationObserver back_observer(active_tab);
+ chrome::GoBack(browser(), WindowOpenDisposition::CURRENT_TAB);
+ back_observer.Wait();
+ // The API should be back.
+ ASSERT_TRUE(
+ GetBoolFromJS(active_tab, "!!window.chrome.embeddedSearch", &result));
+ EXPECT_TRUE(result);
+
+ // Navigate forward to the non-NTP page.
+ content::TestNavigationObserver fwd_observer(active_tab);
+ chrome::GoForward(browser(), WindowOpenDisposition::CURRENT_TAB);
+ fwd_observer.Wait();
+ // The API should be gone.
+ ASSERT_TRUE(
+ GetBoolFromJS(active_tab, "!!window.chrome.embeddedSearch", &result));
+ EXPECT_FALSE(result);
+
+ // Navigate to a new NTP instance.
+ ui_test_utils::NavigateToURLWithDisposition(
+ browser(), ntp_url(), WindowOpenDisposition::CURRENT_TAB,
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
+ ASSERT_TRUE(search::IsInstantNTP(active_tab));
+ // Now the API should be available again.
+ ASSERT_TRUE(
+ GetBoolFromJS(active_tab, "!!window.chrome.embeddedSearch", &result));
+ EXPECT_TRUE(result);
+}
+
IN_PROC_BROWSER_TEST_F(LocalNTPTest, FakeboxRedirectsToOmnibox) {
ASSERT_NO_FATAL_FAILURE(SetupInstant(browser()));
FocusOmnibox();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698