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

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

Issue 1902873002: Convert //extensions/browser/api from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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_api.h"
6
7 #include <memory>
8
5 #include "base/command_line.h" 9 #include "base/command_line.h"
6 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
11 #include "base/memory/ptr_util.h"
7 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
10 #include "content/public/test/test_browser_context.h" 14 #include "content/public/test/test_browser_context.h"
11 #include "extensions/browser/api/extensions_api_client.h" 15 #include "extensions/browser/api/extensions_api_client.h"
12 #include "extensions/browser/api/storage/settings_storage_quota_enforcer.h" 16 #include "extensions/browser/api/storage/settings_storage_quota_enforcer.h"
13 #include "extensions/browser/api/storage/settings_test_util.h" 17 #include "extensions/browser/api/storage/settings_test_util.h"
14 #include "extensions/browser/api/storage/storage_api.h"
15 #include "extensions/browser/api/storage/storage_frontend.h" 18 #include "extensions/browser/api/storage/storage_frontend.h"
16 #include "extensions/browser/api_unittest.h" 19 #include "extensions/browser/api_unittest.h"
17 #include "extensions/browser/event_router.h" 20 #include "extensions/browser/event_router.h"
18 #include "extensions/browser/event_router_factory.h" 21 #include "extensions/browser/event_router_factory.h"
19 #include "extensions/browser/test_extensions_browser_client.h" 22 #include "extensions/browser/test_extensions_browser_client.h"
20 #include "extensions/browser/value_store/leveldb_value_store.h" 23 #include "extensions/browser/value_store/leveldb_value_store.h"
21 #include "extensions/browser/value_store/value_store.h" 24 #include "extensions/browser/value_store/value_store.h"
22 #include "extensions/browser/value_store/value_store_factory_impl.h" 25 #include "extensions/browser/value_store/value_store_factory_impl.h"
23 #include "extensions/common/manifest.h" 26 #include "extensions/common/manifest.h"
24 #include "extensions/common/test_util.h" 27 #include "extensions/common/test_util.h"
25 #include "third_party/leveldatabase/src/include/leveldb/db.h" 28 #include "third_party/leveldatabase/src/include/leveldb/db.h"
26 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h" 29 #include "third_party/leveldatabase/src/include/leveldb/write_batch.h"
27 30
28 namespace extensions { 31 namespace extensions {
29 32
30 namespace { 33 namespace {
31 34
32 // Caller owns the returned object. 35 // Caller owns the returned object.
33 scoped_ptr<KeyedService> CreateStorageFrontendForTesting( 36 std::unique_ptr<KeyedService> CreateStorageFrontendForTesting(
34 content::BrowserContext* context) { 37 content::BrowserContext* context) {
35 scoped_refptr<ValueStoreFactory> factory = 38 scoped_refptr<ValueStoreFactory> factory =
36 new ValueStoreFactoryImpl(context->GetPath()); 39 new ValueStoreFactoryImpl(context->GetPath());
37 return StorageFrontend::CreateForTesting(factory, context); 40 return StorageFrontend::CreateForTesting(factory, context);
38 } 41 }
39 42
40 scoped_ptr<KeyedService> BuildEventRouter(content::BrowserContext* context) { 43 std::unique_ptr<KeyedService> BuildEventRouter(
41 return make_scoped_ptr(new extensions::EventRouter(context, nullptr)); 44 content::BrowserContext* context) {
45 return base::WrapUnique(new extensions::EventRouter(context, nullptr));
42 } 46 }
43 47
44 } // namespace 48 } // namespace
45 49
46 class StorageApiUnittest : public ApiUnitTest { 50 class StorageApiUnittest : public ApiUnitTest {
47 public: 51 public:
48 StorageApiUnittest() {} 52 StorageApiUnittest() {}
49 ~StorageApiUnittest() override {} 53 ~StorageApiUnittest() override {}
50 54
51 protected: 55 protected:
52 // Runs the storage.set() API function with local storage. 56 // Runs the storage.set() API function with local storage.
53 void RunSetFunction(const std::string& key, const std::string& value) { 57 void RunSetFunction(const std::string& key, const std::string& value) {
54 RunFunction( 58 RunFunction(
55 new StorageStorageAreaSetFunction(), 59 new StorageStorageAreaSetFunction(),
56 base::StringPrintf( 60 base::StringPrintf(
57 "[\"local\", {\"%s\": \"%s\"}]", key.c_str(), value.c_str())); 61 "[\"local\", {\"%s\": \"%s\"}]", key.c_str(), value.c_str()));
58 } 62 }
59 63
60 // Runs the storage.get() API function with the local storage, and populates 64 // Runs the storage.get() API function with the local storage, and populates
61 // |value| with the string result. 65 // |value| with the string result.
62 testing::AssertionResult RunGetFunction(const std::string& key, 66 testing::AssertionResult RunGetFunction(const std::string& key,
63 std::string* value) { 67 std::string* value) {
64 scoped_ptr<base::Value> result = RunFunctionAndReturnValue( 68 std::unique_ptr<base::Value> result = RunFunctionAndReturnValue(
65 new StorageStorageAreaGetFunction(), 69 new StorageStorageAreaGetFunction(),
66 base::StringPrintf("[\"local\", \"%s\"]", key.c_str())); 70 base::StringPrintf("[\"local\", \"%s\"]", key.c_str()));
67 if (!result.get()) 71 if (!result.get())
68 return testing::AssertionFailure() << "No result"; 72 return testing::AssertionFailure() << "No result";
69 base::DictionaryValue* dict = NULL; 73 base::DictionaryValue* dict = NULL;
70 if (!result->GetAsDictionary(&dict)) 74 if (!result->GetAsDictionary(&dict))
71 return testing::AssertionFailure() << result.get() 75 return testing::AssertionFailure() << result.get()
72 << " was not a dictionary."; 76 << " was not a dictionary.";
73 if (!dict->GetString(key, value)) { 77 if (!dict->GetString(key, value)) {
74 return testing::AssertionFailure() << " could not retrieve a string from" 78 return testing::AssertionFailure() << " could not retrieve a string from"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 EXPECT_TRUE(leveldb_store->Get(kKey)->status().IsCorrupted()); 122 EXPECT_TRUE(leveldb_store->Get(kKey)->status().IsCorrupted());
119 123
120 // 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
121 // store behind the scenes). 125 // store behind the scenes).
122 RunSetFunction(kKey, kValue); 126 RunSetFunction(kKey, kValue);
123 EXPECT_TRUE(RunGetFunction(kKey, &result)); 127 EXPECT_TRUE(RunGetFunction(kKey, &result));
124 EXPECT_EQ(kValue, result); 128 EXPECT_EQ(kValue, result);
125 } 129 }
126 130
127 } // namespace extensions 131 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/browser/api/storage/storage_api.cc ('k') | extensions/browser/api/storage/storage_frontend.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698