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

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: Removed instant support code from InstantPage 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
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..0b1435a77b42c4e20b35c672ce0182e79bd3bbc6 100644
--- a/chrome/browser/ui/search/instant_page_unittest.cc
+++ b/chrome/browser/ui/search/instant_page_unittest.cc
@@ -4,10 +4,14 @@
#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/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"
@@ -64,20 +68,33 @@ class FakePage : public InstantPage {
}
using InstantPage::SetContents;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(FakePage);
};
} // namespace
class InstantPageTest : public ChromeRenderViewHostTestHarness {
public:
+ virtual void SetUp() OVERRIDE;
+
scoped_ptr<FakePage> page;
FakePageDelegate delegate;
};
-TEST_F(InstantPageTest, IsLocal) {
+void InstantPageTest::SetUp() {
+ CommandLine::ForCurrentProcess()->AppendSwitch(
+ switches::kEnableInstantExtendedAPI);
+ ChromeRenderViewHostTestHarness::SetUp();
+ SearchTabHelper::CreateForWebContents(web_contents());
page.reset(new FakePage(&delegate, ""));
- EXPECT_FALSE(page->IsLocal());
+ EXPECT_FALSE(page->supports_instant());
samarth 2013/05/10 01:32:38 I'd prefer keeping the EXPECT checks in the tests
kmadhusu 2013/05/13 17:13:24 Done.
page->SetContents(web_contents());
+}
+
+TEST_F(InstantPageTest, IsLocal) {
+ EXPECT_FALSE(page->IsLocal());
NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
EXPECT_TRUE(page->IsLocal());
NavigateAndCommit(GURL("http://example.com"));
@@ -87,27 +104,48 @@ TEST_F(InstantPageTest, IsLocal) {
}
TEST_F(InstantPageTest, DetermineIfPageSupportsInstant_Local) {
- page.reset(new FakePage(&delegate, ""));
- EXPECT_FALSE(page->supports_instant());
- page->SetContents(web_contents());
NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
EXPECT_TRUE(page->IsLocal());
EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), true))
.Times(1);
- page->DetermineIfPageSupportsInstant();
+ SearchTabHelper::FromWebContents(web_contents())->
+ DetermineIfPageSupportsInstant();
EXPECT_TRUE(page->supports_instant());
}
TEST_F(InstantPageTest, DetermineIfPageSupportsInstant_NonLocal) {
- page.reset(new FakePage(&delegate, ""));
- EXPECT_FALSE(page->supports_instant());
- page->SetContents(web_contents());
NavigateAndCommit(GURL("http://example.com/"));
EXPECT_FALSE(page->IsLocal());
process()->sink().ClearMessages();
- page->DetermineIfPageSupportsInstant();
+ 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(InstantPageTest, 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());
}

Powered by Google App Engine
This is Rietveld 408576698