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

Side by Side Diff: chrome/browser/metrics/chrome_setup_metrics_provider_unittest.cc

Issue 1537743006: Persist setup metrics and have Chrome report them during UMA upload. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@shared-histograms
Patch Set: Created 5 years 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 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/metrics/chrome_setup_metrics_provider.h"
6
7 #include "base/basictypes.h"
8 #include "base/files/file_util.h"
9 #include "base/files/scoped_temp_dir.h"
10 #include "base/metrics/histogram.h"
11 #include "base/metrics/histogram_persistence.h"
12 #include "base/metrics/persistent_memory_allocator.h"
13 #include "base/prefs/pref_registry_simple.h"
14 #include "base/prefs/testing_pref_service.h"
15 #include "chrome/installer/util/google_update_constants.h"
16 #include "components/metrics/metrics_pref_names.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18
19 using namespace base;
20
21 class ChromeSetupMetricsProviderTest : public testing::Test {
22 protected:
23 ChromeSetupMetricsProviderTest() : prefs_(new TestingPrefServiceSimple) {
24 EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
25 prefs_->registry()->RegisterInt64Pref(metrics::prefs::kSetupMetricsLastSeen,
26 0);
27 }
28
29 TestingPrefServiceSimple* prefs() { return prefs_.get(); }
30 FilePath temp_dir() { return temp_dir_.path(); }
31 FilePath metrics_file() {
32 return temp_dir_.path().AppendASCII(
33 google_update::kSetupHistogramAllocatorName);
34 }
35
36 ChromeSetupMetricsProvider* provider() {
37 if (!provider_) {
38 provider_.reset(new ChromeSetupMetricsProvider(nullptr, prefs()));
39 provider_->SetProgramDirectory(temp_dir());
40 }
41 return provider_.get();
42 }
43
44 private:
45 ScopedTempDir temp_dir_;
46 scoped_ptr<TestingPrefServiceSimple> prefs_;
47 scoped_ptr<ChromeSetupMetricsProvider> provider_;
48
49 DISALLOW_COPY_AND_ASSIGN(ChromeSetupMetricsProviderTest);
50 };
51
52
53 TEST_F(ChromeSetupMetricsProviderTest, AccessMetrics) {
54 ASSERT_FALSE(PathExists(metrics_file()));
55
56 {
57 SetPersistentHistogramMemoryAllocator(
58 new LocalPersistentMemoryAllocator(
59 64 << 10, 0, google_update::kSetupHistogramAllocatorName));
60 HistogramBase* foo = Histogram::FactoryGet("foo", 1, 100, 10, 0);
61 HistogramBase* bar = Histogram::FactoryGet("bar", 1, 100, 10, 0);
62 foo->Add(42);
63 bar->Add(84);
64
65 scoped_ptr<PersistentMemoryAllocator> allocator(
66 ReleasePersistentHistogramMemoryAllocator());
67 File writer(metrics_file(), File::FLAG_CREATE | File::FLAG_WRITE);
68 EXPECT_TRUE(writer.IsValid());
69 writer.Write(0, (const char*)allocator->data(), allocator->used());
70 }
71
72 ASSERT_TRUE(PathExists(metrics_file()));
73 EXPECT_FALSE(provider()->metrics_found_.load());
74 EXPECT_FALSE(provider()->metrics_file_);
75 provider()->CheckForSetupMetrics();
76 EXPECT_TRUE(provider()->metrics_found_.load());
77 EXPECT_TRUE(provider()->metrics_file_);
78
79 EXPECT_FALSE(provider()->metrics_allocator_);
80 provider()->OnDidCreateMetricsLog();
81 EXPECT_TRUE(provider()->metrics_allocator_);
82 EXPECT_TRUE(provider()->metrics_found_.load());
83 EXPECT_FALSE(provider()->metrics_file_);
84 provider()->OnDidCreateMetricsLog();
85 EXPECT_FALSE(provider()->metrics_allocator_);
86 EXPECT_FALSE(provider()->metrics_found_.load());
87 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698