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

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

Issue 2051663003: base::ListValue::Append cleanup: pass unique_ptr instead of the released pointer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 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 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 399
400 path = data_dir().AppendASCII("empty_manifest"); 400 path = data_dir().AppendASCII("empty_manifest");
401 api::EntryPicker::SkipPickerAndAlwaysSelectPathForTest(&path); 401 api::EntryPicker::SkipPickerAndAlwaysSelectPathForTest(&path);
402 402
403 // Try loading a bad extension (it should fail, and we should get an error). 403 // Try loading a bad extension (it should fail, and we should get an error).
404 function = new api::DeveloperPrivateLoadUnpackedFunction(); 404 function = new api::DeveloperPrivateLoadUnpackedFunction();
405 function->SetRenderFrameHost(web_contents->GetMainFrame()); 405 function->SetRenderFrameHost(web_contents->GetMainFrame());
406 base::ListValue unpacked_args; 406 base::ListValue unpacked_args;
407 std::unique_ptr<base::DictionaryValue> options(new base::DictionaryValue()); 407 std::unique_ptr<base::DictionaryValue> options(new base::DictionaryValue());
408 options->SetBoolean("failQuietly", true); 408 options->SetBoolean("failQuietly", true);
409 unpacked_args.Append(options.release()); 409 unpacked_args.Append(std::move(options));
410 current_ids = registry()->enabled_extensions().GetIDs(); 410 current_ids = registry()->enabled_extensions().GetIDs();
411 EXPECT_FALSE(RunFunction(function, unpacked_args)); 411 EXPECT_FALSE(RunFunction(function, unpacked_args));
412 EXPECT_EQ(manifest_errors::kManifestUnreadable, function->GetError()); 412 EXPECT_EQ(manifest_errors::kManifestUnreadable, function->GetError());
413 // We should have no new extensions installed. 413 // We should have no new extensions installed.
414 EXPECT_EQ(0u, base::STLSetDifference<ExtensionIdSet>( 414 EXPECT_EQ(0u, base::STLSetDifference<ExtensionIdSet>(
415 registry()->enabled_extensions().GetIDs(), 415 registry()->enabled_extensions().GetIDs(),
416 current_ids).size()); 416 current_ids).size());
417 } 417 }
418 418
419 // Test developerPrivate.requestFileSource. 419 // Test developerPrivate.requestFileSource.
420 TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateRequestFileSource) { 420 TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivateRequestFileSource) {
421 // Testing of this function seems light, but that's because it basically just 421 // Testing of this function seems light, but that's because it basically just
422 // forwards to reading a file to a string, and highlighting it - both of which 422 // forwards to reading a file to a string, and highlighting it - both of which
423 // are already tested separately. 423 // are already tested separately.
424 const Extension* extension = LoadUnpackedExtension(); 424 const Extension* extension = LoadUnpackedExtension();
425 const char kErrorMessage[] = "Something went wrong"; 425 const char kErrorMessage[] = "Something went wrong";
426 api::developer_private::RequestFileSourceProperties properties; 426 api::developer_private::RequestFileSourceProperties properties;
427 properties.extension_id = extension->id(); 427 properties.extension_id = extension->id();
428 properties.path_suffix = "manifest.json"; 428 properties.path_suffix = "manifest.json";
429 properties.message = kErrorMessage; 429 properties.message = kErrorMessage;
430 properties.manifest_key.reset(new std::string("name")); 430 properties.manifest_key.reset(new std::string("name"));
431 431
432 scoped_refptr<UIThreadExtensionFunction> function( 432 scoped_refptr<UIThreadExtensionFunction> function(
433 new api::DeveloperPrivateRequestFileSourceFunction()); 433 new api::DeveloperPrivateRequestFileSourceFunction());
434 base::ListValue file_source_args; 434 base::ListValue file_source_args;
435 file_source_args.Append(properties.ToValue().release()); 435 file_source_args.Append(properties.ToValue());
436 EXPECT_TRUE(RunFunction(function, file_source_args)) << function->GetError(); 436 EXPECT_TRUE(RunFunction(function, file_source_args)) << function->GetError();
437 437
438 const base::Value* response_value = nullptr; 438 const base::Value* response_value = nullptr;
439 ASSERT_TRUE(function->GetResultList()->Get(0u, &response_value)); 439 ASSERT_TRUE(function->GetResultList()->Get(0u, &response_value));
440 std::unique_ptr<api::developer_private::RequestFileSourceResponse> response = 440 std::unique_ptr<api::developer_private::RequestFileSourceResponse> response =
441 api::developer_private::RequestFileSourceResponse::FromValue( 441 api::developer_private::RequestFileSourceResponse::FromValue(
442 *response_value); 442 *response_value);
443 EXPECT_FALSE(response->before_highlight.empty()); 443 EXPECT_FALSE(response->before_highlight.empty());
444 EXPECT_EQ("\"name\": \"foo\"", response->highlight); 444 EXPECT_EQ("\"name\": \"foo\"", response->highlight);
445 EXPECT_FALSE(response->after_highlight.empty()); 445 EXPECT_FALSE(response->after_highlight.empty());
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 .Append( 542 .Append(
543 DictionaryBuilder().Set("extensionId", extension->id()).Build()) 543 DictionaryBuilder().Set("extensionId", extension->id()).Build())
544 .Build(); 544 .Build();
545 function = new api::DeveloperPrivateDeleteExtensionErrorsFunction(); 545 function = new api::DeveloperPrivateDeleteExtensionErrorsFunction();
546 EXPECT_TRUE(RunFunction(function, *args)) << function->GetError(); 546 EXPECT_TRUE(RunFunction(function, *args)) << function->GetError();
547 // No more errors! 547 // No more errors!
548 EXPECT_TRUE(error_console->GetErrorsForExtension(extension->id()).empty()); 548 EXPECT_TRUE(error_console->GetErrorsForExtension(extension->id()).empty());
549 } 549 }
550 550
551 } // namespace extensions 551 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698