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

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

Issue 14911005: Move instant support to SearchTabHelper. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed review comments Created 7 years, 7 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 | « chrome/browser/ui/search/instant_page.cc ('k') | chrome/browser/ui/search/instant_tab.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/search/instant_page_unittest.cc
diff --git a/chrome/browser/ui/search/instant_page_unittest.cc b/chrome/browser/ui/search/instant_page_unittest.cc
index 73c345f57017e8f5aff41e902576cc56b22a2615..3c42edce2631fa74bb01e470936b65500c671d75 100644
--- a/chrome/browser/ui/search/instant_page_unittest.cc
+++ b/chrome/browser/ui/search/instant_page_unittest.cc
@@ -4,10 +4,15 @@
#include "chrome/browser/ui/search/instant_page.h"
+#include "base/command_line.h"
#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/ui/search/search_tab_helper.h"
+#include "chrome/common/chrome_switches.h"
#include "chrome/common/render_messages.h"
#include "chrome/common/url_constants.h"
+#include "chrome/test/base/browser_with_test_window_test.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
+#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/mock_render_process_host.h"
#include "googleurl/src/gurl.h"
@@ -74,9 +79,27 @@ class InstantPageTest : public ChromeRenderViewHostTestHarness {
FakePageDelegate delegate;
};
+
+class InstantSupportTest : public ChromeRenderViewHostTestHarness {
+ public:
+ virtual void SetUp() OVERRIDE {
+ CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kEnableInstantExtendedAPI);
+ ChromeRenderViewHostTestHarness::SetUp();
+ SearchTabHelper::CreateForWebContents(web_contents());
+ page.reset(new FakePage(&delegate, ""));
+ EXPECT_FALSE(page->supports_instant());
+ page->SetContents(web_contents());
+ }
+
+ scoped_ptr<FakePage> page;
+ FakePageDelegate delegate;
+};
+
+
TEST_F(InstantPageTest, IsLocal) {
page.reset(new FakePage(&delegate, ""));
- EXPECT_FALSE(page->IsLocal());
+ EXPECT_FALSE(page->supports_instant());
Jered 2013/05/09 16:32:43 Is this change intentional? This is testing the Is
kmadhusu 2013/05/09 16:37:33 oops. This is caused by a merge conflict mistake.
page->SetContents(web_contents());
NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
EXPECT_TRUE(page->IsLocal());
@@ -111,3 +134,42 @@ TEST_F(InstantPageTest, DetermineIfPageSupportsInstant_NonLocal) {
ASSERT_TRUE(message != NULL);
EXPECT_EQ(web_contents()->GetRoutingID(), message->routing_id());
}
+
+// Test to verify that ChromeViewMsg_DetermineIfPageSupportsInstant message is
+// dispatched by SearchTabHelper.
+TEST_F(InstantSupportTest, DispatchDetermineIfPageSupportsInstantMsg) {
+ NavigateAndCommit(GURL("http://example.com/"));
+ process()->sink().ClearMessages();
+ EXPECT_FALSE(page->IsLocal());
+ SearchTabHelper::FromWebContents(web_contents())->
+ DetermineIfPageSupportsInstant();
+ const IPC::Message* message = process()->sink().GetFirstMessageMatching(
+ ChromeViewMsg_DetermineIfPageSupportsInstant::ID);
+ ASSERT_TRUE(message != NULL);
+ EXPECT_EQ(web_contents()->GetRoutingID(), message->routing_id());
+}
+
+// Test to verify that ChromeViewMsg_DetermineIfPageSupportsInstant message
+// reply handler updates the instant support state in InstantPage.
+TEST_F(InstantSupportTest, PageSupportsInstant) {
+ NavigateAndCommit(GURL("http://example.com/"));
+ process()->sink().ClearMessages();
+ SearchTabHelper::FromWebContents(web_contents())->
+ DetermineIfPageSupportsInstant();
+ const IPC::Message* message = process()->sink().GetFirstMessageMatching(
+ ChromeViewMsg_DetermineIfPageSupportsInstant::ID);
+ ASSERT_TRUE(message != NULL);
+ EXPECT_EQ(web_contents()->GetRoutingID(), message->routing_id());
+
+ EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), true))
+ .Times(1);
+
+ // Assume the page supports instant. Invoke the message reply handler to make
+ // sure the InstantPage is notified about the instant support state.
+ const content::NavigationEntry* entry =
+ web_contents()->GetController().GetActiveEntry();
+ EXPECT_TRUE(entry);
+ SearchTabHelper::FromWebContents(web_contents())->
+ OnInstantSupportDeterminedMsgReceived(entry->GetPageID(), true);
+ EXPECT_TRUE(page->supports_instant());
+}
« no previous file with comments | « chrome/browser/ui/search/instant_page.cc ('k') | chrome/browser/ui/search/instant_tab.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698