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

Side by Side Diff: chrome/browser/captive_portal/captive_portal_tab_helper_unittest.cc

Issue 10837146: Fix how captive portals track which page is loading. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Undo accidental change Created 8 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/captive_portal/captive_portal_tab_helper.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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/captive_portal/captive_portal_tab_helper.h" 5 #include "chrome/browser/captive_portal/captive_portal_tab_helper.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/memory/scoped_ptr.h"
8 #include "chrome/browser/captive_portal/captive_portal_service.h" 9 #include "chrome/browser/captive_portal/captive_portal_service.h"
9 #include "chrome/browser/captive_portal/captive_portal_tab_reloader.h" 10 #include "chrome/browser/captive_portal/captive_portal_tab_reloader.h"
11 #include "chrome/browser/ui/tab_contents/test_tab_contents.h"
10 #include "chrome/common/chrome_notification_types.h" 12 #include "chrome/common/chrome_notification_types.h"
11 #include "content/public/browser/notification_details.h" 13 #include "content/public/browser/notification_details.h"
12 #include "content/public/browser/notification_service.h" 14 #include "content/public/browser/notification_service.h"
13 #include "content/public/browser/notification_source.h" 15 #include "content/public/browser/notification_source.h"
14 #include "content/public/browser/notification_types.h" 16 #include "content/public/browser/notification_types.h"
17 #include "content/public/browser/render_view_host.h"
18 #include "content/public/browser/render_process_host.h"
19 #include "content/public/browser/web_contents.h"
20 #include "content/public/test/test_browser_thread.h"
15 #include "net/base/net_errors.h" 21 #include "net/base/net_errors.h"
16 #include "testing/gmock/include/gmock/gmock.h" 22 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gtest/include/gtest/gtest.h" 23 #include "testing/gtest/include/gtest/gtest.h"
18 24
19 namespace captive_portal { 25 namespace captive_portal {
20 26
21 namespace { 27 namespace {
22 28
23 const char* const kHttpUrl = "http://whatever.com/"; 29 const char* const kHttpUrl = "http://whatever.com/";
24 const char* const kHttpsUrl = "https://whatever.com/"; 30 const char* const kHttpsUrl = "https://whatever.com/";
31
32 // Used for cross-process navigations. Shouldn't actually matter whether this
33 // is different from kHttpsUrl, but best to keep things consistent.
34 const char* const kHttpsUrl2 = "https://cross_process.com/";
35
25 // Error pages use a "data:" URL. Shouldn't actually matter what this is. 36 // Error pages use a "data:" URL. Shouldn't actually matter what this is.
26 const char* const kErrorPageUrl = "data:blah"; 37 const char* const kErrorPageUrl = "data:blah";
27 38
39 // Some navigations behave differently depending on if they're cross-process
40 // or not.
41 enum NavigationType {
42 kSameProcess,
43 kCrossProcess,
44 };
45
28 } // namespace 46 } // namespace
29 47
30 class MockCaptivePortalTabReloader : public CaptivePortalTabReloader { 48 class MockCaptivePortalTabReloader : public CaptivePortalTabReloader {
31 public: 49 public:
32 MockCaptivePortalTabReloader() 50 MockCaptivePortalTabReloader()
33 : CaptivePortalTabReloader(NULL, NULL, base::Callback<void()>()) { 51 : CaptivePortalTabReloader(NULL, NULL, base::Callback<void()>()) {
34 } 52 }
35 53
36 MOCK_METHOD1(OnLoadStart, void(bool)); 54 MOCK_METHOD1(OnLoadStart, void(bool));
37 MOCK_METHOD1(OnLoadCommitted, void(int)); 55 MOCK_METHOD1(OnLoadCommitted, void(int));
38 MOCK_METHOD0(OnAbort, void()); 56 MOCK_METHOD0(OnAbort, void());
39 MOCK_METHOD1(OnRedirect, void(bool)); 57 MOCK_METHOD1(OnRedirect, void(bool));
40 MOCK_METHOD2(OnCaptivePortalResults, void(Result, Result)); 58 MOCK_METHOD2(OnCaptivePortalResults, void(Result, Result));
41 }; 59 };
42 60
43 class CaptivePortalTabHelperTest : public testing::Test { 61 // Inherits from the TabContentsTestHarness to gain access to
62 // CreateTestWebContents. Since the tests need to micromanage order of
63 // WebContentsObserver function calls, does not actually make sure of
64 // the harness in any other way.
65 class CaptivePortalTabHelperTest : public TabContentsTestHarness {
44 public: 66 public:
45 CaptivePortalTabHelperTest() 67 CaptivePortalTabHelperTest()
46 : tab_helper_(NULL, NULL), 68 : tab_helper_(NULL, NULL),
47 mock_reloader_(new testing::StrictMock<MockCaptivePortalTabReloader>) { 69 mock_reloader_(new testing::StrictMock<MockCaptivePortalTabReloader>),
70 ui_thread_(content::BrowserThread::UI, &message_loop_) {
48 tab_helper_.SetTabReloaderForTest(mock_reloader_); 71 tab_helper_.SetTabReloaderForTest(mock_reloader_);
49 } 72 }
50 virtual ~CaptivePortalTabHelperTest() {} 73 virtual ~CaptivePortalTabHelperTest() {}
51 74
75 virtual void SetUp() OVERRIDE {
76 TabContentsTestHarness::SetUp();
77 web_contents1_.reset(CreateTestWebContents());
78 web_contents2_.reset(CreateTestWebContents());
79 }
80
81 virtual void TearDown() OVERRIDE {
82 web_contents2_.reset(NULL);
83 web_contents1_.reset(NULL);
84 TabContentsTestHarness::TearDown();
85 }
86
52 // Simulates a successful load of |url|. 87 // Simulates a successful load of |url|.
53 void SimulateSuccess(const GURL& url) { 88 void SimulateSuccess(const GURL& url,
89 content::RenderViewHost* render_view_host) {
54 EXPECT_CALL(mock_reloader(), OnLoadStart(url.SchemeIsSecure())).Times(1); 90 EXPECT_CALL(mock_reloader(), OnLoadStart(url.SchemeIsSecure())).Times(1);
55 tab_helper().DidStartProvisionalLoadForFrame(1, true, url, false, NULL); 91 tab_helper().DidStartProvisionalLoadForFrame(
92 1, true, url, false, render_view_host);
56 93
57 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::OK)).Times(1); 94 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::OK)).Times(1);
58 tab_helper().DidCommitProvisionalLoadForFrame( 95 tab_helper().DidCommitProvisionalLoadForFrame(
59 1, true, url, content::PAGE_TRANSITION_LINK, NULL); 96 1, true, url, content::PAGE_TRANSITION_LINK, render_view_host);
60 } 97 }
61 98
62 // Simulates a connection timeout while requesting |url|. 99 // Simulates a connection timeout while requesting |url|.
63 void SimulateTimeout(const GURL& url) { 100 void SimulateTimeout(const GURL& url,
101 content::RenderViewHost* render_view_host) {
64 EXPECT_CALL(mock_reloader(), OnLoadStart(url.SchemeIsSecure())).Times(1); 102 EXPECT_CALL(mock_reloader(), OnLoadStart(url.SchemeIsSecure())).Times(1);
65 tab_helper().DidStartProvisionalLoadForFrame(1, true, url, false, NULL); 103 tab_helper().DidStartProvisionalLoadForFrame(
104 1, true, url, false, render_view_host);
66 105
67 tab_helper().DidFailProvisionalLoad( 106 tab_helper().DidFailProvisionalLoad(
68 1, true, url, net::ERR_TIMED_OUT, string16(), NULL); 107 1, true, url, net::ERR_TIMED_OUT, string16(), render_view_host);
69 108
70 // Provisional load starts for the error page. 109 // Provisional load starts for the error page.
71 tab_helper().DidStartProvisionalLoadForFrame( 110 tab_helper().DidStartProvisionalLoadForFrame(
72 1, true, GURL(kErrorPageUrl), true, NULL); 111 1, true, GURL(kErrorPageUrl), true, render_view_host);
73 112
74 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::ERR_TIMED_OUT)).Times(1); 113 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::ERR_TIMED_OUT)).Times(1);
75 tab_helper().DidCommitProvisionalLoadForFrame( 114 tab_helper().DidCommitProvisionalLoadForFrame(
76 1, true, GURL(kErrorPageUrl), content::PAGE_TRANSITION_LINK, NULL); 115 1, true, GURL(kErrorPageUrl), content::PAGE_TRANSITION_LINK,
116 render_view_host);
77 } 117 }
78 118
79 // Simulates an abort while requesting |url|. 119 // Simulates an abort while requesting |url|.
80 void SimulateAbort(const GURL& url) { 120 void SimulateAbort(const GURL& url,
121 content::RenderViewHost* render_view_host,
122 NavigationType navigation_type) {
81 EXPECT_CALL(mock_reloader(), OnLoadStart(url.SchemeIsSecure())).Times(1); 123 EXPECT_CALL(mock_reloader(), OnLoadStart(url.SchemeIsSecure())).Times(1);
82 tab_helper().DidStartProvisionalLoadForFrame(1, true, url, false, NULL); 124 tab_helper().DidStartProvisionalLoadForFrame(
125 1, true, url, false, render_view_host);
83 126
84 EXPECT_CALL(mock_reloader(), OnAbort()).Times(1); 127 EXPECT_CALL(mock_reloader(), OnAbort()).Times(1);
85 tab_helper().DidFailProvisionalLoad( 128 if (navigation_type == kSameProcess) {
86 1, true, url, net::ERR_ABORTED, string16(), NULL); 129 tab_helper().DidFailProvisionalLoad(
130 1, true, url, net::ERR_ABORTED, string16(), render_view_host);
131 } else {
132 // For interrupted provisional cross-process navigations, the
133 // RenderViewHost is destroyed without sending a DidFailProvisionalLoad
134 // notification.
135 tab_helper().Observe(
136 content::NOTIFICATION_RENDER_VIEW_HOST_DELETED,
137 content::Source<content::RenderViewHost>(render_view_host),
138 content::NotificationService::NoDetails());
139 }
140
141 // Make sure that above call resulted in abort, for tests that continue
142 // after the abort.
143 EXPECT_CALL(mock_reloader(), OnAbort()).Times(0);
87 } 144 }
88 145
89 // Simulates an abort while loading an error page. 146 // Simulates an abort while loading an error page.
90 void SimulateAbortTimeout(const GURL& url) { 147 void SimulateAbortTimeout(const GURL& url,
148 content::RenderViewHost* render_view_host,
149 NavigationType navigation_type) {
91 EXPECT_CALL(mock_reloader(), OnLoadStart(url.SchemeIsSecure())).Times(1); 150 EXPECT_CALL(mock_reloader(), OnLoadStart(url.SchemeIsSecure())).Times(1);
92 tab_helper().DidStartProvisionalLoadForFrame(1, true, url, false, NULL); 151 tab_helper().DidStartProvisionalLoadForFrame(
152 1, true, url, false, render_view_host);
93 153
94 tab_helper().DidFailProvisionalLoad( 154 tab_helper().DidFailProvisionalLoad(
95 1, true, url, net::ERR_TIMED_OUT, string16(), NULL); 155 1, true, url, net::ERR_TIMED_OUT, string16(), render_view_host);
96 156
97 // Start event for the error page. 157 // Start event for the error page.
98 tab_helper().DidStartProvisionalLoadForFrame(1, true, url, true, NULL); 158 tab_helper().DidStartProvisionalLoadForFrame(
159 1, true, url, true, render_view_host);
99 160
100 EXPECT_CALL(mock_reloader(), OnAbort()).Times(1); 161 EXPECT_CALL(mock_reloader(), OnAbort()).Times(1);
101 tab_helper().DidFailProvisionalLoad( 162 if (navigation_type == kSameProcess) {
102 1, true, url, net::ERR_ABORTED, string16(), NULL); 163 tab_helper().DidFailProvisionalLoad(
164 1, true, url, net::ERR_ABORTED, string16(), render_view_host);
165 } else {
166 // For interrupted provisional cross-process navigations, the
167 // RenderViewHost is destroyed without sending a DidFailProvisionalLoad
168 // notification.
169 tab_helper().Observe(
170 content::NOTIFICATION_RENDER_VIEW_HOST_DELETED,
171 content::Source<content::RenderViewHost>(render_view_host),
172 content::NotificationService::NoDetails());
173 }
174
175 // Make sure that above call resulted in abort, for tests that continue
176 // after the abort.
177 EXPECT_CALL(mock_reloader(), OnAbort()).Times(0);
103 } 178 }
104 179
105 CaptivePortalTabHelper& tab_helper() { 180 CaptivePortalTabHelper& tab_helper() {
106 return tab_helper_; 181 return tab_helper_;
107 } 182 }
108 183
109 // Simulates a captive portal redirect by calling the Observe method. 184 // Simulates a captive portal redirect by calling the Observe method.
110 void ObservePortalResult(Result previous_result, Result result) { 185 void ObservePortalResult(Result previous_result, Result result) {
111 content::Source<Profile> source_profile(NULL); 186 content::Source<Profile> source_profile(NULL);
112 187
113 CaptivePortalService::Results results; 188 CaptivePortalService::Results results;
114 results.previous_result = previous_result; 189 results.previous_result = previous_result;
115 results.result = result; 190 results.result = result;
116 content::Details<CaptivePortalService::Results> details_results(&results); 191 content::Details<CaptivePortalService::Results> details_results(&results);
117 192
118 EXPECT_CALL(mock_reloader(), OnCaptivePortalResults(previous_result, 193 EXPECT_CALL(mock_reloader(), OnCaptivePortalResults(previous_result,
119 result)).Times(1); 194 result)).Times(1);
120 tab_helper().Observe(chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT, 195 tab_helper().Observe(chrome::NOTIFICATION_CAPTIVE_PORTAL_CHECK_RESULT,
121 source_profile, 196 source_profile,
122 details_results); 197 details_results);
123 } 198 }
124 199
125 // Simulates a redirect. Uses OnRedirect rather than Observe, for simplicity. 200 // Simulates a redirect. Uses OnRedirect rather than Observe, for simplicity.
126 void OnRedirect(int64 frame_id, const GURL& new_url) { 201 void OnRedirect(ResourceType::Type type, const GURL& new_url, int child_id) {
127 content::Source<content::WebContents> source_contents(NULL); 202 tab_helper().OnRedirect(child_id, type, new_url);
128
129 tab_helper().OnRedirect(frame_id, new_url);
130 } 203 }
131 204
132 MockCaptivePortalTabReloader& mock_reloader() { return *mock_reloader_; } 205 MockCaptivePortalTabReloader& mock_reloader() { return *mock_reloader_; }
133 206
134 void SetIsLoginTab() { 207 void SetIsLoginTab() {
135 tab_helper().SetIsLoginTab(); 208 tab_helper().SetIsLoginTab();
136 } 209 }
137 210
211 content::RenderViewHost* render_view_host1() {
212 return web_contents1_->GetRenderViewHost();
213 }
214
215 content::RenderViewHost* render_view_host2() {
216 return web_contents2_->GetRenderViewHost();
217 }
218
138 private: 219 private:
220 // Only the RenderViewHosts are used.
221 scoped_ptr<content::WebContents> web_contents1_;
222 scoped_ptr<content::WebContents> web_contents2_;
223
139 CaptivePortalTabHelper tab_helper_; 224 CaptivePortalTabHelper tab_helper_;
140 225
141 // Owned by |tab_helper_|. 226 // Owned by |tab_helper_|.
142 testing::StrictMock<MockCaptivePortalTabReloader>* mock_reloader_; 227 testing::StrictMock<MockCaptivePortalTabReloader>* mock_reloader_;
143 228
229 content::TestBrowserThread ui_thread_;
230
144 DISALLOW_COPY_AND_ASSIGN(CaptivePortalTabHelperTest); 231 DISALLOW_COPY_AND_ASSIGN(CaptivePortalTabHelperTest);
145 }; 232 };
146 233
147 TEST_F(CaptivePortalTabHelperTest, HttpSuccess) { 234 TEST_F(CaptivePortalTabHelperTest, HttpSuccess) {
148 SimulateSuccess(GURL(kHttpUrl)); 235 SimulateSuccess(GURL(kHttpUrl), render_view_host1());
149 tab_helper().DidStopLoading(NULL); 236 tab_helper().DidStopLoading(render_view_host1());
150 } 237 }
151 238
152 TEST_F(CaptivePortalTabHelperTest, HttpTimeout) { 239 TEST_F(CaptivePortalTabHelperTest, HttpTimeout) {
153 SimulateTimeout(GURL(kHttpUrl)); 240 SimulateTimeout(GURL(kHttpUrl), render_view_host1());
154 tab_helper().DidStopLoading(NULL); 241 tab_helper().DidStopLoading(render_view_host1());
155 } 242 }
156 243
157 // Same as above, but simulates what happens when the Link Doctor is enabled, 244 // Same as above, but simulates what happens when the Link Doctor is enabled,
158 // which adds another provisional load/commit for the error page, after the 245 // which adds another provisional load/commit for the error page, after the
159 // first two. 246 // first two.
160 TEST_F(CaptivePortalTabHelperTest, HttpTimeoutLinkDoctor) { 247 TEST_F(CaptivePortalTabHelperTest, HttpTimeoutLinkDoctor) {
161 SimulateTimeout(GURL(kHttpUrl)); 248 SimulateTimeout(GURL(kHttpUrl), render_view_host1());
162 249
163 EXPECT_CALL(mock_reloader(), OnLoadStart(false)).Times(1); 250 EXPECT_CALL(mock_reloader(), OnLoadStart(false)).Times(1);
164 // Provisional load starts for the error page. 251 // Provisional load starts for the error page.
165 tab_helper().DidStartProvisionalLoadForFrame( 252 tab_helper().DidStartProvisionalLoadForFrame(
166 1, true, GURL(kErrorPageUrl), true, NULL); 253 1, true, GURL(kErrorPageUrl), true, render_view_host1());
167 254
168 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::OK)).Times(1); 255 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::OK)).Times(1);
169 tab_helper().DidCommitProvisionalLoadForFrame( 256 tab_helper().DidCommitProvisionalLoadForFrame(
170 1, true, GURL(kErrorPageUrl), content::PAGE_TRANSITION_LINK, NULL); 257 1, true, GURL(kErrorPageUrl), content::PAGE_TRANSITION_LINK,
171 tab_helper().DidStopLoading(NULL); 258 render_view_host1());
259 tab_helper().DidStopLoading(render_view_host1());
172 } 260 }
173 261
174 TEST_F(CaptivePortalTabHelperTest, HttpsSuccess) { 262 TEST_F(CaptivePortalTabHelperTest, HttpsSuccess) {
175 SimulateSuccess(GURL(kHttpsUrl)); 263 SimulateSuccess(GURL(kHttpsUrl), render_view_host1());
176 tab_helper().DidStopLoading(NULL); 264 tab_helper().DidStopLoading(render_view_host1());
177 EXPECT_FALSE(tab_helper().IsLoginTab()); 265 EXPECT_FALSE(tab_helper().IsLoginTab());
178 } 266 }
179 267
180 TEST_F(CaptivePortalTabHelperTest, HttpsTimeout) { 268 TEST_F(CaptivePortalTabHelperTest, HttpsTimeout) {
181 SimulateTimeout(GURL(kHttpsUrl)); 269 SimulateTimeout(GURL(kHttpsUrl), render_view_host1());
182 // Make sure no state was carried over from the timeout. 270 // Make sure no state was carried over from the timeout.
183 SimulateSuccess(GURL(kHttpsUrl)); 271 SimulateSuccess(GURL(kHttpsUrl), render_view_host1());
184 EXPECT_FALSE(tab_helper().IsLoginTab()); 272 EXPECT_FALSE(tab_helper().IsLoginTab());
185 } 273 }
186 274
187 TEST_F(CaptivePortalTabHelperTest, HttpsAbort) { 275 TEST_F(CaptivePortalTabHelperTest, HttpsAbort) {
188 SimulateAbort(GURL(kHttpsUrl)); 276 SimulateAbort(GURL(kHttpsUrl), render_view_host1(), kSameProcess);
189 // Make sure no state was carried over from the abort. 277 // Make sure no state was carried over from the abort.
190 SimulateSuccess(GURL(kHttpsUrl)); 278 SimulateSuccess(GURL(kHttpsUrl), render_view_host1());
279 EXPECT_FALSE(tab_helper().IsLoginTab());
280 }
281
282 // A cross-process navigation is aborted by a same-site navigation.
283 TEST_F(CaptivePortalTabHelperTest, AbortCrossProcess) {
284 SimulateAbort(GURL(kHttpsUrl2), render_view_host2(), kCrossProcess);
285 // Make sure no state was carried over from the abort.
286 SimulateSuccess(GURL(kHttpUrl), render_view_host1());
191 EXPECT_FALSE(tab_helper().IsLoginTab()); 287 EXPECT_FALSE(tab_helper().IsLoginTab());
192 } 288 }
193 289
194 // Abort while there's a provisional timeout error page loading. 290 // Abort while there's a provisional timeout error page loading.
195 TEST_F(CaptivePortalTabHelperTest, HttpsAbortTimeout) { 291 TEST_F(CaptivePortalTabHelperTest, HttpsAbortTimeout) {
196 SimulateAbortTimeout(GURL(kHttpsUrl)); 292 SimulateAbortTimeout(GURL(kHttpsUrl), render_view_host1(), kSameProcess);
197 // Make sure no state was carried over from the timeout or the abort. 293 // Make sure no state was carried over from the timeout or the abort.
198 SimulateSuccess(GURL(kHttpsUrl)); 294 SimulateSuccess(GURL(kHttpsUrl), render_view_host1());
199 EXPECT_FALSE(tab_helper().IsLoginTab()); 295 EXPECT_FALSE(tab_helper().IsLoginTab());
296 }
297
298 // Abort a cross-process navigation while there's a provisional timeout error
299 // page loading.
300 TEST_F(CaptivePortalTabHelperTest, AbortTimeoutCrossProcess) {
301 SimulateAbortTimeout(GURL(kHttpsUrl2), render_view_host2(),
302 kCrossProcess);
303 // Make sure no state was carried over from the timeout or the abort.
304 SimulateSuccess(GURL(kHttpsUrl), render_view_host1());
305 EXPECT_FALSE(tab_helper().IsLoginTab());
306 }
307
308 // Opposite case from above - a same-process error page is aborted in favor of
309 // a cross-process one.
310 TEST_F(CaptivePortalTabHelperTest, HttpsAbortTimeoutForCrossProcess) {
311 SimulateAbortTimeout(GURL(kHttpsUrl), render_view_host1(), kSameProcess);
312 // Make sure no state was carried over from the timeout or the abort.
313 SimulateSuccess(GURL(kHttpsUrl2), render_view_host2());
314 EXPECT_FALSE(tab_helper().IsLoginTab());
315 }
316
317 // A provisional same-site navigation is interrupted by a cross-process
318 // navigation without sending an abort first.
319 TEST_F(CaptivePortalTabHelperTest, UnexpectedProvisionalLoad) {
320 GURL same_site_url = GURL(kHttpUrl);
321 GURL cross_process_url = GURL(kHttpsUrl2);
322
323 // A same-site load for the original RenderViewHost starts.
324 EXPECT_CALL(mock_reloader(),
325 OnLoadStart(same_site_url.SchemeIsSecure())).Times(1);
326 tab_helper().DidStartProvisionalLoadForFrame(
327 1, true, same_site_url, false, render_view_host1());
328
329 // It's unexpectedly interrupted by a cross-process navigation, which starts
330 // navigating before the old navigation cancels. We generate an abort message
331 // for the old navigation.
332 EXPECT_CALL(mock_reloader(), OnAbort()).Times(1);
333 EXPECT_CALL(mock_reloader(),
334 OnLoadStart(cross_process_url.SchemeIsSecure())).Times(1);
335 tab_helper().DidStartProvisionalLoadForFrame(
336 1, true, cross_process_url, false, render_view_host2());
337
338 // The cross-process navigation fails.
339 tab_helper().DidFailProvisionalLoad(
340 1, true, cross_process_url, net::ERR_FAILED, string16(),
341 render_view_host2());
342
343 // The same-site navigation finally is aborted.
344 tab_helper().DidFailProvisionalLoad(
345 1, true, same_site_url, net::ERR_ABORTED, string16(),
346 render_view_host1());
347
348 // The provisional load starts for the error page for the cross-process
349 // navigation.
350 tab_helper().DidStartProvisionalLoadForFrame(
351 1, true, GURL(kErrorPageUrl), true, render_view_host2());
352
353 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::ERR_FAILED)).Times(1);
354 tab_helper().DidCommitProvisionalLoadForFrame(
355 1, true, GURL(kErrorPageUrl), content::PAGE_TRANSITION_TYPED,
356 render_view_host2());
357 }
358
359 // Similar to the above test, except the original RenderViewHost manages to
360 // commit before its navigation is aborted.
361 TEST_F(CaptivePortalTabHelperTest, UnexpectedCommit) {
362 GURL same_site_url = GURL(kHttpUrl);
363 GURL cross_process_url = GURL(kHttpsUrl2);
364
365 // A same-site load for the original RenderViewHost starts.
366 EXPECT_CALL(mock_reloader(),
367 OnLoadStart(same_site_url.SchemeIsSecure())).Times(1);
368 tab_helper().DidStartProvisionalLoadForFrame(
369 1, true, same_site_url, false, render_view_host1());
370
371 // It's unexpectedly interrupted by a cross-process navigation, which starts
372 // navigating before the old navigation cancels. We generate an abort message
373 // for the old navigation.
374 EXPECT_CALL(mock_reloader(), OnAbort()).Times(1);
375 EXPECT_CALL(mock_reloader(),
376 OnLoadStart(cross_process_url.SchemeIsSecure())).Times(1);
377 tab_helper().DidStartProvisionalLoadForFrame(
378 1, true, cross_process_url, false, render_view_host2());
379
380 // The cross-process navigation fails.
381 tab_helper().DidFailProvisionalLoad(
382 1, true, cross_process_url, net::ERR_FAILED, string16(),
383 render_view_host2());
384
385 // The same-site navigation succeeds.
386 EXPECT_CALL(mock_reloader(), OnAbort()).Times(1);
387 EXPECT_CALL(mock_reloader(),
388 OnLoadStart(same_site_url.SchemeIsSecure())).Times(1);
389 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::OK)).Times(1);
390 tab_helper().DidCommitProvisionalLoadForFrame(
391 1, true, same_site_url, content::PAGE_TRANSITION_LINK,
392 render_view_host1());
200 } 393 }
201 394
202 // Simulates navigations for a number of subframes, and makes sure no 395 // Simulates navigations for a number of subframes, and makes sure no
203 // CaptivePortalTabHelper function is called. 396 // CaptivePortalTabHelper function is called.
204 TEST_F(CaptivePortalTabHelperTest, HttpsSubframe) { 397 TEST_F(CaptivePortalTabHelperTest, HttpsSubframe) {
205 GURL url = GURL(kHttpsUrl); 398 GURL url = GURL(kHttpsUrl);
206 // Normal load. 399 // Normal load.
207 tab_helper().DidStartProvisionalLoadForFrame(1, false, url, false, NULL); 400 tab_helper().DidStartProvisionalLoadForFrame(
208 tab_helper().DidCommitProvisionalLoadForFrame( 401 1, false, url, false, render_view_host1());
209 1, false, url, content::PAGE_TRANSITION_LINK, NULL); 402 tab_helper().DidCommitProvisionalLoadForFrame(
403 1, false, url, content::PAGE_TRANSITION_LINK, render_view_host1());
210 404
211 // Timeout. 405 // Timeout.
212 tab_helper().DidStartProvisionalLoadForFrame(2, false, url, false, NULL); 406 tab_helper().DidStartProvisionalLoadForFrame(
213 tab_helper().DidFailProvisionalLoad( 407 2, false, url, false, render_view_host1());
214 2, false, url, net::ERR_TIMED_OUT, string16(), NULL); 408 tab_helper().DidFailProvisionalLoad(
215 tab_helper().DidStartProvisionalLoadForFrame(2, false, url, true, NULL); 409 2, false, url, net::ERR_TIMED_OUT, string16(), render_view_host1());
216 tab_helper().DidFailProvisionalLoad( 410 tab_helper().DidStartProvisionalLoadForFrame(
217 2, false, url, net::ERR_ABORTED, string16(), NULL); 411 2, false, url, true, render_view_host1());
412 tab_helper().DidFailProvisionalLoad(
413 2, false, url, net::ERR_ABORTED, string16(), render_view_host1());
218 414
219 // Abort. 415 // Abort.
220 tab_helper().DidStartProvisionalLoadForFrame(3, false, url, false, NULL); 416 tab_helper().DidStartProvisionalLoadForFrame(
221 tab_helper().DidFailProvisionalLoad( 417 3, false, url, false, render_view_host1());
222 3, false, url, net::ERR_ABORTED, string16(), NULL); 418 tab_helper().DidFailProvisionalLoad(
419 3, false, url, net::ERR_ABORTED, string16(), render_view_host1());
223 } 420 }
224 421
225 // Simulates a subframe erroring out at the same time as a provisional load, 422 // Simulates a subframe erroring out at the same time as a provisional load,
226 // but with a different error code. Make sure the TabHelper sees the correct 423 // but with a different error code. Make sure the TabHelper sees the correct
227 // error. 424 // error.
228 TEST_F(CaptivePortalTabHelperTest, HttpsSubframeParallelError) { 425 TEST_F(CaptivePortalTabHelperTest, HttpsSubframeParallelError) {
229 // URL used by both frames. 426 // URL used by both frames.
230 GURL url = GURL(kHttpsUrl); 427 GURL url = GURL(kHttpsUrl);
231 428
232 int frame_id = 2; 429 int frame_id = 2;
233 int subframe_id = 1; 430 int subframe_id = 1;
234 431
235 // Loads start. 432 // Loads start.
236 EXPECT_CALL(mock_reloader(), OnLoadStart(url.SchemeIsSecure())).Times(1); 433 EXPECT_CALL(mock_reloader(), OnLoadStart(url.SchemeIsSecure())).Times(1);
237 tab_helper().DidStartProvisionalLoadForFrame( 434 tab_helper().DidStartProvisionalLoadForFrame(
238 frame_id, true, url, false, NULL); 435 frame_id, true, url, false, render_view_host1());
239 tab_helper().DidStartProvisionalLoadForFrame( 436 tab_helper().DidStartProvisionalLoadForFrame(
240 subframe_id, false, url, false, NULL); 437 subframe_id, false, url, false, render_view_host1());
241 438
242 // Loads return errors. 439 // Loads return errors.
243 tab_helper().DidFailProvisionalLoad( 440 tab_helper().DidFailProvisionalLoad(
244 frame_id, true, url, net::ERR_UNEXPECTED, string16(), NULL); 441 frame_id, true, url, net::ERR_UNEXPECTED, string16(),
442 render_view_host1());
245 tab_helper().DidFailProvisionalLoad( 443 tab_helper().DidFailProvisionalLoad(
246 subframe_id, false, url, net::ERR_TIMED_OUT, string16(), NULL); 444 subframe_id, false, url, net::ERR_TIMED_OUT, string16(),
445 render_view_host1());
247 446
248 // Provisional load starts for the error pages. 447 // Provisional load starts for the error pages.
249 tab_helper().DidStartProvisionalLoadForFrame( 448 tab_helper().DidStartProvisionalLoadForFrame(
250 frame_id, true, url, true, NULL); 449 frame_id, true, url, true, render_view_host1());
251 tab_helper().DidStartProvisionalLoadForFrame( 450 tab_helper().DidStartProvisionalLoadForFrame(
252 subframe_id, false, url, true, NULL); 451 subframe_id, false, url, true, render_view_host1());
253 452
254 // Error page load finishes. 453 // Error page load finishes.
255 tab_helper().DidCommitProvisionalLoadForFrame( 454 tab_helper().DidCommitProvisionalLoadForFrame(
256 subframe_id, false, url, content::PAGE_TRANSITION_AUTO_SUBFRAME, NULL); 455 subframe_id, false, url, content::PAGE_TRANSITION_AUTO_SUBFRAME,
456 render_view_host1());
257 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::ERR_UNEXPECTED)).Times(1); 457 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::ERR_UNEXPECTED)).Times(1);
258 tab_helper().DidCommitProvisionalLoadForFrame( 458 tab_helper().DidCommitProvisionalLoadForFrame(
259 frame_id, true, url, content::PAGE_TRANSITION_LINK, NULL); 459 frame_id, true, url, content::PAGE_TRANSITION_LINK,
460 render_view_host1());
260 } 461 }
261 462
262 // Simulates an HTTP to HTTPS redirect, which then times out. 463 // Simulates an HTTP to HTTPS redirect, which then times out.
263 TEST_F(CaptivePortalTabHelperTest, HttpToHttpsRedirectTimeout) { 464 TEST_F(CaptivePortalTabHelperTest, HttpToHttpsRedirectTimeout) {
264 GURL http_url("http://mail.google.com"); 465 GURL http_url(kHttpUrl);
265 EXPECT_CALL(mock_reloader(), OnLoadStart(false)).Times(1); 466 EXPECT_CALL(mock_reloader(), OnLoadStart(false)).Times(1);
266 tab_helper().DidStartProvisionalLoadForFrame(1, true, http_url, false, NULL); 467 tab_helper().DidStartProvisionalLoadForFrame(
468 1, true, http_url, false, render_view_host1());
267 469
268 GURL https_url("https://mail.google.com"); 470 GURL https_url(kHttpsUrl);
269 EXPECT_CALL(mock_reloader(), OnRedirect(true)).Times(1); 471 EXPECT_CALL(mock_reloader(), OnRedirect(true)).Times(1);
270 OnRedirect(1, https_url); 472 OnRedirect(ResourceType::MAIN_FRAME, https_url,
473 render_view_host1()->GetProcess()->GetID());
271 474
272 tab_helper().DidFailProvisionalLoad( 475 tab_helper().DidFailProvisionalLoad(
273 1, true, https_url, net::ERR_TIMED_OUT, string16(), NULL); 476 1, true, https_url, net::ERR_TIMED_OUT, string16(),
477 render_view_host1());
274 478
275 // Provisional load starts for the error page. 479 // Provisional load starts for the error page.
276 tab_helper().DidStartProvisionalLoadForFrame( 480 tab_helper().DidStartProvisionalLoadForFrame(
277 1, true, GURL(kErrorPageUrl), true, NULL); 481 1, true, GURL(kErrorPageUrl), true, render_view_host1());
278 482
279 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::ERR_TIMED_OUT)).Times(1); 483 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::ERR_TIMED_OUT)).Times(1);
280 tab_helper().DidCommitProvisionalLoadForFrame( 484 tab_helper().DidCommitProvisionalLoadForFrame(
281 1, true, GURL(kErrorPageUrl), content::PAGE_TRANSITION_LINK, NULL); 485 1, true, GURL(kErrorPageUrl), content::PAGE_TRANSITION_LINK,
486 render_view_host1());
282 } 487 }
283 488
284 // Simulates an HTTPS to HTTP redirect. 489 // Simulates an HTTPS to HTTP redirect.
285 TEST_F(CaptivePortalTabHelperTest, HttpsToHttpRedirect) { 490 TEST_F(CaptivePortalTabHelperTest, HttpsToHttpRedirect) {
286 GURL https_url("https://mail.google.com"); 491 GURL https_url(kHttpsUrl);
287 EXPECT_CALL(mock_reloader(), OnLoadStart(true)).Times(1); 492 EXPECT_CALL(mock_reloader(),
288 tab_helper().DidStartProvisionalLoadForFrame(1, true, https_url, false, NULL); 493 OnLoadStart(https_url.SchemeIsSecure())).Times(1);
494 tab_helper().DidStartProvisionalLoadForFrame(1, true, https_url, false,
495 render_view_host1());
289 496
290 GURL http_url("http://mail.google.com"); 497 GURL http_url(kHttpUrl);
291 EXPECT_CALL(mock_reloader(), OnRedirect(false)).Times(1); 498 EXPECT_CALL(mock_reloader(), OnRedirect(http_url.SchemeIsSecure())).Times(1);
292 OnRedirect(1, http_url); 499 OnRedirect(ResourceType::MAIN_FRAME, http_url,
500 render_view_host1()->GetProcess()->GetID());
293 501
294 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::OK)).Times(1); 502 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::OK)).Times(1);
295 tab_helper().DidCommitProvisionalLoadForFrame( 503 tab_helper().DidCommitProvisionalLoadForFrame(
296 1, true, http_url, content::PAGE_TRANSITION_LINK, NULL); 504 1, true, http_url, content::PAGE_TRANSITION_LINK,
505 render_view_host1());
297 } 506 }
298 507
299 // Simulates an HTTPS to HTTPS redirect. 508 // Simulates an HTTPS to HTTPS redirect.
300 TEST_F(CaptivePortalTabHelperTest, HttpToHttpRedirect) { 509 TEST_F(CaptivePortalTabHelperTest, HttpToHttpRedirect) {
301 GURL https_url("https://mail.google.com"); 510 GURL http_url(kHttpUrl);
302 EXPECT_CALL(mock_reloader(), OnLoadStart(true)).Times(1); 511 EXPECT_CALL(mock_reloader(),
303 tab_helper().DidStartProvisionalLoadForFrame(1, true, https_url, false, NULL); 512 OnLoadStart(http_url.SchemeIsSecure())).Times(1);
513 tab_helper().DidStartProvisionalLoadForFrame(
514 1, true, http_url, false, render_view_host1());
304 515
305 GURL http_url("https://www.google.com"); 516 EXPECT_CALL(mock_reloader(), OnRedirect(http_url.SchemeIsSecure())).Times(1);
306 EXPECT_CALL(mock_reloader(), OnRedirect(true)).Times(1); 517 OnRedirect(ResourceType::MAIN_FRAME, http_url,
307 OnRedirect(1, http_url); 518 render_view_host1()->GetProcess()->GetID());
308 519
309 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::OK)).Times(1); 520 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::OK)).Times(1);
310 tab_helper().DidCommitProvisionalLoadForFrame( 521 tab_helper().DidCommitProvisionalLoadForFrame(
311 1, true, http_url, content::PAGE_TRANSITION_LINK, NULL); 522 1, true, http_url, content::PAGE_TRANSITION_LINK,
523 render_view_host1());
312 } 524 }
313 525
314 // Simulates redirect of a subframe. 526 // Simulates redirect of a subframe.
315 TEST_F(CaptivePortalTabHelperTest, SubframeRedirect) { 527 TEST_F(CaptivePortalTabHelperTest, SubframeRedirect) {
316 GURL http_url("http://mail.google.com"); 528 GURL http_url(kHttpUrl);
317 EXPECT_CALL(mock_reloader(), OnLoadStart(false)).Times(1); 529 EXPECT_CALL(mock_reloader(), OnLoadStart(false)).Times(1);
318 tab_helper().DidStartProvisionalLoadForFrame(1, true, http_url, false, NULL); 530 tab_helper().DidStartProvisionalLoadForFrame(
531 1, true, http_url, false, render_view_host1());
319 532
320 GURL https_url("https://mail.google.com"); 533 GURL https_url(kHttpsUrl);
321 OnRedirect(2, https_url); 534 OnRedirect(ResourceType::SUB_FRAME, https_url,
535 render_view_host1()->GetProcess()->GetID());
322 536
323 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::OK)).Times(1); 537 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::OK)).Times(1);
324 tab_helper().DidCommitProvisionalLoadForFrame( 538 tab_helper().DidCommitProvisionalLoadForFrame(
325 1, true, GURL(kErrorPageUrl), content::PAGE_TRANSITION_LINK, NULL); 539 1, true, GURL(kErrorPageUrl), content::PAGE_TRANSITION_LINK,
540 render_view_host1());
541 }
542
543 // Simulates a redirect, for another RenderViewHost.
544 TEST_F(CaptivePortalTabHelperTest, OtherRenderViewHostRedirect) {
545 GURL http_url(kHttpUrl);
546 EXPECT_CALL(mock_reloader(), OnLoadStart(false)).Times(1);
547 tab_helper().DidStartProvisionalLoadForFrame(
548 1, true, http_url, false, render_view_host1());
549
550 // Another RenderViewHost sees a redirect. None of the reloader's functions
551 // should be called.
552 GURL https_url(kHttpsUrl);
553 OnRedirect(ResourceType::MAIN_FRAME, https_url,
554 render_view_host2()->GetProcess()->GetID());
555
556 tab_helper().DidFailProvisionalLoad(
557 1, true, https_url, net::ERR_TIMED_OUT, string16(),
558 render_view_host1());
559
560 // Provisional load starts for the error page.
561 tab_helper().DidStartProvisionalLoadForFrame(
562 1, true, GURL(kErrorPageUrl), true, render_view_host1());
563
564 EXPECT_CALL(mock_reloader(), OnLoadCommitted(net::ERR_TIMED_OUT)).Times(1);
565 tab_helper().DidCommitProvisionalLoadForFrame(
566 1, true, GURL(kErrorPageUrl), content::PAGE_TRANSITION_LINK,
567 render_view_host1());
326 } 568 }
327 569
328 TEST_F(CaptivePortalTabHelperTest, LoginTabLogin) { 570 TEST_F(CaptivePortalTabHelperTest, LoginTabLogin) {
329 EXPECT_FALSE(tab_helper().IsLoginTab()); 571 EXPECT_FALSE(tab_helper().IsLoginTab());
330 SetIsLoginTab(); 572 SetIsLoginTab();
331 EXPECT_TRUE(tab_helper().IsLoginTab()); 573 EXPECT_TRUE(tab_helper().IsLoginTab());
332 574
333 ObservePortalResult(RESULT_INTERNET_CONNECTED, RESULT_INTERNET_CONNECTED); 575 ObservePortalResult(RESULT_INTERNET_CONNECTED, RESULT_INTERNET_CONNECTED);
334 EXPECT_FALSE(tab_helper().IsLoginTab()); 576 EXPECT_FALSE(tab_helper().IsLoginTab());
335 } 577 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 EXPECT_FALSE(tab_helper().IsLoginTab()); 610 EXPECT_FALSE(tab_helper().IsLoginTab());
369 611
370 ObservePortalResult(RESULT_BEHIND_CAPTIVE_PORTAL, RESULT_NO_RESPONSE); 612 ObservePortalResult(RESULT_BEHIND_CAPTIVE_PORTAL, RESULT_NO_RESPONSE);
371 EXPECT_FALSE(tab_helper().IsLoginTab()); 613 EXPECT_FALSE(tab_helper().IsLoginTab());
372 614
373 ObservePortalResult(RESULT_NO_RESPONSE, RESULT_INTERNET_CONNECTED); 615 ObservePortalResult(RESULT_NO_RESPONSE, RESULT_INTERNET_CONNECTED);
374 EXPECT_FALSE(tab_helper().IsLoginTab()); 616 EXPECT_FALSE(tab_helper().IsLoginTab());
375 } 617 }
376 618
377 } // namespace captive_portal 619 } // namespace captive_portal
OLDNEW
« no previous file with comments | « chrome/browser/captive_portal/captive_portal_tab_helper.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698