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

Side by Side Diff: chrome/browser/extensions/api/developer_private/developer_private_api_unittest.cc

Issue 2323993004: Remove use of deprecated base::ListValue::Append(Value*) overload in extensions. (Closed)
Patch Set: ... I hate C++ Created 4 years, 3 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 "chrome/browser/extensions/api/developer_private/developer_private_api. h" 5 #include "chrome/browser/extensions/api/developer_private/developer_private_api. h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 108
109 std::vector<std::unique_ptr<TestExtensionDir>> test_extension_dirs_; 109 std::vector<std::unique_ptr<TestExtensionDir>> test_extension_dirs_;
110 110
111 DISALLOW_COPY_AND_ASSIGN(DeveloperPrivateApiUnitTest); 111 DISALLOW_COPY_AND_ASSIGN(DeveloperPrivateApiUnitTest);
112 }; 112 };
113 113
114 bool DeveloperPrivateApiUnitTest::RunFunction( 114 bool DeveloperPrivateApiUnitTest::RunFunction(
115 const scoped_refptr<UIThreadExtensionFunction>& function, 115 const scoped_refptr<UIThreadExtensionFunction>& function,
116 const base::ListValue& args) { 116 const base::ListValue& args) {
117 return extension_function_test_utils::RunFunction( 117 return extension_function_test_utils::RunFunction(
118 function.get(), base::WrapUnique(args.DeepCopy()), browser(), 118 function.get(), args.CreateDeepCopy(), browser(),
119 extension_function_test_utils::NONE); 119 extension_function_test_utils::NONE);
120 } 120 }
121 121
122 const Extension* DeveloperPrivateApiUnitTest::LoadUnpackedExtension() { 122 const Extension* DeveloperPrivateApiUnitTest::LoadUnpackedExtension() {
123 const char kManifest[] = 123 const char kManifest[] =
124 "{" 124 "{"
125 " \"name\": \"foo\"," 125 " \"name\": \"foo\","
126 " \"version\": \"1.0\"," 126 " \"version\": \"1.0\","
127 " \"manifest_version\": 2," 127 " \"manifest_version\": 2,"
128 " \"permissions\": [\"*://*/*\"]" 128 " \"permissions\": [\"*://*/*\"]"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 return extension.get(); 171 return extension.get();
172 } 172 }
173 173
174 void DeveloperPrivateApiUnitTest::TestExtensionPrefSetting( 174 void DeveloperPrivateApiUnitTest::TestExtensionPrefSetting(
175 const base::Callback<bool()>& has_pref, 175 const base::Callback<bool()>& has_pref,
176 const std::string& key, 176 const std::string& key,
177 const std::string& extension_id) { 177 const std::string& extension_id) {
178 scoped_refptr<UIThreadExtensionFunction> function( 178 scoped_refptr<UIThreadExtensionFunction> function(
179 new api::DeveloperPrivateUpdateExtensionConfigurationFunction()); 179 new api::DeveloperPrivateUpdateExtensionConfigurationFunction());
180 180
181 base::ListValue args;
182 base::DictionaryValue* parameters = new base::DictionaryValue();
183 parameters->SetString("extensionId", extension_id);
184 parameters->SetBoolean(key, true);
185 args.Append(parameters);
186
187 EXPECT_FALSE(has_pref.Run()) << key; 181 EXPECT_FALSE(has_pref.Run()) << key;
188 182
189 EXPECT_FALSE(RunFunction(function, args)) << key; 183 {
190 EXPECT_EQ(std::string("This action requires a user gesture."), 184 auto parameters = base::MakeUnique<base::DictionaryValue>();
191 function->GetError()); 185 parameters->SetString("extensionId", extension_id);
186 parameters->SetBoolean(key, true);
192 187
193 ExtensionFunction::ScopedUserGestureForTests scoped_user_gesture; 188 base::ListValue args;
194 function = new api::DeveloperPrivateUpdateExtensionConfigurationFunction(); 189 args.Append(std::move(parameters));
195 EXPECT_TRUE(RunFunction(function, args)) << key; 190 EXPECT_FALSE(RunFunction(function, args)) << key;
196 EXPECT_TRUE(has_pref.Run()) << key; 191 EXPECT_EQ("This action requires a user gesture.", function->GetError());
197 192
198 parameters->SetBoolean(key, false); 193 ExtensionFunction::ScopedUserGestureForTests scoped_user_gesture;
199 function = new api::DeveloperPrivateUpdateExtensionConfigurationFunction(); 194 function = new api::DeveloperPrivateUpdateExtensionConfigurationFunction();
200 EXPECT_TRUE(RunFunction(function, args)) << key; 195 EXPECT_TRUE(RunFunction(function, args)) << key;
201 EXPECT_FALSE(has_pref.Run()) << key; 196 EXPECT_TRUE(has_pref.Run()) << key;
197 }
198
199 {
200 auto parameters = base::MakeUnique<base::DictionaryValue>();
201 parameters->SetString("extensionId", extension_id);
202 parameters->SetBoolean(key, false);
203
204 base::ListValue args;
205 args.Append(std::move(parameters));
206
207 ExtensionFunction::ScopedUserGestureForTests scoped_user_gesture;
208 function = new api::DeveloperPrivateUpdateExtensionConfigurationFunction();
209 EXPECT_TRUE(RunFunction(function, args)) << key;
210 EXPECT_FALSE(has_pref.Run()) << key;
211 }
202 } 212 }
203 213
204 testing::AssertionResult DeveloperPrivateApiUnitTest::TestPackExtensionFunction( 214 testing::AssertionResult DeveloperPrivateApiUnitTest::TestPackExtensionFunction(
205 const base::ListValue& args, 215 const base::ListValue& args,
206 api::developer_private::PackStatus expected_status, 216 api::developer_private::PackStatus expected_status,
207 int expected_flags) { 217 int expected_flags) {
208 scoped_refptr<UIThreadExtensionFunction> function( 218 scoped_refptr<UIThreadExtensionFunction> function(
209 new api::DeveloperPrivatePackDirectoryFunction()); 219 new api::DeveloperPrivatePackDirectoryFunction());
210 if (!RunFunction(function, args)) 220 if (!RunFunction(function, args))
211 return testing::AssertionFailure() << "Could not run function."; 221 return testing::AssertionFailure() << "Could not run function.";
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 .Append( 570 .Append(
561 DictionaryBuilder().Set("extensionId", extension->id()).Build()) 571 DictionaryBuilder().Set("extensionId", extension->id()).Build())
562 .Build(); 572 .Build();
563 function = new api::DeveloperPrivateDeleteExtensionErrorsFunction(); 573 function = new api::DeveloperPrivateDeleteExtensionErrorsFunction();
564 EXPECT_TRUE(RunFunction(function, *args)) << function->GetError(); 574 EXPECT_TRUE(RunFunction(function, *args)) << function->GetError();
565 // No more errors! 575 // No more errors!
566 EXPECT_TRUE(error_console->GetErrorsForExtension(extension->id()).empty()); 576 EXPECT_TRUE(error_console->GetErrorsForExtension(extension->id()).empty());
567 } 577 }
568 578
569 } // namespace extensions 579 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/debugger/debugger_api.cc ('k') | chrome/browser/extensions/api/downloads/downloads_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698