OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "components/domain_reliability/config.h" | 5 #include "components/domain_reliability/config.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/ptr_util.h" | |
10 #include "base/time/time.h" | 11 #include "base/time/time.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
12 | 13 |
13 namespace domain_reliability { | 14 namespace domain_reliability { |
14 namespace { | 15 namespace { |
15 | 16 |
16 std::unique_ptr<DomainReliabilityConfig> MakeBaseConfig() { | 17 std::unique_ptr<DomainReliabilityConfig> MakeBaseConfig() { |
17 DomainReliabilityConfig* config = new DomainReliabilityConfig(); | 18 DomainReliabilityConfig* config = new DomainReliabilityConfig(); |
18 config->origin = GURL("https://example/"); | 19 config->origin = GURL("https://example/"); |
19 config->include_subdomains = false; | 20 config->include_subdomains = false; |
20 config->collectors.push_back(new GURL("https://example/upload")); | 21 config->collectors.push_back( |
22 base::MakeUnique<GURL>("https://example/upload")); | |
21 config->failure_sample_rate = 1.0; | 23 config->failure_sample_rate = 1.0; |
22 config->success_sample_rate = 0.0; | 24 config->success_sample_rate = 0.0; |
23 EXPECT_TRUE(config->IsValid()); | 25 EXPECT_TRUE(config->IsValid()); |
24 return std::unique_ptr<DomainReliabilityConfig>(config); | 26 return std::unique_ptr<DomainReliabilityConfig>(config); |
25 } | 27 } |
26 | 28 |
27 std::unique_ptr<DomainReliabilityConfig> MakeSampleConfig() { | 29 std::unique_ptr<DomainReliabilityConfig> MakeSampleConfig() { |
28 std::unique_ptr<DomainReliabilityConfig> config(MakeBaseConfig()); | 30 std::unique_ptr<DomainReliabilityConfig> config(MakeBaseConfig()); |
29 config->path_prefixes.push_back(new std::string("/css/")); | 31 config->path_prefixes.push_back(base::MakeUnique<std::string>("/css/")); |
30 config->path_prefixes.push_back(new std::string("/js/")); | 32 config->path_prefixes.push_back(base::MakeUnique<std::string>("/js/")); |
31 EXPECT_TRUE(config->IsValid()); | 33 EXPECT_TRUE(config->IsValid()); |
32 return config; | 34 return config; |
33 } | 35 } |
34 | 36 |
35 class DomainReliabilityConfigTest : public testing::Test { }; | 37 class DomainReliabilityConfigTest : public testing::Test { }; |
36 | 38 |
37 TEST_F(DomainReliabilityConfigTest, IsValid) { | 39 TEST_F(DomainReliabilityConfigTest, IsValid) { |
38 std::unique_ptr<DomainReliabilityConfig> config; | 40 std::unique_ptr<DomainReliabilityConfig> config; |
39 | 41 |
40 config = MakeSampleConfig(); | 42 config = MakeSampleConfig(); |
41 EXPECT_TRUE(config->IsValid()); | 43 EXPECT_TRUE(config->IsValid()); |
42 | 44 |
43 config = MakeSampleConfig(); | 45 config = MakeSampleConfig(); |
44 config->origin = GURL(); | 46 config->origin = GURL(); |
45 EXPECT_FALSE(config->IsValid()); | 47 EXPECT_FALSE(config->IsValid()); |
46 | 48 |
47 config = MakeSampleConfig(); | 49 config = MakeSampleConfig(); |
48 config->collectors.clear(); | 50 config->collectors.clear(); |
49 EXPECT_FALSE(config->IsValid()); | 51 EXPECT_FALSE(config->IsValid()); |
50 | 52 |
51 config = MakeSampleConfig(); | 53 config = MakeSampleConfig(); |
52 delete config->collectors[0]; | 54 config->collectors[0].reset(new GURL()); |
Avi (use Gerrit)
2017/01/09 17:18:29
Why not
config->collectors[0] = base::MakeUnique<
leonhsl(Using Gerrit)
2017/01/10 04:39:36
Done.
| |
53 config->collectors[0] = new GURL(); | |
54 EXPECT_FALSE(config->IsValid()); | 55 EXPECT_FALSE(config->IsValid()); |
55 | 56 |
56 config = MakeSampleConfig(); | 57 config = MakeSampleConfig(); |
57 config->failure_sample_rate = 2.0; | 58 config->failure_sample_rate = 2.0; |
58 EXPECT_FALSE(config->IsValid()); | 59 EXPECT_FALSE(config->IsValid()); |
59 | 60 |
60 config = MakeSampleConfig(); | 61 config = MakeSampleConfig(); |
61 config->success_sample_rate = 2.0; | 62 config->success_sample_rate = 2.0; |
62 EXPECT_FALSE(config->IsValid()); | 63 EXPECT_FALSE(config->IsValid()); |
63 } | 64 } |
(...skipping 21 matching lines...) Expand all Loading... | |
85 EXPECT_EQ(GURL("https://example/upload"), *config->collectors[0]); | 86 EXPECT_EQ(GURL("https://example/upload"), *config->collectors[0]); |
86 EXPECT_EQ(2u, config->path_prefixes.size()); | 87 EXPECT_EQ(2u, config->path_prefixes.size()); |
87 EXPECT_EQ("/css/", *config->path_prefixes[0]); | 88 EXPECT_EQ("/css/", *config->path_prefixes[0]); |
88 EXPECT_EQ("/js/", *config->path_prefixes[1]); | 89 EXPECT_EQ("/js/", *config->path_prefixes[1]); |
89 EXPECT_EQ(0.10, config->failure_sample_rate); | 90 EXPECT_EQ(0.10, config->failure_sample_rate); |
90 EXPECT_EQ(0.01, config->success_sample_rate); | 91 EXPECT_EQ(0.01, config->success_sample_rate); |
91 } | 92 } |
92 | 93 |
93 } // namespace | 94 } // namespace |
94 } // namespace domain_reliability | 95 } // namespace domain_reliability |
OLD | NEW |