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 "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/install_static/test/scoped_install_details.h" | |
| 12 #include "chrome/installer/util/experiment.h" | |
| 13 #include "chrome/installer/util/experiment_metrics.h" | |
| 14 #include "chrome/installer/util/google_update_settings.h" | |
| 15 #include "testing/gtest/include/gtest/gtest.h" | |
| 16 | |
| 17 namespace installer { | |
| 18 | |
| 19 class ExperimentStorageTest : public ::testing::TestWithParam<bool> { | |
|
grt (UTC plus 2)
2017/05/31 12:24:10
please document the parameter
nikunjb
2017/06/02 05:11:23
Done.
| |
| 20 protected: | |
| 21 ExperimentStorageTest() | |
| 22 : system_level_install_(GetParam()), | |
| 23 scoped_install_details_(system_level_install_, 0) {} | |
| 24 | |
| 25 void TestExperimentMetrics(ExperimentMetrics* metrics) { | |
|
grt (UTC plus 2)
2017/05/31 12:24:10
same comment regarding this function name as in ot
nikunjb
2017/06/02 05:11:24
Done.
| |
| 26 metrics->SetState(ExperimentMetrics::kGroupAssigned); | |
| 27 metrics->toast_location = ExperimentMetrics::kOverTaskbarPin; | |
| 28 metrics->toast_count = 1; | |
| 29 metrics->first_toast_offset = 30; | |
| 30 metrics->toast_hour = 3; | |
| 31 metrics->last_used_bucket = 2; | |
| 32 metrics->display_time_bucket = 11; | |
| 33 metrics->session_length_bucket = 36; | |
| 34 } | |
| 35 | |
| 36 void SetUp() { | |
|
grt (UTC plus 2)
2017/05/31 12:24:10
nit: override
nikunjb
2017/06/02 05:11:24
Done.
| |
| 37 ::testing::TestWithParam<bool>::SetUp(); | |
| 38 HKEY root = system_level_install_ ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | |
| 39 ASSERT_NO_FATAL_FAILURE(override_manager_.OverrideRegistry(root)); | |
| 40 | |
| 41 // Create an empty participation key since participation registry is assumed | |
| 42 // to be present for chrome build. | |
| 43 base::win::RegKey key; | |
| 44 key.Create( | |
|
grt (UTC plus 2)
2017/05/31 12:24:10
ASSERT_EQ(ERROR_SUCCESS, key.Create(..));
nikunjb
2017/06/02 05:11:24
Done.
| |
| 45 root, | |
| 46 install_static::InstallDetails::Get().GetClientStateKeyPath().c_str(), | |
| 47 KEY_QUERY_VALUE); | |
|
grt (UTC plus 2)
2017/05/31 12:24:10
KEY_WOW64_32KEY | KEY_QUERY_VALUE
nikunjb
2017/06/02 05:11:23
Done.
| |
| 48 } | |
| 49 | |
| 50 private: | |
| 51 bool system_level_install_; | |
| 52 install_static::ScopedInstallDetails scoped_install_details_; | |
| 53 registry_util::RegistryOverrideManager override_manager_; | |
| 54 }; | |
|
grt (UTC plus 2)
2017/05/31 12:24:10
DISALLOW_COPY_AND_ASSIGN
nikunjb
2017/06/02 05:11:23
Done.
| |
| 55 | |
| 56 TEST_P(ExperimentStorageTest, TestEncodeDecodeMetrics) { | |
| 57 ExperimentMetrics metrics; | |
| 58 TestExperimentMetrics(&metrics); | |
| 59 base::string16 encoded_metrics(ExperimentStorage::EncodeMetrics(metrics)); | |
| 60 EXPECT_EQ(encoded_metrics, base::ASCIIToUTF16("5BIMD4IA")); | |
|
grt (UTC plus 2)
2017/05/31 12:24:10
base::ASCIIToUTF16("5BIMD4IA") -> L"5BIMD4IA"
nikunjb
2017/06/02 05:11:24
Done.
| |
| 61 ExperimentMetrics decoded_metrics; | |
| 62 ASSERT_TRUE( | |
| 63 ExperimentStorage::DecodeMetrics(encoded_metrics, &decoded_metrics)); | |
| 64 EXPECT_EQ(encoded_metrics, ExperimentStorage::EncodeMetrics(decoded_metrics)); | |
|
grt (UTC plus 2)
2017/05/31 12:24:10
? EXPECT_EQ(metrics, decoded_metrics);
nikunjb
2017/06/02 05:11:23
Was checking by re-encoding the decoding the metri
| |
| 65 } | |
|
grt (UTC plus 2)
2017/05/31 12:24:10
could you add a test for an instance with every fi
nikunjb
2017/06/02 05:11:23
Done. Added one for max and one for all 0.
| |
| 66 | |
| 67 TEST_P(ExperimentStorageTest, TestReadWriteParticipation) { | |
| 68 ExperimentStorage storage; | |
| 69 ExperimentStorage::Participation expected = | |
| 70 ExperimentStorage::Participation::kIsParticipating; | |
| 71 ASSERT_TRUE(storage.AcquireLock()->WriteParticipation(expected)); | |
| 72 ExperimentStorage::Participation p; | |
| 73 ASSERT_TRUE(storage.AcquireLock()->ReadParticipation(&p)); | |
| 74 EXPECT_EQ(p, expected); | |
| 75 } | |
| 76 | |
| 77 TEST_P(ExperimentStorageTest, TestLoadStoreExperiment) { | |
| 78 Experiment experiment; | |
| 79 ExperimentMetrics metrics; | |
| 80 TestExperimentMetrics(&metrics); | |
| 81 experiment.InitializeFromMetrics(metrics); | |
| 82 ExperimentStorage storage; | |
| 83 ASSERT_TRUE(storage.AcquireLock()->StoreExperiment(experiment)); | |
| 84 Experiment stored_experiment; | |
| 85 ASSERT_TRUE(storage.AcquireLock()->LoadExperiment(&stored_experiment)); | |
| 86 EXPECT_EQ(stored_experiment.state(), ExperimentMetrics::kGroupAssigned); | |
|
grt (UTC plus 2)
2017/05/31 12:24:10
can you compare the two instances directly (EXPECT
nikunjb
2017/06/02 05:11:23
Done. (Tested with a small number of values set fo
| |
| 87 } | |
| 88 | |
| 89 TEST_P(ExperimentStorageTest, TestLoadStoreMetrics) { | |
| 90 ExperimentStorage storage; | |
| 91 ExperimentMetrics metrics; | |
| 92 TestExperimentMetrics(&metrics); | |
| 93 ASSERT_TRUE(storage.AcquireLock()->StoreMetrics(metrics)); | |
| 94 ExperimentMetrics stored_metrics; | |
| 95 ASSERT_TRUE(storage.AcquireLock()->LoadMetrics(&stored_metrics)); | |
| 96 EXPECT_EQ(ExperimentStorage::EncodeMetrics(stored_metrics), | |
| 97 base::ASCIIToUTF16("5BIMD4IA")); | |
| 98 EXPECT_EQ(ExperimentStorage::EncodeMetrics(stored_metrics), | |
|
grt (UTC plus 2)
2017/05/31 12:24:10
could you compare the instances rather than their
nikunjb
2017/06/02 05:11:24
Done. Added an operator== in ExperimentMetrics (Si
| |
| 99 ExperimentStorage::EncodeMetrics(metrics)); | |
| 100 } | |
| 101 | |
| 102 INSTANTIATE_TEST_CASE_P(UserLevel, | |
| 103 ExperimentStorageTest, | |
| 104 ::testing::Values(false)); | |
| 105 | |
| 106 INSTANTIATE_TEST_CASE_P(SystemLevel, | |
| 107 ExperimentStorageTest, | |
| 108 ::testing::Values(true)); | |
| 109 } // namespace installer | |
|
grt (UTC plus 2)
2017/05/31 12:24:10
nit: blank line above this
nikunjb
2017/06/02 05:11:24
Done.
| |
| OLD | NEW |