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

Unified Diff: chrome/browser/instant/instant_extended_browsertest.cc

Issue 11824050: InstantExtended: Committed NTP (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments. Created 7 years, 11 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
Index: chrome/browser/instant/instant_extended_browsertest.cc
diff --git a/chrome/browser/instant/instant_extended_browsertest.cc b/chrome/browser/instant/instant_extended_browsertest.cc
index 08f8b4d094579c90ea12e3e047faf8820e4c4b55..dc2f1123ad80e61551a7dea784ef53f740e84036 100644
--- a/chrome/browser/instant/instant_extended_browsertest.cc
+++ b/chrome/browser/instant/instant_extended_browsertest.cc
@@ -2,11 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "chrome/browser/instant/instant_loader.h"
+#include "chrome/browser/instant/instant_ntp.h"
+#include "chrome/browser/instant/instant_overlay.h"
+#include "chrome/browser/instant/instant_service.h"
+#include "chrome/browser/instant/instant_service_factory.h"
#include "chrome/browser/instant/instant_test_utils.h"
#include "chrome/browser/ui/search/search.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/common/chrome_notification_types.h"
+#include "chrome/common/url_constants.h"
#include "chrome/test/base/interactive_test_utils.h"
#include "chrome/test/base/ui_test_utils.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/render_process_host.h"
+#include "content/public/browser/web_contents.h"
class InstantExtendedTest : public InstantTestBase {
protected:
@@ -15,6 +24,18 @@ class InstantExtendedTest : public InstantTestBase {
ASSERT_TRUE(test_server()->Start());
instant_url_ = test_server()->GetURL("files/instant_extended.html");
}
+
+ void FocusOmniboxAndWaitForInstantSupport() {
+ content::WindowedNotificationObserver ntp_observer(
+ chrome::NOTIFICATION_INSTANT_NTP_SUPPORT_DETERMINED,
+ content::NotificationService::AllSources());
+ content::WindowedNotificationObserver overlay_observer(
+ chrome::NOTIFICATION_INSTANT_OVERLAY_SUPPORT_DETERMINED,
+ content::NotificationService::AllSources());
+ FocusOmnibox();
+ ntp_observer.Wait();
+ overlay_observer.Wait();
+ }
};
IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ExtendedModeIsOn) {
@@ -34,7 +55,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxFocusLoadsInstant) {
EXPECT_FALSE(omnibox()->model()->has_focus());
// Delete any existing preview.
- instant()->loader_.reset();
+ instant()->overlay_.reset();
EXPECT_FALSE(instant()->GetPreviewContents());
// Refocus the omnibox. The InstantController should've preloaded Instant.
@@ -47,7 +68,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxFocusLoadsInstant) {
EXPECT_TRUE(preview_tab);
// Check that the page supports Instant, but it isn't showing.
- EXPECT_TRUE(instant()->loader_->supports_instant());
+ EXPECT_TRUE(instant()->overlay_->supports_instant());
EXPECT_FALSE(instant()->IsPreviewingSearchResults());
EXPECT_TRUE(instant()->model()->mode().is_default());
@@ -80,3 +101,155 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputShowsOverlay) {
EXPECT_TRUE(instant()->model()->mode().is_search_suggestions());
EXPECT_EQ(preview_tab, instant()->GetPreviewContents());
}
+
+IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NTPIsPreloaded) {
+ // Setup Instant.
+ ASSERT_NO_FATAL_FAILURE(SetupInstant());
+ FocusOmniboxAndWaitForInstantSupport();
+
+ // NTP contents should be preloaded.
+ ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
+ content::WebContents* ntp_contents = instant()->ntp_->contents();
+ EXPECT_TRUE(ntp_contents);
+}
+
+IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPIsUsedInNewTab) {
+ // Setup Instant.
+ ASSERT_NO_FATAL_FAILURE(SetupInstant());
+ FocusOmniboxAndWaitForInstantSupport();
+
+ // NTP contents should be preloaded.
+ ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
+ content::WebContents* ntp_contents = instant()->ntp_->contents();
+ EXPECT_TRUE(ntp_contents);
+
+ // Open new tab. Preloaded NTP contents should have been used.
+ ui_test_utils::NavigateToURLWithDisposition(
+ browser(),
+ GURL(chrome::kChromeUINewTabURL),
+ NEW_FOREGROUND_TAB,
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
+ content::WebContents* active_tab =
+ browser()->tab_strip_model()->GetActiveWebContents();
+ EXPECT_EQ(ntp_contents, active_tab);
+}
+
+IN_PROC_BROWSER_TEST_F(InstantExtendedTest, PreloadedNTPIsUsedInSameTab) {
+ // Setup Instant.
+ ASSERT_NO_FATAL_FAILURE(SetupInstant());
+ FocusOmniboxAndWaitForInstantSupport();
+
+ // NTP contents should be preloaded.
+ ASSERT_NE(static_cast<InstantNTP*>(NULL), instant()->ntp());
+ content::WebContents* ntp_contents = instant()->ntp_->contents();
+ EXPECT_TRUE(ntp_contents);
+
+ // Open new tab. Preloaded NTP contents should have been used.
+ ui_test_utils::NavigateToURLWithDisposition(
+ browser(),
+ GURL(chrome::kChromeUINewTabURL),
+ CURRENT_TAB,
+ ui_test_utils::BROWSER_TEST_NONE);
+ content::WebContents* active_tab =
+ browser()->tab_strip_model()->GetActiveWebContents();
+ EXPECT_EQ(ntp_contents, active_tab);
+}
+
+IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxHasFocusOnNewTab) {
+ // Setup Instant.
+ ASSERT_NO_FATAL_FAILURE(SetupInstant());
+ FocusOmniboxAndWaitForInstantSupport();
+
+ // Explicitly unfocus the omnibox.
+ EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
+ ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER);
+ EXPECT_FALSE(omnibox()->model()->has_focus());
+
+ // Open new tab. Preloaded NTP contents should have been used.
+ ui_test_utils::NavigateToURLWithDisposition(
+ browser(),
+ GURL(chrome::kChromeUINewTabURL),
+ NEW_FOREGROUND_TAB,
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB);
+
+ // Omnibox should have focus.
+ EXPECT_TRUE(omnibox()->model()->has_focus());
+}
+
+IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxEmptyOnNewTabPage) {
+ // Setup Instant.
+ ASSERT_NO_FATAL_FAILURE(SetupInstant());
+ FocusOmniboxAndWaitForInstantSupport();
+
+ // Open new tab. Preloaded NTP contents should have been used.
+ ui_test_utils::NavigateToURLWithDisposition(
+ browser(),
+ GURL(chrome::kChromeUINewTabURL),
+ CURRENT_TAB,
+ ui_test_utils::BROWSER_TEST_NONE);
+
+ // Omnibox should be empty.
+ EXPECT_TRUE(omnibox()->GetText().empty());
+}
+
+IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputOnNTPDoesntShowOverlay) {
+ ASSERT_NO_FATAL_FAILURE(SetupInstant());
+
+ // Focus omnibox and confirm overlay isn't shown.
+ FocusOmniboxAndWaitForInstantSupport();
+ content::WebContents* preview_tab = instant()->GetPreviewContents();
+ EXPECT_TRUE(preview_tab);
+ EXPECT_FALSE(instant()->IsPreviewingSearchResults());
+ EXPECT_TRUE(instant()->model()->mode().is_default());
+
+ // Navigate to the NTP.
+ ui_test_utils::NavigateToURLWithDisposition(
+ browser(),
+ GURL(chrome::kChromeUINewTabURL),
+ CURRENT_TAB,
+ ui_test_utils::BROWSER_TEST_NONE);
+
+ // Typing in the omnibox should not show the overlay.
+ SetOmniboxText("query");
+ EXPECT_FALSE(instant()->IsPreviewingSearchResults());
+ EXPECT_TRUE(instant()->model()->mode().is_default());
+}
+
+IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ProcessIsolation) {
+ // Prior to setup no render process is dedicated to Instant.
+ InstantService* instant_service =
+ InstantServiceFactory::GetForProfile(browser()->profile());
+ ASSERT_NE(static_cast<InstantService*>(NULL), instant_service);
+ EXPECT_EQ(0, instant_service->GetInstantProcessCount());
+
+ // Setup Instant.
+ ASSERT_NO_FATAL_FAILURE(SetupInstant());
+ FocusOmniboxAndWaitForInstantSupport();
+
+ // Now there should be a registered Instant render process.
+ EXPECT_LT(0, instant_service->GetInstantProcessCount());
+
+ // And the Instant overlay and ntp should live inside it.
+ content::WebContents* preview = instant()->GetPreviewContents();
+ EXPECT_TRUE(instant_service->IsInstantProcess(
+ preview->GetRenderProcessHost()->GetID()));
+ content::WebContents* ntp_contents = instant()->ntp_->contents();
+ EXPECT_TRUE(instant_service->IsInstantProcess(
+ ntp_contents->GetRenderProcessHost()->GetID()));
+
+ // Navigating to the NTP should use the Instant render process.
+ ui_test_utils::NavigateToURLWithDisposition(
+ browser(),
+ GURL(chrome::kChromeUINewTabURL),
+ CURRENT_TAB,
+ ui_test_utils::BROWSER_TEST_NONE);
+ content::WebContents* active_tab =
+ browser()->tab_strip_model()->GetActiveWebContents();
+ EXPECT_TRUE(instant_service->IsInstantProcess(
+ active_tab->GetRenderProcessHost()->GetID()));
+
+ // Navigating elsewhere should not use the Instant render process.
+ ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL));
+ EXPECT_FALSE(instant_service->IsInstantProcess(
+ active_tab->GetRenderProcessHost()->GetID()));
+}

Powered by Google App Engine
This is Rietveld 408576698