| 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 { [Cronet stopNetLog]; } |
| 20 }; | 22 }; |
| 21 | 23 |
| 22 TEST(NetLogTest, OpenFile) { | 24 TEST_F(NetLogTest, OpenFile) { |
| 23 bool netlog_started = | 25 bool netlog_started = |
| 24 [Cronet startNetLogToFile:@"cronet_netlog.json" logBytes:YES]; | 26 [Cronet startNetLogToFile:@"cronet_netlog.json" logBytes:YES]; |
| 25 [Cronet stopNetLog]; | |
| 26 | 27 |
| 27 EXPECT_TRUE(netlog_started); | 28 EXPECT_TRUE(netlog_started); |
| 28 } | 29 } |
| 29 | 30 |
| 30 TEST(NetLogTest, CreateFile) { | 31 TEST_F(NetLogTest, CreateFile) { |
| 31 NSString* filename = [[[NSProcessInfo processInfo] globallyUniqueString] | 32 NSString* filename = [[[NSProcessInfo processInfo] globallyUniqueString] |
| 32 stringByAppendingString:@"_netlog.json"]; | 33 stringByAppendingString:@"_netlog.json"]; |
| 33 bool netlog_started = [Cronet startNetLogToFile:filename logBytes:YES]; | 34 bool netlog_started = [Cronet startNetLogToFile:filename logBytes:YES]; |
| 34 [Cronet stopNetLog]; | |
| 35 | 35 |
| 36 bool file_created = [[NSFileManager defaultManager] | 36 bool file_created = [[NSFileManager defaultManager] |
| 37 fileExistsAtPath:[Cronet getNetLogPathForFile:filename]]; | 37 fileExistsAtPath:[Cronet getNetLogPathForFile:filename]]; |
| 38 | 38 |
| 39 [[NSFileManager defaultManager] | 39 [[NSFileManager defaultManager] |
| 40 removeItemAtPath:[Cronet getNetLogPathForFile:filename] | 40 removeItemAtPath:[Cronet getNetLogPathForFile:filename] |
| 41 error:nil]; | 41 error:nil]; |
| 42 | 42 |
| 43 EXPECT_TRUE(netlog_started); | 43 EXPECT_TRUE(netlog_started); |
| 44 EXPECT_TRUE(file_created); | 44 EXPECT_TRUE(file_created); |
| 45 } | 45 } |
| 46 | 46 |
| 47 TEST(NetLogTest, NonExistantDir) { | 47 TEST_F(NetLogTest, NonExistantDir) { |
| 48 NSString* notdir = [[[NSProcessInfo processInfo] globallyUniqueString] | 48 NSString* notdir = [[[NSProcessInfo processInfo] globallyUniqueString] |
| 49 stringByAppendingString:@"/netlog.json"]; | 49 stringByAppendingString:@"/netlog.json"]; |
| 50 bool netlog_started = [Cronet startNetLogToFile:notdir logBytes:NO]; | 50 bool netlog_started = [Cronet startNetLogToFile:notdir logBytes:NO]; |
| 51 | 51 |
| 52 EXPECT_FALSE(netlog_started); | 52 EXPECT_FALSE(netlog_started); |
| 53 } | 53 } |
| 54 | 54 |
| 55 TEST(NetLogTest, ExistantDir) { | 55 TEST_F(NetLogTest, ExistantDir) { |
| 56 NSString* dir = [[NSProcessInfo processInfo] globallyUniqueString]; | 56 NSString* dir = [[NSProcessInfo processInfo] globallyUniqueString]; |
| 57 | 57 |
| 58 bool dir_created = [[NSFileManager defaultManager] | 58 bool dir_created = [[NSFileManager defaultManager] |
| 59 createDirectoryAtPath:[Cronet getNetLogPathForFile:dir] | 59 createDirectoryAtPath:[Cronet getNetLogPathForFile:dir] |
| 60 withIntermediateDirectories:NO | 60 withIntermediateDirectories:NO |
| 61 attributes:nil | 61 attributes:nil |
| 62 error:nil]; | 62 error:nil]; |
| 63 | 63 |
| 64 bool netlog_started = | 64 bool netlog_started = |
| 65 [Cronet startNetLogToFile:[dir stringByAppendingString:@"/netlog.json"] | 65 [Cronet startNetLogToFile:[dir stringByAppendingString:@"/netlog.json"] |
| 66 logBytes:NO]; | 66 logBytes:NO]; |
| 67 | 67 |
| 68 [[NSFileManager defaultManager] | 68 [[NSFileManager defaultManager] |
| 69 removeItemAtPath:[Cronet | 69 removeItemAtPath:[Cronet |
| 70 getNetLogPathForFile: | 70 getNetLogPathForFile: |
| 71 [dir stringByAppendingString:@"/netlog.json"]] | 71 [dir stringByAppendingString:@"/netlog.json"]] |
| 72 error:nil]; | 72 error:nil]; |
| 73 | 73 |
| 74 [[NSFileManager defaultManager] | 74 [[NSFileManager defaultManager] |
| 75 removeItemAtPath:[Cronet getNetLogPathForFile:dir] | 75 removeItemAtPath:[Cronet getNetLogPathForFile:dir] |
| 76 error:nil]; | 76 error:nil]; |
| 77 | 77 |
| 78 EXPECT_TRUE(dir_created); | 78 EXPECT_TRUE(dir_created); |
| 79 EXPECT_TRUE(netlog_started); | 79 EXPECT_TRUE(netlog_started); |
| 80 } | 80 } |
| 81 | 81 |
| 82 TEST(NetLogTest, EmptyFilename) { | 82 TEST_F(NetLogTest, EmptyFilename) { |
| 83 bool netlog_started = [Cronet startNetLogToFile:@"" logBytes:NO]; | 83 bool netlog_started = [Cronet startNetLogToFile:@"" logBytes:NO]; |
| 84 | 84 |
| 85 EXPECT_FALSE(netlog_started); | 85 EXPECT_FALSE(netlog_started); |
| 86 } | 86 } |
| 87 | 87 |
| 88 TEST(NetLogTest, AbsoluteFilename) { | 88 TEST_F(NetLogTest, AbsoluteFilename) { |
| 89 bool netlog_started = | 89 bool netlog_started = |
| 90 [Cronet startNetLogToFile:@"/home/netlog.json" logBytes:NO]; | 90 [Cronet startNetLogToFile:@"/home/netlog.json" logBytes:NO]; |
| 91 | 91 |
| 92 EXPECT_FALSE(netlog_started); | 92 EXPECT_FALSE(netlog_started); |
| 93 } | 93 } |
| 94 } | 94 } |
| OLD | NEW |