Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: components/cronet/ios/test/cronet_netlog_test.mm

Issue 2836063005: [cronet] Add mechanism for restarting CronetEnvironment (Closed)
Patch Set: per #21 Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
12 @interface Cronet (ExposedForTesting)
13 + (void)shutdownForTesting;
14 @end
15
10 namespace cronet { 16 namespace cronet {
11 17
12 void StartCronetIfNecessary();
13
14 class NetLogTest : public ::testing::Test { 18 class NetLogTest : public ::testing::Test {
15 protected: 19 protected:
16 NetLogTest() {} 20 NetLogTest() {}
17 ~NetLogTest() override {} 21 ~NetLogTest() override {}
18 22
19 void SetUp() override { StartCronetIfNecessary(); } 23 void SetUp() override { StartCronet(grpc_support::GetQuicTestServerPort()); }
24
25 void TearDown() override {
26 [Cronet stopNetLog];
27 [Cronet shutdownForTesting];
28 }
20 }; 29 };
21 30
22 TEST(NetLogTest, OpenFile) { 31 TEST_F(NetLogTest, OpenFile) {
23 bool netlog_started = 32 bool netlog_started =
24 [Cronet startNetLogToFile:@"cronet_netlog.json" logBytes:YES]; 33 [Cronet startNetLogToFile:@"cronet_netlog.json" logBytes:YES];
25 [Cronet stopNetLog];
26 34
27 EXPECT_TRUE(netlog_started); 35 EXPECT_TRUE(netlog_started);
28 } 36 }
29 37
30 TEST(NetLogTest, CreateFile) { 38 TEST_F(NetLogTest, CreateFile) {
31 NSString* filename = [[[NSProcessInfo processInfo] globallyUniqueString] 39 NSString* filename = [[[NSProcessInfo processInfo] globallyUniqueString]
32 stringByAppendingString:@"_netlog.json"]; 40 stringByAppendingString:@"_netlog.json"];
33 bool netlog_started = [Cronet startNetLogToFile:filename logBytes:YES]; 41 bool netlog_started = [Cronet startNetLogToFile:filename logBytes:YES];
34 [Cronet stopNetLog];
35 42
36 bool file_created = [[NSFileManager defaultManager] 43 bool file_created = [[NSFileManager defaultManager]
37 fileExistsAtPath:[Cronet getNetLogPathForFile:filename]]; 44 fileExistsAtPath:[Cronet getNetLogPathForFile:filename]];
38 45
39 [[NSFileManager defaultManager] 46 [[NSFileManager defaultManager]
40 removeItemAtPath:[Cronet getNetLogPathForFile:filename] 47 removeItemAtPath:[Cronet getNetLogPathForFile:filename]
41 error:nil]; 48 error:nil];
42 49
43 EXPECT_TRUE(netlog_started); 50 EXPECT_TRUE(netlog_started);
44 EXPECT_TRUE(file_created); 51 EXPECT_TRUE(file_created);
45 } 52 }
46 53
47 TEST(NetLogTest, NonExistantDir) { 54 TEST_F(NetLogTest, NonExistantDir) {
48 NSString* notdir = [[[NSProcessInfo processInfo] globallyUniqueString] 55 NSString* notdir = [[[NSProcessInfo processInfo] globallyUniqueString]
49 stringByAppendingString:@"/netlog.json"]; 56 stringByAppendingString:@"/netlog.json"];
50 bool netlog_started = [Cronet startNetLogToFile:notdir logBytes:NO]; 57 bool netlog_started = [Cronet startNetLogToFile:notdir logBytes:NO];
51 58
52 EXPECT_FALSE(netlog_started); 59 EXPECT_FALSE(netlog_started);
53 } 60 }
54 61
55 TEST(NetLogTest, ExistantDir) { 62 TEST_F(NetLogTest, ExistantDir) {
56 NSString* dir = [[NSProcessInfo processInfo] globallyUniqueString]; 63 NSString* dir = [[NSProcessInfo processInfo] globallyUniqueString];
57 64
58 bool dir_created = [[NSFileManager defaultManager] 65 bool dir_created = [[NSFileManager defaultManager]
59 createDirectoryAtPath:[Cronet getNetLogPathForFile:dir] 66 createDirectoryAtPath:[Cronet getNetLogPathForFile:dir]
60 withIntermediateDirectories:NO 67 withIntermediateDirectories:NO
61 attributes:nil 68 attributes:nil
62 error:nil]; 69 error:nil];
63 70
64 bool netlog_started = 71 bool netlog_started =
65 [Cronet startNetLogToFile:[dir stringByAppendingString:@"/netlog.json"] 72 [Cronet startNetLogToFile:[dir stringByAppendingString:@"/netlog.json"]
66 logBytes:NO]; 73 logBytes:NO];
67 74
68 [[NSFileManager defaultManager] 75 [[NSFileManager defaultManager]
69 removeItemAtPath:[Cronet 76 removeItemAtPath:[Cronet
70 getNetLogPathForFile: 77 getNetLogPathForFile:
71 [dir stringByAppendingString:@"/netlog.json"]] 78 [dir stringByAppendingString:@"/netlog.json"]]
72 error:nil]; 79 error:nil];
73 80
74 [[NSFileManager defaultManager] 81 [[NSFileManager defaultManager]
75 removeItemAtPath:[Cronet getNetLogPathForFile:dir] 82 removeItemAtPath:[Cronet getNetLogPathForFile:dir]
76 error:nil]; 83 error:nil];
77 84
78 EXPECT_TRUE(dir_created); 85 EXPECT_TRUE(dir_created);
79 EXPECT_TRUE(netlog_started); 86 EXPECT_TRUE(netlog_started);
80 } 87 }
81 88
82 TEST(NetLogTest, EmptyFilename) { 89 TEST_F(NetLogTest, EmptyFilename) {
83 bool netlog_started = [Cronet startNetLogToFile:@"" logBytes:NO]; 90 bool netlog_started = [Cronet startNetLogToFile:@"" logBytes:NO];
84 91
85 EXPECT_FALSE(netlog_started); 92 EXPECT_FALSE(netlog_started);
86 } 93 }
87 94
88 TEST(NetLogTest, AbsoluteFilename) { 95 TEST_F(NetLogTest, AbsoluteFilename) {
89 bool netlog_started = 96 bool netlog_started =
90 [Cronet startNetLogToFile:@"/home/netlog.json" logBytes:NO]; 97 [Cronet startNetLogToFile:@"/home/netlog.json" logBytes:NO];
91 98
92 EXPECT_FALSE(netlog_started); 99 EXPECT_FALSE(netlog_started);
93 } 100 }
94 } 101 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698