1 // Copyright 2018 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/extensions/forced_extensions/force_installed_metrics.h"
6
7 #include "base/memory/ptr_util.h"
8 #include "base/optional.h"
9 #include "base/test/metrics/histogram_tester.h"
10 #include "base/time/time.h"
11 #include "base/timer/mock_timer.h"
12 #include "base/values.h"
13 #include "chrome/browser/extensions/external_provider_impl.h"
14 #include "chrome/browser/extensions/forced_extensions/force_installed_test_base.h"
15 #include "chrome/browser/extensions/forced_extensions/force_installed_tracker.h"
16 #include "chrome/browser/extensions/forced_extensions/install_stage_tracker.h"
17 #include "chrome/test/base/testing_browser_process.h"
18 #include "components/sync_preferences/testing_pref_service_syncable.h"
19 #include "content/public/test/browser_task_environment.h"
20 #include "extensions/browser/disable_reason.h"
21 #include "extensions/browser/extension_prefs.h"
22 #include "extensions/browser/extension_registry.h"
23 #include "extensions/browser/install/crx_install_error.h"
24 #include "extensions/browser/pref_names.h"
25 #include "extensions/browser/updater/safe_manifest_parser.h"
26 #include "extensions/common/extension.h"
27 #include "extensions/common/extension_builder.h"
28 #include "extensions/common/manifest.h"
29 #include "extensions/common/value_builder.h"
30 #include "net/base/net_errors.h"
31 #include "testing/gmock/include/gmock/gmock.h"
32 #include "testing/gtest/include/gtest/gtest.h"
33
34 #if defined(OS_CHROMEOS)
35 #include "chrome/browser/chromeos/login/users/fake_chrome_user_manager.h"
36 #include "chrome/browser/chromeos/profiles/profile_helper.h"
37 #include "components/arc/arc_prefs.h"
38 #include "components/user_manager/scoped_user_manager.h"
39 #include "components/user_manager/user_names.h"
40 #endif // defined(OS_CHROMEOS)
41
42 namespace {
43
44 // Intentionally invalid extension id.
45 constexpr char kExtensionId3[] = "cdefghijklmnopqrstuvwxyzabcdefgh";
46
47 const int kFetchTries = 5;
48 // HTTP_UNAUTHORIZED
49 const int kResponseCode = 401;
50
51 constexpr char kLoadTimeStats[] = "Extensions.ForceInstalledLoadTime";
52 constexpr char kReadyTimeStats[] = "Extensions.ForceInstalledReadyTime";
53 constexpr char kTimedOutStats[] = "Extensions.ForceInstalledTimedOutCount";
54 constexpr char kTimedOutNotInstalledStats[] =
55 "Extensions.ForceInstalledTimedOutAndNotInstalledCount";
56 constexpr char kInstallationFailureCacheStatus[] =
57 "Extensions.ForceInstalledFailureCacheStatus";
58 constexpr char kFailureReasonsCWS[] =
59 "Extensions.WebStore_ForceInstalledFailureReason3";
60 constexpr char kFailureReasonsSH[] =
61 "Extensions.OffStore_ForceInstalledFailureReason3";
62 constexpr char kInstallationStages[] = "Extensions.ForceInstalledStage2";
63 constexpr char kInstallCreationStages[] =
64 "Extensions.ForceInstalledCreationStage";
65 constexpr char kInstallationDownloadingStages[] =
66 "Extensions.ForceInstalledDownloadingStage";
67 constexpr char kFailureCrxInstallErrorStats[] =
68 "Extensions.ForceInstalledFailureCrxInstallError";
69 constexpr char kTotalCountStats[] =
70 "Extensions.ForceInstalledTotalCandidateCount";
71 constexpr char kNetworkErrorCodeStats[] =
72 "Extensions.ForceInstalledNetworkErrorCode";
73 constexpr char kHttpErrorCodeStats[] =
74 "Extensions.ForceInstalledHttpErrorCode2";
75 constexpr char kFetchRetriesStats[] = "Extensions.ForceInstalledFetchTries";
76 constexpr char kNetworkErrorCodeManifestFetchFailedStats[] =
77 "Extensions.ForceInstalledManifestFetchFailedNetworkErrorCode";
78 constexpr char kHttpErrorCodeManifestFetchFailedStats[] =
79 "Extensions.ForceInstalledManifestFetchFailedHttpErrorCode2";
80 constexpr char kFetchRetriesManifestFetchFailedStats[] =
81 "Extensions.ForceInstalledManifestFetchFailedFetchTries";
82 constexpr char kSandboxUnpackFailureReason[] =
83 "Extensions.ForceInstalledFailureSandboxUnpackFailureReason";
84 #if defined(OS_CHROMEOS)
85 constexpr char kFailureSessionStats[] =
86 "Extensions.ForceInstalledFailureSessionType";
87 #endif // defined(OS_CHROMEOS)
88 constexpr char kPossibleNonMisconfigurationFailures[] =
89 "Extensions.ForceInstalledSessionsWithNonMisconfigurationFailureOccured";
90 constexpr char kDisableReason[] =
91 "Extensions.ForceInstalledNotLoadedDisableReason";
92 constexpr char kBlocklisted[] = "Extensions.ForceInstalledAndBlackListed";
93 constexpr char kExtensionManifestInvalid[] =
94 "Extensions.ForceInstalledFailureManifestInvalidErrorDetail2";
95 constexpr char kManifestNoUpdatesInfo[] =
96 "Extensions.ForceInstalledFailureNoUpdatesInfo";
97 constexpr char kExtensionManifestInvalidAppStatusError[] =
98 "Extensions.ForceInstalledFailureManifestInvalidAppStatusError";
99 constexpr char kManifestDownloadTimeStats[] =
100 "Extensions.ForceInstalledTime.DownloadingStartTo.ManifestDownloadComplete";
101 constexpr char kCRXDownloadTimeStats[] =
102 "Extensions.ForceInstalledTime.ManifestDownloadCompleteTo."
103 "CRXDownloadComplete";
104 constexpr char kVerificationTimeStats[] =
105 "Extensions.ForceInstalledTime.VerificationStartTo.CopyingStart";
106 constexpr char kCopyingTimeStats[] =
107 "Extensions.ForceInstalledTime.CopyingStartTo.UnpackingStart";
108 constexpr char kUnpackingTimeStats[] =
109 "Extensions.ForceInstalledTime.UnpackingStartTo.CheckingExpectationsStart";
110 constexpr char kCheckingExpectationsTimeStats[] =
111 "Extensions.ForceInstalledTime.CheckingExpectationsStartTo.FinalizingStart";
112 constexpr char kFinalizingTimeStats[] =
113 "Extensions.ForceInstalledTime.FinalizingStartTo.CRXInstallComplete";
114 constexpr char kCrxHeaderInvalidFailureIsCWS[] =
115 "Extensions.ForceInstalledFailureWithCrxHeaderInvalidIsCWS";
116 constexpr char kCrxHeaderInvalidFailureFromCache[] =
117 "Extensions.ForceInstalledFailureWithCrxHeaderInvalidIsFromCache";
118
119 } // namespace
120
121 namespace extensions {
122
123 using testing::_;
124 using testing::Return;
125
126 class ForceInstalledMetricsTest : public ForceInstalledTestBase {
127 public:
128 ForceInstalledMetricsTest() = default;
129
130 ForceInstalledMetricsTest(const ForceInstalledMetricsTest&) = delete;
131 ForceInstalledMetricsTest& operator=(const ForceInstalledMetricsTest&) =
132 delete;
133
SetUp()134 void SetUp() override {
135 ForceInstalledTestBase::SetUp();
136 auto fake_timer = std::make_unique<base::MockOneShotTimer>();
137 fake_timer_ = fake_timer.get();
138 metrics_ = std::make_unique<ForceInstalledMetrics>(
139 registry(), profile(), force_installed_tracker(),
140 std::move(fake_timer));
141 }
142
SetupExtensionManagementPref()143 void SetupExtensionManagementPref() {
144 std::unique_ptr<base::DictionaryValue> extension_entry =
145 DictionaryBuilder()
146 .Set("installation_mode", "allowed")
147 .Set(ExternalProviderImpl::kExternalUpdateUrl, kExtensionUpdateUrl)
148 .Build();
149 prefs()->SetManagedPref(pref_names::kExtensionManagement,
150 DictionaryBuilder()
151 .Set(kExtensionId1, std::move(extension_entry))
152 .Build());
153 }
154
155 // Report downloading manifest stage for both the extensions.
ReportDownloadingManifestStage()156 void ReportDownloadingManifestStage() {
157 install_stage_tracker()->ReportDownloadingStage(
158 kExtensionId1,
159 ExtensionDownloaderDelegate::Stage::DOWNLOADING_MANIFEST);
160 install_stage_tracker()->ReportDownloadingStage(
161 kExtensionId2,
162 ExtensionDownloaderDelegate::Stage::DOWNLOADING_MANIFEST);
163 }
164
ReportInstallationStarted(base::Optional<base::TimeDelta> install_time)165 void ReportInstallationStarted(base::Optional<base::TimeDelta> install_time) {
166 install_stage_tracker()->ReportDownloadingStage(
167 kExtensionId1, ExtensionDownloaderDelegate::Stage::MANIFEST_LOADED);
168 install_stage_tracker()->ReportDownloadingStage(
169 kExtensionId1, ExtensionDownloaderDelegate::Stage::DOWNLOADING_CRX);
170 if (install_time)
171 task_environment_.FastForwardBy(install_time.value());
172 install_stage_tracker()->ReportDownloadingStage(
173 kExtensionId1, ExtensionDownloaderDelegate::Stage::FINISHED);
174 install_stage_tracker()->ReportInstallationStage(
175 kExtensionId1, InstallStageTracker::Stage::INSTALLING);
176 }
177
178 protected:
179 base::HistogramTester histogram_tester_;
180 base::MockOneShotTimer* fake_timer_;
181 std::unique_ptr<ForceInstalledMetrics> metrics_;
182 };
183
TEST_F(ForceInstalledMetricsTest,EmptyForcelist)184 TEST_F(ForceInstalledMetricsTest, EmptyForcelist) {
185 SetupEmptyForceList();
186 EXPECT_FALSE(fake_timer_->IsRunning());
187 // Don't report metrics when the Forcelist is empty.
188 histogram_tester_.ExpectTotalCount(kLoadTimeStats, 0);
189 histogram_tester_.ExpectTotalCount(kReadyTimeStats, 0);
190 histogram_tester_.ExpectTotalCount(kTimedOutStats, 0);
191 histogram_tester_.ExpectTotalCount(kTimedOutNotInstalledStats, 0);
192 histogram_tester_.ExpectTotalCount(kFailureReasonsCWS, 0);
193 histogram_tester_.ExpectTotalCount(kFailureReasonsSH, 0);
194 histogram_tester_.ExpectTotalCount(kInstallationStages, 0);
195 histogram_tester_.ExpectTotalCount(kFailureCrxInstallErrorStats, 0);
196 histogram_tester_.ExpectTotalCount(kTotalCountStats, 0);
197 }
198
TEST_F(ForceInstalledMetricsTest,ExtensionsInstalled)199 TEST_F(ForceInstalledMetricsTest, ExtensionsInstalled) {
200 SetupForceList(true /*is_from_store */);
201 auto ext1 = ExtensionBuilder(kExtensionName1).SetID(kExtensionId1).Build();
202 auto ext2 = ExtensionBuilder(kExtensionName2).SetID(kExtensionId2).Build();
203
204 histogram_tester_.ExpectTotalCount(kLoadTimeStats, 0);
205 force_installed_tracker()->OnExtensionLoaded(profile(), ext1.get());
206 histogram_tester_.ExpectTotalCount(kLoadTimeStats, 0);
207 force_installed_tracker()->OnExtensionLoaded(profile(), ext2.get());
208
209 histogram_tester_.ExpectTotalCount(kLoadTimeStats, 1);
210 histogram_tester_.ExpectTotalCount(kReadyTimeStats, 0);
211 histogram_tester_.ExpectTotalCount(kTimedOutStats, 0);
212 histogram_tester_.ExpectTotalCount(kTimedOutNotInstalledStats, 0);
213 histogram_tester_.ExpectTotalCount(kFailureReasonsCWS, 0);
214 histogram_tester_.ExpectTotalCount(kFailureReasonsSH, 0);
215 histogram_tester_.ExpectTotalCount(kInstallationStages, 0);
216 histogram_tester_.ExpectTotalCount(kFailureCrxInstallErrorStats, 0);
217 histogram_tester_.ExpectUniqueSample(
218 kTotalCountStats,
219 prefs()->GetManagedPref(pref_names::kInstallForceList)->DictSize(), 1);
220 }
221
222 // Verifies that failure is reported for the extensions which are listed in
223 // forced list, and their installation mode are overridden by ExtensionSettings
224 // policy to something else.
TEST_F(ForceInstalledMetricsTest,ExtensionSettingsOverrideForcedList)225 TEST_F(ForceInstalledMetricsTest, ExtensionSettingsOverrideForcedList) {
226 SetupForceList(true /*is_from_store */);
227 SetupExtensionManagementPref();
228 auto ext2 = ExtensionBuilder(kExtensionName2).SetID(kExtensionId2).Build();
229 force_installed_tracker()->OnExtensionLoaded(profile(), ext2.get());
230 // ForceInstalledMetrics shuts down timer because all extension are either
231 // loaded or failed.
232 EXPECT_FALSE(fake_timer_->IsRunning());
233 histogram_tester_.ExpectBucketCount(
234 kFailureReasonsCWS,
235 InstallStageTracker::FailureReason::OVERRIDDEN_BY_SETTINGS, 1);
236 }
237
TEST_F(ForceInstalledMetricsTest,ExtensionsInstallationTimedOut)238 TEST_F(ForceInstalledMetricsTest, ExtensionsInstallationTimedOut) {
239 SetupForceList(true /*is_from_store */);
240 auto ext1 = ExtensionBuilder(kExtensionName1).SetID(kExtensionId1).Build();
241 registry()->AddEnabled(ext1.get());
242 EXPECT_TRUE(fake_timer_->IsRunning());
243 fake_timer_->Fire();
244 // Metrics are reported due to timeout.
245 histogram_tester_.ExpectTotalCount(kLoadTimeStats, 0);
246 histogram_tester_.ExpectUniqueSample(kTimedOutStats, 2, 1);
247 histogram_tester_.ExpectUniqueSample(kTimedOutNotInstalledStats, 1, 1);
248 histogram_tester_.ExpectTotalCount(kFailureReasonsCWS, 1);
249 histogram_tester_.ExpectUniqueSample(
250 kFailureReasonsCWS, InstallStageTracker::FailureReason::IN_PROGRESS, 1);
251 histogram_tester_.ExpectTotalCount(kInstallationStages, 1);
252 histogram_tester_.ExpectTotalCount(kFailureCrxInstallErrorStats, 0);
253 histogram_tester_.ExpectUniqueSample(
254 kTotalCountStats,
255 prefs()->GetManagedPref(pref_names::kInstallForceList)->DictSize(), 1);
256 }
257
258 // Reporting the time for downloading the manifest of an extension and verifying
259 // that it is correctly recorded in the histogram.
TEST_F(ForceInstalledMetricsTest,ExtensionsManifestDownloadTime)260 TEST_F(ForceInstalledMetricsTest, ExtensionsManifestDownloadTime) {
261 SetupForceList(true /*is_from_store */);
262 ReportDownloadingManifestStage();
263 const base::TimeDelta manifest_download_time =
264 base::TimeDelta::FromMilliseconds(200);
265 task_environment_.FastForwardBy(manifest_download_time);
266 install_stage_tracker()->ReportDownloadingStage(
267 kExtensionId1, ExtensionDownloaderDelegate::Stage::MANIFEST_LOADED);
268 auto ext1 = ExtensionBuilder(kExtensionName1).SetID(kExtensionId1).Build();
269 force_installed_tracker()->OnExtensionLoaded(profile(), ext1.get());
270 install_stage_tracker()->ReportFailure(
271 kExtensionId2, InstallStageTracker::FailureReason::MANIFEST_INVALID);
272 // ForceInstalledMetrics shuts down timer because all extension are either
273 // loaded or failed.
274 EXPECT_FALSE(fake_timer_->IsRunning());
275 histogram_tester_.ExpectTotalCount(kManifestDownloadTimeStats, 1);
276 histogram_tester_.ExpectTimeBucketCount(kManifestDownloadTimeStats,
277 manifest_download_time, 1);
278 }
279
280 // Reporting the time for downloading the CRX file of an extension and verifying
281 // that it is correctly recorded in the histogram.
TEST_F(ForceInstalledMetricsTest,ExtensionsCrxDownloadTime)282 TEST_F(ForceInstalledMetricsTest, ExtensionsCrxDownloadTime) {
283 SetupForceList(true /*is_from_store */);
284 ReportDownloadingManifestStage();
285 const base::TimeDelta install_time = base::TimeDelta::FromMilliseconds(200);
286 ReportInstallationStarted(install_time);
287 auto ext1 = ExtensionBuilder(kExtensionName1).SetID(kExtensionId1).Build();
288 force_installed_tracker()->OnExtensionLoaded(profile(), ext1.get());
289 install_stage_tracker()->ReportFailure(
290 kExtensionId2, InstallStageTracker::FailureReason::MANIFEST_INVALID);
291 // ForceInstalledMetrics shuts down timer because all extension are either
292 // loaded or failed.
293 EXPECT_FALSE(fake_timer_->IsRunning());
294 histogram_tester_.ExpectTotalCount(kCRXDownloadTimeStats, 1);
295 histogram_tester_.ExpectTimeBucketCount(kCRXDownloadTimeStats, install_time,
296 1);
297 }
298
TEST_F(ForceInstalledMetricsTest,ExtensionsCrxDownloadTimeWhenFetchedFromCache)299 TEST_F(ForceInstalledMetricsTest,
300 ExtensionsCrxDownloadTimeWhenFetchedFromCache) {
301 SetupForceList(true /*is_from_store */);
302 ReportDownloadingManifestStage();
303 install_stage_tracker()->ReportDownloadingStage(
304 kExtensionId1, ExtensionDownloaderDelegate::Stage::MANIFEST_LOADED);
305 install_stage_tracker()->ReportDownloadingStage(
306 kExtensionId1, ExtensionDownloaderDelegate::Stage::FINISHED);
307 install_stage_tracker()->ReportInstallationStage(
308 kExtensionId1, InstallStageTracker::Stage::INSTALLING);
309 auto ext1 = ExtensionBuilder(kExtensionName1).SetID(kExtensionId1).Build();
310 force_installed_tracker()->OnExtensionLoaded(profile(), ext1.get());
311 install_stage_tracker()->ReportFailure(
312 kExtensionId2, InstallStageTracker::FailureReason::MANIFEST_INVALID);
313 // ForceInstalledMetrics shuts down timer because all extension are either
314 // loaded or failed.
315 EXPECT_FALSE(fake_timer_->IsRunning());
316 // Time should not be recorded when CRX is fetched from cache.
317 histogram_tester_.ExpectTotalCount(kCRXDownloadTimeStats, 0);
318 }
319
320 // Reporting the times for various stages in the extension installation process
321 // and verifying that the time consumed at each stage is correctly recorded in
322 // the histogram.
TEST_F(ForceInstalledMetricsTest,ExtensionsReportInstallationStageTimes)323 TEST_F(ForceInstalledMetricsTest, ExtensionsReportInstallationStageTimes) {
324 SetupForceList(true /*is_from_store */);
325 ReportDownloadingManifestStage();
326 ReportInstallationStarted(base::nullopt);
327 install_stage_tracker()->ReportCRXInstallationStage(
328 kExtensionId1, InstallationStage::kVerification);
329
330 const base::TimeDelta installation_stage_time =
331 base::TimeDelta::FromMilliseconds(200);
332 task_environment_.FastForwardBy(installation_stage_time);
333 install_stage_tracker()->ReportCRXInstallationStage(
334 kExtensionId1, InstallationStage::kCopying);
335
336 task_environment_.FastForwardBy(installation_stage_time);
337 install_stage_tracker()->ReportCRXInstallationStage(
338 kExtensionId1, InstallationStage::kUnpacking);
339
340 task_environment_.FastForwardBy(installation_stage_time);
341 install_stage_tracker()->ReportCRXInstallationStage(
342 kExtensionId1, InstallationStage::kCheckingExpectations);
343
344 task_environment_.FastForwardBy(installation_stage_time);
345 install_stage_tracker()->ReportCRXInstallationStage(
346 kExtensionId1, InstallationStage::kFinalizing);
347
348 task_environment_.FastForwardBy(installation_stage_time);
349 install_stage_tracker()->ReportCRXInstallationStage(
350 kExtensionId1, InstallationStage::kComplete);
351
352 auto ext1 = ExtensionBuilder(kExtensionName1).SetID(kExtensionId1).Build();
353 force_installed_tracker()->OnExtensionLoaded(profile(), ext1.get());
354 install_stage_tracker()->ReportFailure(
355 kExtensionId2, InstallStageTracker::FailureReason::MANIFEST_INVALID);
356 // ForceInstalledMetrics shuts down timer because all extension are either
357 // loaded or failed.
358 EXPECT_FALSE(fake_timer_->IsRunning());
359 histogram_tester_.ExpectTotalCount(kVerificationTimeStats, 1);
360 histogram_tester_.ExpectTimeBucketCount(kVerificationTimeStats,
361 installation_stage_time, 1);
362 histogram_tester_.ExpectTotalCount(kCopyingTimeStats, 1);
363 histogram_tester_.ExpectTimeBucketCount(kCopyingTimeStats,
364 installation_stage_time, 1);
365 histogram_tester_.ExpectTotalCount(kUnpackingTimeStats, 1);
366 histogram_tester_.ExpectTimeBucketCount(kUnpackingTimeStats,
367 installation_stage_time, 1);
368 histogram_tester_.ExpectTotalCount(kCheckingExpectationsTimeStats, 1);
369 histogram_tester_.ExpectTimeBucketCount(kCheckingExpectationsTimeStats,
370 installation_stage_time, 1);
371 histogram_tester_.ExpectTotalCount(kFinalizingTimeStats, 1);
372 histogram_tester_.ExpectTimeBucketCount(kFinalizingTimeStats,
373 installation_stage_time, 1);
374 }
375
376 // Reporting disable reason for the force installed extensions which are
377 // installed but not loaded when extension is disable due to single reason.
TEST_F(ForceInstalledMetricsTest,ExtensionsInstalledButNotLoadedUniqueDisableReason)378 TEST_F(ForceInstalledMetricsTest,
379 ExtensionsInstalledButNotLoadedUniqueDisableReason) {
380 SetupForceList(true /*is_from_store */);
381 auto ext1 = ExtensionBuilder(kExtensionName1).SetID(kExtensionId1).Build();
382 registry()->AddDisabled(ext1.get());
383 ExtensionPrefs::Get(profile())->AddDisableReason(
384 kExtensionId1, disable_reason::DisableReason::DISABLE_NOT_VERIFIED);
385 auto ext2 = ExtensionBuilder(kExtensionName2).SetID(kExtensionId2).Build();
386 registry()->AddEnabled(ext2.get());
387 force_installed_tracker()->OnExtensionLoaded(profile(), ext2.get());
388 // ForceInstalledMetrics should still keep running as kExtensionId1 is
389 // installed but not loaded.
390 EXPECT_TRUE(fake_timer_->IsRunning());
391 fake_timer_->Fire();
392 histogram_tester_.ExpectUniqueSample(
393 kDisableReason, disable_reason::DisableReason::DISABLE_NOT_VERIFIED, 1);
394 }
395
396 // Reporting disable reasons for the force installed extensions which are
397 // installed but not loaded when extension is disable due to multiple reasons.
TEST_F(ForceInstalledMetricsTest,ExtensionsInstalledButNotLoadedMultipleDisableReason)398 TEST_F(ForceInstalledMetricsTest,
399 ExtensionsInstalledButNotLoadedMultipleDisableReason) {
400 SetupForceList(true /*is_from_store */);
401 auto ext1 = ExtensionBuilder(kExtensionName1).SetID(kExtensionId1).Build();
402 registry()->AddDisabled(ext1.get());
403 ExtensionPrefs::Get(profile())->AddDisableReasons(
404 kExtensionId1,
405 disable_reason::DisableReason::DISABLE_NOT_VERIFIED |
406 disable_reason::DisableReason::DISABLE_UNSUPPORTED_REQUIREMENT);
407 auto ext2 = ExtensionBuilder(kExtensionName2).SetID(kExtensionId2).Build();
408 registry()->AddEnabled(ext2.get());
409 force_installed_tracker()->OnExtensionLoaded(profile(), ext2.get());
410 // ForceInstalledMetrics should still keep running as kExtensionId1 is
411 // installed but not loaded.
412 EXPECT_TRUE(fake_timer_->IsRunning());
413 fake_timer_->Fire();
414 // Verifies that only one disable reason is reported;
415 histogram_tester_.ExpectUniqueSample(
416 kDisableReason,
417 disable_reason::DisableReason::DISABLE_UNSUPPORTED_REQUIREMENT, 1);
418 }
419
420 // Reporting DisableReason::DISABLE_NONE for the force installed extensions
421 // which are installed but not loaded when extension is enabled.
TEST_F(ForceInstalledMetricsTest,ExtensionsInstalledButNotLoadedNoDisableReason)422 TEST_F(ForceInstalledMetricsTest,
423 ExtensionsInstalledButNotLoadedNoDisableReason) {
424 SetupForceList(true /*is_from_store */);
425 auto ext1 = ExtensionBuilder(kExtensionName1).SetID(kExtensionId1).Build();
426 registry()->AddEnabled(ext1.get());
427 auto ext2 = ExtensionBuilder(kExtensionName2).SetID(kExtensionId2).Build();
428 registry()->AddEnabled(ext2.get());
429 force_installed_tracker()->OnExtensionLoaded(profile(), ext2.get());
430 // ForceInstalledMetrics should still keep running as kExtensionId1 is
431 // installed but not loaded.
432 EXPECT_TRUE(fake_timer_->IsRunning());
433 fake_timer_->Fire();
434 histogram_tester_.ExpectUniqueSample(
435 kDisableReason, disable_reason::DisableReason::DISABLE_NONE, 1);
436 }
437
TEST_F(ForceInstalledMetricsTest,ExtensionForceInstalledAndBlocklisted)438 TEST_F(ForceInstalledMetricsTest, ExtensionForceInstalledAndBlocklisted) {
439 SetupForceList(true /*is_from_store */);
440 auto ext1 = ExtensionBuilder(kExtensionName1).SetID(kExtensionId1).Build();
441 registry()->AddBlocklisted(ext1.get());
442 auto ext2 = ExtensionBuilder(kExtensionName2).SetID(kExtensionId2).Build();
443 registry()->AddEnabled(ext2.get());
444 force_installed_tracker()->OnExtensionLoaded(profile(), ext2.get());
445 // ForceInstalledMetrics should still keep running as kExtensionId1 is
446 // installed but not loaded.
447 EXPECT_TRUE(fake_timer_->IsRunning());
448 fake_timer_->Fire();
449 histogram_tester_.ExpectUniqueSample(kBlocklisted, 1, 1);
450 }
451
TEST_F(ForceInstalledMetricsTest,ExtensionsInstallationCancelled)452 TEST_F(ForceInstalledMetricsTest, ExtensionsInstallationCancelled) {
453 SetupForceList(true /*is_from_store */);
454 SetupEmptyForceList();
455 // ForceInstalledMetrics does not shut down the timer, because it's still
456 // waiting for the initial extensions to install.
457 EXPECT_TRUE(fake_timer_->IsRunning());
458 histogram_tester_.ExpectTotalCount(kLoadTimeStats, 0);
459 histogram_tester_.ExpectTotalCount(kTimedOutStats, 0);
460 histogram_tester_.ExpectTotalCount(kTimedOutNotInstalledStats, 0);
461 histogram_tester_.ExpectTotalCount(kFailureReasonsCWS, 0);
462 histogram_tester_.ExpectTotalCount(kInstallationStages, 0);
463 histogram_tester_.ExpectTotalCount(kFailureCrxInstallErrorStats, 0);
464 histogram_tester_.ExpectTotalCount(kTotalCountStats, 0);
465 }
466
TEST_F(ForceInstalledMetricsTest,ForcedExtensionsAddedAfterManualExtensions)467 TEST_F(ForceInstalledMetricsTest, ForcedExtensionsAddedAfterManualExtensions) {
468 // Report failure for an extension which is not in forced list.
469 install_stage_tracker()->ReportFailure(
470 kExtensionId3, InstallStageTracker::FailureReason::INVALID_ID);
471 // ForceInstalledMetrics should keep running as the forced extensions are
472 // still not loaded.
473 EXPECT_TRUE(fake_timer_->IsRunning());
474 SetupForceList(true /*is_from_store */);
475
476 auto ext = ExtensionBuilder(kExtensionName1).SetID(kExtensionId1).Build();
477 force_installed_tracker()->OnExtensionLoaded(profile(), ext.get());
478 force_installed_tracker()->OnExtensionReady(profile(), ext.get());
479 install_stage_tracker()->ReportFailure(
480 kExtensionId2, InstallStageTracker::FailureReason::INVALID_ID);
481 // ForceInstalledMetrics shuts down timer because kExtensionId1 was loaded and
482 // kExtensionId2 was failed.
483 EXPECT_FALSE(fake_timer_->IsRunning());
484 histogram_tester_.ExpectBucketCount(
485 kFailureReasonsCWS, InstallStageTracker::FailureReason::INVALID_ID, 1);
486 }
487
TEST_F(ForceInstalledMetricsTest,ExtensionsInstallationTimedOutDifferentReasons)488 TEST_F(ForceInstalledMetricsTest,
489 ExtensionsInstallationTimedOutDifferentReasons) {
490 SetupForceList(true /*is_from_store */);
491 install_stage_tracker()->ReportFailure(
492 kExtensionId1, InstallStageTracker::FailureReason::INVALID_ID);
493 install_stage_tracker()->ReportCrxInstallError(
494 kExtensionId2,
495 InstallStageTracker::FailureReason::CRX_INSTALL_ERROR_OTHER,
496 CrxInstallErrorDetail::UNEXPECTED_ID);
497 // ForceInstalledMetrics shuts down timer because all extension are either
498 // loaded or failed.
499 EXPECT_FALSE(fake_timer_->IsRunning());
500 histogram_tester_.ExpectTotalCount(kLoadTimeStats, 0);
501 histogram_tester_.ExpectUniqueSample(kTimedOutStats, 2, 1);
502 histogram_tester_.ExpectUniqueSample(kTimedOutNotInstalledStats, 2, 1);
503 histogram_tester_.ExpectTotalCount(kFailureReasonsCWS, 2);
504 histogram_tester_.ExpectBucketCount(
505 kFailureReasonsCWS, InstallStageTracker::FailureReason::INVALID_ID, 1);
506 histogram_tester_.ExpectBucketCount(
507 kFailureReasonsCWS,
508 InstallStageTracker::FailureReason::CRX_INSTALL_ERROR_OTHER, 1);
509 histogram_tester_.ExpectTotalCount(kInstallationStages, 0);
510 histogram_tester_.ExpectUniqueSample(kFailureCrxInstallErrorStats,
511 CrxInstallErrorDetail::UNEXPECTED_ID, 1);
512 histogram_tester_.ExpectUniqueSample(
513 kTotalCountStats,
514 prefs()->GetManagedPref(pref_names::kInstallForceList)->DictSize(), 1);
515 }
516
517 // Reporting SandboxedUnpackerFailureReason when the force installed extension
518 // fails to install with error CRX_INSTALL_ERROR_SANDBOXED_UNPACKER_FAILURE.
TEST_F(ForceInstalledMetricsTest,ExtensionsCrxInstallErrorSandboxUnpackFailure)519 TEST_F(ForceInstalledMetricsTest,
520 ExtensionsCrxInstallErrorSandboxUnpackFailure) {
521 SetupForceList(true /*is_from_store */);
522 install_stage_tracker()->ReportSandboxedUnpackerFailureReason(
523 kExtensionId1, SandboxedUnpackerFailureReason::CRX_FILE_NOT_READABLE);
524 install_stage_tracker()->ReportSandboxedUnpackerFailureReason(
525 kExtensionId2, SandboxedUnpackerFailureReason::UNZIP_FAILED);
526 // ForceInstalledMetrics shuts down timer because all extension are either
527 // loaded or failed.
528 EXPECT_FALSE(fake_timer_->IsRunning());
529 histogram_tester_.ExpectTotalCount(kSandboxUnpackFailureReason, 2);
530 histogram_tester_.ExpectBucketCount(
531 kSandboxUnpackFailureReason,
532 SandboxedUnpackerFailureReason::CRX_FILE_NOT_READABLE, 1);
533 histogram_tester_.ExpectBucketCount(
534 kSandboxUnpackFailureReason, SandboxedUnpackerFailureReason::UNZIP_FAILED,
535 1);
536 }
537
538 // Reporting when the extension is downloaded from cache and it fails to install
539 // with error CRX_HEADER_INVALID.
TEST_F(ForceInstalledMetricsTest,ExtensionsCrxHeaderInvalidFromCache)540 TEST_F(ForceInstalledMetricsTest, ExtensionsCrxHeaderInvalidFromCache) {
541 SetupForceList(true /*is_from_store */);
542 install_stage_tracker()->ReportDownloadingCacheStatus(
543 kExtensionId1, ExtensionDownloaderDelegate::CacheStatus::CACHE_HIT);
544 install_stage_tracker()->ReportSandboxedUnpackerFailureReason(
545 kExtensionId1, SandboxedUnpackerFailureReason::CRX_HEADER_INVALID);
546 auto ext2 = ExtensionBuilder(kExtensionName2).SetID(kExtensionId2).Build();
547 registry()->AddEnabled(ext2.get());
548 force_installed_tracker()->OnExtensionLoaded(profile(), ext2.get());
549 // ForceInstalledMetrics shuts down timer because all extension are either
550 // loaded or failed.
551 EXPECT_FALSE(fake_timer_->IsRunning());
552 histogram_tester_.ExpectTotalCount(kSandboxUnpackFailureReason, 1);
553 histogram_tester_.ExpectBucketCount(
554 kSandboxUnpackFailureReason,
555 SandboxedUnpackerFailureReason::CRX_HEADER_INVALID, 1);
556 histogram_tester_.ExpectBucketCount(kCrxHeaderInvalidFailureIsCWS, true, 1);
557 histogram_tester_.ExpectBucketCount(kCrxHeaderInvalidFailureFromCache, true,
558 1);
559 }
560
561 // Reporting when the extension is not downloaded from cache and it fails to
562 // install with error CRX_HEADER_INVALID.
TEST_F(ForceInstalledMetricsTest,ExtensionsCrxHeaderInvalidNotFromCache)563 TEST_F(ForceInstalledMetricsTest, ExtensionsCrxHeaderInvalidNotFromCache) {
564 SetupForceList(true /*is_from_store */);
565 install_stage_tracker()->ReportDownloadingCacheStatus(
566 kExtensionId1, ExtensionDownloaderDelegate::CacheStatus::CACHE_MISS);
567 install_stage_tracker()->ReportSandboxedUnpackerFailureReason(
568 kExtensionId1, SandboxedUnpackerFailureReason::CRX_HEADER_INVALID);
569 auto ext2 = ExtensionBuilder(kExtensionName2).SetID(kExtensionId2).Build();
570 registry()->AddEnabled(ext2.get());
571 force_installed_tracker()->OnExtensionLoaded(profile(), ext2.get());
572 // ForceInstalledMetrics shuts down timer because all extension are either
573 // loaded or failed.
574 EXPECT_FALSE(fake_timer_->IsRunning());
575 histogram_tester_.ExpectTotalCount(kSandboxUnpackFailureReason, 1);
576 histogram_tester_.ExpectBucketCount(
577 kSandboxUnpackFailureReason,
578 SandboxedUnpackerFailureReason::CRX_HEADER_INVALID, 1);
579 histogram_tester_.ExpectBucketCount(kCrxHeaderInvalidFailureIsCWS, true, 1);
580 histogram_tester_.ExpectBucketCount(kCrxHeaderInvalidFailureFromCache, false,
581 1);
582 }
583
584 // Verifies that offstore extension that is downloaded from the update server
585 // and fails with CRX_HEADER_INVALID error is considered as a misconfiguration.
TEST_F(ForceInstalledMetricsTest,ExtensionsCrxHeaderInvalidIsMisconfiguration)586 TEST_F(ForceInstalledMetricsTest,
587 ExtensionsCrxHeaderInvalidIsMisconfiguration) {
588 SetupForceList(false);
589 install_stage_tracker()->ReportDownloadingCacheStatus(
590 kExtensionId1, ExtensionDownloaderDelegate::CacheStatus::CACHE_MISS);
591 install_stage_tracker()->ReportSandboxedUnpackerFailureReason(
592 kExtensionId1, SandboxedUnpackerFailureReason::CRX_HEADER_INVALID);
593 auto ext2 = ExtensionBuilder(kExtensionName2).SetID(kExtensionId2).Build();
594 registry()->AddEnabled(ext2.get());
595 force_installed_tracker()->OnExtensionLoaded(profile(), ext2.get());
596 // ForceInstalledMetrics shuts down timer because all extension are either
597 // loaded or failed.
598 EXPECT_FALSE(fake_timer_->IsRunning());
599 histogram_tester_.ExpectTotalCount(kSandboxUnpackFailureReason, 1);
600 histogram_tester_.ExpectBucketCount(
601 kSandboxUnpackFailureReason,
602 SandboxedUnpackerFailureReason::CRX_HEADER_INVALID, 1);
603 histogram_tester_.ExpectBucketCount(kCrxHeaderInvalidFailureIsCWS, false, 1);
604 histogram_tester_.ExpectBucketCount(kCrxHeaderInvalidFailureFromCache, false,
605 1);
606 histogram_tester_.ExpectBucketCount(kPossibleNonMisconfigurationFailures, 0,
607 1);
608 }
609
610 // Reporting info when the force installed extension fails to install with error
611 // CRX_FETCH_URL_EMPTY due to no updates from the server.
TEST_F(ForceInstalledMetricsTest,ExtensionsNoUpdatesInfoReporting)612 TEST_F(ForceInstalledMetricsTest, ExtensionsNoUpdatesInfoReporting) {
613 SetupForceList(true /*is_from_store */);
614
615 install_stage_tracker()->ReportInfoOnNoUpdatesFailure(kExtensionId1,
616 "disabled by client");
617 install_stage_tracker()->ReportFailure(
618 kExtensionId1, InstallStageTracker::FailureReason::CRX_FETCH_URL_EMPTY);
619 install_stage_tracker()->ReportInfoOnNoUpdatesFailure(kExtensionId2, "");
620 install_stage_tracker()->ReportFailure(
621 kExtensionId2, InstallStageTracker::FailureReason::CRX_FETCH_URL_EMPTY);
622
623 // ForceInstalledMetrics shuts down timer because all extension are either
624 // loaded or failed.
625 EXPECT_FALSE(fake_timer_->IsRunning());
626 histogram_tester_.ExpectTotalCount(kManifestNoUpdatesInfo, 2);
627 histogram_tester_.ExpectBucketCount(
628 kManifestNoUpdatesInfo, InstallStageTracker::NoUpdatesInfo::kEmpty, 1);
629 histogram_tester_.ExpectBucketCount(
630 kManifestNoUpdatesInfo,
631 InstallStageTracker::NoUpdatesInfo::kDisabledByClient, 1);
632 }
633
634 // Regression test to check if the metrics are collected properly for the
635 // extensions which are already installed and loaded and then fail with error
636 // ALREADY_INSTALLED.
TEST_F(ForceInstalledMetricsTest,ExtensionLoadedThenFailedWithAlreadyInstalledError)637 TEST_F(ForceInstalledMetricsTest,
638 ExtensionLoadedThenFailedWithAlreadyInstalledError) {
639 SetupForceList(true /*is_from_store */);
640 auto ext1 = ExtensionBuilder(kExtensionName1).SetID(kExtensionId1).Build();
641 force_installed_tracker()->OnExtensionLoaded(profile(), ext1.get());
642 install_stage_tracker()->ReportFailure(
643 kExtensionId1, InstallStageTracker::FailureReason::ALREADY_INSTALLED);
644 auto ext2 = ExtensionBuilder(kExtensionName2).SetID(kExtensionId2).Build();
645 force_installed_tracker()->OnExtensionLoaded(profile(), ext2.get());
646 // ForceInstalledMetrics shuts down timer because all extension are either
647 // loaded or failed.
648 EXPECT_FALSE(fake_timer_->IsRunning());
649 histogram_tester_.ExpectTotalCount(kLoadTimeStats, 1);
650 histogram_tester_.ExpectTotalCount(kTimedOutStats, 0);
651 histogram_tester_.ExpectTotalCount(kTimedOutNotInstalledStats, 0);
652 }
653
654 // Regression test to check if the metrics are collected properly for the
655 // extensions which are in state READY. Also verifies that the failure reported
656 // after READY state is not reflected in the statistics.
TEST_F(ForceInstalledMetricsTest,ExtensionsReady)657 TEST_F(ForceInstalledMetricsTest, ExtensionsReady) {
658 SetupForceList(true /*is_from_store */);
659 auto ext1 = ExtensionBuilder(kExtensionName1).SetID(kExtensionId1).Build();
660 force_installed_tracker()->OnExtensionLoaded(profile(), ext1.get());
661 force_installed_tracker()->OnExtensionReady(profile(), ext1.get());
662 install_stage_tracker()->ReportFailure(
663 kExtensionId1, InstallStageTracker::FailureReason::ALREADY_INSTALLED);
664 auto ext2 = ExtensionBuilder(kExtensionName2).SetID(kExtensionId2).Build();
665 force_installed_tracker()->OnExtensionLoaded(profile(), ext2.get());
666 force_installed_tracker()->OnExtensionReady(profile(), ext2.get());
667 // ForceInstalledMetrics shuts down timer because all extension are either
668 // loaded or failed.
669 EXPECT_FALSE(fake_timer_->IsRunning());
670 histogram_tester_.ExpectTotalCount(kLoadTimeStats, 1);
671 histogram_tester_.ExpectTotalCount(kReadyTimeStats, 1);
672 histogram_tester_.ExpectTotalCount(kTimedOutStats, 0);
673 histogram_tester_.ExpectTotalCount(kTimedOutNotInstalledStats, 0);
674 histogram_tester_.ExpectTotalCount(kFailureReasonsCWS, 0);
675 }
676
677 // Regression test to check if no metrics are reported for READY state when some
678 // extensions are failed.
TEST_F(ForceInstalledMetricsTest,AllExtensionsNotReady)679 TEST_F(ForceInstalledMetricsTest, AllExtensionsNotReady) {
680 SetupForceList(true /*is_from_store */);
681 auto ext1 = ExtensionBuilder(kExtensionName1).SetID(kExtensionId1).Build();
682 force_installed_tracker()->OnExtensionLoaded(profile(), ext1.get());
683 force_installed_tracker()->OnExtensionReady(profile(), ext1.get());
684 install_stage_tracker()->ReportFailure(
685 kExtensionId2, InstallStageTracker::FailureReason::INVALID_ID);
686 // ForceInstalledMetrics shuts down timer because all extension are either
687 // loaded or failed.
688 EXPECT_FALSE(fake_timer_->IsRunning());
689 histogram_tester_.ExpectTotalCount(kLoadTimeStats, 0);
690 histogram_tester_.ExpectTotalCount(kReadyTimeStats, 0);
691 histogram_tester_.ExpectBucketCount(
692 kFailureReasonsCWS, InstallStageTracker::FailureReason::INVALID_ID, 1);
693 }
694
695 // Verifies that the installation stage is not overwritten by a previous stage.
TEST_F(ForceInstalledMetricsTest,ExtensionsPreviousInstallationStageReportedAgain)696 TEST_F(ForceInstalledMetricsTest,
697 ExtensionsPreviousInstallationStageReportedAgain) {
698 SetupForceList(true /*is_from_store */);
699 auto extension =
700 ExtensionBuilder(kExtensionName1).SetID(kExtensionId1).Build();
701 force_installed_tracker()->OnExtensionLoaded(profile(), extension.get());
702 install_stage_tracker()->ReportInstallationStage(
703 kExtensionId2, InstallStageTracker::Stage::CREATED);
704 install_stage_tracker()->ReportInstallationStage(
705 kExtensionId2, InstallStageTracker::Stage::PENDING);
706 install_stage_tracker()->ReportInstallationStage(
707 kExtensionId2, InstallStageTracker::Stage::CREATED);
708 EXPECT_TRUE(fake_timer_->IsRunning());
709 fake_timer_->Fire();
710 histogram_tester_.ExpectUniqueSample(
711 kFailureReasonsCWS, InstallStageTracker::FailureReason::IN_PROGRESS, 1);
712 histogram_tester_.ExpectBucketCount(kInstallationStages,
713 InstallStageTracker::Stage::PENDING, 1);
714 }
715
716 // Verifies that the installation stage is overwritten if DOWNLOADING stage is
717 // reported again after INSTALLING stage.
TEST_F(ForceInstalledMetricsTest,ExtensionsDownloadingStageReportedAgain)718 TEST_F(ForceInstalledMetricsTest, ExtensionsDownloadingStageReportedAgain) {
719 SetupForceList(true /*is_from_store */);
720 auto extension =
721 ExtensionBuilder(kExtensionName1).SetID(kExtensionId1).Build();
722 force_installed_tracker()->OnExtensionLoaded(profile(), extension.get());
723 install_stage_tracker()->ReportInstallationStage(
724 kExtensionId2, InstallStageTracker::Stage::DOWNLOADING);
725 install_stage_tracker()->ReportInstallationStage(
726 kExtensionId2, InstallStageTracker::Stage::INSTALLING);
727 install_stage_tracker()->ReportInstallationStage(
728 kExtensionId2, InstallStageTracker::Stage::DOWNLOADING);
729 install_stage_tracker()->ReportDownloadingStage(
730 kExtensionId2, ExtensionDownloaderDelegate::Stage::PENDING);
731 EXPECT_TRUE(fake_timer_->IsRunning());
732 fake_timer_->Fire();
733 histogram_tester_.ExpectUniqueSample(
734 kFailureReasonsCWS, InstallStageTracker::FailureReason::IN_PROGRESS, 1);
735 histogram_tester_.ExpectBucketCount(
736 kInstallationStages, InstallStageTracker::Stage::DOWNLOADING, 1);
737 }
738
TEST_F(ForceInstalledMetricsTest,ExtensionsStuck)739 TEST_F(ForceInstalledMetricsTest, ExtensionsStuck) {
740 SetupForceList(true /*is_from_store */);
741 install_stage_tracker()->ReportInstallationStage(
742 kExtensionId1, InstallStageTracker::Stage::PENDING);
743 install_stage_tracker()->ReportInstallationStage(
744 kExtensionId2, InstallStageTracker::Stage::DOWNLOADING);
745 install_stage_tracker()->ReportDownloadingStage(
746 kExtensionId2, ExtensionDownloaderDelegate::Stage::PENDING);
747 EXPECT_TRUE(fake_timer_->IsRunning());
748 fake_timer_->Fire();
749 histogram_tester_.ExpectTotalCount(kLoadTimeStats, 0);
750 histogram_tester_.ExpectUniqueSample(kTimedOutStats, 2, 1);
751 histogram_tester_.ExpectUniqueSample(kTimedOutNotInstalledStats, 2, 1);
752 histogram_tester_.ExpectUniqueSample(
753 kFailureReasonsCWS, InstallStageTracker::FailureReason::IN_PROGRESS, 2);
754 histogram_tester_.ExpectBucketCount(kInstallationStages,
755 InstallStageTracker::Stage::PENDING, 1);
756 histogram_tester_.ExpectBucketCount(
757 kInstallationStages, InstallStageTracker::Stage::DOWNLOADING, 1);
758 histogram_tester_.ExpectTotalCount(kFailureCrxInstallErrorStats, 0);
759 histogram_tester_.ExpectUniqueSample(
760 kTotalCountStats,
761 prefs()->GetManagedPref(pref_names::kInstallForceList)->DictSize(), 1);
762 }
763
TEST_F(ForceInstalledMetricsTest,ExtensionStuckInCreatedStage)764 TEST_F(ForceInstalledMetricsTest, ExtensionStuckInCreatedStage) {
765 SetupForceList(true /*is_from_store */);
766 auto extension =
767 ExtensionBuilder(kExtensionName1).SetID(kExtensionId1).Build();
768 force_installed_tracker()->OnExtensionLoaded(profile(), extension.get());
769 install_stage_tracker()->ReportInstallationStage(
770 kExtensionId2, InstallStageTracker::Stage::CREATED);
771 install_stage_tracker()->ReportInstallCreationStage(
772 kExtensionId2, InstallStageTracker::InstallCreationStage::
773 NOTIFIED_FROM_MANAGEMENT_INITIAL_CREATION_FORCED);
774 EXPECT_TRUE(fake_timer_->IsRunning());
775 fake_timer_->Fire();
776 histogram_tester_.ExpectUniqueSample(
777 kFailureReasonsCWS, InstallStageTracker::FailureReason::IN_PROGRESS, 1);
778 histogram_tester_.ExpectUniqueSample(kInstallationStages,
779 InstallStageTracker::Stage::CREATED, 1);
780 histogram_tester_.ExpectUniqueSample(
781 kInstallCreationStages,
782 InstallStageTracker::InstallCreationStage::
783 NOTIFIED_FROM_MANAGEMENT_INITIAL_CREATION_FORCED,
784 1);
785 }
786
787 #if defined(OS_CHROMEOS)
TEST_F(ForceInstalledMetricsTest,ReportManagedGuestSessionOnExtensionFailure)788 TEST_F(ForceInstalledMetricsTest, ReportManagedGuestSessionOnExtensionFailure) {
789 chromeos::FakeChromeUserManager* fake_user_manager =
790 new chromeos::FakeChromeUserManager();
791 user_manager::ScopedUserManager scoped_user_manager(
792 base::WrapUnique(fake_user_manager));
793 const AccountId account_id =
794 AccountId::FromUserEmail(profile()->GetProfileUserName());
795 user_manager::User* user =
796 fake_user_manager->AddPublicAccountUser(account_id);
797 fake_user_manager->UserLoggedIn(account_id, user->username_hash(),
798 false /* browser_restart */,
799 false /* is_child */);
800 chromeos::ProfileHelper::Get()->SetProfileToUserMappingForTesting(user);
801 SetupForceList(true /*is_from_store */);
802 install_stage_tracker()->ReportFailure(
803 kExtensionId1, InstallStageTracker::FailureReason::INVALID_ID);
804 install_stage_tracker()->ReportCrxInstallError(
805 kExtensionId2,
806 InstallStageTracker::FailureReason::CRX_INSTALL_ERROR_OTHER,
807 CrxInstallErrorDetail::UNEXPECTED_ID);
808 // ForceInstalledMetrics shuts down timer because all extension are either
809 // loaded or failed.
810 EXPECT_FALSE(fake_timer_->IsRunning());
811 histogram_tester_.ExpectBucketCount(
812 kFailureSessionStats,
813 ForceInstalledMetrics::UserType::USER_TYPE_PUBLIC_ACCOUNT, 2);
814 }
815
TEST_F(ForceInstalledMetricsTest,ReportGuestSessionOnExtensionFailure)816 TEST_F(ForceInstalledMetricsTest, ReportGuestSessionOnExtensionFailure) {
817 chromeos::FakeChromeUserManager* fake_user_manager =
818 new chromeos::FakeChromeUserManager();
819 user_manager::ScopedUserManager scoped_user_manager(
820 base::WrapUnique(fake_user_manager));
821 const AccountId account_id =
822 AccountId::FromUserEmail(profile()->GetProfileUserName());
823 user_manager::User* user = fake_user_manager->AddGuestUser();
824 fake_user_manager->UserLoggedIn(account_id, user->username_hash(),
825 false /* browser_restart */,
826 false /* is_child */);
827 chromeos::ProfileHelper::Get()->SetProfileToUserMappingForTesting(user);
828 SetupForceList(true /*is_from_store */);
829 install_stage_tracker()->ReportFailure(
830 kExtensionId1, InstallStageTracker::FailureReason::INVALID_ID);
831 install_stage_tracker()->ReportCrxInstallError(
832 kExtensionId2,
833 InstallStageTracker::FailureReason::CRX_INSTALL_ERROR_OTHER,
834 CrxInstallErrorDetail::UNEXPECTED_ID);
835 // ForceInstalledMetrics shuts down timer because all extension are either
836 // loaded or failed.
837 EXPECT_FALSE(fake_timer_->IsRunning());
838 histogram_tester_.ExpectBucketCount(
839 kFailureSessionStats, ForceInstalledMetrics::UserType::USER_TYPE_GUEST,
840 2);
841 }
842 #endif // defined(OS_CHROMEOS)
843
TEST_F(ForceInstalledMetricsTest,ExtensionsAreDownloading)844 TEST_F(ForceInstalledMetricsTest, ExtensionsAreDownloading) {
845 SetupForceList(true /*is_from_store */);
846 install_stage_tracker()->ReportInstallationStage(
847 kExtensionId1, InstallStageTracker::Stage::DOWNLOADING);
848 install_stage_tracker()->ReportDownloadingStage(
849 kExtensionId1, ExtensionDownloaderDelegate::Stage::DOWNLOADING_MANIFEST);
850 install_stage_tracker()->ReportInstallationStage(
851 kExtensionId2, InstallStageTracker::Stage::DOWNLOADING);
852 install_stage_tracker()->ReportDownloadingStage(
853 kExtensionId2, ExtensionDownloaderDelegate::Stage::DOWNLOADING_CRX);
854 EXPECT_TRUE(fake_timer_->IsRunning());
855 fake_timer_->Fire();
856 histogram_tester_.ExpectTotalCount(kLoadTimeStats, 0);
857 histogram_tester_.ExpectUniqueSample(kTimedOutStats, 2, 1);
858 histogram_tester_.ExpectUniqueSample(kTimedOutNotInstalledStats, 2, 1);
859 histogram_tester_.ExpectUniqueSample(
860 kFailureReasonsCWS, InstallStageTracker::FailureReason::IN_PROGRESS, 2);
861 histogram_tester_.ExpectUniqueSample(
862 kInstallationStages, InstallStageTracker::Stage::DOWNLOADING, 2);
863 histogram_tester_.ExpectTotalCount(kInstallationDownloadingStages, 2);
864 histogram_tester_.ExpectBucketCount(
865 kInstallationDownloadingStages,
866 ExtensionDownloaderDelegate::Stage::DOWNLOADING_MANIFEST, 1);
867 histogram_tester_.ExpectBucketCount(
868 kInstallationDownloadingStages,
869 ExtensionDownloaderDelegate::Stage::DOWNLOADING_CRX, 1);
870 histogram_tester_.ExpectUniqueSample(
871 kTotalCountStats,
872 prefs()->GetManagedPref(pref_names::kInstallForceList)->DictSize(), 1);
873 }
874
875 // Error Codes in case of CRX_FETCH_FAILED.
TEST_F(ForceInstalledMetricsTest,ExtensionCrxFetchFailed)876 TEST_F(ForceInstalledMetricsTest, ExtensionCrxFetchFailed) {
877 SetupForceList(true /*is_from_store */);
878 ExtensionDownloaderDelegate::FailureData data1(net::Error::OK, kResponseCode,
879 kFetchTries);
880 ExtensionDownloaderDelegate::FailureData data2(
881 -net::Error::ERR_INVALID_ARGUMENT, kFetchTries);
882 install_stage_tracker()->ReportFetchError(
883 kExtensionId1, InstallStageTracker::FailureReason::CRX_FETCH_FAILED,
884 data1);
885 install_stage_tracker()->ReportFetchError(
886 kExtensionId2, InstallStageTracker::FailureReason::CRX_FETCH_FAILED,
887 data2);
888 // ForceInstalledMetrics shuts down timer because all extension are either
889 // loaded or failed.
890 EXPECT_FALSE(fake_timer_->IsRunning());
891 histogram_tester_.ExpectBucketCount(kNetworkErrorCodeStats, net::Error::OK,
892 1);
893 histogram_tester_.ExpectBucketCount(kHttpErrorCodeStats, kResponseCode, 1);
894 histogram_tester_.ExpectBucketCount(kNetworkErrorCodeStats,
895 -net::Error::ERR_INVALID_ARGUMENT, 1);
896 histogram_tester_.ExpectBucketCount(kFetchRetriesStats, kFetchTries, 2);
897 }
898
899 // Error Codes in case of MANIFEST_FETCH_FAILED.
TEST_F(ForceInstalledMetricsTest,ExtensionManifestFetchFailed)900 TEST_F(ForceInstalledMetricsTest, ExtensionManifestFetchFailed) {
901 SetupForceList(true /*is_from_store */);
902 ExtensionDownloaderDelegate::FailureData data1(net::Error::OK, kResponseCode,
903 kFetchTries);
904 ExtensionDownloaderDelegate::FailureData data2(
905 -net::Error::ERR_INVALID_ARGUMENT, kFetchTries);
906 install_stage_tracker()->ReportFetchError(
907 kExtensionId1, InstallStageTracker::FailureReason::MANIFEST_FETCH_FAILED,
908 data1);
909 install_stage_tracker()->ReportFetchError(
910 kExtensionId2, InstallStageTracker::FailureReason::MANIFEST_FETCH_FAILED,
911 data2);
912 // ForceInstalledMetrics shuts down timer because all extension are either
913 // loaded or failed.
914 EXPECT_FALSE(fake_timer_->IsRunning());
915 histogram_tester_.ExpectBucketCount(kNetworkErrorCodeManifestFetchFailedStats,
916 net::Error::OK, 1);
917 histogram_tester_.ExpectBucketCount(kHttpErrorCodeManifestFetchFailedStats,
918 kResponseCode, 1);
919 histogram_tester_.ExpectBucketCount(kNetworkErrorCodeManifestFetchFailedStats,
920 -net::Error::ERR_INVALID_ARGUMENT, 1);
921 histogram_tester_.ExpectBucketCount(kFetchRetriesManifestFetchFailedStats,
922 kFetchTries, 2);
923 }
924
925 // Errors occurred because the fetched update manifest was invalid.
TEST_F(ForceInstalledMetricsTest,ExtensionManifestInvalid)926 TEST_F(ForceInstalledMetricsTest, ExtensionManifestInvalid) {
927 SetupForceList(true /*is_from_store */);
928 auto extension =
929 ExtensionBuilder(kExtensionName1).SetID(kExtensionId1).Build();
930 force_installed_tracker()->OnExtensionLoaded(profile(), extension.get());
931 install_stage_tracker()->ReportManifestInvalidFailure(
932 kExtensionId2,
933 ExtensionDownloaderDelegate::FailureData(
934 ManifestInvalidError::INVALID_PROTOCOL_ON_GUPDATE_TAG));
935 // ForceInstalledMetrics shuts down timer because all extension are either
936 // loaded or failed.
937 EXPECT_FALSE(fake_timer_->IsRunning());
938 histogram_tester_.ExpectUniqueSample(
939 kExtensionManifestInvalid,
940 ManifestInvalidError::INVALID_PROTOCOL_ON_GUPDATE_TAG, 1);
941 }
942
943 // Errors occurred because the fetched update manifest was invalid because app
944 // status was not OK. Verifies that this error with app status error as
945 // "error-unknownApplication" is considered as a misconfiguration.
TEST_F(ForceInstalledMetricsTest,ExtensionManifestInvalidAppStatusError)946 TEST_F(ForceInstalledMetricsTest, ExtensionManifestInvalidAppStatusError) {
947 SetupForceList(true /*is_from_store */);
948 auto extension =
949 ExtensionBuilder(kExtensionName1).SetID(kExtensionId1).Build();
950 force_installed_tracker()->OnExtensionLoaded(profile(), extension.get());
951 install_stage_tracker()->ReportManifestInvalidFailure(
952 kExtensionId2,
953 ExtensionDownloaderDelegate::FailureData(
954 ManifestInvalidError::BAD_APP_STATUS, "error-unknownApplication"));
955 // ForceInstalledMetrics shuts down timer because all extension are either
956 // loaded or failed.
957 EXPECT_FALSE(fake_timer_->IsRunning());
958 histogram_tester_.ExpectUniqueSample(kExtensionManifestInvalid,
959 ManifestInvalidError::BAD_APP_STATUS, 1);
960 histogram_tester_.ExpectUniqueSample(
961 kExtensionManifestInvalidAppStatusError,
962 InstallStageTracker::AppStatusError::kErrorUnknownApplication, 1);
963 // Verify that the session with either all the extensions installed
964 // successfully, or all failures as admin-side misconfigurations is recorded
965 // here and BAD_APP_STATUS error is considered as a misconfiguration.
966 histogram_tester_.ExpectBucketCount(kPossibleNonMisconfigurationFailures, 0,
967 1);
968 }
969
970 // Session in which either all the extensions installed successfully, or all
971 // failures are admin-side misconfigurations. This test verifies that failure
972 // CRX_INSTALL_ERROR with detailed error KIOSK_MODE_ONLY is considered as
973 // misconfiguration.
TEST_F(ForceInstalledMetricsTest,NonMisconfigurationFailureNotPresentKioskModeOnlyError)974 TEST_F(ForceInstalledMetricsTest,
975 NonMisconfigurationFailureNotPresentKioskModeOnlyError) {
976 SetupForceList(true /*is_from_store */);
977 auto extension =
978 ExtensionBuilder(kExtensionName1).SetID(kExtensionId1).Build();
979 force_installed_tracker()->OnExtensionLoaded(profile(), extension.get());
980 install_stage_tracker()->ReportCrxInstallError(
981 kExtensionId2,
982 InstallStageTracker::FailureReason::CRX_INSTALL_ERROR_DECLINED,
983 CrxInstallErrorDetail::KIOSK_MODE_ONLY);
984 // ForceInstalledMetrics shuts down timer because all extension are either
985 // loaded or failed.
986 EXPECT_FALSE(fake_timer_->IsRunning());
987 histogram_tester_.ExpectBucketCount(kPossibleNonMisconfigurationFailures, 0,
988 1);
989 }
990
991 // Session in which either all the extensions installed successfully, or all
992 // failures are admin-side misconfigurations. This test verifies that failure
993 // CRX_INSTALL_ERROR with detailed error DISALLOWED_BY_POLICY and when extension
994 // type which is not allowed to install according to policy
995 // kExtensionAllowedTypes is considered as misconfiguration.
TEST_F(ForceInstalledMetricsTest,NonMisconfigurationFailureNotPresentDisallowedByPolicyTypeError)996 TEST_F(ForceInstalledMetricsTest,
997 NonMisconfigurationFailureNotPresentDisallowedByPolicyTypeError) {
998 SetupForceList(true /*is_from_store */);
999 // Set TYPE_EXTENSION and TYPE_THEME as the allowed extension types.
1000 std::unique_ptr<base::Value> list =
1001 ListBuilder().Append("extension").Append("theme").Build();
1002 prefs()->SetManagedPref(pref_names::kAllowedTypes, std::move(list));
1003
1004 auto extension =
1005 ExtensionBuilder(kExtensionName1).SetID(kExtensionId1).Build();
1006 force_installed_tracker()->OnExtensionLoaded(profile(), extension.get());
1007 // Hosted app is not a valid extension type, so this should report an error.
1008 install_stage_tracker()->ReportExtensionType(kExtensionId2,
1009 Manifest::Type::TYPE_HOSTED_APP);
1010 install_stage_tracker()->ReportCrxInstallError(
1011 kExtensionId2,
1012 InstallStageTracker::FailureReason::CRX_INSTALL_ERROR_DECLINED,
1013 CrxInstallErrorDetail::DISALLOWED_BY_POLICY);
1014 // ForceInstalledMetrics shuts down timer because all extension are either
1015 // loaded or failed.
1016 EXPECT_FALSE(fake_timer_->IsRunning());
1017 histogram_tester_.ExpectBucketCount(
1018 kPossibleNonMisconfigurationFailures,
1019 0 /*Misconfiguration failure not present*/, 1 /*Count of the sample*/);
1020 }
1021
1022 // Session in which at least one non misconfiguration failure occurred. One of
1023 // the extension fails to install with DISALLOWED_BY_POLICY error but has
1024 // extension type which is allowed by policy ExtensionAllowedTypes. This is not
1025 // a misconfiguration failure.
TEST_F(ForceInstalledMetricsTest,NonMisconfigurationFailurePresentDisallowedByPolicyError)1026 TEST_F(ForceInstalledMetricsTest,
1027 NonMisconfigurationFailurePresentDisallowedByPolicyError) {
1028 SetupForceList(true /*is_from_store */);
1029
1030 // Set TYPE_EXTENSION and TYPE_THEME as the allowed extension types.
1031 std::unique_ptr<base::Value> list =
1032 ListBuilder().Append("extension").Append("theme").Build();
1033 prefs()->SetManagedPref(pref_names::kAllowedTypes, std::move(list));
1034
1035 auto extension =
1036 ExtensionBuilder(kExtensionName1).SetID(kExtensionId1).Build();
1037 force_installed_tracker()->OnExtensionLoaded(profile(), extension.get());
1038 install_stage_tracker()->ReportExtensionType(kExtensionId2,
1039 Manifest::Type::TYPE_EXTENSION);
1040 install_stage_tracker()->ReportCrxInstallError(
1041 kExtensionId2,
1042 InstallStageTracker::FailureReason::CRX_INSTALL_ERROR_DECLINED,
1043 CrxInstallErrorDetail::DISALLOWED_BY_POLICY);
1044
1045 // ForceInstalledMetrics shuts down timer because all extension are either
1046 // loaded or failed.
1047 EXPECT_FALSE(fake_timer_->IsRunning());
1048 histogram_tester_.ExpectBucketCount(kPossibleNonMisconfigurationFailures,
1049 1 /*Misconfiguration failure present*/,
1050 1 /*Count of the sample*/);
1051 }
1052
1053 // Session in which at least one non misconfiguration failure occurred.
1054 // Misconfiguration failure includes error KIOSK_MODE_ONLY, when force installed
1055 // extension fails to install with failure reason CRX_INSTALL_ERROR.
TEST_F(ForceInstalledMetricsTest,NonMisconfigurationFailurePresent)1056 TEST_F(ForceInstalledMetricsTest, NonMisconfigurationFailurePresent) {
1057 SetupForceList(true /*is_from_store */);
1058 install_stage_tracker()->ReportFailure(
1059 kExtensionId1, InstallStageTracker::FailureReason::INVALID_ID);
1060 install_stage_tracker()->ReportCrxInstallError(
1061 kExtensionId2,
1062 InstallStageTracker::FailureReason::CRX_INSTALL_ERROR_DECLINED,
1063 CrxInstallErrorDetail::KIOSK_MODE_ONLY);
1064 // ForceInstalledMetrics shuts down timer because all extension are either
1065 // loaded or failed.
1066 EXPECT_FALSE(fake_timer_->IsRunning());
1067 histogram_tester_.ExpectBucketCount(kPossibleNonMisconfigurationFailures, 1,
1068 1);
1069 }
1070
1071 #if defined(OS_CHROMEOS)
1072 // Session in which either all the extensions installed successfully, or all
1073 // failures are admin-side misconfigurations. This test verifies that failure
1074 // REPLACED_BY_ARC_APP is not considered as misconfiguration when ARC++ is
1075 // enabled for the profile.
TEST_F(ForceInstalledMetricsTest,NonMisconfigurationFailureNotPresentReplacedByArcAppErrorArcEnabled)1076 TEST_F(ForceInstalledMetricsTest,
1077 NonMisconfigurationFailureNotPresentReplacedByArcAppErrorArcEnabled) {
1078 // Enable ARC++ for this profile.
1079 prefs()->SetManagedPref(arc::prefs::kArcEnabled,
1080 std::make_unique<base::Value>(true));
1081 SetupForceList(true /*is_from_store */);
1082 auto extension =
1083 ExtensionBuilder(kExtensionName1).SetID(kExtensionId1).Build();
1084 force_installed_tracker()->OnExtensionLoaded(profile(), extension.get());
1085 install_stage_tracker()->ReportFailure(
1086 kExtensionId2, InstallStageTracker::FailureReason::REPLACED_BY_ARC_APP);
1087 // ForceInstalledMetrics shuts down timer because all extension are either
1088 // loaded or failed.
1089 EXPECT_FALSE(fake_timer_->IsRunning());
1090 histogram_tester_.ExpectBucketCount(kPossibleNonMisconfigurationFailures, 0,
1091 1);
1092 }
1093
1094 // Session in which at least one non misconfiguration failure occurred. This
1095 // test verifies that failure REPLACED_BY_ARC_APP is not considered as
1096 // misconfiguration when ARC++ is disabled for the profile.
TEST_F(ForceInstalledMetricsTest,NonMisconfigurationFailureNotPresentReplacedByArcAppErrorArcDisabled)1097 TEST_F(ForceInstalledMetricsTest,
1098 NonMisconfigurationFailureNotPresentReplacedByArcAppErrorArcDisabled) {
1099 // Enable ARC++ for this profile.
1100 prefs()->SetManagedPref(arc::prefs::kArcEnabled,
1101 std::make_unique<base::Value>(false));
1102 SetupForceList(true /*is_from_store */);
1103 auto extension =
1104 ExtensionBuilder(kExtensionName1).SetID(kExtensionId1).Build();
1105 force_installed_tracker()->OnExtensionLoaded(profile(), extension.get());
1106 install_stage_tracker()->ReportFailure(
1107 kExtensionId2, InstallStageTracker::FailureReason::REPLACED_BY_ARC_APP);
1108 // ForceInstalledMetrics shuts down timer because all extension are either
1109 // loaded or failed.
1110 EXPECT_FALSE(fake_timer_->IsRunning());
1111 histogram_tester_.ExpectBucketCount(kPossibleNonMisconfigurationFailures, 1,
1112 1);
1113 }
1114 #endif // defined(OS_CHROMEOS)
1115
1116 // Session in which either all the extensions installed successfully, or all
1117 // failures are admin-side misconfigurations. This test verifies that failure
1118 // NOT_PERFORMING_NEW_INSTALL is considered as misconfiguration.
TEST_F(ForceInstalledMetricsTest,NonMisconfigurationFailureNotPresentNotPerformingNewInstallError)1119 TEST_F(ForceInstalledMetricsTest,
1120 NonMisconfigurationFailureNotPresentNotPerformingNewInstallError) {
1121 SetupForceList(true /*is_from_store */);
1122 auto extension =
1123 ExtensionBuilder(kExtensionName1).SetID(kExtensionId1).Build();
1124 force_installed_tracker()->OnExtensionLoaded(profile(), extension.get());
1125 install_stage_tracker()->ReportFailure(
1126 kExtensionId2,
1127 InstallStageTracker::FailureReason::NOT_PERFORMING_NEW_INSTALL);
1128 // ForceInstalledMetrics shuts down timer because all extension are either
1129 // loaded or failed.
1130 EXPECT_FALSE(fake_timer_->IsRunning());
1131 histogram_tester_.ExpectBucketCount(kPossibleNonMisconfigurationFailures, 0,
1132 1);
1133 }
1134
1135 // Session in which either all the extensions installed successfully, or all
1136 // failures are admin-side misconfigurations. This test verifies that failure
1137 // CRX_FETCH_URL_EMPTY with empty info field is considered as misconfiguration.
TEST_F(ForceInstalledMetricsTest,NonMisconfigurationFailureNotPresentCrxFetchUrlEmptyError)1138 TEST_F(ForceInstalledMetricsTest,
1139 NonMisconfigurationFailureNotPresentCrxFetchUrlEmptyError) {
1140 SetupForceList(true /*is_from_store */);
1141 auto extension =
1142 ExtensionBuilder(kExtensionName1).SetID(kExtensionId1).Build();
1143 force_installed_tracker()->OnExtensionLoaded(profile(), extension.get());
1144 install_stage_tracker()->ReportInfoOnNoUpdatesFailure(kExtensionId2, "");
1145 install_stage_tracker()->ReportFailure(
1146 kExtensionId2, InstallStageTracker::FailureReason::CRX_FETCH_URL_EMPTY);
1147 // ForceInstalledMetrics shuts down timer because all extension are either
1148 // loaded or failed.
1149 EXPECT_FALSE(fake_timer_->IsRunning());
1150 histogram_tester_.ExpectBucketCount(kPossibleNonMisconfigurationFailures, 0,
1151 1);
1152 }
1153
1154 // This test verifies that failure CRX_FETCH_URL_EMPTY with non empty info field
1155 // is not considered as a misconfiguration.
TEST_F(ForceInstalledMetricsTest,NonMisconfigurationFailurePresentCrxFetchUrlEmptyError)1156 TEST_F(ForceInstalledMetricsTest,
1157 NonMisconfigurationFailurePresentCrxFetchUrlEmptyError) {
1158 SetupForceList(true /*is_from_store */);
1159 auto extension =
1160 ExtensionBuilder(kExtensionName1).SetID(kExtensionId1).Build();
1161 force_installed_tracker()->OnExtensionLoaded(profile(), extension.get());
1162 install_stage_tracker()->ReportInfoOnNoUpdatesFailure(kExtensionId2,
1163 "rate limit");
1164 install_stage_tracker()->ReportFailure(
1165 kExtensionId2, InstallStageTracker::FailureReason::CRX_FETCH_URL_EMPTY);
1166 // ForceInstalledMetrics shuts down timer because all extension are either
1167 // loaded or failed.
1168 EXPECT_FALSE(fake_timer_->IsRunning());
1169 histogram_tester_.ExpectBucketCount(kPossibleNonMisconfigurationFailures, 0,
1170 0);
1171 }
1172
TEST_F(ForceInstalledMetricsTest,NoExtensionsConfigured)1173 TEST_F(ForceInstalledMetricsTest, NoExtensionsConfigured) {
1174 EXPECT_TRUE(fake_timer_->IsRunning());
1175 fake_timer_->Fire();
1176 histogram_tester_.ExpectTotalCount(kLoadTimeStats, 0);
1177 histogram_tester_.ExpectTotalCount(kReadyTimeStats, 0);
1178 histogram_tester_.ExpectTotalCount(kTimedOutStats, 0);
1179 histogram_tester_.ExpectTotalCount(kTimedOutNotInstalledStats, 0);
1180 histogram_tester_.ExpectTotalCount(kFailureReasonsCWS, 0);
1181 histogram_tester_.ExpectTotalCount(kInstallationStages, 0);
1182 histogram_tester_.ExpectTotalCount(kFailureCrxInstallErrorStats, 0);
1183 histogram_tester_.ExpectTotalCount(kTotalCountStats, 0);
1184 }
1185
TEST_F(ForceInstalledMetricsTest,CachedExtensions)1186 TEST_F(ForceInstalledMetricsTest, CachedExtensions) {
1187 SetupForceList(true /*is_from_store */);
1188 install_stage_tracker()->ReportDownloadingCacheStatus(
1189 kExtensionId1, ExtensionDownloaderDelegate::CacheStatus::CACHE_HIT);
1190 install_stage_tracker()->ReportDownloadingCacheStatus(
1191 kExtensionId2, ExtensionDownloaderDelegate::CacheStatus::CACHE_MISS);
1192 auto ext1 = ExtensionBuilder(kExtensionName1).SetID(kExtensionId1).Build();
1193 registry()->AddEnabled(ext1.get());
1194 EXPECT_TRUE(fake_timer_->IsRunning());
1195 fake_timer_->Fire();
1196 // If an extension was installed successfully, don't mention it in statistics.
1197 histogram_tester_.ExpectUniqueSample(
1198 kInstallationFailureCacheStatus,
1199 ExtensionDownloaderDelegate::CacheStatus::CACHE_MISS, 1);
1200 }
1201
1202 } // namespace extensions
1203