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

Side by Side Diff: chrome/browser/extensions/api/storage/storage_api_unittest.cc

Issue 197413002: Move extensions-related files to using //components/keyed_service. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 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 | Annotate | Revision Log
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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/files/file_path.h" 6 #include "base/files/file_path.h"
7 #include "base/memory/ref_counted.h" 7 #include "base/memory/ref_counted.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "chrome/browser/extensions/api/storage/storage_api.h" 9 #include "chrome/browser/extensions/api/storage/storage_api.h"
10 #include "chrome/browser/extensions/extension_api_unittest.h" 10 #include "chrome/browser/extensions/extension_api_unittest.h"
(...skipping 12 matching lines...) Expand all
23 #include "extensions/common/manifest.h" 23 #include "extensions/common/manifest.h"
24 #include "extensions/common/test_util.h" 24 #include "extensions/common/test_util.h"
25 #include "third_party/leveldatabase/src/include/leveldb/db.h" 25 #include "third_party/leveldatabase/src/include/leveldb/db.h"
26 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" 26 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h"
27 27
28 namespace extensions { 28 namespace extensions {
29 29
30 namespace { 30 namespace {
31 31
32 // Caller owns the returned object. 32 // Caller owns the returned object.
33 BrowserContextKeyedService* CreateSettingsFrontendForTesting( 33 KeyedService* CreateSettingsFrontendForTesting(
34 content::BrowserContext* context) { 34 content::BrowserContext* context) {
35 return SettingsFrontend::CreateForTesting(new LeveldbSettingsStorageFactory(), 35 return SettingsFrontend::CreateForTesting(new LeveldbSettingsStorageFactory(),
36 context); 36 context);
37 } 37 }
38 38
39 } // namespace 39 } // namespace
40 40
41 class StorageApiUnittest : public ExtensionApiUnittest { 41 class StorageApiUnittest : public ExtensionApiUnittest {
42 public: 42 public:
43 virtual void SetUp() OVERRIDE { 43 virtual void SetUp() OVERRIDE {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 if (!dict->GetString(key, value)) { 84 if (!dict->GetString(key, value)) {
85 return testing::AssertionFailure() << " could not retrieve a string from" 85 return testing::AssertionFailure() << " could not retrieve a string from"
86 << dict << " at " << key; 86 << dict << " at " << key;
87 } 87 }
88 return testing::AssertionSuccess(); 88 return testing::AssertionSuccess();
89 } 89 }
90 }; 90 };
91 91
92 TEST_F(StorageApiUnittest, RestoreCorruptedStorage) { 92 TEST_F(StorageApiUnittest, RestoreCorruptedStorage) {
93 // Ensure a SettingsFrontend can be created on demand. The SettingsFrontend 93 // Ensure a SettingsFrontend can be created on demand. The SettingsFrontend
94 // will be owned by the BrowserContextKeyedService system. 94 // will be owned by the KeyedService system.
95 SettingsFrontend::GetFactoryInstance()->SetTestingFactory( 95 SettingsFrontend::GetFactoryInstance()->SetTestingFactory(
96 profile(), &CreateSettingsFrontendForTesting); 96 profile(), &CreateSettingsFrontendForTesting);
97 97
98 const char kKey[] = "key"; 98 const char kKey[] = "key";
99 const char kValue[] = "value"; 99 const char kValue[] = "value";
100 std::string result; 100 std::string result;
101 101
102 // Do a simple set/get combo to make sure the API works. 102 // Do a simple set/get combo to make sure the API works.
103 RunSetFunction(kKey, kValue); 103 RunSetFunction(kKey, kValue);
104 EXPECT_TRUE(RunGetFunction(kKey, &result)); 104 EXPECT_TRUE(RunGetFunction(kKey, &result));
(...skipping 17 matching lines...) Expand all
122 EXPECT_TRUE(leveldb_store->Get(kKey)->IsCorrupted()); 122 EXPECT_TRUE(leveldb_store->Get(kKey)->IsCorrupted());
123 123
124 // Running another set should end up working (even though it will restore the 124 // Running another set should end up working (even though it will restore the
125 // store behind the scenes). 125 // store behind the scenes).
126 RunSetFunction(kKey, kValue); 126 RunSetFunction(kKey, kValue);
127 EXPECT_TRUE(RunGetFunction(kKey, &result)); 127 EXPECT_TRUE(RunGetFunction(kKey, &result));
128 EXPECT_EQ(kValue, result); 128 EXPECT_EQ(kValue, result);
129 } 129 }
130 130
131 } // namespace extensions 131 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698