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

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

Issue 2086223002: Convert instant search messages to Mojo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge Created 4 years, 2 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_tab_unittest.cc
diff --git a/chrome/browser/ui/search/instant_tab_unittest.cc b/chrome/browser/ui/search/instant_tab_unittest.cc
index 06c0b3bda2bf3de7bc371d508fe3d919e3f017fb..4ac6d2219c1fbdff8cc2f002c12916d7cae252b9 100644
--- a/chrome/browser/ui/search/instant_tab_unittest.cc
+++ b/chrome/browser/ui/search/instant_tab_unittest.cc
@@ -9,9 +9,11 @@
#include <memory>
#include "base/command_line.h"
+#include "chrome/browser/ui/search/search_ipc_router.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/search/mock_searchbox.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/chrome_render_view_host_test_harness.h"
#include "content/public/browser/navigation_controller.h"
@@ -23,6 +25,8 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
+using testing::Return;
+
class Profile;
namespace {
@@ -36,8 +40,13 @@ class FakePageDelegate : public InstantTab::Delegate {
void(const content::WebContents* contents,
bool supports_instant));
MOCK_METHOD2(InstantTabAboutToNavigateMainFrame,
- void(const content::WebContents* contents,
- const GURL& url));
+ void(const content::WebContents* contents, const GURL& url));
+};
+
+class MockSearchBoxClientFactory
+ : public SearchIPCRouter::SearchBoxClientFactory {
+ public:
+ MOCK_METHOD0(GetSearchBox, chrome::mojom::SearchBox*(void));
Marc Treib 2016/10/13 09:04:50 nit: You don't need the flexibility of a Mock here
tibell 2016/10/13 23:29:44 I did initially create a fake, but it's more verbo
Marc Treib 2016/10/14 08:58:21 Yep, that's about what I would expect. The class i
};
} // namespace
@@ -52,11 +61,16 @@ class InstantTabTest : public ChromeRenderViewHostTestHarness {
std::unique_ptr<InstantTab> page;
FakePageDelegate delegate;
+ MockSearchBox mock_search_box;
};
void InstantTabTest::SetUp() {
ChromeRenderViewHostTestHarness::SetUp();
SearchTabHelper::CreateForWebContents(web_contents());
+ auto factory = base::MakeUnique<MockSearchBoxClientFactory>();
+ ON_CALL(*factory, GetSearchBox()).WillByDefault(Return(&mock_search_box));
+ search_tab()->ipc_router().set_search_box_client_factory_for_testing(
+ std::move(factory));
}
TEST_F(InstantTabTest, DetermineIfPageSupportsInstant_Local) {
@@ -65,8 +79,7 @@ TEST_F(InstantTabTest, DetermineIfPageSupportsInstant_Local) {
page->Init();
NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), true));
- SearchTabHelper::FromWebContents(web_contents())->
- DetermineIfPageSupportsInstant();
+ search_tab()->DetermineIfPageSupportsInstant();
EXPECT_TRUE(search_tab()->SupportsInstant());
}
@@ -75,13 +88,8 @@ TEST_F(InstantTabTest, DetermineIfPageSupportsInstant_NonLocal) {
EXPECT_FALSE(search_tab()->SupportsInstant());
page->Init();
NavigateAndCommit(GURL("chrome-search://foo/bar"));
- 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(mock_search_box, DetermineIfPageSupportsInstant());
+ search_tab()->DetermineIfPageSupportsInstant();
}
TEST_F(InstantTabTest, PageURLDoesntBelongToInstantRenderer) {
@@ -94,14 +102,10 @@ TEST_F(InstantTabTest, PageURLDoesntBelongToInstantRenderer) {
// SearchTabHelper::DeterminerIfPageSupportsInstant() should return
// immediately without dispatching any message to the renderer.
NavigateAndCommit(GURL("http://www.example.com"));
- process()->sink().ClearMessages();
EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), false));
+ EXPECT_CALL(mock_search_box, DetermineIfPageSupportsInstant()).Times(0);
- SearchTabHelper::FromWebContents(web_contents())->
- DetermineIfPageSupportsInstant();
- const IPC::Message* message = process()->sink().GetFirstMessageMatching(
- ChromeViewMsg_DetermineIfPageSupportsInstant::ID);
- ASSERT_TRUE(message == NULL);
+ search_tab()->DetermineIfPageSupportsInstant();
EXPECT_FALSE(search_tab()->SupportsInstant());
}
@@ -112,13 +116,8 @@ TEST_F(InstantTabTest, PageSupportsInstant) {
EXPECT_FALSE(search_tab()->SupportsInstant());
page->Init();
NavigateAndCommit(GURL("chrome-search://foo/bar"));
- 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(mock_search_box, DetermineIfPageSupportsInstant());
+ search_tab()->DetermineIfPageSupportsInstant();
EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), true));
@@ -127,6 +126,6 @@ TEST_F(InstantTabTest, PageSupportsInstant) {
const content::NavigationEntry* entry =
web_contents()->GetController().GetLastCommittedEntry();
EXPECT_TRUE(entry);
- SearchTabHelper::FromWebContents(web_contents())->InstantSupportChanged(true);
+ search_tab()->InstantSupportChanged(true);
EXPECT_TRUE(search_tab()->SupportsInstant());
}

Powered by Google App Engine
This is Rietveld 408576698