| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 "components/navigation_metrics/navigation_metrics.h" | 5 #include "components/navigation_metrics/navigation_metrics.h" |
| 6 | 6 |
| 7 #include "base/test/histogram_tester.h" | 7 #include "base/test/histogram_tester.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 #include "url/gurl.h" | 9 #include "url/gurl.h" |
| 10 | 10 |
| 11 namespace { | 11 namespace { |
| 12 const char* const kTestUrl = "http://www.example.com"; | 12 const char* const kTestUrl = "http://www.example.com"; |
| 13 const char* const kMainFrameScheme = "Navigation.MainFrameScheme"; | 13 const char* const kMainFrameScheme = "Navigation.MainFrameScheme"; |
| 14 const char* const kMainFrameSchemeDifferentPage = | 14 const char* const kMainFrameSchemeDifferentPage = |
| 15 "Navigation.MainFrameSchemeDifferentPage"; | 15 "Navigation.MainFrameSchemeDifferentPage"; |
| 16 const char* const kMainFrameSchemeOTR = "Navigation.MainFrameSchemeOTR"; |
| 17 const char* const kMainFrameSchemeDifferentPageOTR = |
| 18 "Navigation.MainFrameSchemeDifferentPageOTR"; |
| 16 | 19 |
| 17 } // namespace | 20 } // namespace |
| 18 | 21 |
| 19 namespace navigation_metrics { | 22 namespace navigation_metrics { |
| 20 | 23 |
| 21 TEST(NavigationMetrics, MainFrameSchemeDifferentDocument) { | 24 TEST(NavigationMetrics, MainFrameSchemeDifferentDocument) { |
| 22 base::HistogramTester test; | 25 base::HistogramTester test; |
| 23 | 26 |
| 24 RecordMainFrameNavigation(GURL(kTestUrl), false, false); | 27 RecordMainFrameNavigation(GURL(kTestUrl), false, false); |
| 25 | 28 |
| 26 test.ExpectTotalCount(kMainFrameScheme, 1); | 29 test.ExpectTotalCount(kMainFrameScheme, 1); |
| 27 test.ExpectUniqueSample(kMainFrameScheme, 1 /* http */, 1); | 30 test.ExpectUniqueSample(kMainFrameScheme, 1 /* http */, 1); |
| 28 test.ExpectTotalCount(kMainFrameSchemeDifferentPage, 1); | 31 test.ExpectTotalCount(kMainFrameSchemeDifferentPage, 1); |
| 29 test.ExpectUniqueSample(kMainFrameSchemeDifferentPage, 1 /* http */, 1); | 32 test.ExpectUniqueSample(kMainFrameSchemeDifferentPage, 1 /* http */, 1); |
| 33 test.ExpectTotalCount(kMainFrameSchemeOTR, 0); |
| 34 test.ExpectTotalCount(kMainFrameSchemeDifferentPageOTR, 0); |
| 30 } | 35 } |
| 31 | 36 |
| 32 TEST(NavigationMetrics, MainFrameSchemeSameDocument) { | 37 TEST(NavigationMetrics, MainFrameSchemeSameDocument) { |
| 33 base::HistogramTester test; | 38 base::HistogramTester test; |
| 34 | 39 |
| 35 RecordMainFrameNavigation(GURL(kTestUrl), true, false); | 40 RecordMainFrameNavigation(GURL(kTestUrl), true, false); |
| 36 | 41 |
| 37 test.ExpectTotalCount(kMainFrameScheme, 1); | 42 test.ExpectTotalCount(kMainFrameScheme, 1); |
| 38 test.ExpectUniqueSample(kMainFrameScheme, 1 /* http */, 1); | 43 test.ExpectUniqueSample(kMainFrameScheme, 1 /* http */, 1); |
| 39 test.ExpectTotalCount(kMainFrameSchemeDifferentPage, 0); | 44 test.ExpectTotalCount(kMainFrameSchemeDifferentPage, 0); |
| 45 test.ExpectTotalCount(kMainFrameSchemeOTR, 0); |
| 46 test.ExpectTotalCount(kMainFrameSchemeDifferentPageOTR, 0); |
| 47 } |
| 48 |
| 49 TEST(NavigationMetrics, MainFrameSchemeDifferentDocumentOTR) { |
| 50 base::HistogramTester test; |
| 51 |
| 52 RecordMainFrameNavigation(GURL(kTestUrl), false, true); |
| 53 |
| 54 test.ExpectTotalCount(kMainFrameScheme, 1); |
| 55 test.ExpectUniqueSample(kMainFrameScheme, 1 /* http */, 1); |
| 56 test.ExpectTotalCount(kMainFrameSchemeDifferentPage, 1); |
| 57 test.ExpectUniqueSample(kMainFrameSchemeDifferentPage, 1 /* http */, 1); |
| 58 test.ExpectTotalCount(kMainFrameSchemeOTR, 1); |
| 59 test.ExpectUniqueSample(kMainFrameSchemeOTR, 1 /* http */, 1); |
| 60 test.ExpectTotalCount(kMainFrameSchemeDifferentPageOTR, 1); |
| 61 test.ExpectUniqueSample(kMainFrameSchemeDifferentPageOTR, 1 /* http */, 1); |
| 62 } |
| 63 |
| 64 TEST(NavigationMetrics, MainFrameSchemeSameDocumentOTR) { |
| 65 base::HistogramTester test; |
| 66 |
| 67 RecordMainFrameNavigation(GURL(kTestUrl), true, true); |
| 68 |
| 69 test.ExpectTotalCount(kMainFrameScheme, 1); |
| 70 test.ExpectUniqueSample(kMainFrameScheme, 1 /* http */, 1); |
| 71 test.ExpectTotalCount(kMainFrameSchemeDifferentPage, 0); |
| 72 test.ExpectTotalCount(kMainFrameSchemeOTR, 1); |
| 73 test.ExpectUniqueSample(kMainFrameSchemeOTR, 1 /* http */, 1); |
| 74 test.ExpectTotalCount(kMainFrameSchemeDifferentPageOTR, 0); |
| 40 } | 75 } |
| 41 | 76 |
| 42 } // namespace navigation_metrics | 77 } // namespace navigation_metrics |
| OLD | NEW |