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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/search/instant_page.h" 5 #include "chrome/browser/ui/search/instant_page.h"
6 6
7 #include "base/command_line.h"
7 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "chrome/browser/ui/search/search_tab_helper.h"
10 #include "chrome/common/chrome_switches.h"
8 #include "chrome/common/render_messages.h" 11 #include "chrome/common/render_messages.h"
9 #include "chrome/common/url_constants.h" 12 #include "chrome/common/url_constants.h"
13 #include "chrome/test/base/browser_with_test_window_test.h"
10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 14 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
15 #include "content/public/browser/navigation_entry.h"
11 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
12 #include "content/public/test/mock_render_process_host.h" 17 #include "content/public/test/mock_render_process_host.h"
13 #include "googleurl/src/gurl.h" 18 #include "googleurl/src/gurl.h"
14 #include "ipc/ipc_test_sink.h" 19 #include "ipc/ipc_test_sink.h"
15 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
17 22
18 namespace { 23 namespace {
19 24
20 class FakePageDelegate : public InstantPage::Delegate { 25 class FakePageDelegate : public InstantPage::Delegate {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 }; 72 };
68 73
69 } // namespace 74 } // namespace
70 75
71 class InstantPageTest : public ChromeRenderViewHostTestHarness { 76 class InstantPageTest : public ChromeRenderViewHostTestHarness {
72 public: 77 public:
73 scoped_ptr<FakePage> page; 78 scoped_ptr<FakePage> page;
74 FakePageDelegate delegate; 79 FakePageDelegate delegate;
75 }; 80 };
76 81
82
83 class InstantSupportTest : public ChromeRenderViewHostTestHarness {
84 public:
85 virtual void SetUp() OVERRIDE {
86 CommandLine::ForCurrentProcess()->AppendSwitch(
87 switches::kEnableInstantExtendedAPI);
88 ChromeRenderViewHostTestHarness::SetUp();
89 SearchTabHelper::CreateForWebContents(web_contents());
90 page.reset(new FakePage(&delegate, ""));
91 EXPECT_FALSE(page->supports_instant());
92 page->SetContents(web_contents());
93 }
94
95 scoped_ptr<FakePage> page;
96 FakePageDelegate delegate;
97 };
98
99
77 TEST_F(InstantPageTest, IsLocal) { 100 TEST_F(InstantPageTest, IsLocal) {
78 page.reset(new FakePage(&delegate, "")); 101 page.reset(new FakePage(&delegate, ""));
79 EXPECT_FALSE(page->IsLocal()); 102 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.
80 page->SetContents(web_contents()); 103 page->SetContents(web_contents());
81 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); 104 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
82 EXPECT_TRUE(page->IsLocal()); 105 EXPECT_TRUE(page->IsLocal());
83 NavigateAndCommit(GURL("http://example.com")); 106 NavigateAndCommit(GURL("http://example.com"));
84 EXPECT_FALSE(page->IsLocal()); 107 EXPECT_FALSE(page->IsLocal());
85 NavigateAndCommit(GURL(chrome::kChromeSearchLocalGoogleNtpUrl)); 108 NavigateAndCommit(GURL(chrome::kChromeSearchLocalGoogleNtpUrl));
86 EXPECT_TRUE(page->IsLocal()); 109 EXPECT_TRUE(page->IsLocal());
87 } 110 }
88 111
89 TEST_F(InstantPageTest, DetermineIfPageSupportsInstant_Local) { 112 TEST_F(InstantPageTest, DetermineIfPageSupportsInstant_Local) {
(...skipping 14 matching lines...) Expand all
104 page->SetContents(web_contents()); 127 page->SetContents(web_contents());
105 NavigateAndCommit(GURL("http://example.com/")); 128 NavigateAndCommit(GURL("http://example.com/"));
106 EXPECT_FALSE(page->IsLocal()); 129 EXPECT_FALSE(page->IsLocal());
107 process()->sink().ClearMessages(); 130 process()->sink().ClearMessages();
108 page->DetermineIfPageSupportsInstant(); 131 page->DetermineIfPageSupportsInstant();
109 const IPC::Message* message = process()->sink().GetFirstMessageMatching( 132 const IPC::Message* message = process()->sink().GetFirstMessageMatching(
110 ChromeViewMsg_DetermineIfPageSupportsInstant::ID); 133 ChromeViewMsg_DetermineIfPageSupportsInstant::ID);
111 ASSERT_TRUE(message != NULL); 134 ASSERT_TRUE(message != NULL);
112 EXPECT_EQ(web_contents()->GetRoutingID(), message->routing_id()); 135 EXPECT_EQ(web_contents()->GetRoutingID(), message->routing_id());
113 } 136 }
137
138 // Test to verify that ChromeViewMsg_DetermineIfPageSupportsInstant message is
139 // dispatched by SearchTabHelper.
140 TEST_F(InstantSupportTest, DispatchDetermineIfPageSupportsInstantMsg) {
141 NavigateAndCommit(GURL("http://example.com/"));
142 process()->sink().ClearMessages();
143 EXPECT_FALSE(page->IsLocal());
144 SearchTabHelper::FromWebContents(web_contents())->
145 DetermineIfPageSupportsInstant();
146 const IPC::Message* message = process()->sink().GetFirstMessageMatching(
147 ChromeViewMsg_DetermineIfPageSupportsInstant::ID);
148 ASSERT_TRUE(message != NULL);
149 EXPECT_EQ(web_contents()->GetRoutingID(), message->routing_id());
150 }
151
152 // Test to verify that ChromeViewMsg_DetermineIfPageSupportsInstant message
153 // reply handler updates the instant support state in InstantPage.
154 TEST_F(InstantSupportTest, PageSupportsInstant) {
155 NavigateAndCommit(GURL("http://example.com/"));
156 process()->sink().ClearMessages();
157 SearchTabHelper::FromWebContents(web_contents())->
158 DetermineIfPageSupportsInstant();
159 const IPC::Message* message = process()->sink().GetFirstMessageMatching(
160 ChromeViewMsg_DetermineIfPageSupportsInstant::ID);
161 ASSERT_TRUE(message != NULL);
162 EXPECT_EQ(web_contents()->GetRoutingID(), message->routing_id());
163
164 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), true))
165 .Times(1);
166
167 // Assume the page supports instant. Invoke the message reply handler to make
168 // sure the InstantPage is notified about the instant support state.
169 const content::NavigationEntry* entry =
170 web_contents()->GetController().GetActiveEntry();
171 EXPECT_TRUE(entry);
172 SearchTabHelper::FromWebContents(web_contents())->
173 OnInstantSupportDeterminedMsgReceived(entry->GetPageID(), true);
174 EXPECT_TRUE(page->supports_instant());
175 }
OLDNEW
« 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