Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "content/browser/service_worker/service_worker_metrics.h" | |
| 6 | |
| 7 #include "base/test/histogram_tester.h" | |
| 8 #include "content/browser/service_worker/embedded_worker_status.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 | |
| 11 namespace content { | |
| 12 | |
| 13 namespace { | |
| 14 const std::string kNavigationPreloadSuffix = "_NavigationPreloadEnabled"; | |
| 15 const std::string kStartWorkerExistingProcessSuffix = | |
| 16 "_StartWorkerExistingProcess"; | |
| 17 const std::string kPreparationTime = | |
| 18 "ServiceWorker.ActivatedWorkerPreparationForMainFrame.Time"; | |
| 19 const std::string kPreparationType = | |
| 20 "ServiceWorker.ActivatedWorkerPreparationForMainFrame.Type"; | |
| 21 } | |
|
horo
2017/01/18 12:26:41
} // namespace
falken
2017/01/18 15:02:33
Done.
| |
| 22 | |
| 23 TEST(ServiceWorkerMetricsTest, ActivatedWorkerPreparation) { | |
| 24 base::TimeDelta time = base::TimeDelta::FromMilliseconds(123); | |
| 25 { | |
| 26 // Test preparation when the worker was STARTING. | |
| 27 base::HistogramTester histogram_tester; | |
| 28 ServiceWorkerMetrics::RecordActivatedWorkerPreparationForMainFrame( | |
| 29 time, EmbeddedWorkerStatus::STARTING, | |
| 30 ServiceWorkerMetrics::StartSituation::UNKNOWN, | |
| 31 false /* did_navigation_preload */); | |
| 32 histogram_tester.ExpectUniqueSample( | |
| 33 kPreparationType, | |
| 34 static_cast<int>(ServiceWorkerMetrics::WorkerPreparationType::STARTING), | |
| 35 1); | |
| 36 histogram_tester.ExpectTotalCount( | |
| 37 kPreparationType + kNavigationPreloadSuffix, 0); | |
| 38 histogram_tester.ExpectTimeBucketCount(kPreparationTime, time, 1); | |
| 39 histogram_tester.ExpectTimeBucketCount(kPreparationTime + "_StartingWorker", | |
| 40 time, 1); | |
| 41 histogram_tester.ExpectTotalCount( | |
| 42 kPreparationTime + kNavigationPreloadSuffix, 0); | |
| 43 } | |
| 44 | |
| 45 { | |
| 46 // Test preparation when the worker started up during startup. | |
| 47 base::HistogramTester histogram_tester; | |
| 48 ServiceWorkerMetrics::RecordActivatedWorkerPreparationForMainFrame( | |
| 49 time, EmbeddedWorkerStatus::STOPPED, | |
| 50 ServiceWorkerMetrics::StartSituation::DURING_STARTUP, | |
| 51 true /* did_navigation_preload */); | |
| 52 histogram_tester.ExpectUniqueSample( | |
| 53 kPreparationType, | |
| 54 static_cast<int>( | |
| 55 ServiceWorkerMetrics::WorkerPreparationType::START_DURING_STARTUP), | |
| 56 1); | |
| 57 histogram_tester.ExpectUniqueSample( | |
| 58 kPreparationType + kNavigationPreloadSuffix, | |
| 59 static_cast<int>( | |
| 60 ServiceWorkerMetrics::WorkerPreparationType::START_DURING_STARTUP), | |
| 61 1); | |
| 62 histogram_tester.ExpectTimeBucketCount(kPreparationTime, time, 1); | |
| 63 histogram_tester.ExpectTimeBucketCount( | |
| 64 kPreparationTime + kNavigationPreloadSuffix, time, 1); | |
| 65 histogram_tester.ExpectTotalCount(kPreparationTime + | |
| 66 kStartWorkerExistingProcessSuffix + | |
| 67 kNavigationPreloadSuffix, | |
| 68 0); | |
| 69 } | |
|
horo
2017/01/18 12:26:41
Please check this:
histogram_tester.ExpectTot
falken
2017/01/18 15:02:33
Done.
| |
| 70 | |
| 71 { | |
| 72 // Test preparation when the worker started up in an existing process. | |
| 73 base::HistogramTester histogram_tester; | |
| 74 ServiceWorkerMetrics::RecordActivatedWorkerPreparationForMainFrame( | |
| 75 time, EmbeddedWorkerStatus::STOPPED, | |
| 76 ServiceWorkerMetrics::StartSituation::EXISTING_PROCESS, | |
| 77 true /* did_navigation_preload */); | |
| 78 histogram_tester.ExpectUniqueSample( | |
| 79 kPreparationType, | |
| 80 static_cast<int>(ServiceWorkerMetrics::WorkerPreparationType:: | |
| 81 START_IN_EXISTING_PROCESS), | |
| 82 1); | |
| 83 histogram_tester.ExpectUniqueSample( | |
| 84 kPreparationType + kNavigationPreloadSuffix, | |
| 85 static_cast<int>(ServiceWorkerMetrics::WorkerPreparationType:: | |
| 86 START_IN_EXISTING_PROCESS), | |
| 87 1); | |
| 88 histogram_tester.ExpectTimeBucketCount(kPreparationTime, time, 1); | |
| 89 histogram_tester.ExpectTimeBucketCount( | |
| 90 kPreparationTime + kNavigationPreloadSuffix, time, 1); | |
| 91 histogram_tester.ExpectTimeBucketCount( | |
| 92 kPreparationTime + kStartWorkerExistingProcessSuffix + | |
| 93 kNavigationPreloadSuffix, | |
| 94 time, 1); | |
| 95 } | |
| 96 } | |
| 97 | |
| 98 } // namespace | |
|
horo
2017/01/18 12:26:41
} // namespace content
falken
2017/01/18 15:02:33
Done.
| |
| OLD | NEW |