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

Side by Side Diff: chrome/browser/page_load_metrics/page_load_metrics_util_unittest.cc

Issue 2880323003: Various cleaups for AMP page load metrics. (Closed)
Patch Set: address comment 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
« no previous file with comments | « chrome/browser/page_load_metrics/page_load_metrics_util.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/page_load_metrics/page_load_metrics_util.h"
6
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "url/gurl.h"
9
10 class PageLoadMetricsUtilTest : public testing::Test {};
11
12 TEST_F(PageLoadMetricsUtilTest, IsGoogleHostname) {
13 struct {
14 bool expected_result;
15 const char* url;
16 } test_cases[] = {
17 {true, "https://google.com/"},
18 {true, "https://google.com/index.html"},
19 {true, "https://www.google.com/"},
20 {true, "https://www.google.com/search"},
21 {true, "https://www.google.com/a/b/c/d"},
22 {true, "https://www.google.co.uk/"},
23 {true, "https://www.google.co.in/"},
24 {true, "https://other.google.com/"},
25 {true, "https://other.www.google.com/"},
26 {true, "https://www.other.google.com/"},
27 {true, "https://www.www.google.com/"},
28 {false, ""},
29 {false, "a"},
30 {false, "*"},
31 {false, "com"},
32 {false, "co.uk"},
33 {false, "google"},
34 {false, "google.com"},
35 {false, "www.google.com"},
36 {false, "https:///"},
37 {false, "https://a/"},
38 {false, "https://*/"},
39 {false, "https://com/"},
40 {false, "https://co.uk/"},
41 {false, "https://google/"},
42 {false, "https://*.com/"},
43 {false, "https://www.*.com/"},
44 {false, "https://www.google.appspot.com/"},
45 {false, "https://www.google.example.com/"},
46 };
47 for (const auto& test : test_cases) {
48 EXPECT_EQ(test.expected_result,
49 page_load_metrics::IsGoogleHostname(GURL(test.url)))
50 << "For URL: " << test.url;
51 }
52 }
53
54 TEST_F(PageLoadMetricsUtilTest, GetGoogleHostnamePrefix) {
55 struct {
56 bool expected_result;
57 const char* expected_prefix;
58 const char* url;
59 } test_cases[] = {
60 {false, "", "https://example.com/"},
61 {true, "", "https://google.com/"},
62 {true, "www", "https://www.google.com/"},
63 {true, "news", "https://news.google.com/"},
64 {true, "www", "https://www.google.co.uk/"},
65 {true, "other", "https://other.google.com/"},
66 {true, "other.www", "https://other.www.google.com/"},
67 {true, "www.other", "https://www.other.google.com/"},
68 {true, "www.www", "https://www.www.google.com/"},
69 };
70 for (const auto& test : test_cases) {
71 base::Optional<std::string> result =
72 page_load_metrics::GetGoogleHostnamePrefix(GURL(test.url));
73 EXPECT_EQ(test.expected_result, result.has_value())
74 << "For URL: " << test.url;
75 if (result) {
76 EXPECT_EQ(test.expected_prefix, result.value())
77 << "Prefix for URL: " << test.url;
78 }
79 }
80 }
OLDNEW
« no previous file with comments | « chrome/browser/page_load_metrics/page_load_metrics_util.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698