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

Side by Side Diff: extensions/browser/api/storage/storage_frontend_unittest.cc

Issue 2664753002: Remove base::StringValue (Closed)
Patch Set: Rebase Created 3 years, 9 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/browser/api/storage/storage_frontend.h" 5 #include "extensions/browser/api/storage/storage_frontend.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 const std::string id = "ext"; 96 const std::string id = "ext";
97 scoped_refptr<const Extension> extension = 97 scoped_refptr<const Extension> extension =
98 util::AddExtensionWithId(browser_context(), id, Manifest::TYPE_EXTENSION); 98 util::AddExtensionWithId(browser_context(), id, Manifest::TYPE_EXTENSION);
99 99
100 ValueStore* storage = 100 ValueStore* storage =
101 util::GetStorage(extension, settings::LOCAL, frontend_.get()); 101 util::GetStorage(extension, settings::LOCAL, frontend_.get());
102 102
103 // The correctness of Get/Set/Remove/Clear is tested elsewhere so no need to 103 // The correctness of Get/Set/Remove/Clear is tested elsewhere so no need to
104 // be too rigorous. 104 // be too rigorous.
105 { 105 {
106 base::StringValue bar("bar"); 106 base::Value bar("bar");
107 ValueStore::WriteResult result = storage->Set(DEFAULTS, "foo", bar); 107 ValueStore::WriteResult result = storage->Set(DEFAULTS, "foo", bar);
108 ASSERT_TRUE(result->status().ok()); 108 ASSERT_TRUE(result->status().ok());
109 } 109 }
110 110
111 { 111 {
112 ValueStore::ReadResult result = storage->Get(); 112 ValueStore::ReadResult result = storage->Get();
113 ASSERT_TRUE(result->status().ok()); 113 ASSERT_TRUE(result->status().ok());
114 EXPECT_FALSE(result->settings().empty()); 114 EXPECT_FALSE(result->settings().empty());
115 } 115 }
116 116
117 ResetFrontend(); 117 ResetFrontend();
118 storage = util::GetStorage(extension, settings::LOCAL, frontend_.get()); 118 storage = util::GetStorage(extension, settings::LOCAL, frontend_.get());
119 119
120 { 120 {
121 ValueStore::ReadResult result = storage->Get(); 121 ValueStore::ReadResult result = storage->Get();
122 ASSERT_TRUE(result->status().ok()); 122 ASSERT_TRUE(result->status().ok());
123 EXPECT_FALSE(result->settings().empty()); 123 EXPECT_FALSE(result->settings().empty());
124 } 124 }
125 } 125 }
126 126
127 TEST_F(ExtensionSettingsFrontendTest, SettingsClearedOnUninstall) { 127 TEST_F(ExtensionSettingsFrontendTest, SettingsClearedOnUninstall) {
128 const std::string id = "ext"; 128 const std::string id = "ext";
129 scoped_refptr<const Extension> extension = util::AddExtensionWithId( 129 scoped_refptr<const Extension> extension = util::AddExtensionWithId(
130 browser_context(), id, Manifest::TYPE_LEGACY_PACKAGED_APP); 130 browser_context(), id, Manifest::TYPE_LEGACY_PACKAGED_APP);
131 131
132 ValueStore* storage = 132 ValueStore* storage =
133 util::GetStorage(extension, settings::LOCAL, frontend_.get()); 133 util::GetStorage(extension, settings::LOCAL, frontend_.get());
134 134
135 { 135 {
136 base::StringValue bar("bar"); 136 base::Value bar("bar");
137 ValueStore::WriteResult result = storage->Set(DEFAULTS, "foo", bar); 137 ValueStore::WriteResult result = storage->Set(DEFAULTS, "foo", bar);
138 ASSERT_TRUE(result->status().ok()); 138 ASSERT_TRUE(result->status().ok());
139 } 139 }
140 140
141 // This would be triggered by extension uninstall via a DataDeleter. 141 // This would be triggered by extension uninstall via a DataDeleter.
142 frontend_->DeleteStorageSoon(id); 142 frontend_->DeleteStorageSoon(id);
143 base::RunLoop().RunUntilIdle(); 143 base::RunLoop().RunUntilIdle();
144 144
145 // The storage area may no longer be valid post-uninstall, so re-request. 145 // The storage area may no longer be valid post-uninstall, so re-request.
146 storage = util::GetStorage(extension, settings::LOCAL, frontend_.get()); 146 storage = util::GetStorage(extension, settings::LOCAL, frontend_.get());
147 { 147 {
148 ValueStore::ReadResult result = storage->Get(); 148 ValueStore::ReadResult result = storage->Get();
149 ASSERT_TRUE(result->status().ok()); 149 ASSERT_TRUE(result->status().ok());
150 EXPECT_TRUE(result->settings().empty()); 150 EXPECT_TRUE(result->settings().empty());
151 } 151 }
152 } 152 }
153 153
154 TEST_F(ExtensionSettingsFrontendTest, LeveldbDatabaseDeletedFromDiskOnClear) { 154 TEST_F(ExtensionSettingsFrontendTest, LeveldbDatabaseDeletedFromDiskOnClear) {
155 const std::string id = "ext"; 155 const std::string id = "ext";
156 scoped_refptr<const Extension> extension = 156 scoped_refptr<const Extension> extension =
157 util::AddExtensionWithId(browser_context(), id, Manifest::TYPE_EXTENSION); 157 util::AddExtensionWithId(browser_context(), id, Manifest::TYPE_EXTENSION);
158 158
159 ValueStore* storage = 159 ValueStore* storage =
160 util::GetStorage(extension, settings::LOCAL, frontend_.get()); 160 util::GetStorage(extension, settings::LOCAL, frontend_.get());
161 161
162 { 162 {
163 base::StringValue bar("bar"); 163 base::Value bar("bar");
164 ValueStore::WriteResult result = storage->Set(DEFAULTS, "foo", bar); 164 ValueStore::WriteResult result = storage->Set(DEFAULTS, "foo", bar);
165 ASSERT_TRUE(result->status().ok()); 165 ASSERT_TRUE(result->status().ok());
166 EXPECT_TRUE(base::PathExists(temp_dir_.GetPath())); 166 EXPECT_TRUE(base::PathExists(temp_dir_.GetPath()));
167 } 167 }
168 168
169 // Should need to both clear the database and delete the frontend for the 169 // Should need to both clear the database and delete the frontend for the
170 // leveldb database to be deleted from disk. 170 // leveldb database to be deleted from disk.
171 { 171 {
172 ValueStore::WriteResult result = storage->Clear(); 172 ValueStore::WriteResult result = storage->Clear();
173 ASSERT_TRUE(result->status().ok()); 173 ASSERT_TRUE(result->status().ok());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 std::unique_ptr<base::Value> megabyte = util::CreateMegabyte(); 215 std::unique_ptr<base::Value> megabyte = util::CreateMegabyte();
216 for (int i = 0; i < 5; ++i) { 216 for (int i = 0; i < 5; ++i) {
217 local_storage->Set(DEFAULTS, base::IntToString(i), *megabyte); 217 local_storage->Set(DEFAULTS, base::IntToString(i), *megabyte);
218 } 218 }
219 219
220 EXPECT_FALSE( 220 EXPECT_FALSE(
221 local_storage->Set(DEFAULTS, "WillError", *megabyte)->status().ok()); 221 local_storage->Set(DEFAULTS, "WillError", *megabyte)->status().ok());
222 } 222 }
223 223
224 } // namespace extensions 224 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/storage/settings_test_util.cc ('k') | extensions/browser/api/system_storage/system_storage_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698