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

Side by Side Diff: content/browser/download/save_package_unittest.cc

Issue 2032283002: Remove refcounting from SavePackage. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 (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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <memory>
8 #include <string> 9 #include <string>
9 10
10 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
11 #include "base/files/scoped_temp_dir.h" 12 #include "base/files/scoped_temp_dir.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
14 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
15 #include "build/build_config.h" 16 #include "build/build_config.h"
16 #include "content/browser/download/save_package.h" 17 #include "content/browser/download/save_package.h"
17 #include "content/public/common/url_constants.h" 18 #include "content/public/common/url_constants.h"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 99 }
99 100
100 protected: 101 protected:
101 void SetUp() override { 102 void SetUp() override {
102 RenderViewHostImplTestHarness::SetUp(); 103 RenderViewHostImplTestHarness::SetUp();
103 104
104 // Do the initialization in SetUp so contents() is initialized by 105 // Do the initialization in SetUp so contents() is initialized by
105 // RenderViewHostImplTestHarness::SetUp. 106 // RenderViewHostImplTestHarness::SetUp.
106 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 107 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
107 108
108 save_package_success_ = new SavePackage(contents(), 109 save_package_success_ = base::WrapUnique(new SavePackage(
109 temp_dir_.path().AppendASCII("testfile" HTML_EXTENSION), 110 contents(), temp_dir_.path().AppendASCII("testfile" HTML_EXTENSION),
110 temp_dir_.path().AppendASCII("testfile_files")); 111 temp_dir_.path().AppendASCII("testfile_files")));
111 112
112 // We need to construct a path that is *almost* kMaxFilePathLength long 113 // We need to construct a path that is *almost* kMaxFilePathLength long
113 long_file_name.reserve(kMaxFilePathLength + long_file_name.length()); 114 long_file_name.reserve(kMaxFilePathLength + long_file_name.length());
114 while (long_file_name.length() < kMaxFilePathLength) 115 while (long_file_name.length() < kMaxFilePathLength)
115 long_file_name += long_file_name; 116 long_file_name += long_file_name;
116 long_file_name.resize( 117 long_file_name.resize(
117 kMaxFilePathLength - 9 - temp_dir_.path().value().length()); 118 kMaxFilePathLength - 9 - temp_dir_.path().value().length());
118 119
119 save_package_fail_ = new SavePackage(contents(), 120 save_package_fail_ = base::WrapUnique(new SavePackage(
121 contents(),
120 temp_dir_.path().AppendASCII(long_file_name + HTML_EXTENSION), 122 temp_dir_.path().AppendASCII(long_file_name + HTML_EXTENSION),
121 temp_dir_.path().AppendASCII(long_file_name + "_files")); 123 temp_dir_.path().AppendASCII(long_file_name + "_files")));
122 } 124 }
123 125
124 private: 126 private:
125 // SavePackage for successfully generating file name. 127 // SavePackage for successfully generating file name.
126 scoped_refptr<SavePackage> save_package_success_; 128 std::unique_ptr<SavePackage> save_package_success_;
127 // SavePackage for failed generating file name. 129 // SavePackage for failed generating file name.
128 scoped_refptr<SavePackage> save_package_fail_; 130 std::unique_ptr<SavePackage> save_package_fail_;
129 131
130 base::ScopedTempDir temp_dir_; 132 base::ScopedTempDir temp_dir_;
131 }; 133 };
132 134
133 static const struct { 135 static const struct {
134 const char* disposition; 136 const char* disposition;
135 const char* url; 137 const char* url;
136 const base::FilePath::CharType* expected_name; 138 const base::FilePath::CharType* expected_name;
137 bool need_htm_ext; 139 bool need_htm_ext;
138 } kGeneratedFiles[] = { 140 } kGeneratedFiles[] = {
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 }; 395 };
394 396
395 // Crashing on Windows, see http://crbug.com/79365 397 // Crashing on Windows, see http://crbug.com/79365
396 #if defined(OS_WIN) 398 #if defined(OS_WIN)
397 #define MAYBE_TestSuggestedSaveNames DISABLED_TestSuggestedSaveNames 399 #define MAYBE_TestSuggestedSaveNames DISABLED_TestSuggestedSaveNames
398 #else 400 #else
399 #define MAYBE_TestSuggestedSaveNames TestSuggestedSaveNames 401 #define MAYBE_TestSuggestedSaveNames TestSuggestedSaveNames
400 #endif 402 #endif
401 TEST_F(SavePackageTest, MAYBE_TestSuggestedSaveNames) { 403 TEST_F(SavePackageTest, MAYBE_TestSuggestedSaveNames) {
402 for (size_t i = 0; i < arraysize(kSuggestedSaveNames); ++i) { 404 for (size_t i = 0; i < arraysize(kSuggestedSaveNames); ++i) {
403 scoped_refptr<SavePackage> save_package( 405 std::unique_ptr<SavePackage> save_package(
404 new SavePackage(contents(), base::FilePath(), base::FilePath())); 406 new SavePackage(contents(), base::FilePath(), base::FilePath()));
405 save_package->page_url_ = GURL(kSuggestedSaveNames[i].page_url); 407 save_package->page_url_ = GURL(kSuggestedSaveNames[i].page_url);
406 save_package->title_ = kSuggestedSaveNames[i].page_title; 408 save_package->title_ = kSuggestedSaveNames[i].page_title;
407 409
408 base::FilePath save_name = save_package->GetSuggestedNameForSaveAs( 410 base::FilePath save_name = save_package->GetSuggestedNameForSaveAs(
409 kSuggestedSaveNames[i].ensure_html_extension, std::string()); 411 kSuggestedSaveNames[i].ensure_html_extension, std::string());
410 EXPECT_EQ(kSuggestedSaveNames[i].expected_name, save_name.value()) << 412 EXPECT_EQ(kSuggestedSaveNames[i].expected_name, save_name.value()) <<
411 "Test case " << i; 413 "Test case " << i;
412 } 414 }
413 } 415 }
(...skipping 13 matching lines...) Expand all
427 GURL mock_url = net::URLRequestMockHTTPJob::GetMockUrl("save_page/a.htm"); 429 GURL mock_url = net::URLRequestMockHTTPJob::GetMockUrl("save_page/a.htm");
428 GURL view_source_url = 430 GURL view_source_url =
429 GURL(kViewSourceScheme + std::string(":") + mock_url.spec()); 431 GURL(kViewSourceScheme + std::string(":") + mock_url.spec());
430 GURL actual_url = net::URLRequestMockHTTPJob::GetMockUrl("save_page/a.htm"); 432 GURL actual_url = net::URLRequestMockHTTPJob::GetMockUrl("save_page/a.htm");
431 NavigateAndCommit(view_source_url); 433 NavigateAndCommit(view_source_url);
432 EXPECT_EQ(actual_url, GetUrlToBeSaved()); 434 EXPECT_EQ(actual_url, GetUrlToBeSaved());
433 EXPECT_EQ(view_source_url, contents()->GetLastCommittedURL()); 435 EXPECT_EQ(view_source_url, contents()->GetLastCommittedURL());
434 } 436 }
435 437
436 } // namespace content 438 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698