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

Side by Side Diff: content/browser/frame_host/navigation_handle_impl_unittest.cc

Issue 2161073002: Adds RequestContextType information to the NavigationHandle. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "base/macros.h" 5 #include "base/macros.h"
6 #include "content/browser/frame_host/navigation_handle_impl.h" 6 #include "content/browser/frame_host/navigation_handle_impl.h"
7 #include "content/public/browser/navigation_throttle.h" 7 #include "content/public/browser/navigation_throttle.h"
8 #include "content/public/common/request_context_type.h"
8 #include "content/test/test_render_frame_host.h" 9 #include "content/test/test_render_frame_host.h"
9 10
10 namespace content { 11 namespace content {
11 12
12 // Test version of a NavigationThrottle. It will always return the current 13 // Test version of a NavigationThrottle. It will always return the current
13 // NavigationThrottle::ThrottleCheckResult |result_|, It also monitors the 14 // NavigationThrottle::ThrottleCheckResult |result_|, It also monitors the
14 // number of times WillStartRequest, WillRedirectRequest, and 15 // number of times WillStartRequest, WillRedirectRequest, and
15 // WillProcessResponse were called. 16 // WillProcessResponse were called.
16 class TestNavigationThrottle : public NavigationThrottle { 17 class TestNavigationThrottle : public NavigationThrottle {
17 public: 18 public:
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 public: 61 public:
61 NavigationHandleImplTest() 62 NavigationHandleImplTest()
62 : was_callback_called_(false), 63 : was_callback_called_(false),
63 callback_result_(NavigationThrottle::DEFER) {} 64 callback_result_(NavigationThrottle::DEFER) {}
64 65
65 void SetUp() override { 66 void SetUp() override {
66 RenderViewHostImplTestHarness::SetUp(); 67 RenderViewHostImplTestHarness::SetUp();
67 test_handle_ = NavigationHandleImpl::Create( 68 test_handle_ = NavigationHandleImpl::Create(
68 GURL(), main_test_rfh()->frame_tree_node(), true, false, false, 69 GURL(), main_test_rfh()->frame_tree_node(), true, false, false,
69 base::TimeTicks::Now(), 0); 70 base::TimeTicks::Now(), 0);
71 EXPECT_EQ(REQUEST_CONTEXT_TYPE_UNSPECIFIED,
72 test_handle_->request_context_type_);
70 } 73 }
71 74
72 void TearDown() override { 75 void TearDown() override {
73 // Release the |test_handle_| before destroying the WebContents, to match 76 // Release the |test_handle_| before destroying the WebContents, to match
74 // the WebContentsObserverSanityChecker expectations. 77 // the WebContentsObserverSanityChecker expectations.
75 test_handle_.reset(); 78 test_handle_.reset();
76 RenderViewHostImplTestHarness::TearDown(); 79 RenderViewHostImplTestHarness::TearDown();
77 } 80 }
78 81
79 bool IsDeferringStart() { 82 bool IsDeferringStart() {
(...skipping 16 matching lines...) Expand all
96 // returns DEFER, |callback_result_| will be set to the actual result of 99 // returns DEFER, |callback_result_| will be set to the actual result of
97 // the throttle checks when they are finished. 100 // the throttle checks when they are finished.
98 void SimulateWillStartRequest() { 101 void SimulateWillStartRequest() {
99 was_callback_called_ = false; 102 was_callback_called_ = false;
100 callback_result_ = NavigationThrottle::DEFER; 103 callback_result_ = NavigationThrottle::DEFER;
101 104
102 // It's safe to use base::Unretained since the NavigationHandle is owned by 105 // It's safe to use base::Unretained since the NavigationHandle is owned by
103 // the NavigationHandleImplTest. 106 // the NavigationHandleImplTest.
104 test_handle_->WillStartRequest( 107 test_handle_->WillStartRequest(
105 "GET", nullptr, Referrer(), false, ui::PAGE_TRANSITION_LINK, false, 108 "GET", nullptr, Referrer(), false, ui::PAGE_TRANSITION_LINK, false,
109 REQUEST_CONTEXT_TYPE_LOCATION,
106 base::Bind(&NavigationHandleImplTest::UpdateThrottleCheckResult, 110 base::Bind(&NavigationHandleImplTest::UpdateThrottleCheckResult,
107 base::Unretained(this))); 111 base::Unretained(this)));
108 } 112 }
109 113
110 // Helper function to call WillRedirectRequest on |handle|. If this function 114 // Helper function to call WillRedirectRequest on |handle|. If this function
111 // returns DEFER, |callback_result_| will be set to the actual result of the 115 // returns DEFER, |callback_result_| will be set to the actual result of the
112 // throttle checks when they are finished. 116 // throttle checks when they are finished.
113 // TODO(clamy): this should also simulate that WillStartRequest was called if 117 // TODO(clamy): this should also simulate that WillStartRequest was called if
114 // it has not been called before. 118 // it has not been called before.
115 void SimulateWillRedirectRequest() { 119 void SimulateWillRedirectRequest() {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 NavigationThrottle::ThrottleCheckResult result) { 175 NavigationThrottle::ThrottleCheckResult result) {
172 callback_result_ = result; 176 callback_result_ = result;
173 was_callback_called_ = true; 177 was_callback_called_ = true;
174 } 178 }
175 179
176 std::unique_ptr<NavigationHandleImpl> test_handle_; 180 std::unique_ptr<NavigationHandleImpl> test_handle_;
177 bool was_callback_called_; 181 bool was_callback_called_;
178 NavigationThrottle::ThrottleCheckResult callback_result_; 182 NavigationThrottle::ThrottleCheckResult callback_result_;
179 }; 183 };
180 184
185 // Checks that the request_context_type is properly set.
186 // Note: can be extended to cover more internal members.
187 TEST_F(NavigationHandleImplTest, SimpleDataChecks) {
188 SimulateWillStartRequest();
189 EXPECT_EQ(REQUEST_CONTEXT_TYPE_LOCATION,
190 test_handle()->GetRequestContextType());
191
192 test_handle()->Resume();
193 SimulateWillRedirectRequest();
194 EXPECT_EQ(REQUEST_CONTEXT_TYPE_LOCATION,
195 test_handle()->GetRequestContextType());
196
197 test_handle()->Resume();
198 SimulateWillProcessResponse();
199 EXPECT_EQ(REQUEST_CONTEXT_TYPE_LOCATION,
200 test_handle()->GetRequestContextType());
201 }
202
181 // Checks that a deferred navigation can be properly resumed. 203 // Checks that a deferred navigation can be properly resumed.
182 TEST_F(NavigationHandleImplTest, ResumeDeferred) { 204 TEST_F(NavigationHandleImplTest, ResumeDeferred) {
183 TestNavigationThrottle* test_throttle = 205 TestNavigationThrottle* test_throttle =
184 CreateTestNavigationThrottle(NavigationThrottle::DEFER); 206 CreateTestNavigationThrottle(NavigationThrottle::DEFER);
185 EXPECT_FALSE(IsDeferringStart()); 207 EXPECT_FALSE(IsDeferringStart());
186 EXPECT_FALSE(IsDeferringRedirect()); 208 EXPECT_FALSE(IsDeferringRedirect());
187 EXPECT_FALSE(IsDeferringResponse()); 209 EXPECT_FALSE(IsDeferringResponse());
188 EXPECT_EQ(0, test_throttle->will_start_calls()); 210 EXPECT_EQ(0, test_throttle->will_start_calls());
189 EXPECT_EQ(0, test_throttle->will_redirect_calls()); 211 EXPECT_EQ(0, test_throttle->will_redirect_calls());
190 EXPECT_EQ(0, test_throttle->will_process_response_calls()); 212 EXPECT_EQ(0, test_throttle->will_process_response_calls());
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result()); 661 EXPECT_EQ(NavigationThrottle::CANCEL_AND_IGNORE, callback_result());
640 EXPECT_EQ(0, cancel_throttle->will_start_calls()); 662 EXPECT_EQ(0, cancel_throttle->will_start_calls());
641 EXPECT_EQ(0, cancel_throttle->will_redirect_calls()); 663 EXPECT_EQ(0, cancel_throttle->will_redirect_calls());
642 EXPECT_EQ(1, cancel_throttle->will_process_response_calls()); 664 EXPECT_EQ(1, cancel_throttle->will_process_response_calls());
643 EXPECT_EQ(0, proceed_throttle->will_start_calls()); 665 EXPECT_EQ(0, proceed_throttle->will_start_calls());
644 EXPECT_EQ(0, proceed_throttle->will_redirect_calls()); 666 EXPECT_EQ(0, proceed_throttle->will_redirect_calls());
645 EXPECT_EQ(0, proceed_throttle->will_process_response_calls()); 667 EXPECT_EQ(0, proceed_throttle->will_process_response_calls());
646 } 668 }
647 669
648 } // namespace content 670 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/frame_host/navigation_handle_impl_browsertest.cc ('k') | content/browser/frame_host/navigation_request.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698