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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/page_load_metrics/page_load_metrics_util_unittest.cc
diff --git a/chrome/browser/page_load_metrics/page_load_metrics_util_unittest.cc b/chrome/browser/page_load_metrics/page_load_metrics_util_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6704311a1b6327a92fd8f6ebc418a75a8c8e2143
--- /dev/null
+++ b/chrome/browser/page_load_metrics/page_load_metrics_util_unittest.cc
@@ -0,0 +1,80 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/page_load_metrics/page_load_metrics_util.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+#include "url/gurl.h"
+
+class PageLoadMetricsUtilTest : public testing::Test {};
+
+TEST_F(PageLoadMetricsUtilTest, IsGoogleHostname) {
+ struct {
+ bool expected_result;
+ const char* url;
+ } test_cases[] = {
+ {true, "https://google.com/"},
+ {true, "https://google.com/index.html"},
+ {true, "https://www.google.com/"},
+ {true, "https://www.google.com/search"},
+ {true, "https://www.google.com/a/b/c/d"},
+ {true, "https://www.google.co.uk/"},
+ {true, "https://www.google.co.in/"},
+ {true, "https://other.google.com/"},
+ {true, "https://other.www.google.com/"},
+ {true, "https://www.other.google.com/"},
+ {true, "https://www.www.google.com/"},
+ {false, ""},
+ {false, "a"},
+ {false, "*"},
+ {false, "com"},
+ {false, "co.uk"},
+ {false, "google"},
+ {false, "google.com"},
+ {false, "www.google.com"},
+ {false, "https:///"},
+ {false, "https://a/"},
+ {false, "https://*/"},
+ {false, "https://com/"},
+ {false, "https://co.uk/"},
+ {false, "https://google/"},
+ {false, "https://*.com/"},
+ {false, "https://www.*.com/"},
+ {false, "https://www.google.appspot.com/"},
+ {false, "https://www.google.example.com/"},
+ };
+ for (const auto& test : test_cases) {
+ EXPECT_EQ(test.expected_result,
+ page_load_metrics::IsGoogleHostname(GURL(test.url)))
+ << "For URL: " << test.url;
+ }
+}
+
+TEST_F(PageLoadMetricsUtilTest, GetGoogleHostnamePrefix) {
+ struct {
+ bool expected_result;
+ const char* expected_prefix;
+ const char* url;
+ } test_cases[] = {
+ {false, "", "https://example.com/"},
+ {true, "", "https://google.com/"},
+ {true, "www", "https://www.google.com/"},
+ {true, "news", "https://news.google.com/"},
+ {true, "www", "https://www.google.co.uk/"},
+ {true, "other", "https://other.google.com/"},
+ {true, "other.www", "https://other.www.google.com/"},
+ {true, "www.other", "https://www.other.google.com/"},
+ {true, "www.www", "https://www.www.google.com/"},
+ };
+ for (const auto& test : test_cases) {
+ base::Optional<std::string> result =
+ page_load_metrics::GetGoogleHostnamePrefix(GURL(test.url));
+ EXPECT_EQ(test.expected_result, result.has_value())
+ << "For URL: " << test.url;
+ if (result) {
+ EXPECT_EQ(test.expected_prefix, result.value())
+ << "Prefix for URL: " << test.url;
+ }
+ }
+}
« 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