Commit 4ab438c6 authored by Eugene But's avatar Eugene But Committed by Commit Bot

Removed unused code from RequestTrackerImpl.

Removed CRWRequestTrackerDelegate and SSLCarrier classes because no one
implements CRWRequestTrackerDelegate protocol after moving to WKWebView.

Bug: 585700, 579697
Change-Id: I1895ed00a6134a9e4d08f7a511b1f451c2f2a841
Reviewed-on: https://chromium-review.googlesource.com/691216Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Reviewed-by: default avatarJérôme Lebel <jlebel@chromium.org>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Commit-Queue: Eugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#505432}
parent be192595
......@@ -160,7 +160,7 @@ void RegisterUserAgentForUIWebView(NSString* user_agent) {
DCHECK(g_external_browser_state);
g_request_tracker = web::RequestTrackerImpl::CreateTrackerForRequestGroupID(
ChromeWebView::kExternalRequestGroupID, g_external_browser_state,
[self requestContextForExternalService:externalService], nil);
[self requestContextForExternalService:externalService]);
}
return [[UIWebView alloc] initWithFrame:CGRectZero];
}
......
......@@ -500,7 +500,6 @@ void HttpProtocolHandlerCore::StartReading() {
#endif // !defined(NDEBUG)
if (tracker_) {
tracker_->CaptureHeaders(net_request_);
long long expectedContentLength = [response expectedContentLength];
if (expectedContentLength > 0)
tracker_->CaptureExpectedLength(net_request_, expectedContentLength);
......
......@@ -67,9 +67,6 @@ class RequestTracker {
// Informs the tracker that a request has started.
virtual void StartRequest(URLRequest* request) = 0;
// Informs the tracker that the headers for the request are available.
virtual void CaptureHeaders(URLRequest* request) = 0;
// Informs the tracker the expected length of the result, if known.
virtual void CaptureExpectedLength(const URLRequest* request,
uint64_t length) = 0;
......
......@@ -99,7 +99,6 @@ source_set("web") {
"net/cookie_notification_bridge.mm",
"net/crw_cert_verification_controller.h",
"net/crw_cert_verification_controller.mm",
"net/crw_request_tracker_delegate.h",
"net/crw_ssl_status_updater.h",
"net/crw_ssl_status_updater.mm",
"net/request_group_util.h",
......
// Copyright 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_WEB_NET_CRW_REQUEST_TRACKER_DELEGATE_H_
#define IOS_WEB_NET_CRW_REQUEST_TRACKER_DELEGATE_H_
#include <vector>
#include "net/cert/cert_status_flags.h"
class GURL;
namespace net {
class HttpResponseHeaders;
class SSLInfo;
class X509Certificate;
}
namespace web {
struct SSLStatus;
}
// All the methods in this protocol must be sent on the main thread.
@protocol CRWRequestTrackerDelegate
// The tracker calls this method every time there is a change in the SSL status
// of a page. The info is whatever object was passed to TrimToURL().
- (void)updatedSSLStatus:(const web::SSLStatus&)sslStatus
forPageUrl:(const GURL&)url
userInfo:(id)userInfo;
// The tracker calls this method when it receives response headers.
- (void)handleResponseHeaders:(net::HttpResponseHeaders*)headers
requestUrl:(const GURL&)requestUrl;
// Update the progress.
- (void)updatedProgress:(float)progress;
// This method is called when a certificate with an error is in use.
- (void)certificateUsed:(net::X509Certificate*)certificate
forHost:(const std::string&)host
status:(net::CertStatus)status;
// Called when all the active allowed certificates need to be cleared. This
// happens during the TrimToURL(), which corresponds to a navigation.
- (void)clearCertificates;
@end
#endif // IOS_WEB_NET_CRW_REQUEST_TRACKER_DELEGATE_H_
......@@ -18,21 +18,18 @@
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#import "ios/net/request_tracker.h"
#import "ios/web/net/crw_request_tracker_delegate.h"
#include "ios/web/public/web_thread.h"
#include "net/cert/cert_status_flags.h"
#include "net/url_request/url_request_context_getter.h"
#include "url/gurl.h"
@class SSLCarrier;
@class CRWSSLCarrier;
struct TrackerCounts;
namespace net {
class HttpResponseHeaders;
class URLRequest;
class URLRequestContext;
class SSLInfo;
class X509Certificate;
}
namespace web {
......@@ -116,8 +113,7 @@ class RequestTrackerImpl
static scoped_refptr<RequestTrackerImpl> CreateTrackerForRequestGroupID(
NSString* request_group_id,
BrowserState* browser_state,
net::URLRequestContextGetter* context_getter,
id<CRWRequestTrackerDelegate> delegate);
net::URLRequestContextGetter* context_getter);
// The network layer has no way to know which network request is the primary
// one for a page load. The tab knows, either because it initiated the page
......@@ -189,7 +185,6 @@ class RequestTrackerImpl
// RequestTracker implementation.
void StartRequest(net::URLRequest* request) override;
void CaptureHeaders(net::URLRequest* request) override;
void CaptureExpectedLength(const net::URLRequest* request,
uint64_t length) override;
void CaptureReceivedBytes(const net::URLRequest* request,
......@@ -213,8 +208,7 @@ class RequestTrackerImpl
// Private. RequestTrackerImpls are created through
// CreateTrackerForRequestGroupID().
RequestTrackerImpl(NSString* request_group_id,
net::URLRequestContextGetter* context_getter,
id<CRWRequestTrackerDelegate> delegate);
net::URLRequestContextGetter* context_getter);
void InitOnIOThread(
const scoped_refptr<web::CertificatePolicyCache>& policy_cache);
......@@ -242,9 +236,6 @@ class RequestTrackerImpl
// and load progress.
void StackNotification();
// Notify the consumer about the SSL status of this tracker's page load.
void SSLNotify();
// If the counts is for a request currently waiting for the user to approve it
// will reevaluate the approval.
void EvaluateSSLCallbackForCounts(TrackerCounts* counts);
......@@ -264,7 +255,6 @@ class RequestTrackerImpl
// The URL change notification is often late, therefore the mixed content
// status and the certificate policies may need to be recomputed.
void RecomputeMixedContent(const TrackerCounts* split_position);
void RecomputeCertificatePolicy(const TrackerCounts* split_position);
// Remove all finished request up to the last instance of |url|. If url is not
// found, this will clear all the requests.
......@@ -278,30 +268,6 @@ class RequestTrackerImpl
// |load_success| indicates if the page successfully loaded.
void StopPageLoad(const GURL& url, bool load_success);
#pragma mark Private Consumer API
// Private methods that call into delegate methods.
// Notify* methods are posted to the UI thread by the provider API
// methods.
// Has the delegate handle |headers| for |request_url|.
void NotifyResponseHeaders(net::HttpResponseHeaders* headers,
const GURL& request_url);
// Notifies the deleage of certificate use.
void NotifyCertificateUsed(net::X509Certificate* certificate,
const std::string& host,
net::CertStatus status);
// Notifies the deleate of a load completion estimate.
void NotifyUpdatedProgress(float estimate);
// Has the delegate clear SSL certificates.
void NotifyClearCertificates();
// Notifies the delegate of an SSL status update.
void NotifyUpdatedSSLStatus(base::scoped_nsobject<CRWSSLCarrier> carrier);
#pragma mark Internal utilities for task posting
// Posts |task| to |thread|. Must not be called from |thread|. If |thread| is
// the IO thread, silently returns if |is_closing_| is true.
......@@ -318,11 +284,6 @@ class RequestTrackerImpl
// only from the IO thread.
NSString* UnsafeDescription();
#pragma mark Non thread-safe fields, only accessed from the main thread.
// The RequestTrackerImpl delegate. All changes and access to this object
// should be done on the main thread.
id<CRWRequestTrackerDelegate> delegate_; // Weak.
#pragma mark Non thread-safe fields, only accessed from the IO thread.
// All the tracked requests for the page, indexed by net::URLRequest (Cast as
// a void* to avoid the temptation of accessing it from the wrong thread).
......
......@@ -8,27 +8,19 @@
#include <stddef.h>
#include <stdint.h>
#include "base/bind_helpers.h"
#include "base/containers/hash_tables.h"
#include "base/location.h"
#include "base/logging.h"
#import "base/mac/bind_objc_block.h"
#import "base/mac/scoped_nsobject.h"
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "base/strings/string_util.h"
#include "base/strings/sys_string_conversions.h"
#include "base/synchronization/lock.h"
#include "ios/web/history_state_util.h"
#import "ios/web/net/crw_request_tracker_delegate.h"
#include "ios/web/public/browser_state.h"
#include "ios/web/public/certificate_policy_cache.h"
#include "ios/web/public/ssl_status.h"
#include "ios/web/public/url_util.h"
#include "ios/web/public/web_thread.h"
#import "net/base/mac/url_conversions.h"
#include "net/base/net_errors.h"
#include "net/http/http_response_headers.h"
#include "net/url_request/url_request.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......@@ -93,16 +85,6 @@ void InitializeGlobals() {
// identifier is needed for tracker (e.g. storing certs).
int g_next_request_tracker_id = 0;
// IsIntranetHost logic and its associated kDot constant are lifted directly
// from content/browser/ssl/ssl_policy.cc. Unfortunately that particular file
// has way too many dependencies on content to be used on iOS.
static const char kDot = '.';
static bool IsIntranetHost(const std::string& host) {
const size_t dot = host.find(kDot);
return dot == std::string::npos || dot == host.length() - 1;
}
// Add |tracker| to |g_trackers| under |key|.
static void RegisterTracker(web::RequestTrackerImpl* tracker, NSString* key) {
DCHECK_CURRENTLY_ON(web::WebThread::UI);
......@@ -201,131 +183,6 @@ struct TrackerCounts {
DISALLOW_COPY_AND_ASSIGN(TrackerCounts);
};
// A SSL carrier is used to transport SSL information to the UI via its
// encapsulation in a block. Once the object is constructed all public methods
// can be called from any thread safely. This object is designed so it is
// instantiated on the IO thread but may be accessed from the UI thread.
@interface CRWSSLCarrier : NSObject {
@private
scoped_refptr<web::RequestTrackerImpl> tracker_;
net::SSLInfo sslInfo_;
GURL url_;
web::SSLStatus status_;
}
// Designated initializer.
- (id)initWithTracker:(web::RequestTrackerImpl*)tracker
counts:(const TrackerCounts*)counts;
// URL of the request.
- (const GURL&)url;
// Returns a SSLStatus representing the state of the page. This assumes the
// target carrier is the main page request.
- (const web::SSLStatus&)sslStatus;
// Returns a SSLInfo with a reference to the certificate and SSL information.
- (const net::SSLInfo&)sslInfo;
// Internal method used to build the SSLStatus object. Called from the
// initializer to make sure it is invoked on the network thread.
- (void)buildSSLStatus;
@end
@implementation CRWSSLCarrier
- (id)initWithTracker:(web::RequestTrackerImpl*)tracker
counts:(const TrackerCounts*)counts {
self = [super init];
if (self) {
tracker_ = tracker;
url_ = counts->url;
sslInfo_ = counts->ssl_info;
[self buildSSLStatus];
}
return self;
}
- (const GURL&)url {
return url_;
}
- (const net::SSLInfo&)sslInfo {
return sslInfo_;
}
- (const web::SSLStatus&)sslStatus {
return status_;
}
- (void)buildSSLStatus {
DCHECK_CURRENTLY_ON(web::WebThread::IO);
if (!sslInfo_.is_valid())
return;
status_.certificate = sslInfo_.cert;
status_.cert_status = sslInfo_.cert_status;
if (status_.cert_status & net::CERT_STATUS_COMMON_NAME_INVALID) {
// CAs issue certificates for intranet hosts to everyone. Therefore, we
// mark intranet hosts as being non-unique.
if (IsIntranetHost(url_.host())) {
status_.cert_status |= net::CERT_STATUS_NON_UNIQUE_NAME;
}
}
status_.connection_status = sslInfo_.connection_status;
if (tracker_->has_mixed_content()) {
// TODO(noyau): In iOS there is no notion of resource type. The insecure
// content could be an image (DISPLAYED_INSECURE_CONTENT) or a script
// (RAN_INSECURE_CONTENT). The status of the page is different for both, but
// there is not enough information from UIWebView to differentiate the two
// cases.
status_.content_status = web::SSLStatus::DISPLAYED_INSECURE_CONTENT;
} else {
status_.content_status = web::SSLStatus::NORMAL_CONTENT;
}
if (!url_.SchemeIsCryptographic()) {
// Should not happen as the sslInfo is valid.
NOTREACHED();
status_.security_style = web::SECURITY_STYLE_UNAUTHENTICATED;
} else if (net::IsCertStatusError(status_.cert_status) &&
!net::IsCertStatusMinorError(status_.cert_status)) {
// Minor errors don't lower the security style to
// SECURITY_STYLE_AUTHENTICATION_BROKEN.
status_.security_style = web::SECURITY_STYLE_AUTHENTICATION_BROKEN;
} else {
// This page is secure.
status_.security_style = web::SECURITY_STYLE_AUTHENTICATED;
}
}
- (NSString*)description {
NSString* sslInfo = @"";
if (sslInfo_.is_valid()) {
switch (status_.security_style) {
case web::SECURITY_STYLE_UNKNOWN:
case web::SECURITY_STYLE_UNAUTHENTICATED:
sslInfo = @"Unexpected SSL state ";
break;
case web::SECURITY_STYLE_AUTHENTICATION_BROKEN:
sslInfo = @"Not secure ";
break;
case web::SECURITY_STYLE_AUTHENTICATED:
if (status_.content_status ==
web::SSLStatus::DISPLAYED_INSECURE_CONTENT)
sslInfo = @"Mixed ";
else
sslInfo = @"Secure ";
break;
}
}
NSURL* url = net::NSURLWithGURL(url_);
return [NSString stringWithFormat:@"<%@%@>", sslInfo, url];
}
@end
namespace web {
#pragma mark Consumer API
......@@ -335,13 +192,12 @@ scoped_refptr<RequestTrackerImpl>
RequestTrackerImpl::CreateTrackerForRequestGroupID(
NSString* request_group_id,
BrowserState* browser_state,
net::URLRequestContextGetter* context_getter,
id<CRWRequestTrackerDelegate> delegate) {
net::URLRequestContextGetter* context_getter) {
DCHECK_CURRENTLY_ON(web::WebThread::UI);
DCHECK(request_group_id);
scoped_refptr<RequestTrackerImpl> tracker =
new RequestTrackerImpl(request_group_id, context_getter, delegate);
new RequestTrackerImpl(request_group_id, context_getter);
scoped_refptr<CertificatePolicyCache> policy_cache =
BrowserState::GetCertificatePolicyCache(browser_state);
......@@ -394,8 +250,6 @@ void RequestTrackerImpl::Close() {
},
base::RetainedRef(this)));
// Disable the delegate.
delegate_ = nil;
// The user_info is no longer needed.
user_info_.reset();
}
......@@ -492,21 +346,6 @@ void RequestTrackerImpl::StartRequest(net::URLRequest* request) {
Notify();
}
void RequestTrackerImpl::CaptureHeaders(net::URLRequest* request) {
DCHECK_CURRENTLY_ON(web::WebThread::IO);
if (is_closing_)
return;
if (!request->response_headers())
return;
scoped_refptr<net::HttpResponseHeaders> headers(request->response_headers());
web::WebThread::PostTask(
web::WebThread::UI, FROM_HERE,
base::Bind(&RequestTrackerImpl::NotifyResponseHeaders, this,
base::RetainedRef(headers), request->url()));
}
void RequestTrackerImpl::CaptureExpectedLength(const net::URLRequest* request,
uint64_t length) {
DCHECK_CURRENTLY_ON(web::WebThread::IO);
......@@ -581,18 +420,6 @@ void RequestTrackerImpl::CaptureCertificatePolicyCache(
// Notify the delegate that a judgment has been used.
DCHECK(judgment == CertPolicy::ALLOWED);
if (counts_by_request_.count(request)) {
const net::SSLInfo& ssl_info = request->ssl_info();
TrackerCounts* counts = counts_by_request_[request];
counts->allowed_by_user = true;
if (ssl_info.is_valid())
counts->ssl_info = ssl_info;
web::WebThread::PostTask(
web::WebThread::UI, FROM_HERE,
base::Bind(&RequestTrackerImpl::NotifyCertificateUsed, this,
base::RetainedRef(ssl_info.cert), host,
ssl_info.cert_status));
}
should_continue.Run(true);
}
......@@ -647,10 +474,8 @@ void RequestTrackerImpl::ScheduleIOTask(const base::Closure& task) {
RequestTrackerImpl::RequestTrackerImpl(
NSString* request_group_id,
net::URLRequestContextGetter* context_getter,
id<CRWRequestTrackerDelegate> delegate)
: delegate_(delegate),
previous_estimate_(0.0f), // Not active by default.
net::URLRequestContextGetter* context_getter)
: previous_estimate_(0.0f), // Not active by default.
estimate_start_index_(0),
notification_depth_(0),
has_mixed_content_(false),
......@@ -735,80 +560,6 @@ void RequestTrackerImpl::StackNotification() {
--notification_depth_;
if (notification_depth_)
return;
SSLNotify();
if (is_loading_) {
float estimate = EstimatedProgress();
if (estimate != -1.0f) {
web::WebThread::PostTask(
web::WebThread::UI, FROM_HERE,
base::Bind(&RequestTrackerImpl::NotifyUpdatedProgress, this,
estimate));
}
}
}
void RequestTrackerImpl::SSLNotify() {
DCHECK_CURRENTLY_ON(web::WebThread::IO);
if (is_closing_)
return;
if (counts_.empty())
return; // Nothing yet to notify.
if (!page_url_.SchemeIsCryptographic())
return;
const GURL page_origin = page_url_.GetOrigin();
for (const auto& tracker_count : counts_) {
if (!tracker_count->ssl_info.is_valid())
continue; // No SSL info at this point in time on this tracker.
GURL request_origin = tracker_count->url.GetOrigin();
if (request_origin != page_origin)
continue; // Not interesting in the context of the page.
base::scoped_nsobject<CRWSSLCarrier> carrier([[CRWSSLCarrier alloc]
initWithTracker:this
counts:tracker_count.get()]);
web::WebThread::PostTask(
web::WebThread::UI, FROM_HERE,
base::Bind(&RequestTrackerImpl::NotifyUpdatedSSLStatus, this, carrier));
break;
}
}
void RequestTrackerImpl::NotifyResponseHeaders(
net::HttpResponseHeaders* headers,
const GURL& request_url) {
DCHECK_CURRENTLY_ON(web::WebThread::UI);
[delegate_ handleResponseHeaders:headers requestUrl:request_url];
}
void RequestTrackerImpl::NotifyCertificateUsed(
net::X509Certificate* certificate,
const std::string& host,
net::CertStatus status) {
DCHECK_CURRENTLY_ON(web::WebThread::UI);
[delegate_ certificateUsed:certificate forHost:host status:status];
}
void RequestTrackerImpl::NotifyUpdatedProgress(float estimate) {
DCHECK_CURRENTLY_ON(web::WebThread::UI);
[delegate_ updatedProgress:estimate];
}
void RequestTrackerImpl::NotifyClearCertificates() {
DCHECK_CURRENTLY_ON(web::WebThread::UI);
[delegate_ clearCertificates];
}
void RequestTrackerImpl::NotifyUpdatedSSLStatus(
base::scoped_nsobject<CRWSSLCarrier> carrier) {
DCHECK_CURRENTLY_ON(web::WebThread::UI);
[delegate_ updatedSSLStatus:[carrier sslStatus]
forPageUrl:[carrier url]
userInfo:user_info_];
}
void RequestTrackerImpl::EvaluateSSLCallbackForCounts(TrackerCounts* counts) {
......@@ -1033,31 +784,7 @@ void RequestTrackerImpl::RecomputeMixedContent(
// Resend a notification for the |page_url_| informing the upper layer
// that the mixed content was a red herring.
has_mixed_content_ = false;
SSLNotify();
}
}
}
void RequestTrackerImpl::RecomputeCertificatePolicy(
const TrackerCounts* splitPosition) {
DCHECK_CURRENTLY_ON(web::WebThread::IO);
// Clear the judgments for the old URL.
web::WebThread::PostTask(
web::WebThread::UI, FROM_HERE,
base::Bind(&RequestTrackerImpl::NotifyClearCertificates, this));
// Report judgements for the new URL.
for (auto it = counts_.rbegin(); it != counts_.rend(); ++it) {
TrackerCounts* counts = it->get();
if (counts->allowed_by_user) {
std::string host = counts->url.host();
web::WebThread::PostTask(
web::WebThread::UI, FROM_HERE,
base::Bind(&RequestTrackerImpl::NotifyCertificateUsed, this,
base::RetainedRef(counts->ssl_info.cert), host,
counts->ssl_info.cert_status));
}
if (counts == splitPosition)
break;
}
}
......@@ -1113,7 +840,6 @@ void RequestTrackerImpl::TrimToURL(const GURL& full_url, id user_info) {
}
}
RecomputeMixedContent(split_position);
RecomputeCertificatePolicy(split_position);
// Trim up to that element.
auto it = counts_.begin();
......
......@@ -40,8 +40,7 @@
#error "This file requires ARC support."
#endif
@interface RequestTrackerNotificationReceiverTest
: NSObject<CRWRequestTrackerDelegate> {
@interface RequestTrackerNotificationReceiverTest : NSObject {
@public
float value_;
float max_;
......@@ -65,50 +64,14 @@
return self;
}
- (void)updatedProgress:(float)progress {
if (progress > 0.0f) {
if (progress < value_) {
error_ = [NSString
stringWithFormat:@"going down from %f to %f", value_, progress];
}
value_ = progress;
} else {
value_ = 0.0f;
}
if (value_ > max_) {
max_ = value_;
}
}
- (NSString*)error {
return error_;
}
- (void)handleResponseHeaders:(net::HttpResponseHeaders*)headers
requestUrl:(const GURL&)requestUrl {
headers_ = headers;
}
- (net::HttpResponseHeaders*)headers {
return headers_.get();
}
- (void)updatedSSLStatus:(const web::SSLStatus&)sslStatus
forPageUrl:(const GURL&)url
userInfo:(id)userInfo {
// Nothing. yet.
}
- (void)certificateUsed:(net::X509Certificate*)certificate
forHost:(const std::string&)host
status:(net::CertStatus)status {
// Nothing, yet.
}
- (void)clearCertificates {
// Nothing, yet.
}
@end
namespace {
......@@ -142,12 +105,8 @@ class RequestTrackerTest : public PlatformTest {
DCHECK_CURRENTLY_ON(web::WebThread::UI);
request_group_id_ = [NSString stringWithFormat:@"test%d", g_count++];
receiver_ = [[RequestTrackerNotificationReceiverTest alloc] init];
tracker_ = web::RequestTrackerImpl::CreateTrackerForRequestGroupID(
request_group_id_,
&browser_state_,
browser_state_.GetRequestContext(),
receiver_);
request_group_id_, &browser_state_, browser_state_.GetRequestContext());
}
void TearDown() override {
......@@ -159,7 +118,6 @@ class RequestTrackerTest : public PlatformTest {
web::TestWebThread ui_thread_;
web::TestWebThread io_thread_;
RequestTrackerNotificationReceiverTest* receiver_;
scoped_refptr<web::RequestTrackerImpl> tracker_;
NSString* request_group_id_;
web::TestBrowserState browser_state_;
......@@ -193,8 +151,6 @@ class RequestTrackerTest : public PlatformTest {
DCHECK_CURRENTLY_ON(web::WebThread::UI);
base::Time maxDate = base::Time::Now() + base::TimeDelta::FromSeconds(10);
while (!condition()) {
if ([receiver_ error])
return [receiver_ error];
if (base::Time::Now() > maxDate)
return @"Time is up, too slow to go";
base::RunLoop().RunUntilIdle();
......@@ -203,28 +159,14 @@ class RequestTrackerTest : public PlatformTest {
return nil;
}
NSString* CheckActive() {
NSString* message = WaitUntilLoop(^{
return (receiver_->value_ > 0.0f);
});
if (!message && (receiver_->max_ == 0.0f))
message = @"Max should be greater than 0.0";
return message;
}
void TrimRequest(NSString* tab_id, const GURL& url) {
DCHECK_CURRENTLY_ON(web::WebThread::UI);
receiver_->value_ = 0.0f;
receiver_->max_ = 0.0f;
tracker_->StartPageLoad(url, nil);
}
void EndPage(NSString* tab_id, const GURL& url) {
DCHECK_CURRENTLY_ON(web::WebThread::UI);
tracker_->FinishPageLoad(url, false);
receiver_->value_ = 0.0f;
receiver_->max_ = 0.0f;
base::RunLoop().RunUntilIdle();
}
......@@ -276,7 +218,6 @@ TEST_F(RequestTrackerTest, OnePage) {
tracker_->StartRequest(GetRequest(0));
// Start page load.
TrimRequest(request_group_id_, GetURL(0));
EXPECT_NSEQ(nil, CheckActive());
// Stop the request.
tracker_->StopRequest(GetRequest(0));
......@@ -293,7 +234,6 @@ TEST_F(RequestTrackerTest, OneSecurePage) {
// Start a request.
tracker_->StartRequest(request);
tracker_->CaptureReceivedBytes(request, 42);
EXPECT_NSEQ(nil, CheckActive());
// Stop the request.
tracker_->StopRequest(request);
......@@ -307,18 +247,14 @@ TEST_F(RequestTrackerTest, OnePageAndResources) {
// Start two requests.
tracker_->StartRequest(GetRequest(0));
tracker_->StartRequest(GetRequest(1));
EXPECT_NSEQ(nil, CheckActive());
tracker_->StopRequest(GetRequest(0));
tracker_->StartRequest(GetRequest(2));
EXPECT_NSEQ(nil, CheckActive());
tracker_->StopRequest(GetRequest(1));
tracker_->StartRequest(GetRequest(3));
EXPECT_NSEQ(nil, CheckActive());
tracker_->StopRequest(GetRequest(2));
tracker_->StartRequest(GetRequest(4));
EXPECT_NSEQ(nil, CheckActive());
tracker_->StopRequest(GetRequest(3));
tracker_->StopRequest(GetRequest(4));
......@@ -331,7 +267,6 @@ TEST_F(RequestTrackerTest, OnePageOneBigImage) {
tracker_->StartRequest(GetRequest(0));
tracker_->StopRequest(GetRequest(0));
tracker_->StartRequest(GetRequest(1));
EXPECT_NSEQ(nil, CheckActive());
tracker_->CaptureReceivedBytes(GetRequest(1), 10);
tracker_->CaptureExpectedLength(GetRequest(1), 100);
......@@ -339,7 +274,6 @@ TEST_F(RequestTrackerTest, OnePageOneBigImage) {
tracker_->CaptureReceivedBytes(GetRequest(1), 10);
tracker_->CaptureReceivedBytes(GetRequest(1), 10);
tracker_->CaptureReceivedBytes(GetRequest(1), 10);
EXPECT_NSEQ(nil, CheckActive());
tracker_->CaptureReceivedBytes(GetRequest(1), 10);
tracker_->CaptureReceivedBytes(GetRequest(1), 10);
......@@ -354,10 +288,8 @@ TEST_F(RequestTrackerTest, TwoPagesPostStart) {
tracker_->StartRequest(GetRequest(0));
TrimRequest(request_group_id_, GetURL(0));
EXPECT_NSEQ(nil, CheckActive());
tracker_->StartRequest(GetRequest(1));
tracker_->StartRequest(GetRequest(2));
EXPECT_NSEQ(nil, CheckActive());
tracker_->StopRequest(GetRequest(0));
tracker_->StopRequest(GetRequest(1));
......@@ -367,7 +299,6 @@ TEST_F(RequestTrackerTest, TwoPagesPostStart) {
tracker_->StartRequest(GetRequest(3));
TrimRequest(request_group_id_, GetURL(3));
EXPECT_NSEQ(nil, CheckActive());
tracker_->StopRequest(GetRequest(3));
EndPage(request_group_id_, GetURL(3));
......@@ -377,10 +308,8 @@ TEST_F(RequestTrackerTest, TwoPagesPreStart) {
tracker_->StartRequest(GetRequest(0));
TrimRequest(request_group_id_, GetURL(0));
EXPECT_NSEQ(nil, CheckActive());
tracker_->StartRequest(GetRequest(1));
tracker_->StartRequest(GetRequest(2));
EXPECT_NSEQ(nil, CheckActive());
tracker_->StopRequest(GetRequest(0));
tracker_->StopRequest(GetRequest(1));
......@@ -397,58 +326,21 @@ TEST_F(RequestTrackerTest, TwoPagesNoWait) {
tracker_->StartRequest(GetRequest(0));
TrimRequest(request_group_id_, GetURL(0));
EXPECT_NSEQ(nil, CheckActive());
tracker_->StartRequest(GetRequest(1));
tracker_->StartRequest(GetRequest(2));
EXPECT_NSEQ(nil, CheckActive());
tracker_->StopRequest(GetRequest(0));
tracker_->StopRequest(GetRequest(1));
tracker_->StopRequest(GetRequest(2));
EXPECT_NSEQ(nil, CheckActive());
TrimRequest(request_group_id_, GetURL(3));
tracker_->StartRequest(GetRequest(3));
EXPECT_NSEQ(nil, CheckActive());
tracker_->StopRequest(GetRequest(3));
EXPECT_NSEQ(nil, CheckActive());
EndPage(request_group_id_, GetURL(3));
}
TEST_F(RequestTrackerTest, CaptureHeaders) {
std::string headers =
"HTTP/1.1 200 OK\n"
"content-type: multipart/mixed; boundary=inner\n"
"content-disposition: attachment; filename=\"name.pdf\"\n"
"X-Auto-Login: Hello World\n\n";
for (size_t i = 0; i < headers.length(); i++) {
if (headers.data()[i] == '\n')
const_cast<char*>(headers.data())[i] = '\0';
}
net::URLRequest* request = GetRequest(0);
// TODO(mmenke): This is really bizarre. Do something more reasonable.
const_cast<net::HttpResponseInfo&>(request->response_info()).headers =
new net::HttpResponseHeaders(headers);
std::unique_ptr<net::URLRequestTestJob> job(new net::URLRequestTestJob(
request, request->context()->network_delegate(), headers, "", false));
AddInterceptorToRequest(0)->set_main_intercept_job(std::move(job));
request->Start();
tracker_->StartRequest(request);
tracker_->CaptureHeaders(request);
tracker_->StopRequest(request);
base::RunLoop().RunUntilIdle();
EXPECT_TRUE([receiver_ headers]->HasHeaderValue("X-Auto-Login",
"Hello World"));
std::string mimeType;
EXPECT_TRUE([receiver_ headers]->GetMimeType(&mimeType));
EXPECT_EQ("multipart/mixed", mimeType);
EXPECT_TRUE([receiver_ headers]->HasHeaderValue(
"Content-Disposition", "attachment; filename=\"name.pdf\""));
}
// Do-nothing mock CertificatePolicyCache. Allows all certs for all hosts.
class MockCertificatePolicyCache : public web::CertificatePolicyCache {
public:
......
......@@ -7,7 +7,6 @@
#import <UIKit/UIKit.h>
#import "ios/web/net/crw_request_tracker_delegate.h"
#import "ios/web/public/web_state/js/crw_js_injection_evaluator.h"
#import "ios/web/public/web_state/ui/crw_web_delegate.h"
#include "ios/web/public/web_state/url_verification_constants.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment