OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 "content/test/test_navigation_url_loader_delegate.h" |
| 6 |
| 7 #include "base/run_loop.h" |
| 8 #include "content/public/browser/stream_handle.h" |
| 9 #include "content/public/common/resource_response.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 |
| 12 namespace content { |
| 13 |
| 14 TestNavigationURLLoaderDelegate::TestNavigationURLLoaderDelegate() |
| 15 : net_error_(0), on_request_handled_counter_(0) {} |
| 16 |
| 17 TestNavigationURLLoaderDelegate::~TestNavigationURLLoaderDelegate() {} |
| 18 |
| 19 void TestNavigationURLLoaderDelegate::WaitForRequestRedirected() { |
| 20 request_redirected_.reset(new base::RunLoop); |
| 21 request_redirected_->Run(); |
| 22 request_redirected_.reset(); |
| 23 } |
| 24 |
| 25 void TestNavigationURLLoaderDelegate::WaitForResponseStarted() { |
| 26 response_started_.reset(new base::RunLoop); |
| 27 response_started_->Run(); |
| 28 response_started_.reset(); |
| 29 } |
| 30 |
| 31 void TestNavigationURLLoaderDelegate::WaitForRequestFailed() { |
| 32 request_failed_.reset(new base::RunLoop); |
| 33 request_failed_->Run(); |
| 34 request_failed_.reset(); |
| 35 } |
| 36 |
| 37 void TestNavigationURLLoaderDelegate::WaitForRequestStarted() { |
| 38 request_started_.reset(new base::RunLoop); |
| 39 request_started_->Run(); |
| 40 request_started_.reset(); |
| 41 } |
| 42 |
| 43 void TestNavigationURLLoaderDelegate::ReleaseBody() { |
| 44 body_.reset(); |
| 45 } |
| 46 |
| 47 void TestNavigationURLLoaderDelegate::OnRequestRedirected( |
| 48 const net::RedirectInfo& redirect_info, |
| 49 const scoped_refptr<ResourceResponse>& response) { |
| 50 redirect_info_ = redirect_info; |
| 51 redirect_response_ = response; |
| 52 ASSERT_TRUE(request_redirected_); |
| 53 request_redirected_->Quit(); |
| 54 } |
| 55 |
| 56 void TestNavigationURLLoaderDelegate::OnResponseStarted( |
| 57 const scoped_refptr<ResourceResponse>& response, |
| 58 scoped_ptr<StreamHandle> body) { |
| 59 response_ = response; |
| 60 body_ = std::move(body); |
| 61 ASSERT_TRUE(response_started_); |
| 62 response_started_->Quit(); |
| 63 } |
| 64 |
| 65 void TestNavigationURLLoaderDelegate::OnRequestFailed(bool in_cache, |
| 66 int net_error) { |
| 67 net_error_ = net_error; |
| 68 if (request_failed_) |
| 69 request_failed_->Quit(); |
| 70 } |
| 71 |
| 72 void TestNavigationURLLoaderDelegate::OnRequestStarted( |
| 73 base::TimeTicks timestamp) { |
| 74 ASSERT_FALSE(timestamp.is_null()); |
| 75 ++on_request_handled_counter_; |
| 76 if (request_started_) |
| 77 request_started_->Quit(); |
| 78 } |
| 79 |
| 80 } // namespace content |
OLD | NEW |