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

Side by Side Diff: chrome/browser/extensions/api/audio_modem/audio_modem_api_unittest.cc

Issue 1549233002: Convert Pass()→std::move() in //chrome/browser/extensions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 12 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <map> 5 #include <map>
6 #include <string> 6 #include <string>
7 #include <utility> 7 #include <utility>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 return params; 65 return params;
66 } 66 }
67 67
68 BinaryValue* CreateToken(const std::string& token) { 68 BinaryValue* CreateToken(const std::string& token) {
69 return BinaryValue::CreateWithCopiedBuffer(token.c_str(), token.size()); 69 return BinaryValue::CreateWithCopiedBuffer(token.c_str(), token.size());
70 } 70 }
71 71
72 scoped_ptr<ListValue> CreateList(Value* single_elt) { 72 scoped_ptr<ListValue> CreateList(Value* single_elt) {
73 scoped_ptr<ListValue> list(new ListValue); 73 scoped_ptr<ListValue> list(new ListValue);
74 list->Append(single_elt); 74 list->Append(single_elt);
75 return list.Pass(); 75 return list;
76 } 76 }
77 77
78 scoped_ptr<ListValue> CreateList(Value* elt1, Value* elt2) { 78 scoped_ptr<ListValue> CreateList(Value* elt1, Value* elt2) {
79 scoped_ptr<ListValue> list(new ListValue); 79 scoped_ptr<ListValue> list(new ListValue);
80 list->Append(elt1); 80 list->Append(elt1);
81 list->Append(elt2); 81 list->Append(elt2);
82 return list.Pass(); 82 return list;
83 } 83 }
84 84
85 DictionaryValue* CreateReceivedToken(const std::string& token, 85 DictionaryValue* CreateReceivedToken(const std::string& token,
86 const std::string& audio_band) { 86 const std::string& audio_band) {
87 DictionaryValue* out = new DictionaryValue; 87 DictionaryValue* out = new DictionaryValue;
88 out->Set("token", CreateToken(token)); 88 out->Set("token", CreateToken(token));
89 out->SetString("band", audio_band); 89 out->SetString("band", audio_band);
90 return out; 90 return out;
91 } 91 }
92 92
(...skipping 16 matching lines...) Expand all
109 // Callback to receive events. First argument is 109 // Callback to receive events. First argument is
110 // the extension id to receive the event. 110 // the extension id to receive the event.
111 using EventCallback = base::Callback<void(const std::string&, 111 using EventCallback = base::Callback<void(const std::string&,
112 scoped_ptr<Event>)>; 112 scoped_ptr<Event>)>;
113 113
114 explicit StubEventRouter(BrowserContext* context) 114 explicit StubEventRouter(BrowserContext* context)
115 : EventRouter(context, nullptr) {} 115 : EventRouter(context, nullptr) {}
116 116
117 void DispatchEventToExtension(const std::string& extension_id, 117 void DispatchEventToExtension(const std::string& extension_id,
118 scoped_ptr<Event> event) override { 118 scoped_ptr<Event> event) override {
119 event_callback_.Run(extension_id, event.Pass()); 119 event_callback_.Run(extension_id, std::move(event));
120 } 120 }
121 121
122 void SetEventCallBack(EventCallback event_callback) { 122 void SetEventCallBack(EventCallback event_callback) {
123 event_callback_ = event_callback; 123 event_callback_ = event_callback;
124 } 124 }
125 125
126 void ClearEventCallback() { 126 void ClearEventCallback() {
127 event_callback_.Reset(); 127 event_callback_.Reset();
128 } 128 }
129 129
(...skipping 15 matching lines...) Expand all
145 ~AudioModemApiUnittest() override {} 145 ~AudioModemApiUnittest() override {}
146 146
147 protected: 147 protected:
148 template<typename Function> 148 template<typename Function>
149 const std::string RunFunction(scoped_ptr<ListValue> args, 149 const std::string RunFunction(scoped_ptr<ListValue> args,
150 const Extension* extension) { 150 const Extension* extension) {
151 scoped_refptr<UIThreadExtensionFunction> function(new Function); 151 scoped_refptr<UIThreadExtensionFunction> function(new Function);
152 function->set_extension(extension); 152 function->set_extension(extension);
153 function->set_browser_context(profile()); 153 function->set_browser_context(profile());
154 function->set_has_callback(true); 154 function->set_has_callback(true);
155 ext_test_utils::RunFunction( 155 ext_test_utils::RunFunction(function.get(), std::move(args), browser(),
156 function.get(), args.Pass(), browser(), ext_test_utils::NONE); 156 ext_test_utils::NONE);
157 157
158 std::string result_status; 158 std::string result_status;
159 CHECK(function->GetResultList()->GetString(0, &result_status)); 159 CHECK(function->GetResultList()->GetString(0, &result_status));
160 return result_status; 160 return result_status;
161 } 161 }
162 162
163 template<typename Function> 163 template<typename Function>
164 const std::string RunFunction(scoped_ptr<ListValue> args) { 164 const std::string RunFunction(scoped_ptr<ListValue> args) {
165 return RunFunction<Function>(args.Pass(), GetExtension(std::string())); 165 return RunFunction<Function>(std::move(args), GetExtension(std::string()));
166 } 166 }
167 167
168 StubModem* GetModem() const { 168 StubModem* GetModem() const {
169 return g_modems[profile()]; 169 return g_modems[profile()];
170 } 170 }
171 171
172 const Extension* GetExtension(const std::string& name) { 172 const Extension* GetExtension(const std::string& name) {
173 if (!extensions_by_name_[name].get()) { 173 if (!extensions_by_name_[name].get()) {
174 scoped_ptr<DictionaryValue> extension_definition(new DictionaryValue); 174 scoped_ptr<DictionaryValue> extension_definition(new DictionaryValue);
175 extension_definition->SetString("name", name); 175 extension_definition->SetString("name", name);
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 expected_token.reset(CreateReceivedToken("1234", "inaudible")); 371 expected_token.reset(CreateReceivedToken("1234", "inaudible"));
372 EXPECT_TRUE(ReceivedSingleToken(GetEventsForExtension("ext2")[1].get(), 372 EXPECT_TRUE(ReceivedSingleToken(GetEventsForExtension("ext2")[1].get(),
373 expected_token.get())); 373 expected_token.get()));
374 374
375 EXPECT_EQ("success", RunFunction<AudioModemStopReceiveFunction>( 375 EXPECT_EQ("success", RunFunction<AudioModemStopReceiveFunction>(
376 CreateList(new StringValue("inaudible")), GetExtension("ext2"))); 376 CreateList(new StringValue("inaudible")), GetExtension("ext2")));
377 EXPECT_FALSE(GetModem()->IsRecording(INAUDIBLE)); 377 EXPECT_FALSE(GetModem()->IsRecording(INAUDIBLE));
378 } 378 }
379 379
380 } // namespace extensions 380 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698