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

Side by Side Diff: chrome/installer/util/experiment_storage_unittest.cc

Issue 2889323004: Win 10 Inactive toast experiment metrics and storage modifications. (Closed)
Patch Set: Apply comments from 2898843002 Created 3 years, 7 months 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 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 "chrome/installer/util/experiment_storage.h"
6
7 #include "base/base64.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "base/test/test_reg_util_win.h"
10 #include "chrome/install_static/install_details.h"
11 #include "chrome/installer/util/experiment.h"
12 #include "chrome/installer/util/experiment_metrics.h"
13 #include "chrome/installer/util/google_update_settings.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 namespace installer {
17
18 class ExperimentStorageTest : public ::testing::Test {
19 protected:
20 void TestExperimentMetrics(ExperimentMetrics* metrics) {
21 metrics->SetState(ExperimentMetrics::kGroupAssigned);
22 metrics->toast_location = ExperimentMetrics::kOverTaskbarPin;
23 metrics->toast_count = 1;
24 metrics->first_toast_offset = 30;
25 metrics->toast_hour = 3;
26 metrics->last_used_bucket = 2;
27 metrics->display_time_bucket = 11;
28 metrics->session_length_bucket = 36;
29 }
30
31 void SetUp() {
32 const install_static::InstallDetails& details =
grt (UTC plus 2) 2017/05/24 13:43:39 please make this a parameterized test with a bool
nikunjb 2017/05/30 21:45:02 Done.
33 install_static::InstallDetails::Get();
34 HKEY root = details.system_level() ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
35 registry_util::RegistryOverrideManager override_manager;
grt (UTC plus 2) 2017/05/24 13:43:39 this needs to be a member variable of the class so
nikunjb 2017/05/30 21:45:01 Done.
36 ASSERT_NO_FATAL_FAILURE(override_manager.OverrideRegistry(root));
37 GoogleUpdateSettings::SetGoogleUpdateIntegrationForTesting(true);
grt (UTC plus 2) 2017/05/24 13:43:39 i propose getting rid of this in favor of moving t
nikunjb 2017/05/30 21:45:02 SGTM.
38 }
39
40 void TearDown() {
41 GoogleUpdateSettings::SetGoogleUpdateIntegrationForTesting(false);
42 }
43 };
44
45 TEST_F(ExperimentStorageTest, TestEncodeDecodeMetrics) {
46 ExperimentMetrics metrics;
47 TestExperimentMetrics(&metrics);
48 base::string16 encoded_metrics(ExperimentStorage::EncodeMetrics(metrics));
49 ExperimentMetrics decoded_metrics;
50 ASSERT_TRUE(
51 ExperimentStorage::DecodeMetrics(encoded_metrics, &decoded_metrics));
52 ASSERT_EQ(encoded_metrics, base::ASCIIToUTF16("5BIMD4IA"));
grt (UTC plus 2) 2017/05/24 13:43:39 move this up so it immediately follows line 48, an
nikunjb 2017/05/30 21:45:02 Done.
53 base::string16 decoded_metrics_str(
54 ExperimentStorage::EncodeMetrics(decoded_metrics));
55 ASSERT_EQ(encoded_metrics, decoded_metrics_str);
grt (UTC plus 2) 2017/05/24 13:43:38 EXPECT rather than ASSERT, and inline the call to
nikunjb 2017/05/30 21:45:01 Done.
56 }
57
58 TEST_F(ExperimentStorageTest, TestReadWriteParticipation) {
59 #if defined(GOOGLE_CHROME_BUILD)
grt (UTC plus 2) 2017/05/24 13:43:38 i don't think this is needed here
nikunjb 2017/05/30 21:45:02 Done.
60 ExperimentStorage storage;
61 ExperimentStorage::Participation expected =
62 ExperimentStorage::Participation::kIsParticipating;
63 ASSERT_TRUE(storage.AcquireLock()->WriteParticipation(expected));
64 ExperimentStorage::Participation p;
65 ASSERT_TRUE(storage.AcquireLock()->ReadParticipation(&p));
66 ASSERT_EQ(p, expected);
67 #endif
68 }
69
70 TEST_F(ExperimentStorageTest, TestLoadStoreExperiment) {
71 #if defined(GOOGLE_CHROME_BUILD)
72 Experiment experiment;
73 ExperimentMetrics metrics;
74 TestExperimentMetrics(&metrics);
75 experiment.InitializeFromMetrics(metrics);
76 ExperimentStorage storage;
77 ASSERT_TRUE(storage.AcquireLock()->StoreExperiment(experiment));
78 Experiment stored_experiment;
79 ASSERT_TRUE(storage.AcquireLock()->LoadExperiment(&stored_experiment));
80 ASSERT_EQ(stored_experiment.state(), ExperimentMetrics::kGroupAssigned);
81 #endif
82 }
83
84 TEST_F(ExperimentStorageTest, TestLoadStoreMetrics) {
85 #if defined(GOOGLE_CHROME_BUILD)
86 ExperimentStorage storage;
87 ExperimentMetrics metrics;
88 TestExperimentMetrics(&metrics);
89 ASSERT_TRUE(storage.AcquireLock()->StoreMetrics(metrics));
90 ExperimentMetrics stored_metrics;
91 ASSERT_TRUE(storage.AcquireLock()->LoadMetrics(&stored_metrics));
92 base::string16 encoded_metrics(ExperimentStorage::EncodeMetrics(metrics));
93 base::string16 encoded_stored_metrics(
94 ExperimentStorage::EncodeMetrics(stored_metrics));
95 ASSERT_EQ(encoded_stored_metrics, encoded_metrics);
96 ASSERT_EQ(encoded_stored_metrics, base::ASCIIToUTF16("5BIMD4IA"));
97 #endif
98 }
99 } // namespace installer
grt (UTC plus 2) 2017/05/24 13:43:38 nit: blank line before this
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698