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

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

Issue 14197014: Add TestBrowserThreadBundle into RenderViewHostTestHarness. Kill some unnecessary real threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merged ToT Created 7 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 | 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 <string> 5 #include <string>
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "content/browser/browser_thread_impl.h"
13 #include "content/browser/download/save_package.h" 12 #include "content/browser/download/save_package.h"
14 #include "content/browser/renderer_host/test_render_view_host.h" 13 #include "content/browser/renderer_host/test_render_view_host.h"
15 #include "content/test/net/url_request_mock_http_job.h" 14 #include "content/test/net/url_request_mock_http_job.h"
16 #include "content/test/test_web_contents.h" 15 #include "content/test/test_web_contents.h"
17 #include "googleurl/src/gurl.h" 16 #include "googleurl/src/gurl.h"
18 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
19 18
20 namespace content { 19 namespace content {
21 20
22 #define FPL FILE_PATH_LITERAL 21 #define FPL FILE_PATH_LITERAL
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 return false; 60 return false;
62 } 61 }
63 62
64 return true; 63 return true;
65 } 64 }
66 65
67 } // namespace 66 } // namespace
68 67
69 class SavePackageTest : public RenderViewHostImplTestHarness { 68 class SavePackageTest : public RenderViewHostImplTestHarness {
70 public: 69 public:
71 SavePackageTest() : browser_thread_(BrowserThread::UI, &message_loop_) {
72 }
73
74 bool GetGeneratedFilename(bool need_success_generate_filename, 70 bool GetGeneratedFilename(bool need_success_generate_filename,
75 const std::string& disposition, 71 const std::string& disposition,
76 const std::string& url, 72 const std::string& url,
77 bool need_htm_ext, 73 bool need_htm_ext,
78 base::FilePath::StringType* generated_name) { 74 base::FilePath::StringType* generated_name) {
79 SavePackage* save_package; 75 SavePackage* save_package;
80 if (need_success_generate_filename) 76 if (need_success_generate_filename)
81 save_package = save_package_success_.get(); 77 save_package = save_package_success_.get();
82 else 78 else
83 save_package = save_package_fail_.get(); 79 save_package = save_package_fail_.get();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 long_file_name += long_file_name; 112 long_file_name += long_file_name;
117 long_file_name.resize( 113 long_file_name.resize(
118 kMaxFilePathLength - 9 - temp_dir_.path().value().length()); 114 kMaxFilePathLength - 9 - temp_dir_.path().value().length());
119 115
120 save_package_fail_ = new SavePackage(contents(), 116 save_package_fail_ = new SavePackage(contents(),
121 temp_dir_.path().AppendASCII(long_file_name + HTML_EXTENSION), 117 temp_dir_.path().AppendASCII(long_file_name + HTML_EXTENSION),
122 temp_dir_.path().AppendASCII(long_file_name + "_files")); 118 temp_dir_.path().AppendASCII(long_file_name + "_files"));
123 } 119 }
124 120
125 private: 121 private:
126 BrowserThreadImpl browser_thread_;
127
128 // SavePackage for successfully generating file name. 122 // SavePackage for successfully generating file name.
129 scoped_refptr<SavePackage> save_package_success_; 123 scoped_refptr<SavePackage> save_package_success_;
130 // SavePackage for failed generating file name. 124 // SavePackage for failed generating file name.
131 scoped_refptr<SavePackage> save_package_fail_; 125 scoped_refptr<SavePackage> save_package_fail_;
132 126
133 base::ScopedTempDir temp_dir_; 127 base::ScopedTempDir temp_dir_;
134
135 DISALLOW_COPY_AND_ASSIGN(SavePackageTest);
136 }; 128 };
137 129
138 static const struct { 130 static const struct {
139 const char* disposition; 131 const char* disposition;
140 const char* url; 132 const char* url;
141 const base::FilePath::CharType* expected_name; 133 const base::FilePath::CharType* expected_name;
142 bool need_htm_ext; 134 bool need_htm_ext;
143 } kGeneratedFiles[] = { 135 } kGeneratedFiles[] = {
144 // We mainly focus on testing duplicated names here, since retrieving file 136 // We mainly focus on testing duplicated names here, since retrieving file
145 // name from disposition and url has been tested in DownloadManagerTest. 137 // name from disposition and url has been tested in DownloadManagerTest.
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl( 431 GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl(
440 base::FilePath(kTestDir).Append(file_name)); 432 base::FilePath(kTestDir).Append(file_name));
441 GURL actual_url = URLRequestMockHTTPJob::GetMockUrl( 433 GURL actual_url = URLRequestMockHTTPJob::GetMockUrl(
442 base::FilePath(kTestDir).Append(file_name)); 434 base::FilePath(kTestDir).Append(file_name));
443 NavigateAndCommit(view_source_url); 435 NavigateAndCommit(view_source_url);
444 EXPECT_EQ(actual_url, GetUrlToBeSaved()); 436 EXPECT_EQ(actual_url, GetUrlToBeSaved());
445 EXPECT_EQ(view_source_url, contents()->GetURL()); 437 EXPECT_EQ(view_source_url, contents()->GetURL());
446 } 438 }
447 439
448 } // namespace content 440 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/devtools/devtools_manager_unittest.cc ('k') | content/browser/gpu/shader_disk_cache_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698