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

Unified Diff: chrome/browser/extensions/api/audio_modem/audio_modem_api_unittest.cc

Issue 1871713002: Convert //chrome/browser/extensions from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and fix header 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/audio_modem/audio_modem_api_unittest.cc
diff --git a/chrome/browser/extensions/api/audio_modem/audio_modem_api_unittest.cc b/chrome/browser/extensions/api/audio_modem/audio_modem_api_unittest.cc
index b180ca70484b75484a3301743a5c93cda23a0ee1..f72d44a24404e60457740b3337b0acc0387baee1 100644
--- a/chrome/browser/extensions/api/audio_modem/audio_modem_api_unittest.cc
+++ b/chrome/browser/extensions/api/audio_modem/audio_modem_api_unittest.cc
@@ -2,16 +2,18 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "chrome/browser/extensions/api/audio_modem/audio_modem_api.h"
+
#include <map>
+#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/callback.h"
+#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted.h"
-#include "base/memory/scoped_ptr.h"
#include "base/values.h"
-#include "chrome/browser/extensions/api/audio_modem/audio_modem_api.h"
#include "chrome/browser/extensions/extension_api_unittest.h"
#include "chrome/browser/extensions/extension_function_test_utils.h"
#include "chrome/browser/extensions/test_extension_system.h"
@@ -48,13 +50,13 @@ namespace {
std::map<BrowserContext*, StubModem*> g_modems;
// Create a test AudioModemAPI and store the modem it uses.
-scoped_ptr<KeyedService> ApiFactoryFunction(BrowserContext* context) {
+std::unique_ptr<KeyedService> ApiFactoryFunction(BrowserContext* context) {
StubModem* modem = new StubModem;
g_modems[context] = modem;
- return make_scoped_ptr(new AudioModemAPI(
+ return base::WrapUnique(new AudioModemAPI(
context,
- make_scoped_ptr<audio_modem::WhispernetClient>(new StubWhispernetClient),
- make_scoped_ptr<audio_modem::Modem>(modem)));
+ base::WrapUnique<audio_modem::WhispernetClient>(new StubWhispernetClient),
+ base::WrapUnique<audio_modem::Modem>(modem)));
}
DictionaryValue* CreateParams(const std::string& audio_band) {
@@ -69,14 +71,14 @@ BinaryValue* CreateToken(const std::string& token) {
return BinaryValue::CreateWithCopiedBuffer(token.c_str(), token.size());
}
-scoped_ptr<ListValue> CreateList(Value* single_elt) {
- scoped_ptr<ListValue> list(new ListValue);
+std::unique_ptr<ListValue> CreateList(Value* single_elt) {
+ std::unique_ptr<ListValue> list(new ListValue);
list->Append(single_elt);
return list;
}
-scoped_ptr<ListValue> CreateList(Value* elt1, Value* elt2) {
- scoped_ptr<ListValue> list(new ListValue);
+std::unique_ptr<ListValue> CreateList(Value* elt1, Value* elt2) {
+ std::unique_ptr<ListValue> list(new ListValue);
list->Append(elt1);
list->Append(elt2);
return list;
@@ -108,14 +110,14 @@ class StubEventRouter : public EventRouter {
public:
// Callback to receive events. First argument is
// the extension id to receive the event.
- using EventCallback = base::Callback<void(const std::string&,
- scoped_ptr<Event>)>;
+ using EventCallback =
+ base::Callback<void(const std::string&, std::unique_ptr<Event>)>;
explicit StubEventRouter(BrowserContext* context)
: EventRouter(context, nullptr) {}
void DispatchEventToExtension(const std::string& extension_id,
- scoped_ptr<Event> event) override {
+ std::unique_ptr<Event> event) override {
event_callback_.Run(extension_id, std::move(event));
}
@@ -132,9 +134,9 @@ class StubEventRouter : public EventRouter {
};
// StubEventRouter factory function
-scoped_ptr<KeyedService> StubEventRouterFactoryFunction(
+std::unique_ptr<KeyedService> StubEventRouterFactoryFunction(
content::BrowserContext* context) {
- return make_scoped_ptr(new StubEventRouter(context));
+ return base::WrapUnique(new StubEventRouter(context));
}
} // namespace
@@ -145,8 +147,8 @@ class AudioModemApiUnittest : public ExtensionApiUnittest {
~AudioModemApiUnittest() override {}
protected:
- template<typename Function>
- const std::string RunFunction(scoped_ptr<ListValue> args,
+ template <typename Function>
+ const std::string RunFunction(std::unique_ptr<ListValue> args,
const Extension* extension) {
scoped_refptr<UIThreadExtensionFunction> function(new Function);
function->set_extension(extension);
@@ -160,8 +162,8 @@ class AudioModemApiUnittest : public ExtensionApiUnittest {
return result_status;
}
- template<typename Function>
- const std::string RunFunction(scoped_ptr<ListValue> args) {
+ template <typename Function>
+ const std::string RunFunction(std::unique_ptr<ListValue> args) {
return RunFunction<Function>(std::move(args), GetExtension(std::string()));
}
@@ -171,7 +173,8 @@ class AudioModemApiUnittest : public ExtensionApiUnittest {
const Extension* GetExtension(const std::string& name) {
if (!extensions_by_name_[name].get()) {
- scoped_ptr<DictionaryValue> extension_definition(new DictionaryValue);
+ std::unique_ptr<DictionaryValue> extension_definition(
+ new DictionaryValue);
extension_definition->SetString("name", name);
extension_definition->SetString("version", "1.0");
extensions_by_name_[name] = api_test_utils::CreateExtension(
@@ -181,14 +184,14 @@ class AudioModemApiUnittest : public ExtensionApiUnittest {
return extensions_by_name_[name].get();
}
- const std::vector<scoped_ptr<const Event>>& GetEventsForExtension(
+ const std::vector<std::unique_ptr<const Event>>& GetEventsForExtension(
const std::string& name) {
const Extension* extension = extensions_by_name_[name].get();
DCHECK(extension);
return events_by_extension_id_[extension->id()];
}
- const std::vector<scoped_ptr<const Event>>& GetEvents() {
+ const std::vector<std::unique_ptr<const Event>>& GetEvents() {
return GetEventsForExtension(std::string());
}
@@ -206,13 +209,13 @@ class AudioModemApiUnittest : public ExtensionApiUnittest {
}
void CaptureEvent(const std::string& extension_id,
- scoped_ptr<Event> event) {
+ std::unique_ptr<Event> event) {
events_by_extension_id_[extension_id].push_back(std::move(event));
}
std::map<std::string, scoped_refptr<Extension>> extensions_by_name_;
- std::map<std::string, std::vector<scoped_ptr<const Event>>>
+ std::map<std::string, std::vector<std::unique_ptr<const Event>>>
events_by_extension_id_;
};
@@ -262,7 +265,7 @@ TEST_F(AudioModemApiUnittest, ReceiveBasic) {
// Check the tokens received.
EXPECT_EQ(1u, GetEvents().size());
- scoped_ptr<ListValue> expected_tokens(new ListValue);
+ std::unique_ptr<ListValue> expected_tokens(new ListValue);
expected_tokens->Append(CreateReceivedToken("1234", "audible"));
expected_tokens->Append(CreateReceivedToken("ABCD", "audible"));
ListValue* received_tokens;
@@ -351,7 +354,7 @@ TEST_F(AudioModemApiUnittest, ReceiveMultiple) {
EXPECT_EQ(1u, GetEventsForExtension("ext2").size());
// Check the token received.
- scoped_ptr<DictionaryValue> expected_token(
+ std::unique_ptr<DictionaryValue> expected_token(
CreateReceivedToken("abcd", "inaudible"));
EXPECT_TRUE(ReceivedSingleToken(GetEventsForExtension("ext1")[0].get(),
expected_token.get()));

Powered by Google App Engine
This is Rietveld 408576698