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

Side by Side Diff: chrome/browser/extensions/api/downloads/downloads_api_unittest.cc

Issue 11458003: Remove scoped_refptr::release which is confusing and causes leaks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: duh Created 8 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 extension_function_test_utils::RunFunctionFlags GetFlags() { 461 extension_function_test_utils::RunFunctionFlags GetFlags() {
462 return current_browser()->profile()->IsOffTheRecord() ? 462 return current_browser()->profile()->IsOffTheRecord() ?
463 extension_function_test_utils::INCLUDE_INCOGNITO : 463 extension_function_test_utils::INCLUDE_INCOGNITO :
464 extension_function_test_utils::NONE; 464 extension_function_test_utils::NONE;
465 } 465 }
466 466
467 // extension_function_test_utils::RunFunction*() only uses browser for its 467 // extension_function_test_utils::RunFunction*() only uses browser for its
468 // profile(), so pass it the on-record browser so that it always uses the 468 // profile(), so pass it the on-record browser so that it always uses the
469 // on-record profile to match real-life behavior. 469 // on-record profile to match real-life behavior.
470 470
471 base::Value* RunFunctionAndReturnResult(UIThreadExtensionFunction* function, 471 base::Value* RunFunctionAndReturnResult(
472 const std::string& args) { 472 scoped_refptr<UIThreadExtensionFunction> function,
473 scoped_refptr<UIThreadExtensionFunction> delete_function(function); 473 const std::string& args) {
474 SetUpExtensionFunction(function); 474 SetUpExtensionFunction(function.get());
475 return extension_function_test_utils::RunFunctionAndReturnSingleResult( 475 return extension_function_test_utils::RunFunctionAndReturnSingleResult(
476 function, args, browser(), GetFlags()); 476 function.get(), args, browser(), GetFlags());
477 } 477 }
478 478
479 std::string RunFunctionAndReturnError(UIThreadExtensionFunction* function, 479 std::string RunFunctionAndReturnError(
480 const std::string& args) { 480 scoped_refptr<UIThreadExtensionFunction> function,
481 scoped_refptr<UIThreadExtensionFunction> delete_function(function); 481 const std::string& args) {
482 SetUpExtensionFunction(function); 482 SetUpExtensionFunction(function.get());
483 return extension_function_test_utils::RunFunctionAndReturnError( 483 return extension_function_test_utils::RunFunctionAndReturnError(
484 function, args, browser(), GetFlags()); 484 function.get(), args, browser(), GetFlags());
485 } 485 }
486 486
487 bool RunFunctionAndReturnString(UIThreadExtensionFunction* function, 487 bool RunFunctionAndReturnString(
488 const std::string& args, 488 scoped_refptr<UIThreadExtensionFunction> function,
489 std::string* result_string) { 489 const std::string& args,
490 SetUpExtensionFunction(function); 490 std::string* result_string) {
491 SetUpExtensionFunction(function.get());
491 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(function, args)); 492 scoped_ptr<base::Value> result(RunFunctionAndReturnResult(function, args));
492 EXPECT_TRUE(result.get()); 493 EXPECT_TRUE(result.get());
493 return result.get() && result->GetAsString(result_string); 494 return result.get() && result->GetAsString(result_string);
494 } 495 }
495 496
496 std::string DownloadItemIdAsArgList(const DownloadItem* download_item) { 497 std::string DownloadItemIdAsArgList(const DownloadItem* download_item) {
497 return base::StringPrintf("[%d]", download_item->GetId()); 498 return base::StringPrintf("[%d]", download_item->GetId());
498 } 499 }
499 500
500 const FilePath& downloads_directory() { 501 const FilePath& downloads_directory() {
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, 876 EXPECT_STREQ(download_extension_errors::kInvalidOperationError,
876 error.c_str()); 877 error.c_str());
877 878
878 // Calling resume on a non-existent download yields kInvalidOperationError 879 // Calling resume on a non-existent download yields kInvalidOperationError
879 error = RunFunctionAndReturnError( 880 error = RunFunctionAndReturnError(
880 new DownloadsResumeFunction(), "[-42]"); 881 new DownloadsResumeFunction(), "[-42]");
881 EXPECT_STREQ(download_extension_errors::kInvalidOperationError, 882 EXPECT_STREQ(download_extension_errors::kInvalidOperationError,
882 error.c_str()); 883 error.c_str());
883 } 884 }
884 885
885 UIThreadExtensionFunction* MockedGetFileIconFunction( 886 scoped_refptr<UIThreadExtensionFunction> MockedGetFileIconFunction(
886 const FilePath& expected_path, 887 const FilePath& expected_path,
887 IconLoader::IconSize icon_size, 888 IconLoader::IconSize icon_size,
888 const std::string& response) { 889 const std::string& response) {
889 scoped_refptr<DownloadsGetFileIconFunction> function( 890 scoped_refptr<DownloadsGetFileIconFunction> function(
890 new DownloadsGetFileIconFunction()); 891 new DownloadsGetFileIconFunction());
891 function->SetIconExtractorForTesting(new MockIconExtractorImpl( 892 function->SetIconExtractorForTesting(new MockIconExtractorImpl(
892 expected_path, icon_size, response)); 893 expected_path, icon_size, response));
893 return function.release(); 894 return function;
894 } 895 }
895 896
896 // Test downloads.getFileIcon() on in-progress, finished, cancelled and deleted 897 // Test downloads.getFileIcon() on in-progress, finished, cancelled and deleted
897 // download items. 898 // download items.
898 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest, 899 IN_PROC_BROWSER_TEST_F(DownloadExtensionTest,
899 DownloadExtensionTest_FileIcon_Active) { 900 DownloadExtensionTest_FileIcon_Active) {
900 DownloadItem* download_item = CreateSlowTestDownload(); 901 DownloadItem* download_item = CreateSlowTestDownload();
901 ASSERT_TRUE(download_item); 902 ASSERT_TRUE(download_item);
902 ASSERT_FALSE(download_item->GetTargetFilePath().empty()); 903 ASSERT_FALSE(download_item->GetTargetFilePath().empty());
903 std::string args32(base::StringPrintf("[%d, {\"size\": 32}]", 904 std::string args32(base::StringPrintf("[%d, {\"size\": 32}]",
(...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after
2073 " \"state\": {" 2074 " \"state\": {"
2074 " \"previous\": \"in_progress\"," 2075 " \"previous\": \"in_progress\","
2075 " \"current\": \"complete\"}}]", 2076 " \"current\": \"complete\"}}]",
2076 result_id, 2077 result_id,
2077 GetFilename("on_record.txt.crdownload").c_str(), 2078 GetFilename("on_record.txt.crdownload").c_str(),
2078 GetFilename("on_record.txt").c_str()))); 2079 GetFilename("on_record.txt").c_str())));
2079 std::string disk_data; 2080 std::string disk_data;
2080 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data)); 2081 EXPECT_TRUE(file_util::ReadFileToString(item->GetFullPath(), &disk_data));
2081 EXPECT_STREQ(kPayloadData, disk_data.c_str()); 2082 EXPECT_STREQ(kPayloadData, disk_data.c_str());
2082 } 2083 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698