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

Side by Side Diff: chrome/browser/ui/search/instant_tab_unittest.cc

Issue 2885853002: Instant: remove InstantSupportState (Closed)
Patch Set: Created 3 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/search/instant_tab.h"
6
7 #include <stdint.h>
8
9 #include <memory>
10
11 #include "base/command_line.h"
12 #include "chrome/browser/ui/search/search_ipc_router.h"
13 #include "chrome/browser/ui/search/search_tab_helper.h"
14 #include "chrome/common/chrome_switches.h"
15 #include "chrome/common/render_messages.h"
16 #include "chrome/common/search/mock_searchbox.h"
17 #include "chrome/common/url_constants.h"
18 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
19 #include "content/public/browser/navigation_controller.h"
20 #include "content/public/browser/navigation_entry.h"
21 #include "content/public/browser/web_contents.h"
22 #include "content/public/test/mock_render_process_host.h"
23 #include "ipc/ipc_test_sink.h"
24 #include "testing/gmock/include/gmock/gmock.h"
25 #include "testing/gtest/include/gtest/gtest.h"
26 #include "url/gurl.h"
27
28 using testing::Return;
29
30 class Profile;
31
32 namespace {
33
34 class FakePageDelegate : public InstantTab::Delegate {
35 public:
36 virtual ~FakePageDelegate() {
37 }
38
39 MOCK_METHOD2(InstantTabAboutToNavigateMainFrame,
40 void(const content::WebContents* contents, const GURL& url));
41 };
42
43 class MockSearchBoxClientFactory
44 : public SearchIPCRouter::SearchBoxClientFactory {
45 public:
46 MOCK_METHOD0(GetSearchBox, chrome::mojom::SearchBox*(void));
47 };
48
49 } // namespace
50
51 class InstantTabTest : public ChromeRenderViewHostTestHarness {
52 public:
53 void SetUp() override;
54
55 SearchTabHelper* search_tab() {
56 return SearchTabHelper::FromWebContents(web_contents());
57 }
58
59 bool SupportsInstant() {
60 return search_tab()->model()->instant_support() == INSTANT_SUPPORT_YES;
61 }
62
63 std::unique_ptr<InstantTab> page;
64 FakePageDelegate delegate;
65 MockSearchBox mock_search_box;
66 };
67
68 void InstantTabTest::SetUp() {
69 ChromeRenderViewHostTestHarness::SetUp();
70 SearchTabHelper::CreateForWebContents(web_contents());
71 auto factory = base::MakeUnique<MockSearchBoxClientFactory>();
72 ON_CALL(*factory, GetSearchBox()).WillByDefault(Return(&mock_search_box));
73 search_tab()
74 ->ipc_router_for_testing()
75 .set_search_box_client_factory_for_testing(std::move(factory));
76 }
77
78 TEST_F(InstantTabTest, PageURLDoesntBelongToInstantRenderer) {
79 page.reset(new InstantTab(&delegate, web_contents()));
80 EXPECT_FALSE(SupportsInstant());
81 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
82 page->Init();
83
84 // Navigate to a page URL that doesn't belong to Instant renderer.
85 NavigateAndCommit(GURL("http://www.example.com"));
86
87 EXPECT_FALSE(SupportsInstant());
88 }
89
90 TEST_F(InstantTabTest, PageSupportsInstant) {
91 page.reset(new InstantTab(&delegate, web_contents()));
92 EXPECT_FALSE(SupportsInstant());
93 page->Init();
94 NavigateAndCommit(GURL("chrome-search://foo/bar"));
95
96 // Assume the page supports instant. Invoke the message reply handler to make
97 // sure the InstantTab is notified about the instant support state.
98 const content::NavigationEntry* entry =
99 web_contents()->GetController().GetLastCommittedEntry();
100 EXPECT_TRUE(entry);
101 search_tab()->InstantSupportChanged(true);
102 EXPECT_TRUE(SupportsInstant());
103 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser_instant_controller.cc ('k') | chrome/browser/ui/search/search_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698