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 "chrome/browser/metrics/rappor/sampling.h" | 5 #include "chrome/browser/metrics/rappor/sampling.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "url/gurl.h" | 8 #include "url/gurl.h" |
9 | 9 |
10 namespace rappor { | 10 namespace rappor { |
11 | 11 |
12 // Test that extracting the sample works correctly for different schemes. | 12 // Test that extracting the sample works correctly for different schemes. |
13 TEST(RapporSamplingTest, GetDomainAndRegistrySampleFromGURLTest) { | 13 TEST(RapporSamplingTest, GetDomainAndRegistrySampleFromGURLTest) { |
14 EXPECT_EQ("google.com", GetDomainAndRegistrySampleFromGURL( | 14 EXPECT_EQ("google.com", GetDomainAndRegistrySampleFromGURL( |
15 GURL("https://www.GoOgLe.com:80/blah"))); | 15 GURL("https://www.GoOgLe.com:80/blah"))); |
16 EXPECT_EQ("file://", GetDomainAndRegistrySampleFromGURL( | 16 EXPECT_EQ("file://", GetDomainAndRegistrySampleFromGURL( |
17 GURL("file://foo/bar/baz"))); | 17 GURL("file://foo/bar/baz"))); |
18 EXPECT_EQ("chrome-extension://abc1234", GetDomainAndRegistrySampleFromGURL( | 18 EXPECT_EQ("chrome-extension://abc1234", GetDomainAndRegistrySampleFromGURL( |
19 GURL("chrome-extension://abc1234/foo.html"))); | 19 GURL("chrome-extension://abc1234/foo.html"))); |
20 EXPECT_EQ("chrome-search://local-ntp", GetDomainAndRegistrySampleFromGURL( | 20 EXPECT_EQ("chrome-search://local-ntp", GetDomainAndRegistrySampleFromGURL( |
21 GURL("chrome-search://local-ntp/local-ntp.html"))); | 21 GURL("chrome-search://local-ntp/local-ntp.html"))); |
| 22 EXPECT_EQ("localhost", GetDomainAndRegistrySampleFromGURL( |
| 23 GURL("http://localhost:8000/foo.html"))); |
| 24 EXPECT_EQ("localhost", GetDomainAndRegistrySampleFromGURL( |
| 25 GURL("http://127.0.0.1/foo.html"))); |
| 26 EXPECT_EQ("ip_address", GetDomainAndRegistrySampleFromGURL( |
| 27 GURL("http://192.168.0.1/foo.html"))); |
| 28 EXPECT_EQ("ip_address", GetDomainAndRegistrySampleFromGURL( |
| 29 GURL("http://[2001:db8::1]/"))); |
| 30 EXPECT_EQ("", GetDomainAndRegistrySampleFromGURL( |
| 31 GURL("http://www/"))); |
| 32 EXPECT_EQ("www.corp", GetDomainAndRegistrySampleFromGURL( |
| 33 GURL("http://www.corp/"))); |
22 } | 34 } |
23 | 35 |
24 // Make sure recording a sample during tests, when the Rappor service is NULL, | 36 // Make sure recording a sample during tests, when the Rappor service is NULL, |
25 // doesn't cause a crash. | 37 // doesn't cause a crash. |
26 TEST(RapporSamplingTest, SmokeTest) { | 38 TEST(RapporSamplingTest, SmokeTest) { |
27 SampleDomainAndRegistryFromGURL(std::string(), GURL()); | 39 SampleDomainAndRegistryFromGURL(std::string(), GURL()); |
28 } | 40 } |
29 | 41 |
30 } // namespace rappor | 42 } // namespace rappor |
OLD | NEW |