Commit 7f811a91 authored by Lily Houghton's avatar Lily Houghton Committed by Commit Bot

[Cronet] Define CronetMetrics class implementing the iOS...

[Cronet] Define CronetMetrics class implementing the iOS NSURLSessionTaskTransactionMetrics interface

This creates a class |CronetMetrics| which provides setters for all of the propeties defined in
NSURLSessionTaskTransactionMetrics.

Bug: 702796
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Icdcc917001c0ceb20107e2f128dba88259330f78
Reviewed-on: https://chromium-review.googlesource.com/744401
Commit-Queue: Lily Houghton <lilyhoughton@chromium.org>
Reviewed-by: default avatarMisha Efimov <mef@chromium.org>
Cr-Commit-Position: refs/heads/master@{#515444}
parent 7d840bcd
...@@ -79,6 +79,8 @@ _cronet_sources = [ ...@@ -79,6 +79,8 @@ _cronet_sources = [
"Cronet.mm", "Cronet.mm",
"cronet_environment.h", "cronet_environment.h",
"cronet_environment.mm", "cronet_environment.mm",
"cronet_metrics.h",
"cronet_metrics.mm",
] ]
_cronet_public_headers = [ "Cronet.h" ] _cronet_public_headers = [ "Cronet.h" ]
......
// Copyright 2017 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 COMPONENTS_CRONET_IOS_CRONET_METRICS_H_
#define COMPONENTS_CRONET_IOS_CRONET_METRICS_H_
#import <Foundation/Foundation.h>
#include "components/grpc_support/include/bidirectional_stream_c.h"
FOUNDATION_EXPORT GRPC_SUPPORT_EXPORT NS_AVAILABLE_IOS(10.0)
@interface CronetMetrics : NSURLSessionTaskTransactionMetrics
@property(copy, readwrite) NSURLRequest* request;
@property(copy, readwrite) NSURLResponse* response;
@property(copy, readwrite) NSDate* fetchStartDate;
@property(copy, readwrite) NSDate* domainLookupStartDate;
@property(copy, readwrite) NSDate* domainLookupEndDate;
@property(copy, readwrite) NSDate* connectStartDate;
@property(copy, readwrite) NSDate* secureConnectionStartDate;
@property(copy, readwrite) NSDate* secureConnectionEndDate;
@property(copy, readwrite) NSDate* connectEndDate;
@property(copy, readwrite) NSDate* requestStartDate;
@property(copy, readwrite) NSDate* requestEndDate;
@property(copy, readwrite) NSDate* responseStartDate;
@property(copy, readwrite) NSDate* responseEndDate;
@property(copy, readwrite) NSString* networkProtocolName;
@property(assign, readwrite, getter=isProxyConnection) BOOL proxyConnection;
@property(assign, readwrite, getter=isReusedConnection) BOOL reusedConnection;
@property(assign, readwrite)
NSURLSessionTaskMetricsResourceFetchType resourceFetchType;
@end
#endif // COMPONENTS_CRONET_IOS_CRONET_METRICS_H_
// Copyright 2017 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.
#import "components/cronet/ios/cronet_metrics.h"
@implementation CronetMetrics
@synthesize request = _request;
@synthesize response = _response;
@synthesize fetchStartDate = _fetchStartDate;
@synthesize domainLookupStartDate = _domainLookupStartDate;
@synthesize domainLookupEndDate = _domainLookupEndDate;
@synthesize connectStartDate = _connectStartDate;
@synthesize secureConnectionStartDate = _secureConnectionStartDate;
@synthesize secureConnectionEndDate = _secureConnectionEndDate;
@synthesize connectEndDate = _connectEndDate;
@synthesize requestStartDate = _requestStartDate;
@synthesize requestEndDate = _requestEndDate;
@synthesize responseStartDate = _responseStartDate;
@synthesize responseEndDate = _responseEndDate;
@synthesize networkProtocolName = _networkProtocolName;
@synthesize proxyConnection = _proxyConnection;
@synthesize reusedConnection = _reusedConnection;
@synthesize resourceFetchType = _resourceFetchType;
@end
...@@ -8,8 +8,10 @@ import("//testing/test.gni") ...@@ -8,8 +8,10 @@ import("//testing/test.gni")
test("cronet_test") { test("cronet_test") {
testonly = true testonly = true
sources = [ sources = [
"../cronet_metrics.h", # used for unit testing of private interface
"cronet_acceptlang_test.mm", "cronet_acceptlang_test.mm",
"cronet_http_test.mm", "cronet_http_test.mm",
"cronet_metrics_test.mm",
"cronet_netlog_test.mm", "cronet_netlog_test.mm",
"cronet_performance_test.mm", "cronet_performance_test.mm",
"cronet_pkp_test.mm", "cronet_pkp_test.mm",
......
// Copyright 2017 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.
#import <Cronet/Cronet.h>
#include "components/cronet/ios/cronet_metrics.h"
#include "components/cronet/ios/test/cronet_test_base.h"
#include "testing/gtest_mac.h"
namespace cronet {
class CronetMetricsTest : public CronetTestBase {
};
TEST_F(CronetMetricsTest, Setters) {
if (@available(iOS 10, *)) {
CronetMetrics* cronet_metrics = [[CronetMetrics alloc] init];
NSDate* test_date = [NSDate date];
NSURLRequest* test_req = [NSURLRequest
requestWithURL:[NSURL URLWithString:@"test.example.com"]];
NSURLResponse* test_resp = [[NSURLResponse alloc]
initWithURL:[NSURL URLWithString:@"test.example.com"]
MIMEType:@"text/plain"
expectedContentLength:128
textEncodingName:@"ascii"];
[cronet_metrics setRequest:test_req];
[cronet_metrics setResponse:test_resp];
[cronet_metrics setFetchStartDate:test_date];
[cronet_metrics setDomainLookupStartDate:test_date];
[cronet_metrics setDomainLookupEndDate:test_date];
[cronet_metrics setConnectStartDate:test_date];
[cronet_metrics setSecureConnectionStartDate:test_date];
[cronet_metrics setSecureConnectionEndDate:test_date];
[cronet_metrics setConnectEndDate:test_date];
[cronet_metrics setRequestStartDate:test_date];
[cronet_metrics setRequestEndDate:test_date];
[cronet_metrics setResponseStartDate:test_date];
[cronet_metrics setResponseEndDate:test_date];
[cronet_metrics setNetworkProtocolName:@"http/2"];
[cronet_metrics setProxyConnection:YES];
[cronet_metrics setReusedConnection:YES];
[cronet_metrics setResourceFetchType:
NSURLSessionTaskMetricsResourceFetchTypeNetworkLoad];
NSURLSessionTaskTransactionMetrics* metrics = cronet_metrics;
EXPECT_EQ([metrics request], test_req);
EXPECT_EQ([metrics response], test_resp);
EXPECT_EQ([metrics fetchStartDate], test_date);
EXPECT_EQ([metrics domainLookupStartDate], test_date);
EXPECT_EQ([metrics domainLookupEndDate], test_date);
EXPECT_EQ([metrics connectStartDate], test_date);
EXPECT_EQ([metrics secureConnectionStartDate], test_date);
EXPECT_EQ([metrics secureConnectionEndDate], test_date);
EXPECT_EQ([metrics connectEndDate], test_date);
EXPECT_EQ([metrics requestStartDate], test_date);
EXPECT_EQ([metrics requestEndDate], test_date);
EXPECT_EQ([metrics responseStartDate], test_date);
EXPECT_EQ([metrics responseEndDate], test_date);
EXPECT_EQ([metrics networkProtocolName], @"http/2");
EXPECT_EQ([metrics isProxyConnection], YES);
EXPECT_EQ([metrics isReusedConnection], YES);
EXPECT_EQ([metrics resourceFetchType],
NSURLSessionTaskMetricsResourceFetchTypeNetworkLoad);
}
}
} // namespace cronet
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