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

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: improve tests 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
(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, IsGoogleHostnameAndGetPrefix) {
55 struct {
56 bool expected_result;
57 const char* expected_prefx;
58 const char* url;
59 } test_cases[] = {
60 {true, "", "https://google.com/"},
61 {true, "www", "https://www.google.com/"},
62 {true, "news", "https://news.google.com/"},
63 {true, "www", "https://www.google.co.uk/"},
64 {true, "other", "https://other.google.com/"},
65 {true, "other.www", "https://other.www.google.com/"},
66 {true, "www.other", "https://www.other.google.com/"},
67 {true, "www.www", "https://www.www.google.com/"},
68 };
69 for (const auto& test : test_cases) {
70 base::StringPiece prefix;
71 EXPECT_EQ(test.expected_result,
72 page_load_metrics::IsGoogleHostnameAndGetPrefix(GURL(test.url),
73 &prefix))
74 << "For URL: " << test.url;
75 if (test.expected_result) {
76 EXPECT_EQ(test.expected_prefx, prefix) << "Prefix for URL: " << test.url;
77 }
78 }
79 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698