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

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: remove Times(1) Created 4 years, 4 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
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());
74 page->Init(web_contents());
75 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); 65 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
76 EXPECT_TRUE(page->IsLocal()); 66 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())-> 67 SearchTabHelper::FromWebContents(web_contents())->
90 DetermineIfPageSupportsInstant(); 68 DetermineIfPageSupportsInstant();
91 EXPECT_TRUE(page->supports_instant()); 69 EXPECT_TRUE(search_tab()->SupportsInstant());
92 } 70 }
93 71
94 TEST_F(InstantTabTest, DetermineIfPageSupportsInstant_NonLocal) { 72 TEST_F(InstantTabTest, DetermineIfPageSupportsInstant_NonLocal) {
95 page.reset(new InstantTab(&delegate)); 73 page.reset(new InstantTab(&delegate, web_contents()));
96 EXPECT_FALSE(page->supports_instant()); 74 EXPECT_FALSE(search_tab()->SupportsInstant());
97 page->Init(web_contents());
98 NavigateAndCommit(GURL("chrome-search://foo/bar")); 75 NavigateAndCommit(GURL("chrome-search://foo/bar"));
99 EXPECT_FALSE(page->IsLocal());
100 process()->sink().ClearMessages(); 76 process()->sink().ClearMessages();
101 SearchTabHelper::FromWebContents(web_contents())-> 77 SearchTabHelper::FromWebContents(web_contents())->
102 DetermineIfPageSupportsInstant(); 78 DetermineIfPageSupportsInstant();
103 const IPC::Message* message = process()->sink().GetFirstMessageMatching( 79 const IPC::Message* message = process()->sink().GetFirstMessageMatching(
104 ChromeViewMsg_DetermineIfPageSupportsInstant::ID); 80 ChromeViewMsg_DetermineIfPageSupportsInstant::ID);
105 ASSERT_TRUE(message != NULL); 81 ASSERT_TRUE(message != NULL);
106 EXPECT_EQ(web_contents()->GetRoutingID(), message->routing_id()); 82 EXPECT_EQ(web_contents()->GetRoutingID(), message->routing_id());
107 } 83 }
108 84
109 TEST_F(InstantTabTest, PageURLDoesntBelongToInstantRenderer) { 85 TEST_F(InstantTabTest, PageURLDoesntBelongToInstantRenderer) {
110 page.reset(new InstantTab(&delegate)); 86 page.reset(new InstantTab(&delegate, web_contents()));
111 EXPECT_FALSE(page->supports_instant()); 87 EXPECT_FALSE(search_tab()->SupportsInstant());
112 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl)); 88 NavigateAndCommit(GURL(chrome::kChromeSearchLocalNtpUrl));
113 page->Init(web_contents());
114 89
115 // Navigate to a page URL that doesn't belong to Instant renderer. 90 // Navigate to a page URL that doesn't belong to Instant renderer.
116 // SearchTabHelper::DeterminerIfPageSupportsInstant() should return 91 // SearchTabHelper::DeterminerIfPageSupportsInstant() should return
117 // immediately without dispatching any message to the renderer. 92 // immediately without dispatching any message to the renderer.
118 NavigateAndCommit(GURL("http://www.example.com")); 93 NavigateAndCommit(GURL("http://www.example.com"));
119 EXPECT_FALSE(page->IsLocal());
120 process()->sink().ClearMessages(); 94 process()->sink().ClearMessages();
121 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), false)) 95 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), false));
122 .Times(1);
123 96
124 SearchTabHelper::FromWebContents(web_contents())-> 97 SearchTabHelper::FromWebContents(web_contents())->
125 DetermineIfPageSupportsInstant(); 98 DetermineIfPageSupportsInstant();
126 const IPC::Message* message = process()->sink().GetFirstMessageMatching( 99 const IPC::Message* message = process()->sink().GetFirstMessageMatching(
127 ChromeViewMsg_DetermineIfPageSupportsInstant::ID); 100 ChromeViewMsg_DetermineIfPageSupportsInstant::ID);
128 ASSERT_TRUE(message == NULL); 101 ASSERT_TRUE(message == NULL);
129 EXPECT_FALSE(page->supports_instant()); 102 EXPECT_FALSE(search_tab()->SupportsInstant());
130 } 103 }
131 104
132 // Test to verify that ChromeViewMsg_DetermineIfPageSupportsInstant message 105 // Test to verify that ChromeViewMsg_DetermineIfPageSupportsInstant message
133 // reply handler updates the instant support state in InstantTab. 106 // reply handler updates the instant support state in InstantTab.
134 TEST_F(InstantTabTest, PageSupportsInstant) { 107 TEST_F(InstantTabTest, PageSupportsInstant) {
135 page.reset(new InstantTab(&delegate)); 108 page.reset(new InstantTab(&delegate, web_contents()));
136 EXPECT_FALSE(page->supports_instant()); 109 EXPECT_FALSE(search_tab()->SupportsInstant());
137 page->Init(web_contents());
138 NavigateAndCommit(GURL("chrome-search://foo/bar")); 110 NavigateAndCommit(GURL("chrome-search://foo/bar"));
139 process()->sink().ClearMessages(); 111 process()->sink().ClearMessages();
140 SearchTabHelper::FromWebContents(web_contents())-> 112 SearchTabHelper::FromWebContents(web_contents())->
141 DetermineIfPageSupportsInstant(); 113 DetermineIfPageSupportsInstant();
142 const IPC::Message* message = process()->sink().GetFirstMessageMatching( 114 const IPC::Message* message = process()->sink().GetFirstMessageMatching(
143 ChromeViewMsg_DetermineIfPageSupportsInstant::ID); 115 ChromeViewMsg_DetermineIfPageSupportsInstant::ID);
144 ASSERT_TRUE(message != NULL); 116 ASSERT_TRUE(message != NULL);
145 EXPECT_EQ(web_contents()->GetRoutingID(), message->routing_id()); 117 EXPECT_EQ(web_contents()->GetRoutingID(), message->routing_id());
146 118
147 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), true)) 119 EXPECT_CALL(delegate, InstantSupportDetermined(web_contents(), true));
148 .Times(1);
149 120
150 // Assume the page supports instant. Invoke the message reply handler to make 121 // Assume the page supports instant. Invoke the message reply handler to make
151 // sure the InstantTab is notified about the instant support state. 122 // sure the InstantTab is notified about the instant support state.
152 const content::NavigationEntry* entry = 123 const content::NavigationEntry* entry =
153 web_contents()->GetController().GetLastCommittedEntry(); 124 web_contents()->GetController().GetLastCommittedEntry();
154 EXPECT_TRUE(entry); 125 EXPECT_TRUE(entry);
155 SearchTabHelper::FromWebContents(web_contents())->InstantSupportChanged(true); 126 SearchTabHelper::FromWebContents(web_contents())->InstantSupportChanged(true);
156 EXPECT_TRUE(page->supports_instant()); 127 EXPECT_TRUE(search_tab()->SupportsInstant());
157 } 128 }
OLDNEW
« chrome/browser/ui/search/instant_controller.cc ('K') | « 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