Chromium Code Reviews| 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 #import <Cronet/Cronet.h> | |
| 6 #import <Foundation/Foundation.h> | |
| 7 | |
| 8 #include "base/logging.h" | |
|
mef
2016/12/20 17:56:41
nit: unused
| |
| 9 #include "base/mac/scoped_nsobject.h" | |
|
mef
2016/12/20 17:56:41
nit: unused
| |
| 10 #include "base/strings/sys_string_conversions.h" | |
|
mef
2016/12/20 17:56:41
nit: unused
| |
| 11 #include "components/cronet/ios/test/test_server.h" | |
|
mef
2016/12/20 17:56:41
nit: unused
| |
| 12 #include "net/base/mac/url_conversions.h" | |
|
mef
2016/12/20 17:56:41
nit: unused
| |
| 13 #include "net/base/net_errors.h" | |
|
mef
2016/12/20 17:56:41
nit: unused
| |
| 14 #include "net/cert/mock_cert_verifier.h" | |
|
mef
2016/12/20 17:56:41
nit: unused
| |
| 15 #include "testing/gtest/include/gtest/gtest.h" | |
| 16 #include "testing/gtest_mac.h" | |
|
mef
2016/12/20 17:56:41
nit: unused
| |
| 17 #include "url/gurl.h" | |
|
mef
2016/12/20 17:56:41
nit: unused
| |
| 18 | |
| 19 namespace cronet { | |
| 20 | |
| 21 void StartCronetIfNecessary(); | |
| 22 | |
| 23 class NetLogTest : public ::testing::Test { | |
| 24 protected: | |
| 25 NetLogTest() {} | |
| 26 ~NetLogTest() override {} | |
| 27 | |
| 28 void SetUp() override { StartCronetIfNecessary(); } | |
| 29 }; | |
| 30 | |
| 31 TEST(NetLogTest, OpenFile) { | |
| 32 bool netlog_started = | |
| 33 [Cronet startNetLogToFile:@"cronet_netlog.json" logBytes:YES]; | |
| 34 [Cronet stopNetLog]; | |
| 35 | |
| 36 EXPECT_TRUE(netlog_started); | |
| 37 } | |
| 38 | |
| 39 TEST(NetLogTest, CreateFile) { | |
| 40 NSString* filename = [[[NSProcessInfo processInfo] globallyUniqueString] | |
| 41 stringByAppendingString:@"_netlog.json"]; | |
| 42 bool netlog_started = [Cronet startNetLogToFile:filename logBytes:YES]; | |
| 43 [Cronet stopNetLog]; | |
| 44 | |
| 45 bool file_created = [[NSFileManager defaultManager] | |
| 46 fileExistsAtPath:[Cronet getNetLogPathForFile:filename]]; | |
| 47 | |
| 48 [[NSFileManager defaultManager] | |
| 49 removeItemAtPath:[Cronet getNetLogPathForFile:filename] | |
| 50 error:nil]; | |
| 51 | |
| 52 EXPECT_TRUE(netlog_started); | |
| 53 EXPECT_TRUE(file_created); | |
| 54 } | |
| 55 | |
| 56 TEST(NetLogTest, NonExistantDir) { | |
| 57 NSString* notdir = [[[NSProcessInfo processInfo] globallyUniqueString] | |
| 58 stringByAppendingString:@"/netlog.json"]; | |
| 59 bool netlog_started = [Cronet startNetLogToFile:notdir logBytes:NO]; | |
| 60 | |
| 61 EXPECT_FALSE(netlog_started); | |
| 62 } | |
| 63 | |
| 64 TEST(NetLogTest, ExistantDir) { | |
| 65 NSString* dir = [[NSProcessInfo processInfo] globallyUniqueString]; | |
| 66 | |
| 67 bool dir_created = [[NSFileManager defaultManager] | |
| 68 createDirectoryAtPath:[Cronet getNetLogPathForFile:dir] | |
| 69 withIntermediateDirectories:NO | |
| 70 attributes:nil | |
| 71 error:nil]; | |
| 72 | |
| 73 bool netlog_started = | |
| 74 [Cronet startNetLogToFile:[dir stringByAppendingString:@"/netlog.json"] | |
| 75 logBytes:NO]; | |
| 76 | |
| 77 [[NSFileManager defaultManager] | |
| 78 removeItemAtPath:[Cronet | |
| 79 getNetLogPathForFile: | |
| 80 [dir stringByAppendingString:@"/netlog.json"]] | |
| 81 error:nil]; | |
| 82 | |
| 83 [[NSFileManager defaultManager] | |
| 84 removeItemAtPath:[Cronet getNetLogPathForFile:dir] | |
| 85 error:nil]; | |
| 86 | |
| 87 EXPECT_TRUE(dir_created); | |
| 88 EXPECT_TRUE(netlog_started); | |
| 89 } | |
| 90 | |
| 91 TEST(NetLogTest, EmptyFilename) { | |
| 92 bool netlog_started = [Cronet startNetLogToFile:@"" logBytes:NO]; | |
| 93 | |
| 94 EXPECT_FALSE(netlog_started); | |
| 95 } | |
| 96 | |
| 97 TEST(NetLogTest, AbsoluteFilename) { | |
| 98 bool netlog_started = | |
| 99 [Cronet startNetLogToFile:@"/home/netlog.json" logBytes:NO]; | |
| 100 | |
| 101 EXPECT_FALSE(netlog_started); | |
| 102 } | |
| 103 } | |
| OLD | NEW |