[email protected] | ea3e497 | 2012-04-12 03:41:37 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
brettw | f00b9b4 | 2016-02-01 22:11:38 | [diff] [blame] | 5 | #include "components/prefs/json_pref_store.h" |
[email protected] | 00c8782 | 2012-11-27 19:09:17 | [diff] [blame] | 6 | |
avi | 9ef8bb0 | 2015-12-24 05:29:36 | [diff] [blame] | 7 | #include <stdint.h> |
| 8 | |
dcheng | 5f043bc | 2016-04-22 19:09:06 | [diff] [blame] | 9 | #include <memory> |
danakj | 0c8d4aa | 2015-11-25 05:29:58 | [diff] [blame] | 10 | #include <utility> |
| 11 | |
[email protected] | e33c951 | 2014-05-12 02:24:13 | [diff] [blame] | 12 | #include "base/bind.h" |
[email protected] | e3177dd5 | 2014-08-13 20:22:14 | [diff] [blame] | 13 | #include "base/files/file_util.h" |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 14 | #include "base/files/scoped_temp_dir.h" |
skyostil | 054861d | 2015-04-30 19:06:15 | [diff] [blame] | 15 | #include "base/location.h" |
avi | 9ef8bb0 | 2015-12-24 05:29:36 | [diff] [blame] | 16 | #include "base/macros.h" |
dcheng | 5f043bc | 2016-04-22 19:09:06 | [diff] [blame] | 17 | #include "base/memory/ptr_util.h" |
[email protected] | 3b63f8f4 | 2011-03-28 01:54:15 | [diff] [blame] | 18 | #include "base/memory/ref_counted.h" |
raymes | bfb910a | 2015-04-29 07:43:09 | [diff] [blame] | 19 | #include "base/metrics/histogram_samples.h" |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 20 | #include "base/path_service.h" |
[email protected] | f7b98b3 | 2013-02-05 08:14:15 | [diff] [blame] | 21 | #include "base/run_loop.h" |
skyostil | 054861d | 2015-04-30 19:06:15 | [diff] [blame] | 22 | #include "base/single_thread_task_runner.h" |
[email protected] | dfa049e | 2013-02-07 02:57:22 | [diff] [blame] | 23 | #include "base/strings/string_number_conversions.h" |
[email protected] | d529cb0 | 2013-06-10 19:06:57 | [diff] [blame] | 24 | #include "base/strings/string_util.h" |
[email protected] | a4ea1f1 | 2013-06-07 18:37:07 | [diff] [blame] | 25 | #include "base/strings/utf_string_conversions.h" |
brettw | 58cd1f1 | 2016-01-30 05:56:05 | [diff] [blame] | 26 | #include "base/test/histogram_tester.h" |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 27 | #include "base/test/scoped_task_environment.h" |
raymes | bfb910a | 2015-04-29 07:43:09 | [diff] [blame] | 28 | #include "base/test/simple_test_clock.h" |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 29 | #include "base/threading/sequenced_task_runner_handle.h" |
[email protected] | 0de615a | 2012-11-08 04:40:59 | [diff] [blame] | 30 | #include "base/threading/sequenced_worker_pool.h" |
[email protected] | 34b9963 | 2011-01-01 01:01:06 | [diff] [blame] | 31 | #include "base/threading/thread.h" |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 32 | #include "base/values.h" |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 33 | #include "components/prefs/persistent_pref_store_unittest.h" |
brettw | f00b9b4 | 2016-02-01 22:11:38 | [diff] [blame] | 34 | #include "components/prefs/pref_filter.h" |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 35 | #include "testing/gmock/include/gmock/gmock.h" |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 36 | #include "testing/gtest/include/gtest/gtest.h" |
| 37 | |
[email protected] | 7e3ec42c | 2012-12-16 05:13:21 | [diff] [blame] | 38 | namespace base { |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 39 | namespace { |
| 40 | |
[email protected] | 5bfdcfd | 2012-11-22 22:08:24 | [diff] [blame] | 41 | const char kHomePage[] = "homepage"; |
| 42 | |
brettw | 58cd1f1 | 2016-01-30 05:56:05 | [diff] [blame] | 43 | const char kReadJson[] = |
| 44 | "{\n" |
| 45 | " \"homepage\": \"http://www.cnn.com\",\n" |
| 46 | " \"some_directory\": \"/usr/local/\",\n" |
| 47 | " \"tabs\": {\n" |
| 48 | " \"new_windows_in_tabs\": true,\n" |
| 49 | " \"max_tabs\": 20\n" |
| 50 | " }\n" |
| 51 | "}"; |
| 52 | |
| 53 | const char kInvalidJson[] = "!@#$%^&"; |
| 54 | |
| 55 | // Expected output for tests using RunBasicJsonPrefStoreTest(). |
| 56 | const char kWriteGolden[] = |
| 57 | "{\"homepage\":\"http://www.cnn.com\"," |
| 58 | "\"long_int\":{\"pref\":\"214748364842\"}," |
| 59 | "\"some_directory\":\"/usr/sbin/\"," |
| 60 | "\"tabs\":{\"max_tabs\":10,\"new_windows_in_tabs\":false}}"; |
| 61 | |
raymes | bfb910a | 2015-04-29 07:43:09 | [diff] [blame] | 62 | // Set the time on the given SimpleTestClock to the given time in minutes. |
| 63 | void SetCurrentTimeInMinutes(double minutes, base::SimpleTestClock* clock) { |
| 64 | const int32_t kBaseTimeMins = 100; |
| 65 | clock->SetNow(base::Time::FromDoubleT((kBaseTimeMins + minutes) * 60)); |
| 66 | } |
| 67 | |
[email protected] | e33c951 | 2014-05-12 02:24:13 | [diff] [blame] | 68 | // A PrefFilter that will intercept all calls to FilterOnLoad() and hold on |
| 69 | // to the |prefs| until explicitly asked to release them. |
| 70 | class InterceptingPrefFilter : public PrefFilter { |
| 71 | public: |
| 72 | InterceptingPrefFilter(); |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 73 | InterceptingPrefFilter(OnWriteCallbackPair callback_pair); |
dcheng | 5648818 | 2014-10-21 10:54:51 | [diff] [blame] | 74 | ~InterceptingPrefFilter() override; |
[email protected] | e33c951 | 2014-05-12 02:24:13 | [diff] [blame] | 75 | |
| 76 | // PrefFilter implementation: |
dcheng | 5648818 | 2014-10-21 10:54:51 | [diff] [blame] | 77 | void FilterOnLoad( |
[email protected] | e33c951 | 2014-05-12 02:24:13 | [diff] [blame] | 78 | const PostFilterOnLoadCallback& post_filter_on_load_callback, |
dcheng | 5f043bc | 2016-04-22 19:09:06 | [diff] [blame] | 79 | std::unique_ptr<base::DictionaryValue> pref_store_contents) override; |
dcheng | 5648818 | 2014-10-21 10:54:51 | [diff] [blame] | 80 | void FilterUpdate(const std::string& path) override {} |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 81 | OnWriteCallbackPair FilterSerializeData( |
| 82 | base::DictionaryValue* pref_store_contents) override { |
| 83 | return on_write_callback_pair_; |
| 84 | } |
[email protected] | e33c951 | 2014-05-12 02:24:13 | [diff] [blame] | 85 | |
| 86 | bool has_intercepted_prefs() const { return intercepted_prefs_ != NULL; } |
| 87 | |
[email protected] | cfcf0e5 | 2014-06-20 18:29:47 | [diff] [blame] | 88 | // Finalize an intercepted read, handing |intercepted_prefs_| back to its |
[email protected] | e33c951 | 2014-05-12 02:24:13 | [diff] [blame] | 89 | // JsonPrefStore. |
| 90 | void ReleasePrefs(); |
| 91 | |
| 92 | private: |
| 93 | PostFilterOnLoadCallback post_filter_on_load_callback_; |
dcheng | 5f043bc | 2016-04-22 19:09:06 | [diff] [blame] | 94 | std::unique_ptr<base::DictionaryValue> intercepted_prefs_; |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 95 | OnWriteCallbackPair on_write_callback_pair_; |
[email protected] | e33c951 | 2014-05-12 02:24:13 | [diff] [blame] | 96 | |
| 97 | DISALLOW_COPY_AND_ASSIGN(InterceptingPrefFilter); |
| 98 | }; |
| 99 | |
| 100 | InterceptingPrefFilter::InterceptingPrefFilter() {} |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 101 | |
| 102 | InterceptingPrefFilter::InterceptingPrefFilter( |
| 103 | OnWriteCallbackPair callback_pair) { |
| 104 | on_write_callback_pair_ = callback_pair; |
| 105 | } |
| 106 | |
[email protected] | e33c951 | 2014-05-12 02:24:13 | [diff] [blame] | 107 | InterceptingPrefFilter::~InterceptingPrefFilter() {} |
| 108 | |
| 109 | void InterceptingPrefFilter::FilterOnLoad( |
| 110 | const PostFilterOnLoadCallback& post_filter_on_load_callback, |
dcheng | 5f043bc | 2016-04-22 19:09:06 | [diff] [blame] | 111 | std::unique_ptr<base::DictionaryValue> pref_store_contents) { |
[email protected] | e33c951 | 2014-05-12 02:24:13 | [diff] [blame] | 112 | post_filter_on_load_callback_ = post_filter_on_load_callback; |
danakj | 0c8d4aa | 2015-11-25 05:29:58 | [diff] [blame] | 113 | intercepted_prefs_ = std::move(pref_store_contents); |
[email protected] | e33c951 | 2014-05-12 02:24:13 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | void InterceptingPrefFilter::ReleasePrefs() { |
| 117 | EXPECT_FALSE(post_filter_on_load_callback_.is_null()); |
danakj | 0c8d4aa | 2015-11-25 05:29:58 | [diff] [blame] | 118 | post_filter_on_load_callback_.Run(std::move(intercepted_prefs_), false); |
[email protected] | e33c951 | 2014-05-12 02:24:13 | [diff] [blame] | 119 | post_filter_on_load_callback_.Reset(); |
| 120 | } |
| 121 | |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 122 | class MockPrefStoreObserver : public PrefStore::Observer { |
| 123 | public: |
| 124 | MOCK_METHOD1(OnPrefValueChanged, void (const std::string&)); |
| 125 | MOCK_METHOD1(OnInitializationCompleted, void (bool)); |
| 126 | }; |
| 127 | |
| 128 | class MockReadErrorDelegate : public PersistentPrefStore::ReadErrorDelegate { |
| 129 | public: |
| 130 | MOCK_METHOD1(OnError, void(PersistentPrefStore::PrefReadError)); |
| 131 | }; |
| 132 | |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 133 | enum class CommitPendingWriteMode { |
| 134 | WITHOUT_CALLBACK, |
| 135 | WITH_CALLBACK, |
| 136 | }; |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 137 | |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 138 | void CommitPendingWrite( |
| 139 | JsonPrefStore* pref_store, |
| 140 | CommitPendingWriteMode commit_pending_write_mode, |
| 141 | base::test::ScopedTaskEnvironment* scoped_task_environment) { |
| 142 | if (commit_pending_write_mode == CommitPendingWriteMode::WITHOUT_CALLBACK) { |
| 143 | pref_store->CommitPendingWrite(OnceClosure()); |
| 144 | scoped_task_environment->RunUntilIdle(); |
| 145 | } else { |
Francois Doray | 5f54795 | 2017-07-25 21:02:05 | [diff] [blame^] | 146 | TestCommitPendingWriteWithCallback(pref_store, scoped_task_environment); |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 147 | } |
| 148 | } |
| 149 | |
| 150 | class JsonPrefStoreTest |
| 151 | : public testing::TestWithParam<CommitPendingWriteMode> { |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 152 | public: |
Francois Doray | 5f54795 | 2017-07-25 21:02:05 | [diff] [blame^] | 153 | JsonPrefStoreTest() |
| 154 | : scoped_task_environment_( |
| 155 | base::test::ScopedTaskEnvironment::MainThreadType::DEFAULT, |
| 156 | base::test::ScopedTaskEnvironment::ExecutionMode::QUEUED) {} |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 157 | |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 158 | protected: |
dcheng | 8aef3761 | 2014-12-23 02:56:47 | [diff] [blame] | 159 | void SetUp() override { |
[email protected] | 3a305db | 2011-04-12 13:40:53 | [diff] [blame] | 160 | ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 161 | } |
| 162 | |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 163 | base::test::ScopedTaskEnvironment scoped_task_environment_; |
[email protected] | e33c951 | 2014-05-12 02:24:13 | [diff] [blame] | 164 | |
[email protected] | 3a305db | 2011-04-12 13:40:53 | [diff] [blame] | 165 | // The path to temporary directory used to contain the test operations. |
[email protected] | ea1a3f6 | 2012-11-16 20:34:23 | [diff] [blame] | 166 | base::ScopedTempDir temp_dir_; |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 167 | |
| 168 | DISALLOW_COPY_AND_ASSIGN(JsonPrefStoreTest); |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 169 | }; |
| 170 | |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 171 | } // namespace |
| 172 | |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 173 | // Test fallback behavior for a nonexistent file. |
| 174 | TEST_F(JsonPrefStoreTest, NonExistentFile) { |
vabr | 8023d87 | 2016-09-15 08:12:22 | [diff] [blame] | 175 | base::FilePath bogus_input_file = temp_dir_.GetPath().AppendASCII("read.txt"); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 176 | ASSERT_FALSE(PathExists(bogus_input_file)); |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 177 | auto pref_store = base::MakeRefCounted<JsonPrefStore>(bogus_input_file); |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 178 | EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_NO_FILE, |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 179 | pref_store->ReadPrefs()); |
| 180 | EXPECT_FALSE(pref_store->ReadOnly()); |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | // Test fallback behavior for an invalid file. |
| 184 | TEST_F(JsonPrefStoreTest, InvalidFile) { |
vabr | 8023d87 | 2016-09-15 08:12:22 | [diff] [blame] | 185 | base::FilePath invalid_file = temp_dir_.GetPath().AppendASCII("invalid.json"); |
brettw | 58cd1f1 | 2016-01-30 05:56:05 | [diff] [blame] | 186 | ASSERT_LT(0, base::WriteFile(invalid_file, |
| 187 | kInvalidJson, arraysize(kInvalidJson) - 1)); |
| 188 | |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 189 | auto pref_store = base::MakeRefCounted<JsonPrefStore>(invalid_file); |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 190 | EXPECT_EQ(PersistentPrefStore::PREF_READ_ERROR_JSON_PARSE, |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 191 | pref_store->ReadPrefs()); |
| 192 | EXPECT_FALSE(pref_store->ReadOnly()); |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 193 | |
| 194 | // The file should have been moved aside. |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 195 | EXPECT_FALSE(PathExists(invalid_file)); |
vabr | 8023d87 | 2016-09-15 08:12:22 | [diff] [blame] | 196 | base::FilePath moved_aside = temp_dir_.GetPath().AppendASCII("invalid.bad"); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 197 | EXPECT_TRUE(PathExists(moved_aside)); |
brettw | 58cd1f1 | 2016-01-30 05:56:05 | [diff] [blame] | 198 | |
| 199 | std::string moved_aside_contents; |
| 200 | ASSERT_TRUE(base::ReadFileToString(moved_aside, &moved_aside_contents)); |
| 201 | EXPECT_EQ(kInvalidJson, moved_aside_contents); |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 202 | } |
| 203 | |
brettw | 58cd1f1 | 2016-01-30 05:56:05 | [diff] [blame] | 204 | // This function is used to avoid code duplication while testing synchronous |
| 205 | // and asynchronous version of the JsonPrefStore loading. It validates that the |
| 206 | // given output file's contents matches kWriteGolden. |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 207 | void RunBasicJsonPrefStoreTest( |
| 208 | JsonPrefStore* pref_store, |
| 209 | const base::FilePath& output_file, |
| 210 | CommitPendingWriteMode commit_pending_write_mode, |
| 211 | base::test::ScopedTaskEnvironment* scoped_task_environment) { |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 212 | const char kNewWindowsInTabs[] = "tabs.new_windows_in_tabs"; |
| 213 | const char kMaxTabs[] = "tabs.max_tabs"; |
| 214 | const char kLongIntPref[] = "long_int.pref"; |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 215 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 216 | std::string cnn("http://www.cnn.com"); |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 217 | |
[email protected] | 68bf41a | 2011-03-25 16:38:31 | [diff] [blame] | 218 | const Value* actual; |
[email protected] | 5bfdcfd | 2012-11-22 22:08:24 | [diff] [blame] | 219 | EXPECT_TRUE(pref_store->GetValue(kHomePage, &actual)); |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 220 | std::string string_value; |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 221 | EXPECT_TRUE(actual->GetAsString(&string_value)); |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 222 | EXPECT_EQ(cnn, string_value); |
| 223 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 224 | const char kSomeDirectory[] = "some_directory"; |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 225 | |
[email protected] | 892f1d6 | 2012-11-08 18:24:34 | [diff] [blame] | 226 | EXPECT_TRUE(pref_store->GetValue(kSomeDirectory, &actual)); |
[email protected] | 023ad6ab | 2013-02-17 05:07:23 | [diff] [blame] | 227 | base::FilePath::StringType path; |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 228 | EXPECT_TRUE(actual->GetAsString(&path)); |
[email protected] | 023ad6ab | 2013-02-17 05:07:23 | [diff] [blame] | 229 | EXPECT_EQ(base::FilePath::StringType(FILE_PATH_LITERAL("/usr/local/")), path); |
| 230 | base::FilePath some_path(FILE_PATH_LITERAL("/usr/sbin/")); |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 231 | |
estade | 0bd407f | 2015-06-26 18:16:18 | [diff] [blame] | 232 | pref_store->SetValue(kSomeDirectory, |
jdoerrie | 122c4da | 2017-03-06 11:12:04 | [diff] [blame] | 233 | base::MakeUnique<Value>(some_path.value()), |
raymes | 76de1af | 2015-05-06 03:22:21 | [diff] [blame] | 234 | WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
[email protected] | 892f1d6 | 2012-11-08 18:24:34 | [diff] [blame] | 235 | EXPECT_TRUE(pref_store->GetValue(kSomeDirectory, &actual)); |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 236 | EXPECT_TRUE(actual->GetAsString(&path)); |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 237 | EXPECT_EQ(some_path.value(), path); |
| 238 | |
| 239 | // Test reading some other data types from sub-dictionaries. |
[email protected] | 892f1d6 | 2012-11-08 18:24:34 | [diff] [blame] | 240 | EXPECT_TRUE(pref_store->GetValue(kNewWindowsInTabs, &actual)); |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 241 | bool boolean = false; |
| 242 | EXPECT_TRUE(actual->GetAsBoolean(&boolean)); |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 243 | EXPECT_TRUE(boolean); |
| 244 | |
jdoerrie | 23972357 | 2017-03-02 12:09:19 | [diff] [blame] | 245 | pref_store->SetValue(kNewWindowsInTabs, base::MakeUnique<Value>(false), |
raymes | 76de1af | 2015-05-06 03:22:21 | [diff] [blame] | 246 | WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
[email protected] | 892f1d6 | 2012-11-08 18:24:34 | [diff] [blame] | 247 | EXPECT_TRUE(pref_store->GetValue(kNewWindowsInTabs, &actual)); |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 248 | EXPECT_TRUE(actual->GetAsBoolean(&boolean)); |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 249 | EXPECT_FALSE(boolean); |
| 250 | |
[email protected] | 892f1d6 | 2012-11-08 18:24:34 | [diff] [blame] | 251 | EXPECT_TRUE(pref_store->GetValue(kMaxTabs, &actual)); |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 252 | int integer = 0; |
| 253 | EXPECT_TRUE(actual->GetAsInteger(&integer)); |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 254 | EXPECT_EQ(20, integer); |
jdoerrie | 23972357 | 2017-03-02 12:09:19 | [diff] [blame] | 255 | pref_store->SetValue(kMaxTabs, base::MakeUnique<Value>(10), |
raymes | 76de1af | 2015-05-06 03:22:21 | [diff] [blame] | 256 | WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
[email protected] | 892f1d6 | 2012-11-08 18:24:34 | [diff] [blame] | 257 | EXPECT_TRUE(pref_store->GetValue(kMaxTabs, &actual)); |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 258 | EXPECT_TRUE(actual->GetAsInteger(&integer)); |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 259 | EXPECT_EQ(10, integer); |
| 260 | |
jdoerrie | 122c4da | 2017-03-06 11:12:04 | [diff] [blame] | 261 | pref_store->SetValue( |
| 262 | kLongIntPref, |
| 263 | base::MakeUnique<Value>(base::Int64ToString(214748364842LL)), |
| 264 | WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
[email protected] | 892f1d6 | 2012-11-08 18:24:34 | [diff] [blame] | 265 | EXPECT_TRUE(pref_store->GetValue(kLongIntPref, &actual)); |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 266 | EXPECT_TRUE(actual->GetAsString(&string_value)); |
avi | 9ef8bb0 | 2015-12-24 05:29:36 | [diff] [blame] | 267 | int64_t value; |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 268 | base::StringToInt64(string_value, &value); |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 269 | EXPECT_EQ(214748364842LL, value); |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 270 | |
| 271 | // Serialize and compare to expected output. |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 272 | CommitPendingWrite(pref_store, commit_pending_write_mode, |
| 273 | scoped_task_environment); |
brettw | 58cd1f1 | 2016-01-30 05:56:05 | [diff] [blame] | 274 | |
| 275 | std::string output_contents; |
| 276 | ASSERT_TRUE(base::ReadFileToString(output_file, &output_contents)); |
| 277 | EXPECT_EQ(kWriteGolden, output_contents); |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 278 | ASSERT_TRUE(base::DeleteFile(output_file, false)); |
[email protected] | 277404c2 | 2010-04-22 13:09:45 | [diff] [blame] | 279 | } |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 280 | |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 281 | TEST_P(JsonPrefStoreTest, Basic) { |
vabr | 8023d87 | 2016-09-15 08:12:22 | [diff] [blame] | 282 | base::FilePath input_file = temp_dir_.GetPath().AppendASCII("write.json"); |
brettw | 58cd1f1 | 2016-01-30 05:56:05 | [diff] [blame] | 283 | ASSERT_LT(0, base::WriteFile(input_file, |
| 284 | kReadJson, arraysize(kReadJson) - 1)); |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 285 | |
| 286 | // Test that the persistent value can be loaded. |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 287 | ASSERT_TRUE(PathExists(input_file)); |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 288 | auto pref_store = base::MakeRefCounted<JsonPrefStore>(input_file); |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 289 | ASSERT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, pref_store->ReadPrefs()); |
[email protected] | e33c951 | 2014-05-12 02:24:13 | [diff] [blame] | 290 | EXPECT_FALSE(pref_store->ReadOnly()); |
| 291 | EXPECT_TRUE(pref_store->IsInitializationComplete()); |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 292 | |
| 293 | // The JSON file looks like this: |
| 294 | // { |
| 295 | // "homepage": "http://www.cnn.com", |
| 296 | // "some_directory": "/usr/local/", |
| 297 | // "tabs": { |
| 298 | // "new_windows_in_tabs": true, |
| 299 | // "max_tabs": 20 |
| 300 | // } |
| 301 | // } |
| 302 | |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 303 | RunBasicJsonPrefStoreTest(pref_store.get(), input_file, GetParam(), |
| 304 | &scoped_task_environment_); |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 305 | } |
| 306 | |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 307 | TEST_P(JsonPrefStoreTest, BasicAsync) { |
vabr | 8023d87 | 2016-09-15 08:12:22 | [diff] [blame] | 308 | base::FilePath input_file = temp_dir_.GetPath().AppendASCII("write.json"); |
brettw | 58cd1f1 | 2016-01-30 05:56:05 | [diff] [blame] | 309 | ASSERT_LT(0, base::WriteFile(input_file, |
| 310 | kReadJson, arraysize(kReadJson) - 1)); |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 311 | |
| 312 | // Test that the persistent value can be loaded. |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 313 | auto pref_store = base::MakeRefCounted<JsonPrefStore>(input_file); |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 314 | |
[email protected] | 0de615a | 2012-11-08 04:40:59 | [diff] [blame] | 315 | { |
| 316 | MockPrefStoreObserver mock_observer; |
| 317 | pref_store->AddObserver(&mock_observer); |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 318 | |
[email protected] | 0de615a | 2012-11-08 04:40:59 | [diff] [blame] | 319 | MockReadErrorDelegate* mock_error_delegate = new MockReadErrorDelegate; |
| 320 | pref_store->ReadPrefsAsync(mock_error_delegate); |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 321 | |
[email protected] | 0de615a | 2012-11-08 04:40:59 | [diff] [blame] | 322 | EXPECT_CALL(mock_observer, OnInitializationCompleted(true)).Times(1); |
| 323 | EXPECT_CALL(*mock_error_delegate, |
| 324 | OnError(PersistentPrefStore::PREF_READ_ERROR_NONE)).Times(0); |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 325 | scoped_task_environment_.RunUntilIdle(); |
[email protected] | 0de615a | 2012-11-08 04:40:59 | [diff] [blame] | 326 | pref_store->RemoveObserver(&mock_observer); |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 327 | |
[email protected] | e33c951 | 2014-05-12 02:24:13 | [diff] [blame] | 328 | EXPECT_FALSE(pref_store->ReadOnly()); |
| 329 | EXPECT_TRUE(pref_store->IsInitializationComplete()); |
[email protected] | 0de615a | 2012-11-08 04:40:59 | [diff] [blame] | 330 | } |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 331 | |
| 332 | // The JSON file looks like this: |
| 333 | // { |
| 334 | // "homepage": "http://www.cnn.com", |
| 335 | // "some_directory": "/usr/local/", |
| 336 | // "tabs": { |
| 337 | // "new_windows_in_tabs": true, |
| 338 | // "max_tabs": 20 |
| 339 | // } |
| 340 | // } |
| 341 | |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 342 | RunBasicJsonPrefStoreTest(pref_store.get(), input_file, GetParam(), |
| 343 | &scoped_task_environment_); |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 344 | } |
| 345 | |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 346 | TEST_P(JsonPrefStoreTest, PreserveEmptyValues) { |
vabr | 8023d87 | 2016-09-15 08:12:22 | [diff] [blame] | 347 | FilePath pref_file = temp_dir_.GetPath().AppendASCII("empty_values.json"); |
[email protected] | aa328339 | 2013-11-27 01:38:24 | [diff] [blame] | 348 | |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 349 | auto pref_store = base::MakeRefCounted<JsonPrefStore>(pref_file); |
[email protected] | aa328339 | 2013-11-27 01:38:24 | [diff] [blame] | 350 | |
| 351 | // Set some keys with empty values. |
jdoerrie | 3a7275f8 | 2017-05-31 05:58:33 | [diff] [blame] | 352 | pref_store->SetValue("list", base::MakeUnique<base::ListValue>(), |
raymes | 76de1af | 2015-05-06 03:22:21 | [diff] [blame] | 353 | WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
jdoerrie | 3a7275f8 | 2017-05-31 05:58:33 | [diff] [blame] | 354 | pref_store->SetValue("dict", base::MakeUnique<base::DictionaryValue>(), |
raymes | 76de1af | 2015-05-06 03:22:21 | [diff] [blame] | 355 | WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
[email protected] | aa328339 | 2013-11-27 01:38:24 | [diff] [blame] | 356 | |
| 357 | // Write to file. |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 358 | CommitPendingWrite(pref_store.get(), GetParam(), &scoped_task_environment_); |
[email protected] | aa328339 | 2013-11-27 01:38:24 | [diff] [blame] | 359 | |
| 360 | // Reload. |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 361 | pref_store = base::MakeRefCounted<JsonPrefStore>(pref_file); |
[email protected] | aa328339 | 2013-11-27 01:38:24 | [diff] [blame] | 362 | ASSERT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, pref_store->ReadPrefs()); |
| 363 | ASSERT_FALSE(pref_store->ReadOnly()); |
| 364 | |
| 365 | // Check values. |
| 366 | const Value* result = NULL; |
| 367 | EXPECT_TRUE(pref_store->GetValue("list", &result)); |
| 368 | EXPECT_TRUE(ListValue().Equals(result)); |
| 369 | EXPECT_TRUE(pref_store->GetValue("dict", &result)); |
| 370 | EXPECT_TRUE(DictionaryValue().Equals(result)); |
| 371 | } |
| 372 | |
[email protected] | eeedaa69 | 2014-01-30 09:22:27 | [diff] [blame] | 373 | // This test is just documenting some potentially non-obvious behavior. It |
| 374 | // shouldn't be taken as normative. |
| 375 | TEST_F(JsonPrefStoreTest, RemoveClearsEmptyParent) { |
vabr | 8023d87 | 2016-09-15 08:12:22 | [diff] [blame] | 376 | FilePath pref_file = temp_dir_.GetPath().AppendASCII("empty_values.json"); |
[email protected] | eeedaa69 | 2014-01-30 09:22:27 | [diff] [blame] | 377 | |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 378 | auto pref_store = base::MakeRefCounted<JsonPrefStore>(pref_file); |
[email protected] | eeedaa69 | 2014-01-30 09:22:27 | [diff] [blame] | 379 | |
dcheng | 5f043bc | 2016-04-22 19:09:06 | [diff] [blame] | 380 | std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue); |
[email protected] | eeedaa69 | 2014-01-30 09:22:27 | [diff] [blame] | 381 | dict->SetString("key", "value"); |
danakj | 0c8d4aa | 2015-11-25 05:29:58 | [diff] [blame] | 382 | pref_store->SetValue("dict", std::move(dict), |
raymes | 76de1af | 2015-05-06 03:22:21 | [diff] [blame] | 383 | WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
[email protected] | eeedaa69 | 2014-01-30 09:22:27 | [diff] [blame] | 384 | |
raymes | 76de1af | 2015-05-06 03:22:21 | [diff] [blame] | 385 | pref_store->RemoveValue("dict.key", |
| 386 | WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
[email protected] | eeedaa69 | 2014-01-30 09:22:27 | [diff] [blame] | 387 | |
| 388 | const base::Value* retrieved_dict = NULL; |
| 389 | bool has_dict = pref_store->GetValue("dict", &retrieved_dict); |
| 390 | EXPECT_FALSE(has_dict); |
| 391 | } |
| 392 | |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 393 | // Tests asynchronous reading of the file when there is no file. |
| 394 | TEST_F(JsonPrefStoreTest, AsyncNonExistingFile) { |
vabr | 8023d87 | 2016-09-15 08:12:22 | [diff] [blame] | 395 | base::FilePath bogus_input_file = temp_dir_.GetPath().AppendASCII("read.txt"); |
[email protected] | 756748414 | 2013-07-11 17:36:07 | [diff] [blame] | 396 | ASSERT_FALSE(PathExists(bogus_input_file)); |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 397 | auto pref_store = base::MakeRefCounted<JsonPrefStore>(bogus_input_file); |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 398 | MockPrefStoreObserver mock_observer; |
| 399 | pref_store->AddObserver(&mock_observer); |
| 400 | |
| 401 | MockReadErrorDelegate *mock_error_delegate = new MockReadErrorDelegate; |
| 402 | pref_store->ReadPrefsAsync(mock_error_delegate); |
| 403 | |
| 404 | EXPECT_CALL(mock_observer, OnInitializationCompleted(true)).Times(1); |
| 405 | EXPECT_CALL(*mock_error_delegate, |
| 406 | OnError(PersistentPrefStore::PREF_READ_ERROR_NO_FILE)).Times(1); |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 407 | scoped_task_environment_.RunUntilIdle(); |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 408 | pref_store->RemoveObserver(&mock_observer); |
| 409 | |
| 410 | EXPECT_FALSE(pref_store->ReadOnly()); |
| 411 | } |
[email protected] | ea3e497 | 2012-04-12 03:41:37 | [diff] [blame] | 412 | |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 413 | TEST_P(JsonPrefStoreTest, ReadWithInterceptor) { |
vabr | 8023d87 | 2016-09-15 08:12:22 | [diff] [blame] | 414 | base::FilePath input_file = temp_dir_.GetPath().AppendASCII("write.json"); |
brettw | 58cd1f1 | 2016-01-30 05:56:05 | [diff] [blame] | 415 | ASSERT_LT(0, base::WriteFile(input_file, |
| 416 | kReadJson, arraysize(kReadJson) - 1)); |
[email protected] | e33c951 | 2014-05-12 02:24:13 | [diff] [blame] | 417 | |
dcheng | 5f043bc | 2016-04-22 19:09:06 | [diff] [blame] | 418 | std::unique_ptr<InterceptingPrefFilter> intercepting_pref_filter( |
[email protected] | e33c951 | 2014-05-12 02:24:13 | [diff] [blame] | 419 | new InterceptingPrefFilter()); |
| 420 | InterceptingPrefFilter* raw_intercepting_pref_filter_ = |
| 421 | intercepting_pref_filter.get(); |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 422 | auto pref_store = base::MakeRefCounted<JsonPrefStore>( |
| 423 | input_file, base::CreateSequencedTaskRunnerWithTraits({base::MayBlock()}), |
| 424 | std::move(intercepting_pref_filter)); |
[email protected] | e33c951 | 2014-05-12 02:24:13 | [diff] [blame] | 425 | |
| 426 | ASSERT_EQ(PersistentPrefStore::PREF_READ_ERROR_ASYNCHRONOUS_TASK_INCOMPLETE, |
| 427 | pref_store->ReadPrefs()); |
| 428 | EXPECT_FALSE(pref_store->ReadOnly()); |
| 429 | |
| 430 | // The store shouldn't be considered initialized until the interceptor |
| 431 | // returns. |
| 432 | EXPECT_TRUE(raw_intercepting_pref_filter_->has_intercepted_prefs()); |
| 433 | EXPECT_FALSE(pref_store->IsInitializationComplete()); |
| 434 | EXPECT_FALSE(pref_store->GetValue(kHomePage, NULL)); |
| 435 | |
| 436 | raw_intercepting_pref_filter_->ReleasePrefs(); |
| 437 | |
| 438 | EXPECT_FALSE(raw_intercepting_pref_filter_->has_intercepted_prefs()); |
| 439 | EXPECT_TRUE(pref_store->IsInitializationComplete()); |
| 440 | EXPECT_TRUE(pref_store->GetValue(kHomePage, NULL)); |
| 441 | |
| 442 | // The JSON file looks like this: |
| 443 | // { |
| 444 | // "homepage": "http://www.cnn.com", |
| 445 | // "some_directory": "/usr/local/", |
| 446 | // "tabs": { |
| 447 | // "new_windows_in_tabs": true, |
| 448 | // "max_tabs": 20 |
| 449 | // } |
| 450 | // } |
| 451 | |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 452 | RunBasicJsonPrefStoreTest(pref_store.get(), input_file, GetParam(), |
| 453 | &scoped_task_environment_); |
[email protected] | e33c951 | 2014-05-12 02:24:13 | [diff] [blame] | 454 | } |
| 455 | |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 456 | TEST_P(JsonPrefStoreTest, ReadAsyncWithInterceptor) { |
vabr | 8023d87 | 2016-09-15 08:12:22 | [diff] [blame] | 457 | base::FilePath input_file = temp_dir_.GetPath().AppendASCII("write.json"); |
brettw | 58cd1f1 | 2016-01-30 05:56:05 | [diff] [blame] | 458 | ASSERT_LT(0, base::WriteFile(input_file, |
| 459 | kReadJson, arraysize(kReadJson) - 1)); |
[email protected] | e33c951 | 2014-05-12 02:24:13 | [diff] [blame] | 460 | |
dcheng | 5f043bc | 2016-04-22 19:09:06 | [diff] [blame] | 461 | std::unique_ptr<InterceptingPrefFilter> intercepting_pref_filter( |
[email protected] | e33c951 | 2014-05-12 02:24:13 | [diff] [blame] | 462 | new InterceptingPrefFilter()); |
| 463 | InterceptingPrefFilter* raw_intercepting_pref_filter_ = |
| 464 | intercepting_pref_filter.get(); |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 465 | auto pref_store = base::MakeRefCounted<JsonPrefStore>( |
| 466 | input_file, base::CreateSequencedTaskRunnerWithTraits({base::MayBlock()}), |
| 467 | std::move(intercepting_pref_filter)); |
[email protected] | e33c951 | 2014-05-12 02:24:13 | [diff] [blame] | 468 | |
| 469 | MockPrefStoreObserver mock_observer; |
| 470 | pref_store->AddObserver(&mock_observer); |
| 471 | |
| 472 | // Ownership of the |mock_error_delegate| is handed to the |pref_store| below. |
| 473 | MockReadErrorDelegate* mock_error_delegate = new MockReadErrorDelegate; |
| 474 | |
| 475 | { |
| 476 | pref_store->ReadPrefsAsync(mock_error_delegate); |
| 477 | |
| 478 | EXPECT_CALL(mock_observer, OnInitializationCompleted(true)).Times(0); |
| 479 | // EXPECT_CALL(*mock_error_delegate, |
| 480 | // OnError(PersistentPrefStore::PREF_READ_ERROR_NONE)).Times(0); |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 481 | scoped_task_environment_.RunUntilIdle(); |
[email protected] | e33c951 | 2014-05-12 02:24:13 | [diff] [blame] | 482 | |
| 483 | EXPECT_FALSE(pref_store->ReadOnly()); |
| 484 | EXPECT_TRUE(raw_intercepting_pref_filter_->has_intercepted_prefs()); |
| 485 | EXPECT_FALSE(pref_store->IsInitializationComplete()); |
| 486 | EXPECT_FALSE(pref_store->GetValue(kHomePage, NULL)); |
| 487 | } |
| 488 | |
| 489 | { |
| 490 | EXPECT_CALL(mock_observer, OnInitializationCompleted(true)).Times(1); |
| 491 | // EXPECT_CALL(*mock_error_delegate, |
| 492 | // OnError(PersistentPrefStore::PREF_READ_ERROR_NONE)).Times(0); |
| 493 | |
| 494 | raw_intercepting_pref_filter_->ReleasePrefs(); |
| 495 | |
| 496 | EXPECT_FALSE(pref_store->ReadOnly()); |
| 497 | EXPECT_FALSE(raw_intercepting_pref_filter_->has_intercepted_prefs()); |
| 498 | EXPECT_TRUE(pref_store->IsInitializationComplete()); |
| 499 | EXPECT_TRUE(pref_store->GetValue(kHomePage, NULL)); |
| 500 | } |
| 501 | |
| 502 | pref_store->RemoveObserver(&mock_observer); |
| 503 | |
| 504 | // The JSON file looks like this: |
| 505 | // { |
| 506 | // "homepage": "http://www.cnn.com", |
| 507 | // "some_directory": "/usr/local/", |
| 508 | // "tabs": { |
| 509 | // "new_windows_in_tabs": true, |
| 510 | // "max_tabs": 20 |
| 511 | // } |
| 512 | // } |
| 513 | |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 514 | RunBasicJsonPrefStoreTest(pref_store.get(), input_file, GetParam(), |
| 515 | &scoped_task_environment_); |
[email protected] | e33c951 | 2014-05-12 02:24:13 | [diff] [blame] | 516 | } |
| 517 | |
raymes | bfb910a | 2015-04-29 07:43:09 | [diff] [blame] | 518 | TEST_F(JsonPrefStoreTest, WriteCountHistogramTestBasic) { |
brettw | 58cd1f1 | 2016-01-30 05:56:05 | [diff] [blame] | 519 | base::HistogramTester histogram_tester; |
| 520 | |
raymes | bfb910a | 2015-04-29 07:43:09 | [diff] [blame] | 521 | SimpleTestClock* test_clock = new SimpleTestClock; |
| 522 | SetCurrentTimeInMinutes(0, test_clock); |
| 523 | JsonPrefStore::WriteCountHistogram histogram( |
| 524 | base::TimeDelta::FromSeconds(10), |
| 525 | base::FilePath(FILE_PATH_LITERAL("/tmp/Local State")), |
dcheng | 5f043bc | 2016-04-22 19:09:06 | [diff] [blame] | 526 | std::unique_ptr<base::Clock>(test_clock)); |
avi | 9ef8bb0 | 2015-12-24 05:29:36 | [diff] [blame] | 527 | int32_t report_interval = |
raymes | bfb910a | 2015-04-29 07:43:09 | [diff] [blame] | 528 | JsonPrefStore::WriteCountHistogram::kHistogramWriteReportIntervalMins; |
| 529 | |
| 530 | histogram.RecordWriteOccured(); |
| 531 | |
| 532 | SetCurrentTimeInMinutes(1.5 * report_interval, test_clock); |
| 533 | histogram.ReportOutstandingWrites(); |
dcheng | 5f043bc | 2016-04-22 19:09:06 | [diff] [blame] | 534 | std::unique_ptr<HistogramSamples> samples = |
raymes | bfb910a | 2015-04-29 07:43:09 | [diff] [blame] | 535 | histogram.GetHistogram()->SnapshotSamples(); |
brettw | 58cd1f1 | 2016-01-30 05:56:05 | [diff] [blame] | 536 | |
| 537 | std::string histogram_name = histogram.GetHistogram()->histogram_name(); |
| 538 | histogram_tester.ExpectBucketCount(histogram_name, 1, 1); |
| 539 | histogram_tester.ExpectTotalCount(histogram_name, 1); |
raymes | bfb910a | 2015-04-29 07:43:09 | [diff] [blame] | 540 | |
| 541 | ASSERT_EQ("Settings.JsonDataWriteCount.Local_State", |
| 542 | histogram.GetHistogram()->histogram_name()); |
| 543 | ASSERT_TRUE(histogram.GetHistogram()->HasConstructionArguments(1, 30, 31)); |
| 544 | } |
| 545 | |
| 546 | TEST_F(JsonPrefStoreTest, WriteCountHistogramTestSinglePeriod) { |
brettw | 58cd1f1 | 2016-01-30 05:56:05 | [diff] [blame] | 547 | base::HistogramTester histogram_tester; |
| 548 | |
raymes | bfb910a | 2015-04-29 07:43:09 | [diff] [blame] | 549 | SimpleTestClock* test_clock = new SimpleTestClock; |
| 550 | SetCurrentTimeInMinutes(0, test_clock); |
| 551 | JsonPrefStore::WriteCountHistogram histogram( |
| 552 | base::TimeDelta::FromSeconds(10), |
| 553 | base::FilePath(FILE_PATH_LITERAL("/tmp/Local State")), |
dcheng | 5f043bc | 2016-04-22 19:09:06 | [diff] [blame] | 554 | std::unique_ptr<base::Clock>(test_clock)); |
avi | 9ef8bb0 | 2015-12-24 05:29:36 | [diff] [blame] | 555 | int32_t report_interval = |
raymes | bfb910a | 2015-04-29 07:43:09 | [diff] [blame] | 556 | JsonPrefStore::WriteCountHistogram::kHistogramWriteReportIntervalMins; |
| 557 | |
| 558 | histogram.RecordWriteOccured(); |
| 559 | SetCurrentTimeInMinutes(0.5 * report_interval, test_clock); |
| 560 | histogram.RecordWriteOccured(); |
| 561 | SetCurrentTimeInMinutes(0.7 * report_interval, test_clock); |
| 562 | histogram.RecordWriteOccured(); |
| 563 | |
| 564 | // Nothing should be recorded until the report period has elapsed. |
brettw | 58cd1f1 | 2016-01-30 05:56:05 | [diff] [blame] | 565 | std::string histogram_name = histogram.GetHistogram()->histogram_name(); |
| 566 | histogram_tester.ExpectTotalCount(histogram_name, 0); |
raymes | bfb910a | 2015-04-29 07:43:09 | [diff] [blame] | 567 | |
| 568 | SetCurrentTimeInMinutes(1.3 * report_interval, test_clock); |
| 569 | histogram.RecordWriteOccured(); |
| 570 | |
| 571 | // Now the report period has elapsed. |
brettw | 58cd1f1 | 2016-01-30 05:56:05 | [diff] [blame] | 572 | histogram_tester.ExpectBucketCount(histogram_name, 3, 1); |
| 573 | histogram_tester.ExpectTotalCount(histogram_name, 1); |
raymes | bfb910a | 2015-04-29 07:43:09 | [diff] [blame] | 574 | |
| 575 | // The last write won't be recorded because the second count period hasn't |
| 576 | // fully elapsed. |
| 577 | SetCurrentTimeInMinutes(1.5 * report_interval, test_clock); |
| 578 | histogram.ReportOutstandingWrites(); |
| 579 | |
brettw | 58cd1f1 | 2016-01-30 05:56:05 | [diff] [blame] | 580 | histogram_tester.ExpectBucketCount(histogram_name, 3, 1); |
| 581 | histogram_tester.ExpectTotalCount(histogram_name, 1); |
raymes | bfb910a | 2015-04-29 07:43:09 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | TEST_F(JsonPrefStoreTest, WriteCountHistogramTestMultiplePeriods) { |
brettw | 58cd1f1 | 2016-01-30 05:56:05 | [diff] [blame] | 585 | base::HistogramTester histogram_tester; |
| 586 | |
raymes | bfb910a | 2015-04-29 07:43:09 | [diff] [blame] | 587 | SimpleTestClock* test_clock = new SimpleTestClock; |
| 588 | SetCurrentTimeInMinutes(0, test_clock); |
| 589 | JsonPrefStore::WriteCountHistogram histogram( |
| 590 | base::TimeDelta::FromSeconds(10), |
| 591 | base::FilePath(FILE_PATH_LITERAL("/tmp/Local State")), |
dcheng | 5f043bc | 2016-04-22 19:09:06 | [diff] [blame] | 592 | std::unique_ptr<base::Clock>(test_clock)); |
avi | 9ef8bb0 | 2015-12-24 05:29:36 | [diff] [blame] | 593 | int32_t report_interval = |
raymes | bfb910a | 2015-04-29 07:43:09 | [diff] [blame] | 594 | JsonPrefStore::WriteCountHistogram::kHistogramWriteReportIntervalMins; |
| 595 | |
| 596 | histogram.RecordWriteOccured(); |
| 597 | SetCurrentTimeInMinutes(0.5 * report_interval, test_clock); |
| 598 | histogram.RecordWriteOccured(); |
| 599 | SetCurrentTimeInMinutes(0.7 * report_interval, test_clock); |
| 600 | histogram.RecordWriteOccured(); |
| 601 | SetCurrentTimeInMinutes(1.3 * report_interval, test_clock); |
| 602 | histogram.RecordWriteOccured(); |
| 603 | SetCurrentTimeInMinutes(1.5 * report_interval, test_clock); |
| 604 | histogram.RecordWriteOccured(); |
| 605 | SetCurrentTimeInMinutes(2.1 * report_interval, test_clock); |
| 606 | histogram.RecordWriteOccured(); |
| 607 | SetCurrentTimeInMinutes(2.5 * report_interval, test_clock); |
| 608 | histogram.RecordWriteOccured(); |
| 609 | SetCurrentTimeInMinutes(2.7 * report_interval, test_clock); |
| 610 | histogram.RecordWriteOccured(); |
| 611 | SetCurrentTimeInMinutes(3.3 * report_interval, test_clock); |
| 612 | histogram.RecordWriteOccured(); |
| 613 | |
| 614 | // The last write won't be recorded because the second count period hasn't |
| 615 | // fully elapsed |
| 616 | SetCurrentTimeInMinutes(3.5 * report_interval, test_clock); |
| 617 | histogram.ReportOutstandingWrites(); |
brettw | 58cd1f1 | 2016-01-30 05:56:05 | [diff] [blame] | 618 | std::string histogram_name = histogram.GetHistogram()->histogram_name(); |
| 619 | histogram_tester.ExpectBucketCount(histogram_name, 3, 2); |
| 620 | histogram_tester.ExpectBucketCount(histogram_name, 2, 1); |
| 621 | histogram_tester.ExpectTotalCount(histogram_name, 3); |
raymes | bfb910a | 2015-04-29 07:43:09 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | TEST_F(JsonPrefStoreTest, WriteCountHistogramTestPeriodWithGaps) { |
brettw | 58cd1f1 | 2016-01-30 05:56:05 | [diff] [blame] | 625 | base::HistogramTester histogram_tester; |
| 626 | |
raymes | bfb910a | 2015-04-29 07:43:09 | [diff] [blame] | 627 | SimpleTestClock* test_clock = new SimpleTestClock; |
| 628 | SetCurrentTimeInMinutes(0, test_clock); |
| 629 | JsonPrefStore::WriteCountHistogram histogram( |
| 630 | base::TimeDelta::FromSeconds(10), |
| 631 | base::FilePath(FILE_PATH_LITERAL("/tmp/Local State")), |
dcheng | 5f043bc | 2016-04-22 19:09:06 | [diff] [blame] | 632 | std::unique_ptr<base::Clock>(test_clock)); |
avi | 9ef8bb0 | 2015-12-24 05:29:36 | [diff] [blame] | 633 | int32_t report_interval = |
raymes | bfb910a | 2015-04-29 07:43:09 | [diff] [blame] | 634 | JsonPrefStore::WriteCountHistogram::kHistogramWriteReportIntervalMins; |
| 635 | |
| 636 | // 1 write in the first period. |
| 637 | histogram.RecordWriteOccured(); |
| 638 | |
| 639 | // No writes in the second and third periods. |
| 640 | |
| 641 | // 2 writes in the fourth period. |
| 642 | SetCurrentTimeInMinutes(3.1 * report_interval, test_clock); |
| 643 | histogram.RecordWriteOccured(); |
| 644 | SetCurrentTimeInMinutes(3.3 * report_interval, test_clock); |
| 645 | histogram.RecordWriteOccured(); |
| 646 | |
| 647 | // No writes in the fifth period. |
| 648 | |
| 649 | // 3 writes in the sixth period. |
| 650 | SetCurrentTimeInMinutes(5.1 * report_interval, test_clock); |
| 651 | histogram.RecordWriteOccured(); |
| 652 | SetCurrentTimeInMinutes(5.3 * report_interval, test_clock); |
| 653 | histogram.RecordWriteOccured(); |
| 654 | SetCurrentTimeInMinutes(5.5 * report_interval, test_clock); |
| 655 | histogram.RecordWriteOccured(); |
| 656 | |
| 657 | SetCurrentTimeInMinutes(6.1 * report_interval, test_clock); |
| 658 | histogram.ReportOutstandingWrites(); |
brettw | 58cd1f1 | 2016-01-30 05:56:05 | [diff] [blame] | 659 | std::string histogram_name = histogram.GetHistogram()->histogram_name(); |
| 660 | histogram_tester.ExpectBucketCount(histogram_name, 0, 3); |
| 661 | histogram_tester.ExpectBucketCount(histogram_name, 1, 1); |
| 662 | histogram_tester.ExpectBucketCount(histogram_name, 2, 1); |
| 663 | histogram_tester.ExpectBucketCount(histogram_name, 3, 1); |
| 664 | histogram_tester.ExpectTotalCount(histogram_name, 6); |
raymes | bfb910a | 2015-04-29 07:43:09 | [diff] [blame] | 665 | } |
| 666 | |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 667 | INSTANTIATE_TEST_CASE_P( |
| 668 | WithoutCallback, |
| 669 | JsonPrefStoreTest, |
| 670 | ::testing::Values(CommitPendingWriteMode::WITHOUT_CALLBACK)); |
| 671 | INSTANTIATE_TEST_CASE_P( |
| 672 | WithCallback, |
| 673 | JsonPrefStoreTest, |
| 674 | ::testing::Values(CommitPendingWriteMode::WITH_CALLBACK)); |
| 675 | |
raymes | 4b6e14e | 2015-05-12 00:10:30 | [diff] [blame] | 676 | class JsonPrefStoreLossyWriteTest : public JsonPrefStoreTest { |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 677 | public: |
| 678 | JsonPrefStoreLossyWriteTest() = default; |
| 679 | |
raymes | 4b6e14e | 2015-05-12 00:10:30 | [diff] [blame] | 680 | protected: |
| 681 | void SetUp() override { |
| 682 | JsonPrefStoreTest::SetUp(); |
vabr | 8023d87 | 2016-09-15 08:12:22 | [diff] [blame] | 683 | test_file_ = temp_dir_.GetPath().AppendASCII("test.json"); |
raymes | 4b6e14e | 2015-05-12 00:10:30 | [diff] [blame] | 684 | } |
| 685 | |
raymes | 4b6e14e | 2015-05-12 00:10:30 | [diff] [blame] | 686 | scoped_refptr<JsonPrefStore> CreatePrefStore() { |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 687 | return base::MakeRefCounted<JsonPrefStore>(test_file_); |
raymes | 4b6e14e | 2015-05-12 00:10:30 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | // Return the ImportantFileWriter for a given JsonPrefStore. |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 691 | ImportantFileWriter* GetImportantFileWriter(JsonPrefStore* pref_store) { |
raymes | 4b6e14e | 2015-05-12 00:10:30 | [diff] [blame] | 692 | return &(pref_store->writer_); |
| 693 | } |
| 694 | |
| 695 | // Get the contents of kTestFile. Pumps the message loop before returning the |
| 696 | // result. |
| 697 | std::string GetTestFileContents() { |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 698 | scoped_task_environment_.RunUntilIdle(); |
raymes | 4b6e14e | 2015-05-12 00:10:30 | [diff] [blame] | 699 | std::string file_contents; |
| 700 | ReadFileToString(test_file_, &file_contents); |
| 701 | return file_contents; |
| 702 | } |
| 703 | |
| 704 | private: |
| 705 | base::FilePath test_file_; |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 706 | |
| 707 | DISALLOW_COPY_AND_ASSIGN(JsonPrefStoreLossyWriteTest); |
raymes | 4b6e14e | 2015-05-12 00:10:30 | [diff] [blame] | 708 | }; |
| 709 | |
| 710 | TEST_F(JsonPrefStoreLossyWriteTest, LossyWriteBasic) { |
| 711 | scoped_refptr<JsonPrefStore> pref_store = CreatePrefStore(); |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 712 | ImportantFileWriter* file_writer = GetImportantFileWriter(pref_store.get()); |
raymes | 4b6e14e | 2015-05-12 00:10:30 | [diff] [blame] | 713 | |
| 714 | // Set a normal pref and check that it gets scheduled to be written. |
| 715 | ASSERT_FALSE(file_writer->HasPendingWrite()); |
jdoerrie | 122c4da | 2017-03-06 11:12:04 | [diff] [blame] | 716 | pref_store->SetValue("normal", base::MakeUnique<base::Value>("normal"), |
raymes | 4b6e14e | 2015-05-12 00:10:30 | [diff] [blame] | 717 | WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
| 718 | ASSERT_TRUE(file_writer->HasPendingWrite()); |
| 719 | file_writer->DoScheduledWrite(); |
| 720 | ASSERT_EQ("{\"normal\":\"normal\"}", GetTestFileContents()); |
| 721 | ASSERT_FALSE(file_writer->HasPendingWrite()); |
| 722 | |
| 723 | // Set a lossy pref and check that it is not scheduled to be written. |
| 724 | // SetValue/RemoveValue. |
jdoerrie | 122c4da | 2017-03-06 11:12:04 | [diff] [blame] | 725 | pref_store->SetValue("lossy", base::MakeUnique<base::Value>("lossy"), |
raymes | 4b6e14e | 2015-05-12 00:10:30 | [diff] [blame] | 726 | WriteablePrefStore::LOSSY_PREF_WRITE_FLAG); |
| 727 | ASSERT_FALSE(file_writer->HasPendingWrite()); |
| 728 | pref_store->RemoveValue("lossy", WriteablePrefStore::LOSSY_PREF_WRITE_FLAG); |
| 729 | ASSERT_FALSE(file_writer->HasPendingWrite()); |
| 730 | |
| 731 | // SetValueSilently/RemoveValueSilently. |
jdoerrie | 122c4da | 2017-03-06 11:12:04 | [diff] [blame] | 732 | pref_store->SetValueSilently("lossy", base::MakeUnique<base::Value>("lossy"), |
raymes | 4b6e14e | 2015-05-12 00:10:30 | [diff] [blame] | 733 | WriteablePrefStore::LOSSY_PREF_WRITE_FLAG); |
| 734 | ASSERT_FALSE(file_writer->HasPendingWrite()); |
| 735 | pref_store->RemoveValueSilently("lossy", |
| 736 | WriteablePrefStore::LOSSY_PREF_WRITE_FLAG); |
| 737 | ASSERT_FALSE(file_writer->HasPendingWrite()); |
| 738 | |
| 739 | // ReportValueChanged. |
jdoerrie | 122c4da | 2017-03-06 11:12:04 | [diff] [blame] | 740 | pref_store->SetValue("lossy", base::MakeUnique<base::Value>("lossy"), |
raymes | 4b6e14e | 2015-05-12 00:10:30 | [diff] [blame] | 741 | WriteablePrefStore::LOSSY_PREF_WRITE_FLAG); |
| 742 | ASSERT_FALSE(file_writer->HasPendingWrite()); |
| 743 | pref_store->ReportValueChanged("lossy", |
| 744 | WriteablePrefStore::LOSSY_PREF_WRITE_FLAG); |
| 745 | ASSERT_FALSE(file_writer->HasPendingWrite()); |
| 746 | |
| 747 | // Call CommitPendingWrite and check that the lossy pref and the normal pref |
| 748 | // are there with the last values set above. |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 749 | pref_store->CommitPendingWrite(base::OnceClosure()); |
raymes | 4b6e14e | 2015-05-12 00:10:30 | [diff] [blame] | 750 | ASSERT_FALSE(file_writer->HasPendingWrite()); |
| 751 | ASSERT_EQ("{\"lossy\":\"lossy\",\"normal\":\"normal\"}", |
| 752 | GetTestFileContents()); |
| 753 | } |
| 754 | |
| 755 | TEST_F(JsonPrefStoreLossyWriteTest, LossyWriteMixedLossyFirst) { |
| 756 | scoped_refptr<JsonPrefStore> pref_store = CreatePrefStore(); |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 757 | ImportantFileWriter* file_writer = GetImportantFileWriter(pref_store.get()); |
raymes | 4b6e14e | 2015-05-12 00:10:30 | [diff] [blame] | 758 | |
| 759 | // Set a lossy pref and check that it is not scheduled to be written. |
| 760 | ASSERT_FALSE(file_writer->HasPendingWrite()); |
jdoerrie | 122c4da | 2017-03-06 11:12:04 | [diff] [blame] | 761 | pref_store->SetValue("lossy", base::MakeUnique<base::Value>("lossy"), |
raymes | 4b6e14e | 2015-05-12 00:10:30 | [diff] [blame] | 762 | WriteablePrefStore::LOSSY_PREF_WRITE_FLAG); |
| 763 | ASSERT_FALSE(file_writer->HasPendingWrite()); |
| 764 | |
| 765 | // Set a normal pref and check that it is scheduled to be written. |
jdoerrie | 122c4da | 2017-03-06 11:12:04 | [diff] [blame] | 766 | pref_store->SetValue("normal", base::MakeUnique<base::Value>("normal"), |
raymes | 4b6e14e | 2015-05-12 00:10:30 | [diff] [blame] | 767 | WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
| 768 | ASSERT_TRUE(file_writer->HasPendingWrite()); |
| 769 | |
| 770 | // Call DoScheduledWrite and check both prefs get written. |
| 771 | file_writer->DoScheduledWrite(); |
| 772 | ASSERT_EQ("{\"lossy\":\"lossy\",\"normal\":\"normal\"}", |
| 773 | GetTestFileContents()); |
| 774 | ASSERT_FALSE(file_writer->HasPendingWrite()); |
| 775 | } |
| 776 | |
| 777 | TEST_F(JsonPrefStoreLossyWriteTest, LossyWriteMixedLossySecond) { |
| 778 | scoped_refptr<JsonPrefStore> pref_store = CreatePrefStore(); |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 779 | ImportantFileWriter* file_writer = GetImportantFileWriter(pref_store.get()); |
raymes | 4b6e14e | 2015-05-12 00:10:30 | [diff] [blame] | 780 | |
| 781 | // Set a normal pref and check that it is scheduled to be written. |
| 782 | ASSERT_FALSE(file_writer->HasPendingWrite()); |
jdoerrie | 122c4da | 2017-03-06 11:12:04 | [diff] [blame] | 783 | pref_store->SetValue("normal", base::MakeUnique<base::Value>("normal"), |
raymes | 4b6e14e | 2015-05-12 00:10:30 | [diff] [blame] | 784 | WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
| 785 | ASSERT_TRUE(file_writer->HasPendingWrite()); |
| 786 | |
| 787 | // Set a lossy pref and check that the write is still scheduled. |
jdoerrie | 122c4da | 2017-03-06 11:12:04 | [diff] [blame] | 788 | pref_store->SetValue("lossy", base::MakeUnique<base::Value>("lossy"), |
raymes | 4b6e14e | 2015-05-12 00:10:30 | [diff] [blame] | 789 | WriteablePrefStore::LOSSY_PREF_WRITE_FLAG); |
| 790 | ASSERT_TRUE(file_writer->HasPendingWrite()); |
| 791 | |
| 792 | // Call DoScheduledWrite and check both prefs get written. |
| 793 | file_writer->DoScheduledWrite(); |
| 794 | ASSERT_EQ("{\"lossy\":\"lossy\",\"normal\":\"normal\"}", |
| 795 | GetTestFileContents()); |
| 796 | ASSERT_FALSE(file_writer->HasPendingWrite()); |
| 797 | } |
| 798 | |
benwells | 2673059 | 2015-05-28 13:08:08 | [diff] [blame] | 799 | TEST_F(JsonPrefStoreLossyWriteTest, ScheduleLossyWrite) { |
| 800 | scoped_refptr<JsonPrefStore> pref_store = CreatePrefStore(); |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 801 | ImportantFileWriter* file_writer = GetImportantFileWriter(pref_store.get()); |
benwells | 2673059 | 2015-05-28 13:08:08 | [diff] [blame] | 802 | |
| 803 | // Set a lossy pref and check that it is not scheduled to be written. |
jdoerrie | 122c4da | 2017-03-06 11:12:04 | [diff] [blame] | 804 | pref_store->SetValue("lossy", base::MakeUnique<base::Value>("lossy"), |
benwells | 2673059 | 2015-05-28 13:08:08 | [diff] [blame] | 805 | WriteablePrefStore::LOSSY_PREF_WRITE_FLAG); |
| 806 | ASSERT_FALSE(file_writer->HasPendingWrite()); |
| 807 | |
| 808 | // Schedule pending lossy writes and check that it is scheduled. |
| 809 | pref_store->SchedulePendingLossyWrites(); |
| 810 | ASSERT_TRUE(file_writer->HasPendingWrite()); |
| 811 | |
| 812 | // Call CommitPendingWrite and check that the lossy pref is there with the |
| 813 | // last value set above. |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 814 | pref_store->CommitPendingWrite(base::OnceClosure()); |
benwells | 2673059 | 2015-05-28 13:08:08 | [diff] [blame] | 815 | ASSERT_FALSE(file_writer->HasPendingWrite()); |
| 816 | ASSERT_EQ("{\"lossy\":\"lossy\"}", GetTestFileContents()); |
| 817 | } |
| 818 | |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 819 | class SuccessfulWriteReplyObserver { |
| 820 | public: |
| 821 | SuccessfulWriteReplyObserver() = default; |
| 822 | |
| 823 | // Returns true if a successful write was observed via on_successful_write() |
| 824 | // and resets the observation state to false regardless. |
| 825 | bool GetAndResetObservationState() { |
| 826 | bool was_successful_write_observed = successful_write_reply_observed_; |
| 827 | successful_write_reply_observed_ = false; |
| 828 | return was_successful_write_observed; |
| 829 | } |
| 830 | |
| 831 | // Register OnWrite() to be called on the next write of |json_pref_store|. |
| 832 | void ObserveNextWriteCallback(JsonPrefStore* json_pref_store); |
| 833 | |
| 834 | void OnSuccessfulWrite() { |
| 835 | EXPECT_FALSE(successful_write_reply_observed_); |
| 836 | successful_write_reply_observed_ = true; |
| 837 | } |
| 838 | |
| 839 | private: |
| 840 | bool successful_write_reply_observed_ = false; |
| 841 | |
| 842 | DISALLOW_COPY_AND_ASSIGN(SuccessfulWriteReplyObserver); |
| 843 | }; |
| 844 | |
| 845 | void SuccessfulWriteReplyObserver::ObserveNextWriteCallback( |
| 846 | JsonPrefStore* json_pref_store) { |
| 847 | json_pref_store->RegisterOnNextSuccessfulWriteReply( |
| 848 | base::Bind(&SuccessfulWriteReplyObserver::OnSuccessfulWrite, |
| 849 | base::Unretained(this))); |
| 850 | } |
| 851 | |
| 852 | enum WriteCallbackObservationState { |
| 853 | NOT_CALLED, |
| 854 | CALLED_WITH_ERROR, |
| 855 | CALLED_WITH_SUCCESS, |
| 856 | }; |
| 857 | |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 858 | class WriteCallbacksObserver { |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 859 | public: |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 860 | WriteCallbacksObserver() = default; |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 861 | |
| 862 | // Register OnWrite() to be called on the next write of |json_pref_store|. |
| 863 | void ObserveNextWriteCallback(JsonPrefStore* json_pref_store); |
| 864 | |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 865 | // Returns whether OnPreWrite() was called, and resets the observation state |
| 866 | // to false. |
| 867 | bool GetAndResetPreWriteObservationState(); |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 868 | |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 869 | // Returns the |WriteCallbackObservationState| which was observed, then resets |
| 870 | // it to |NOT_CALLED|. |
| 871 | WriteCallbackObservationState GetAndResetPostWriteObservationState(); |
| 872 | |
| 873 | JsonPrefStore::OnWriteCallbackPair GetCallbackPair() { |
| 874 | return std::make_pair( |
| 875 | base::Bind(&WriteCallbacksObserver::OnPreWrite, base::Unretained(this)), |
| 876 | base::Bind(&WriteCallbacksObserver::OnPostWrite, |
| 877 | base::Unretained(this))); |
| 878 | } |
| 879 | |
| 880 | void OnPreWrite() { |
| 881 | EXPECT_FALSE(pre_write_called_); |
| 882 | pre_write_called_ = true; |
| 883 | } |
| 884 | |
| 885 | void OnPostWrite(bool success) { |
| 886 | EXPECT_EQ(NOT_CALLED, post_write_observation_state_); |
| 887 | post_write_observation_state_ = |
| 888 | success ? CALLED_WITH_SUCCESS : CALLED_WITH_ERROR; |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | private: |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 892 | bool pre_write_called_ = false; |
| 893 | WriteCallbackObservationState post_write_observation_state_ = NOT_CALLED; |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 894 | |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 895 | DISALLOW_COPY_AND_ASSIGN(WriteCallbacksObserver); |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 896 | }; |
| 897 | |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 898 | void WriteCallbacksObserver::ObserveNextWriteCallback(JsonPrefStore* writer) { |
| 899 | writer->RegisterOnNextWriteSynchronousCallbacks(GetCallbackPair()); |
| 900 | } |
| 901 | |
| 902 | bool WriteCallbacksObserver::GetAndResetPreWriteObservationState() { |
| 903 | bool observation_state = pre_write_called_; |
| 904 | pre_write_called_ = false; |
| 905 | return observation_state; |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 906 | } |
| 907 | |
| 908 | WriteCallbackObservationState |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 909 | WriteCallbacksObserver::GetAndResetPostWriteObservationState() { |
| 910 | WriteCallbackObservationState state = post_write_observation_state_; |
| 911 | pre_write_called_ = false; |
| 912 | post_write_observation_state_ = NOT_CALLED; |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 913 | return state; |
| 914 | } |
| 915 | |
| 916 | class JsonPrefStoreCallbackTest : public JsonPrefStoreTest { |
| 917 | public: |
| 918 | JsonPrefStoreCallbackTest() = default; |
| 919 | |
| 920 | protected: |
| 921 | void SetUp() override { |
| 922 | JsonPrefStoreTest::SetUp(); |
vabr | 5d919d6 | 2016-09-30 08:55:36 | [diff] [blame] | 923 | test_file_ = temp_dir_.GetPath().AppendASCII("test.json"); |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | scoped_refptr<JsonPrefStore> CreatePrefStore() { |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 927 | return base::MakeRefCounted<JsonPrefStore>(test_file_); |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | // Return the ImportantFileWriter for a given JsonPrefStore. |
| 931 | ImportantFileWriter* GetImportantFileWriter(JsonPrefStore* pref_store) { |
| 932 | return &(pref_store->writer_); |
| 933 | } |
| 934 | |
| 935 | void TriggerFakeWriteForCallback(JsonPrefStore* pref_store, bool success) { |
| 936 | JsonPrefStore::PostWriteCallback( |
| 937 | base::Bind(&JsonPrefStore::RunOrScheduleNextSuccessfulWriteCallback, |
| 938 | pref_store->AsWeakPtr()), |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 939 | base::Bind(&WriteCallbacksObserver::OnPostWrite, |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 940 | base::Unretained(&write_callback_observer_)), |
| 941 | base::SequencedTaskRunnerHandle::Get(), success); |
| 942 | } |
| 943 | |
| 944 | SuccessfulWriteReplyObserver successful_write_reply_observer_; |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 945 | WriteCallbacksObserver write_callback_observer_; |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 946 | |
| 947 | private: |
| 948 | base::FilePath test_file_; |
| 949 | |
| 950 | DISALLOW_COPY_AND_ASSIGN(JsonPrefStoreCallbackTest); |
| 951 | }; |
| 952 | |
Francois Doray | 5f54795 | 2017-07-25 21:02:05 | [diff] [blame^] | 953 | TEST_F(JsonPrefStoreCallbackTest, TestSerializeDataCallbacks) { |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 954 | base::FilePath input_file = temp_dir_.GetPath().AppendASCII("write.json"); |
| 955 | ASSERT_LT(0, |
| 956 | base::WriteFile(input_file, kReadJson, arraysize(kReadJson) - 1)); |
| 957 | |
| 958 | std::unique_ptr<InterceptingPrefFilter> intercepting_pref_filter( |
| 959 | new InterceptingPrefFilter(write_callback_observer_.GetCallbackPair())); |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 960 | auto pref_store = base::MakeRefCounted<JsonPrefStore>( |
| 961 | input_file, base::CreateSequencedTaskRunnerWithTraits({base::MayBlock()}), |
| 962 | std::move(intercepting_pref_filter)); |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 963 | ImportantFileWriter* file_writer = GetImportantFileWriter(pref_store.get()); |
| 964 | |
| 965 | EXPECT_EQ(NOT_CALLED, |
| 966 | write_callback_observer_.GetAndResetPostWriteObservationState()); |
jdoerrie | 122c4da | 2017-03-06 11:12:04 | [diff] [blame] | 967 | pref_store->SetValue("normal", base::MakeUnique<base::Value>("normal"), |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 968 | WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS); |
| 969 | file_writer->DoScheduledWrite(); |
| 970 | |
| 971 | // The observer should not be invoked right away. |
| 972 | EXPECT_FALSE(write_callback_observer_.GetAndResetPreWriteObservationState()); |
| 973 | EXPECT_EQ(NOT_CALLED, |
| 974 | write_callback_observer_.GetAndResetPostWriteObservationState()); |
| 975 | |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 976 | scoped_task_environment_.RunUntilIdle(); |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 977 | |
| 978 | EXPECT_TRUE(write_callback_observer_.GetAndResetPreWriteObservationState()); |
| 979 | EXPECT_EQ(CALLED_WITH_SUCCESS, |
| 980 | write_callback_observer_.GetAndResetPostWriteObservationState()); |
| 981 | } |
| 982 | |
| 983 | TEST_F(JsonPrefStoreCallbackTest, TestPostWriteCallbacks) { |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 984 | scoped_refptr<JsonPrefStore> pref_store = CreatePrefStore(); |
| 985 | ImportantFileWriter* file_writer = GetImportantFileWriter(pref_store.get()); |
| 986 | |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 987 | // Test RegisterOnNextWriteSynchronousCallbacks after |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 988 | // RegisterOnNextSuccessfulWriteReply. |
| 989 | successful_write_reply_observer_.ObserveNextWriteCallback(pref_store.get()); |
| 990 | write_callback_observer_.ObserveNextWriteCallback(pref_store.get()); |
| 991 | file_writer->WriteNow(MakeUnique<std::string>("foo")); |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 992 | scoped_task_environment_.RunUntilIdle(); |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 993 | EXPECT_TRUE(successful_write_reply_observer_.GetAndResetObservationState()); |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 994 | EXPECT_TRUE(write_callback_observer_.GetAndResetPreWriteObservationState()); |
| 995 | EXPECT_EQ(CALLED_WITH_SUCCESS, |
| 996 | write_callback_observer_.GetAndResetPostWriteObservationState()); |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 997 | |
| 998 | // Test RegisterOnNextSuccessfulWriteReply after |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 999 | // RegisterOnNextWriteSynchronousCallbacks. |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 1000 | successful_write_reply_observer_.ObserveNextWriteCallback(pref_store.get()); |
| 1001 | write_callback_observer_.ObserveNextWriteCallback(pref_store.get()); |
| 1002 | file_writer->WriteNow(MakeUnique<std::string>("foo")); |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 1003 | scoped_task_environment_.RunUntilIdle(); |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 1004 | EXPECT_TRUE(successful_write_reply_observer_.GetAndResetObservationState()); |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 1005 | EXPECT_TRUE(write_callback_observer_.GetAndResetPreWriteObservationState()); |
| 1006 | EXPECT_EQ(CALLED_WITH_SUCCESS, |
| 1007 | write_callback_observer_.GetAndResetPostWriteObservationState()); |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 1008 | |
| 1009 | // Test RegisterOnNextSuccessfulWriteReply only. |
| 1010 | successful_write_reply_observer_.ObserveNextWriteCallback(pref_store.get()); |
| 1011 | file_writer->WriteNow(MakeUnique<std::string>("foo")); |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 1012 | scoped_task_environment_.RunUntilIdle(); |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 1013 | EXPECT_TRUE(successful_write_reply_observer_.GetAndResetObservationState()); |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 1014 | EXPECT_FALSE(write_callback_observer_.GetAndResetPreWriteObservationState()); |
| 1015 | EXPECT_EQ(NOT_CALLED, |
| 1016 | write_callback_observer_.GetAndResetPostWriteObservationState()); |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 1017 | |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 1018 | // Test RegisterOnNextWriteSynchronousCallbacks only. |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 1019 | write_callback_observer_.ObserveNextWriteCallback(pref_store.get()); |
| 1020 | file_writer->WriteNow(MakeUnique<std::string>("foo")); |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 1021 | scoped_task_environment_.RunUntilIdle(); |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 1022 | EXPECT_FALSE(successful_write_reply_observer_.GetAndResetObservationState()); |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 1023 | EXPECT_TRUE(write_callback_observer_.GetAndResetPreWriteObservationState()); |
| 1024 | EXPECT_EQ(CALLED_WITH_SUCCESS, |
| 1025 | write_callback_observer_.GetAndResetPostWriteObservationState()); |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 1026 | } |
| 1027 | |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 1028 | TEST_F(JsonPrefStoreCallbackTest, TestPostWriteCallbacksWithFakeFailure) { |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 1029 | scoped_refptr<JsonPrefStore> pref_store = CreatePrefStore(); |
| 1030 | |
| 1031 | // Confirm that the observers are invoked. |
| 1032 | successful_write_reply_observer_.ObserveNextWriteCallback(pref_store.get()); |
| 1033 | TriggerFakeWriteForCallback(pref_store.get(), true); |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 1034 | scoped_task_environment_.RunUntilIdle(); |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 1035 | EXPECT_TRUE(successful_write_reply_observer_.GetAndResetObservationState()); |
| 1036 | EXPECT_EQ(CALLED_WITH_SUCCESS, |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 1037 | write_callback_observer_.GetAndResetPostWriteObservationState()); |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 1038 | |
| 1039 | // Confirm that the observation states were reset. |
| 1040 | EXPECT_FALSE(successful_write_reply_observer_.GetAndResetObservationState()); |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 1041 | EXPECT_EQ(NOT_CALLED, |
| 1042 | write_callback_observer_.GetAndResetPostWriteObservationState()); |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 1043 | |
| 1044 | // Confirm that re-installing the observers works for another write. |
| 1045 | successful_write_reply_observer_.ObserveNextWriteCallback(pref_store.get()); |
| 1046 | TriggerFakeWriteForCallback(pref_store.get(), true); |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 1047 | scoped_task_environment_.RunUntilIdle(); |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 1048 | EXPECT_TRUE(successful_write_reply_observer_.GetAndResetObservationState()); |
| 1049 | EXPECT_EQ(CALLED_WITH_SUCCESS, |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 1050 | write_callback_observer_.GetAndResetPostWriteObservationState()); |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 1051 | |
| 1052 | // Confirm that the successful observer is not invoked by an unsuccessful |
| 1053 | // write, and that the synchronous observer is invoked. |
| 1054 | successful_write_reply_observer_.ObserveNextWriteCallback(pref_store.get()); |
| 1055 | TriggerFakeWriteForCallback(pref_store.get(), false); |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 1056 | scoped_task_environment_.RunUntilIdle(); |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 1057 | EXPECT_FALSE(successful_write_reply_observer_.GetAndResetObservationState()); |
| 1058 | EXPECT_EQ(CALLED_WITH_ERROR, |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 1059 | write_callback_observer_.GetAndResetPostWriteObservationState()); |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 1060 | |
| 1061 | // Do a real write, and confirm that the successful observer was invoked after |
| 1062 | // being set by |PostWriteCallback| by the last TriggerFakeWriteCallback. |
| 1063 | ImportantFileWriter* file_writer = GetImportantFileWriter(pref_store.get()); |
| 1064 | file_writer->WriteNow(MakeUnique<std::string>("foo")); |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 1065 | scoped_task_environment_.RunUntilIdle(); |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 1066 | EXPECT_TRUE(successful_write_reply_observer_.GetAndResetObservationState()); |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 1067 | EXPECT_EQ(NOT_CALLED, |
| 1068 | write_callback_observer_.GetAndResetPostWriteObservationState()); |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 1069 | } |
| 1070 | |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 1071 | TEST_F(JsonPrefStoreCallbackTest, TestPostWriteCallbacksDuringProfileDeath) { |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 1072 | // Create a JsonPrefStore and attach observers to it, then delete it by making |
| 1073 | // it go out of scope to simulate profile switch or Chrome shutdown. |
| 1074 | { |
| 1075 | scoped_refptr<JsonPrefStore> soon_out_of_scope_pref_store = |
| 1076 | CreatePrefStore(); |
| 1077 | ImportantFileWriter* file_writer = |
| 1078 | GetImportantFileWriter(soon_out_of_scope_pref_store.get()); |
| 1079 | successful_write_reply_observer_.ObserveNextWriteCallback( |
| 1080 | soon_out_of_scope_pref_store.get()); |
| 1081 | write_callback_observer_.ObserveNextWriteCallback( |
| 1082 | soon_out_of_scope_pref_store.get()); |
| 1083 | file_writer->WriteNow(MakeUnique<std::string>("foo")); |
| 1084 | } |
Francois Doray | 405dd2d | 2017-06-09 15:23:33 | [diff] [blame] | 1085 | scoped_task_environment_.RunUntilIdle(); |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 1086 | EXPECT_FALSE(successful_write_reply_observer_.GetAndResetObservationState()); |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 1087 | EXPECT_TRUE(write_callback_observer_.GetAndResetPreWriteObservationState()); |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 1088 | EXPECT_EQ(CALLED_WITH_SUCCESS, |
proberge | c503d69 | 2016-09-28 19:51:05 | [diff] [blame] | 1089 | write_callback_observer_.GetAndResetPostWriteObservationState()); |
proberge | fc46ac1 | 2016-09-21 18:03:00 | [diff] [blame] | 1090 | } |
| 1091 | |
vabr | 5d919d6 | 2016-09-30 08:55:36 | [diff] [blame] | 1092 | } // namespace base |