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

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

Issue 159658: Remove duplication of DieFileDie, and move it to proper location. (Closed)
Patch Set: Created 11 years, 4 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
« no previous file with comments | « base/test_file_util_win.cc ('k') | chrome/common/pref_service_uitest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/path_service.h" 6 #include "base/path_service.h"
7 #include "base/platform_thread.h" 7 #include "base/platform_thread.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/test_file_util.h"
9 #include "chrome/app/chrome_dll_resource.h" 10 #include "chrome/app/chrome_dll_resource.h"
10 #include "chrome/browser/net/url_request_mock_http_job.h" 11 #include "chrome/browser/net/url_request_mock_http_job.h"
11 #include "chrome/browser/download/save_package.h" 12 #include "chrome/browser/download/save_package.h"
12 #include "chrome/common/chrome_paths.h" 13 #include "chrome/common/chrome_paths.h"
13 #include "chrome/test/automation/browser_proxy.h" 14 #include "chrome/test/automation/browser_proxy.h"
14 #include "chrome/test/automation/tab_proxy.h" 15 #include "chrome/test/automation/tab_proxy.h"
15 #include "chrome/test/ui/ui_test.h" 16 #include "chrome/test/ui/ui_test.h"
16 #include "net/url_request/url_request_unittest.h" 17 #include "net/url_request/url_request_unittest.h"
17 18
18 const char* const kTestDir = "save_page"; 19 const char* const kTestDir = "save_page";
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 ASSERT_TRUE(file_util::PathExists(server_file_name)); 57 ASSERT_TRUE(file_util::PathExists(server_file_name));
57 58
58 int64 client_file_size = 0; 59 int64 client_file_size = 0;
59 int64 server_file_size = 0; 60 int64 server_file_size = 0;
60 EXPECT_TRUE(file_util::GetFileSize(client_file, &client_file_size)); 61 EXPECT_TRUE(file_util::GetFileSize(client_file, &client_file_size));
61 EXPECT_TRUE(file_util::GetFileSize(server_file_name, &server_file_size)); 62 EXPECT_TRUE(file_util::GetFileSize(server_file_name, &server_file_size));
62 EXPECT_EQ(client_file_size, server_file_size); 63 EXPECT_EQ(client_file_size, server_file_size);
63 EXPECT_TRUE(file_util::ContentsEqual(client_file, server_file_name)); 64 EXPECT_TRUE(file_util::ContentsEqual(client_file, server_file_name));
64 } 65 }
65 66
66 EXPECT_TRUE(DieFileDie(client_file, false)); 67 EXPECT_TRUE(file_util::DieFileDie(client_file, false));
67 } 68 }
68 69
69 virtual void SetUp() { 70 virtual void SetUp() {
70 UITest::SetUp(); 71 UITest::SetUp();
71 EXPECT_TRUE(file_util::CreateNewTempDirectory(FILE_PATH_LITERAL(""), 72 EXPECT_TRUE(file_util::CreateNewTempDirectory(FILE_PATH_LITERAL(""),
72 &save_dir_)); 73 &save_dir_));
73 74
74 download_dir_ = FilePath::FromWStringHack(GetDownloadDirectory()); 75 download_dir_ = FilePath::FromWStringHack(GetDownloadDirectory());
75 } 76 }
76 77
77 virtual void TearDown() { 78 virtual void TearDown() {
78 UITest::TearDown(); 79 UITest::TearDown();
79 DieFileDie(save_dir_, true); 80 file_util::DieFileDie(save_dir_, true);
80 } 81 }
81 82
82 FilePath save_dir_; 83 FilePath save_dir_;
83 FilePath download_dir_; 84 FilePath download_dir_;
84 }; 85 };
85 86
86 // Flaky on Linux: http://code.google.com/p/chromium/issues/detail?id=14746 87 // Flaky on Linux: http://code.google.com/p/chromium/issues/detail?id=14746
87 TEST_F(SavePageTest, SaveHTMLOnly) { 88 TEST_F(SavePageTest, SaveHTMLOnly) {
88 std::string file_name("a.htm"); 89 std::string file_name("a.htm");
89 FilePath full_file_name = save_dir_.AppendASCII(file_name); 90 FilePath full_file_name = save_dir_.AppendASCII(file_name);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 SavePackage::SAVE_AS_COMPLETE_HTML)); 124 SavePackage::SAVE_AS_COMPLETE_HTML));
124 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); 125 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
125 EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get())); 126 EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get()));
126 127
127 CheckFile(dir.AppendASCII("1.png"), FilePath(FILE_PATH_LITERAL("1.png")), 128 CheckFile(dir.AppendASCII("1.png"), FilePath(FILE_PATH_LITERAL("1.png")),
128 true); 129 true);
129 CheckFile(dir.AppendASCII("1.css"), FilePath(FILE_PATH_LITERAL("1.css")), 130 CheckFile(dir.AppendASCII("1.css"), FilePath(FILE_PATH_LITERAL("1.css")),
130 true); 131 true);
131 CheckFile(full_file_name, FilePath::FromWStringHack(UTF8ToWide(file_name)), 132 CheckFile(full_file_name, FilePath::FromWStringHack(UTF8ToWide(file_name)),
132 false); 133 false);
133 EXPECT_TRUE(DieFileDie(dir, true)); 134 EXPECT_TRUE(file_util::DieFileDie(dir, true));
134 } 135 }
135 136
136 TEST_F(SavePageTest, NoSave) { 137 TEST_F(SavePageTest, NoSave) {
137 std::string file_name = "c.htm"; 138 std::string file_name = "c.htm";
138 FilePath full_file_name = save_dir_.AppendASCII(file_name); 139 FilePath full_file_name = save_dir_.AppendASCII(file_name);
139 FilePath dir = save_dir_.AppendASCII("c_files"); 140 FilePath dir = save_dir_.AppendASCII("c_files");
140 141
141 scoped_refptr<TabProxy> tab(GetActiveTab()); 142 scoped_refptr<TabProxy> tab(GetActiveTab());
142 ASSERT_TRUE(tab.get()); 143 ASSERT_TRUE(tab.get());
143 ASSERT_TRUE(tab->NavigateToURL(GURL("about:blank"))); 144 ASSERT_TRUE(tab->NavigateToURL(GURL("about:blank")));
(...skipping 26 matching lines...) Expand all
170 EXPECT_TRUE(browser->RunCommandAsync(IDC_SAVE_PAGE)); 171 EXPECT_TRUE(browser->RunCommandAsync(IDC_SAVE_PAGE));
171 EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get())); 172 EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get()));
172 automation()->SavePackageShouldPromptUser(true); 173 automation()->SavePackageShouldPromptUser(true);
173 174
174 CheckFile(dir.AppendASCII("1.png"), FilePath(FILE_PATH_LITERAL("1.png")), 175 CheckFile(dir.AppendASCII("1.png"), FilePath(FILE_PATH_LITERAL("1.png")),
175 true); 176 true);
176 CheckFile(dir.AppendASCII("1.css"), FilePath(FILE_PATH_LITERAL("1.css")), 177 CheckFile(dir.AppendASCII("1.css"), FilePath(FILE_PATH_LITERAL("1.css")),
177 true); 178 true);
178 CheckFile(full_file_name, FilePath::FromWStringHack(UTF8ToWide(file_name)), 179 CheckFile(full_file_name, FilePath::FromWStringHack(UTF8ToWide(file_name)),
179 false); 180 false);
180 EXPECT_TRUE(DieFileDie(full_file_name, false)); 181 EXPECT_TRUE(file_util::DieFileDie(full_file_name, false));
181 EXPECT_TRUE(DieFileDie(dir, true)); 182 EXPECT_TRUE(file_util::DieFileDie(dir, true));
182 } 183 }
183 184
184 // This tests that a webpage with the title "test.exe" is saved as 185 // This tests that a webpage with the title "test.exe" is saved as
185 // "test.exe.htm". 186 // "test.exe.htm".
186 // We probably don't care to handle this on Linux or Mac. 187 // We probably don't care to handle this on Linux or Mac.
187 #if defined(OS_WIN) 188 #if defined(OS_WIN)
188 TEST_F(SavePageTest, CleanFilenameFromPageTitle) { 189 TEST_F(SavePageTest, CleanFilenameFromPageTitle) {
189 std::string file_name = "c.htm"; 190 std::string file_name = "c.htm";
190 FilePath full_file_name = 191 FilePath full_file_name =
191 download_dir_.AppendASCII(std::string("test.exe") + kAppendedExtension); 192 download_dir_.AppendASCII(std::string("test.exe") + kAppendedExtension);
192 FilePath dir = download_dir_.AppendASCII("test.exe_files"); 193 FilePath dir = download_dir_.AppendASCII("test.exe_files");
193 194
194 GURL url = URLRequestMockHTTPJob::GetMockUrl( 195 GURL url = URLRequestMockHTTPJob::GetMockUrl(
195 UTF8ToWide(std::string(kTestDir) + "/" + file_name)); 196 UTF8ToWide(std::string(kTestDir) + "/" + file_name));
196 scoped_refptr<TabProxy> tab(GetActiveTab()); 197 scoped_refptr<TabProxy> tab(GetActiveTab());
197 ASSERT_TRUE(tab.get()); 198 ASSERT_TRUE(tab.get());
198 ASSERT_TRUE(tab->NavigateToURL(url)); 199 ASSERT_TRUE(tab->NavigateToURL(url));
199 WaitUntilTabCount(1); 200 WaitUntilTabCount(1);
200 201
201 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); 202 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
202 automation()->SavePackageShouldPromptUser(false); 203 automation()->SavePackageShouldPromptUser(false);
203 EXPECT_TRUE(browser->RunCommandAsync(IDC_SAVE_PAGE)); 204 EXPECT_TRUE(browser->RunCommandAsync(IDC_SAVE_PAGE));
204 EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get())); 205 EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get()));
205 automation()->SavePackageShouldPromptUser(true); 206 automation()->SavePackageShouldPromptUser(true);
206 207
207 CheckFile(full_file_name, FilePath::FromWStringHack(UTF8ToWide(file_name)), 208 CheckFile(full_file_name, FilePath::FromWStringHack(UTF8ToWide(file_name)),
208 false); 209 false);
209 EXPECT_TRUE(DieFileDie(full_file_name, false)); 210 EXPECT_TRUE(file_util::DieFileDie(full_file_name, false));
210 EXPECT_TRUE(DieFileDie(dir, true)); 211 EXPECT_TRUE(file_util::DieFileDie(dir, true));
211 } 212 }
212 #endif 213 #endif
OLDNEW
« no previous file with comments | « base/test_file_util_win.cc ('k') | chrome/common/pref_service_uitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698