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

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

Issue 6793008: Replacing base::DIR_TEMP with ScopedTempDir when appropriate. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: I obviously need a Windows test machine. Created 9 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <string> 5 #include <string>
6 6
7 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/memory/scoped_temp_dir.h"
9 #include "base/string_util.h" 10 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/download/save_package.h" 12 #include "chrome/browser/download/save_package.h"
12 #include "chrome/browser/net/url_request_mock_http_job.h" 13 #include "chrome/browser/net/url_request_mock_http_job.h"
13 #include "content/browser/renderer_host/test_render_view_host.h" 14 #include "content/browser/renderer_host/test_render_view_host.h"
14 #include "content/browser/tab_contents/test_tab_contents.h" 15 #include "content/browser/tab_contents/test_tab_contents.h"
15 #include "googleurl/src/gurl.h" 16 #include "googleurl/src/gurl.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 18
18 #define FPL FILE_PATH_LITERAL 19 #define FPL FILE_PATH_LITERAL
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 GURL GetUrlToBeSaved() { 92 GURL GetUrlToBeSaved() {
92 return save_package_success_->GetUrlToBeSaved(); 93 return save_package_success_->GetUrlToBeSaved();
93 } 94 }
94 95
95 protected: 96 protected:
96 virtual void SetUp() { 97 virtual void SetUp() {
97 RenderViewHostTestHarness::SetUp(); 98 RenderViewHostTestHarness::SetUp();
98 99
99 // Do the initialization in SetUp so contents() is initialized by 100 // Do the initialization in SetUp so contents() is initialized by
100 // RenderViewHostTestHarness::SetUp. 101 // RenderViewHostTestHarness::SetUp.
101 FilePath test_dir; 102 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
102 PathService::Get(base::DIR_TEMP, &test_dir);
103 103
104 save_package_success_ = new SavePackage(contents(), 104 save_package_success_ = new SavePackage(contents(),
105 test_dir.AppendASCII("testfile" HTML_EXTENSION), 105 temp_dir_.path().AppendASCII("testfile" HTML_EXTENSION),
106 test_dir.AppendASCII("testfile_files")); 106 temp_dir_.path().AppendASCII("testfile_files"));
107 107
108 // We need to construct a path that is *almost* kMaxFilePathLength long 108 // We need to construct a path that is *almost* kMaxFilePathLength long
109 long_file_name.resize(kMaxFilePathLength + long_file_name.length()); 109 long_file_name.resize(kMaxFilePathLength + long_file_name.length());
110 while (long_file_name.length() < kMaxFilePathLength) 110 while (long_file_name.length() < kMaxFilePathLength)
111 long_file_name += long_file_name; 111 long_file_name += long_file_name;
112 long_file_name.resize(kMaxFilePathLength - 9 - test_dir.value().length()); 112 long_file_name.resize(
113 kMaxFilePathLength - 9 - temp_dir_.path().value().length());
113 114
114 save_package_fail_ = new SavePackage(contents(), 115 save_package_fail_ = new SavePackage(contents(),
115 test_dir.AppendASCII(long_file_name + HTML_EXTENSION), 116 temp_dir_.path().AppendASCII(long_file_name + HTML_EXTENSION),
116 test_dir.AppendASCII(long_file_name + "_files")); 117 temp_dir_.path().AppendASCII(long_file_name + "_files"));
117 } 118 }
118 119
119 private: 120 private:
120 // SavePackage for successfully generating file name. 121 // SavePackage for successfully generating file name.
121 scoped_refptr<SavePackage> save_package_success_; 122 scoped_refptr<SavePackage> save_package_success_;
122 // SavePackage for failed generating file name. 123 // SavePackage for failed generating file name.
123 scoped_refptr<SavePackage> save_package_fail_; 124 scoped_refptr<SavePackage> save_package_fail_;
124 125
126 ScopedTempDir temp_dir_;
127
125 DISALLOW_COPY_AND_ASSIGN(SavePackageTest); 128 DISALLOW_COPY_AND_ASSIGN(SavePackageTest);
126 }; 129 };
127 130
128 static const struct { 131 static const struct {
129 const char* disposition; 132 const char* disposition;
130 const char* url; 133 const char* url;
131 const FilePath::CharType* expected_name; 134 const FilePath::CharType* expected_name;
132 bool need_htm_ext; 135 bool need_htm_ext;
133 } kGeneratedFiles[] = { 136 } kGeneratedFiles[] = {
134 // We mainly focus on testing duplicated names here, since retrieving file 137 // We mainly focus on testing duplicated names here, since retrieving file
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 TEST_F(SavePackageTest, TestGetUrlToBeSavedViewSource) { 384 TEST_F(SavePackageTest, TestGetUrlToBeSavedViewSource) {
382 FilePath file_name(FILE_PATH_LITERAL("a.htm")); 385 FilePath file_name(FILE_PATH_LITERAL("a.htm"));
383 GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl( 386 GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl(
384 FilePath(kTestDir).Append(file_name)); 387 FilePath(kTestDir).Append(file_name));
385 GURL actual_url = URLRequestMockHTTPJob::GetMockUrl( 388 GURL actual_url = URLRequestMockHTTPJob::GetMockUrl(
386 FilePath(kTestDir).Append(file_name)); 389 FilePath(kTestDir).Append(file_name));
387 NavigateAndCommit(view_source_url); 390 NavigateAndCommit(view_source_url);
388 EXPECT_EQ(actual_url, GetUrlToBeSaved()); 391 EXPECT_EQ(actual_url, GetUrlToBeSaved());
389 EXPECT_EQ(view_source_url, contents()->GetURL()); 392 EXPECT_EQ(view_source_url, contents()->GetURL());
390 } 393 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698