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

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

Issue 2166023004: Cleanup in InstantTab and InstantController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: bring back Init() Created 4 years, 5 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
« no previous file with comments | « chrome/browser/ui/search/instant_tab.cc ('k') | no next file » | 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_tab.h" 5 #include "chrome/browser/ui/search/instant_tab.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 17 matching lines...) Expand all
28 namespace { 28 namespace {
29 29
30 class FakePageDelegate : public InstantTab::Delegate { 30 class FakePageDelegate : public InstantTab::Delegate {
31 public: 31 public:
32 virtual ~FakePageDelegate() { 32 virtual ~FakePageDelegate() {
33 } 33 }
34 34
35 MOCK_METHOD2(InstantSupportDetermined, 35 MOCK_METHOD2(InstantSupportDetermined,
36 void(const content::WebContents* contents, 36 void(const content::WebContents* contents,
37 bool supports_instant)); 37 bool supports_instant));
38 MOCK_METHOD1(InstantTabRenderProcessGone,
39 void(const content::WebContents* contents));
40 MOCK_METHOD2(InstantTabAboutToNavigateMainFrame, 38 MOCK_METHOD2(InstantTabAboutToNavigateMainFrame,
41 void(const content::WebContents* contents, 39 void(const content::WebContents* contents,
42 const GURL& url)); 40 const GURL& url));
43 MOCK_METHOD5(NavigateToURL,
44 void(const content::WebContents* contents,
45 const GURL& url,
46 ui::PageTransition transition,
47 WindowOpenDisposition disposition,
48 bool is_search_type));
49 }; 41 };
50 42
51 } // namespace 43 } // namespace
52 44
53 class InstantTabTest : public ChromeRenderViewHostTestHarness { 45 class InstantTabTest : public ChromeRenderViewHostTestHarness {
54 public: 46 public:
55 void SetUp() override; 47 void SetUp() override;
56 48
57 bool MessageWasSent(uint32_t id) { 49 SearchTabHelper* search_tab() {
58 return process()->sink().GetFirstMessageMatching(id) != NULL; 50 return SearchTabHelper::FromWebContents(web_contents());
59 } 51 }
60 52
61 std::unique_ptr<InstantTab> page; 53 std::unique_ptr<InstantTab> page;
62 FakePageDelegate delegate; 54 FakePageDelegate delegate;
63 }; 55 };
64 56
65 void InstantTabTest::SetUp() { 57 void InstantTabTest::SetUp() {
66 ChromeRenderViewHostTestHarness::SetUp(); 58 ChromeRenderViewHostTestHarness::SetUp();
67 SearchTabHelper::CreateForWebContents(web_contents()); 59 SearchTabHelper::CreateForWebContents(web_contents());
68 } 60 }
69 61
70 TEST_F(InstantTabTest, IsLocal) { 62 TEST_F(InstantTabTest, DetermineIfPageSupportsInstant_Local) {
71 page.reset(new InstantTab(&delegate)); 63 page.reset(new InstantTab(&delegate, web_contents()));
72 EXPECT_FALSE(page->supports_instant()); 64 EXPECT_FALSE(search_tab()->SupportsInstant());
73 EXPECT_FALSE(page->IsLocal()); 65 page->Init();
74 page->Init(web_contents());
75 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); 66 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
76 EXPECT_TRUE(page->IsLocal()); 67 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), true));
77 NavigateAndCommit(GURL("http://example.com"));
78 EXPECT_FALSE(page->IsLocal());
79 }
80
81 TEST_F(InstantTabTest, DetermineIfPageSupportsInstant_Local) {
82 page.reset(new InstantTab(&delegate));
83 EXPECT_FALSE(page->supports_instant());
84 page->Init(web_contents());
85 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
86 EXPECT_TRUE(page->IsLocal());
87 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), true))
88 .Times(1);
89 SearchTabHelper::FromWebContents(web_contents())-> 68 SearchTabHelper::FromWebContents(web_contents())->
90 DetermineIfPageSupportsInstant(); 69 DetermineIfPageSupportsInstant();
91 EXPECT_TRUE(page->supports_instant()); 70 EXPECT_TRUE(search_tab()->SupportsInstant());
92 } 71 }
93 72
94 TEST_F(InstantTabTest, DetermineIfPageSupportsInstant_NonLocal) { 73 TEST_F(InstantTabTest, DetermineIfPageSupportsInstant_NonLocal) {
Marc Treib 2016/07/25 12:27:56 Random other thing: This test is BS, or at least i
95 page.reset(new InstantTab(&delegate)); 74 page.reset(new InstantTab(&delegate, web_contents()));
96 EXPECT_FALSE(page->supports_instant()); 75 EXPECT_FALSE(search_tab()->SupportsInstant());
97 page->Init(web_contents()); 76 page->Init();
98 NavigateAndCommit(GURL("chrome-search://foo/bar")); 77 NavigateAndCommit(GURL("chrome-search://foo/bar"));
99 EXPECT_FALSE(page->IsLocal());
100 process()->sink().ClearMessages(); 78 process()->sink().ClearMessages();
101 SearchTabHelper::FromWebContents(web_contents())-> 79 SearchTabHelper::FromWebContents(web_contents())->
102 DetermineIfPageSupportsInstant(); 80 DetermineIfPageSupportsInstant();
103 const IPC::Message* message = process()->sink().GetFirstMessageMatching( 81 const IPC::Message* message = process()->sink().GetFirstMessageMatching(
104 ChromeViewMsg_DetermineIfPageSupportsInstant::ID); 82 ChromeViewMsg_DetermineIfPageSupportsInstant::ID);
105 ASSERT_TRUE(message != NULL); 83 ASSERT_TRUE(message != NULL);
106 EXPECT_EQ(web_contents()->GetRoutingID(), message->routing_id()); 84 EXPECT_EQ(web_contents()->GetRoutingID(), message->routing_id());
107 } 85 }
108 86
109 TEST_F(InstantTabTest, PageURLDoesntBelongToInstantRenderer) { 87 TEST_F(InstantTabTest, PageURLDoesntBelongToInstantRenderer) {
110 page.reset(new InstantTab(&delegate)); 88 page.reset(new InstantTab(&delegate, web_contents()));
111 EXPECT_FALSE(page->supports_instant()); 89 EXPECT_FALSE(search_tab()->SupportsInstant());
112 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); 90 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
113 page->Init(web_contents()); 91 page->Init();
114 92
115 // Navigate to a page URL that doesn't belong to Instant renderer. 93 // Navigate to a page URL that doesn't belong to Instant renderer.
116 // SearchTabHelper::DeterminerIfPageSupportsInstant() should return 94 // SearchTabHelper::DeterminerIfPageSupportsInstant() should return
117 // immediately without dispatching any message to the renderer. 95 // immediately without dispatching any message to the renderer.
118 NavigateAndCommit(GURL("http://www.example.com")); 96 NavigateAndCommit(GURL("http://www.example.com"));
119 EXPECT_FALSE(page->IsLocal());
120 process()->sink().ClearMessages(); 97 process()->sink().ClearMessages();
121 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), false)) 98 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), false));
122 .Times(1);
123 99
124 SearchTabHelper::FromWebContents(web_contents())-> 100 SearchTabHelper::FromWebContents(web_contents())->
125 DetermineIfPageSupportsInstant(); 101 DetermineIfPageSupportsInstant();
126 const IPC::Message* message = process()->sink().GetFirstMessageMatching( 102 const IPC::Message* message = process()->sink().GetFirstMessageMatching(
127 ChromeViewMsg_DetermineIfPageSupportsInstant::ID); 103 ChromeViewMsg_DetermineIfPageSupportsInstant::ID);
128 ASSERT_TRUE(message == NULL); 104 ASSERT_TRUE(message == NULL);
129 EXPECT_FALSE(page->supports_instant()); 105 EXPECT_FALSE(search_tab()->SupportsInstant());
130 } 106 }
131 107
132 // Test to verify that ChromeViewMsg_DetermineIfPageSupportsInstant message 108 // Test to verify that ChromeViewMsg_DetermineIfPageSupportsInstant message
133 // reply handler updates the instant support state in InstantTab. 109 // reply handler updates the instant support state in InstantTab.
134 TEST_F(InstantTabTest, PageSupportsInstant) { 110 TEST_F(InstantTabTest, PageSupportsInstant) {
135 page.reset(new InstantTab(&delegate)); 111 page.reset(new InstantTab(&delegate, web_contents()));
136 EXPECT_FALSE(page->supports_instant()); 112 EXPECT_FALSE(search_tab()->SupportsInstant());
137 page->Init(web_contents()); 113 page->Init();
138 NavigateAndCommit(GURL("chrome-search://foo/bar")); 114 NavigateAndCommit(GURL("chrome-search://foo/bar"));
139 process()->sink().ClearMessages(); 115 process()->sink().ClearMessages();
140 SearchTabHelper::FromWebContents(web_contents())-> 116 SearchTabHelper::FromWebContents(web_contents())->
141 DetermineIfPageSupportsInstant(); 117 DetermineIfPageSupportsInstant();
142 const IPC::Message* message = process()->sink().GetFirstMessageMatching( 118 const IPC::Message* message = process()->sink().GetFirstMessageMatching(
143 ChromeViewMsg_DetermineIfPageSupportsInstant::ID); 119 ChromeViewMsg_DetermineIfPageSupportsInstant::ID);
144 ASSERT_TRUE(message != NULL); 120 ASSERT_TRUE(message != NULL);
145 EXPECT_EQ(web_contents()->GetRoutingID(), message->routing_id()); 121 EXPECT_EQ(web_contents()->GetRoutingID(), message->routing_id());
146 122
147 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), true)) 123 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), true));
148 .Times(1);
149 124
150 // Assume the page supports instant. Invoke the message reply handler to make 125 // Assume the page supports instant. Invoke the message reply handler to make
151 // sure the InstantTab is notified about the instant support state. 126 // sure the InstantTab is notified about the instant support state.
152 const content::NavigationEntry* entry = 127 const content::NavigationEntry* entry =
153 web_contents()->GetController().GetLastCommittedEntry(); 128 web_contents()->GetController().GetLastCommittedEntry();
154 EXPECT_TRUE(entry); 129 EXPECT_TRUE(entry);
155 SearchTabHelper::FromWebContents(web_contents())->InstantSupportChanged(true); 130 SearchTabHelper::FromWebContents(web_contents())->InstantSupportChanged(true);
156 EXPECT_TRUE(page->supports_instant()); 131 EXPECT_TRUE(search_tab()->SupportsInstant());
157 } 132 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/search/instant_tab.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698