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