navigation_metrics_unittest.cc 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. #include "components/navigation_metrics/navigation_metrics.h"
  5. #include "base/test/metrics/histogram_tester.h"
  6. #include "components/profile_metrics/browser_profile_type.h"
  7. #include "testing/gtest/include/gtest/gtest.h"
  8. #include "url/gurl.h"
  9. namespace {
  10. const char* const kTestUrl = "http://www.example.com";
  11. // http://ab.גדהוזח.ij/kl/mn/op.html in A-label form.
  12. constexpr char kRtlUrl[] = "http://ab.xn--6dbcdefg.ij/kl/mn/op.html";
  13. } // namespace
  14. namespace navigation_metrics {
  15. TEST(NavigationMetrics, MainFrameSchemeDifferentDocument) {
  16. base::HistogramTester test;
  17. RecordPrimaryMainFrameNavigation(
  18. GURL(kTestUrl), false, false,
  19. profile_metrics::BrowserProfileType::kRegular);
  20. test.ExpectTotalCount(kMainFrameScheme, 1);
  21. test.ExpectUniqueSample(kMainFrameScheme, 1 /* http */, 1);
  22. test.ExpectTotalCount(kMainFrameSchemeDifferentPage, 1);
  23. test.ExpectUniqueSample(kMainFrameSchemeDifferentPage, 1 /* http */, 1);
  24. test.ExpectTotalCount(kMainFrameSchemeOTR, 0);
  25. test.ExpectTotalCount(kMainFrameSchemeDifferentPageOTR, 0);
  26. test.ExpectTotalCount(kMainFrameProfileType, 1);
  27. test.ExpectUniqueSample(kMainFrameProfileType,
  28. profile_metrics::BrowserProfileType::kRegular, 1);
  29. }
  30. TEST(NavigationMetrics, MainFrameSchemeSameDocument) {
  31. base::HistogramTester test;
  32. RecordPrimaryMainFrameNavigation(
  33. GURL(kTestUrl), true, false,
  34. profile_metrics::BrowserProfileType::kRegular);
  35. test.ExpectTotalCount(kMainFrameScheme, 1);
  36. test.ExpectUniqueSample(kMainFrameScheme, 1 /* http */, 1);
  37. test.ExpectTotalCount(kMainFrameSchemeDifferentPage, 0);
  38. test.ExpectTotalCount(kMainFrameSchemeOTR, 0);
  39. test.ExpectTotalCount(kMainFrameSchemeDifferentPageOTR, 0);
  40. test.ExpectTotalCount(kMainFrameProfileType, 1);
  41. test.ExpectUniqueSample(kMainFrameProfileType,
  42. profile_metrics::BrowserProfileType::kRegular, 1);
  43. }
  44. TEST(NavigationMetrics, MainFrameSchemeDifferentDocumentOTR) {
  45. base::HistogramTester test;
  46. RecordPrimaryMainFrameNavigation(
  47. GURL(kTestUrl), false, true,
  48. profile_metrics::BrowserProfileType::kIncognito);
  49. test.ExpectTotalCount(kMainFrameScheme, 1);
  50. test.ExpectUniqueSample(kMainFrameScheme, 1 /* http */, 1);
  51. test.ExpectTotalCount(kMainFrameSchemeDifferentPage, 1);
  52. test.ExpectUniqueSample(kMainFrameSchemeDifferentPage, 1 /* http */, 1);
  53. test.ExpectTotalCount(kMainFrameSchemeOTR, 1);
  54. test.ExpectUniqueSample(kMainFrameSchemeOTR, 1 /* http */, 1);
  55. test.ExpectTotalCount(kMainFrameSchemeDifferentPageOTR, 1);
  56. test.ExpectUniqueSample(kMainFrameSchemeDifferentPageOTR, 1 /* http */, 1);
  57. test.ExpectTotalCount(kMainFrameProfileType, 1);
  58. test.ExpectUniqueSample(kMainFrameProfileType,
  59. profile_metrics::BrowserProfileType::kIncognito, 1);
  60. }
  61. TEST(NavigationMetrics, MainFrameSchemeSameDocumentOTR) {
  62. base::HistogramTester test;
  63. RecordPrimaryMainFrameNavigation(
  64. GURL(kTestUrl), true, true,
  65. profile_metrics::BrowserProfileType::kIncognito);
  66. test.ExpectTotalCount(kMainFrameScheme, 1);
  67. test.ExpectUniqueSample(kMainFrameScheme, 1 /* http */, 1);
  68. test.ExpectTotalCount(kMainFrameSchemeDifferentPage, 0);
  69. test.ExpectTotalCount(kMainFrameSchemeOTR, 1);
  70. test.ExpectUniqueSample(kMainFrameSchemeOTR, 1 /* http */, 1);
  71. test.ExpectTotalCount(kMainFrameSchemeDifferentPageOTR, 0);
  72. test.ExpectTotalCount(kMainFrameProfileType, 1);
  73. test.ExpectUniqueSample(kMainFrameProfileType,
  74. profile_metrics::BrowserProfileType::kIncognito, 1);
  75. }
  76. TEST(NavigationMetrics, MainFrameDifferentDocumentHasRTLDomainFalse) {
  77. base::HistogramTester test;
  78. RecordPrimaryMainFrameNavigation(
  79. GURL(kTestUrl), false, false,
  80. profile_metrics::BrowserProfileType::kRegular);
  81. test.ExpectTotalCount(kMainFrameHasRTLDomainDifferentPage, 1);
  82. test.ExpectTotalCount(kMainFrameHasRTLDomain, 1);
  83. test.ExpectUniqueSample(kMainFrameHasRTLDomainDifferentPage, 0 /* false */,
  84. 1);
  85. test.ExpectUniqueSample(kMainFrameHasRTLDomain, 0 /* false */, 1);
  86. }
  87. TEST(NavigationMetrics, MainFrameDifferentDocumentHasRTLDomainTrue) {
  88. base::HistogramTester test;
  89. RecordPrimaryMainFrameNavigation(
  90. GURL(kRtlUrl), false, false,
  91. profile_metrics::BrowserProfileType::kRegular);
  92. test.ExpectTotalCount(kMainFrameHasRTLDomainDifferentPage, 1);
  93. test.ExpectTotalCount(kMainFrameHasRTLDomain, 1);
  94. test.ExpectUniqueSample(kMainFrameHasRTLDomainDifferentPage, 1 /* true */, 1);
  95. test.ExpectUniqueSample(kMainFrameHasRTLDomain, 1 /* true */, 1);
  96. }
  97. TEST(NavigationMetrics, MainFrameSameDocumentHasRTLDomainFalse) {
  98. base::HistogramTester test;
  99. RecordPrimaryMainFrameNavigation(
  100. GURL(kTestUrl), true, false,
  101. profile_metrics::BrowserProfileType::kRegular);
  102. test.ExpectTotalCount(kMainFrameHasRTLDomainDifferentPage, 0);
  103. test.ExpectTotalCount(kMainFrameHasRTLDomain, 1);
  104. test.ExpectUniqueSample(kMainFrameHasRTLDomain, 0 /* false */, 1);
  105. }
  106. TEST(NavigationMetrics, MainFrameSameDocumentHasRTLDomainTrue) {
  107. base::HistogramTester test;
  108. RecordPrimaryMainFrameNavigation(
  109. GURL(kRtlUrl), true, false,
  110. profile_metrics::BrowserProfileType::kRegular);
  111. test.ExpectTotalCount(kMainFrameHasRTLDomainDifferentPage, 0);
  112. test.ExpectTotalCount(kMainFrameHasRTLDomain, 1);
  113. test.ExpectUniqueSample(kMainFrameHasRTLDomain, 1 /* true */, 1);
  114. }
  115. } // namespace navigation_metrics