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()); |
+} |