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

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

Issue 7606024: Add Cancel test for SavePackage. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | 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) 2011 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 "base/file_path.h" 5 #include "base/file_path.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/scoped_temp_dir.h" 8 #include "base/scoped_temp_dir.h"
9 #include "chrome/app/chrome_command_ids.h" 9 #include "chrome/app/chrome_command_ids.h"
10 #include "chrome/browser/download/download_history.h" 10 #include "chrome/browser/download/download_history.h"
(...skipping 26 matching lines...) Expand all
37 #endif 37 #endif
38 38
39 class SavePageBrowserTest : public InProcessBrowserTest { 39 class SavePageBrowserTest : public InProcessBrowserTest {
40 protected: 40 protected:
41 void SetUp() { 41 void SetUp() {
42 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir_)); 42 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir_));
43 ASSERT_TRUE(save_dir_.CreateUniqueTempDir()); 43 ASSERT_TRUE(save_dir_.CreateUniqueTempDir());
44 InProcessBrowserTest::SetUp(); 44 InProcessBrowserTest::SetUp();
45 } 45 }
46 46
47 void GetPaths(const std::string& prefix,
48 GURL* url,
49 FilePath* full_file_name,
50 FilePath* dir) {
51 *url = URLRequestMockHTTPJob::GetMockUrl(
52 FilePath(kTestDir).AppendASCII(prefix + ".htm"));
53 ui_test_utils::NavigateToURL(browser(), *url);
Paweł Hajdan Jr. 2011/08/11 17:26:40 GetPath doesn't really correspond to NavigateToURL
achuithb 2011/08/11 23:21:59 The problem is that the function does 2 separate t
Paweł Hajdan Jr. 2011/08/12 16:48:57 SGTM
54
55 *full_file_name = save_dir_.path().AppendASCII(prefix + ".htm");
56 *dir = save_dir_.path().AppendASCII(prefix + "_files");
57 }
58
59 TabContents* GetCurrentTab() const {
60 TabContents* current_tab = browser()->GetSelectedTabContents();
61 EXPECT_TRUE(current_tab);
62 return current_tab;
63 }
64
65
47 GURL WaitForSavePackageToFinish() const { 66 GURL WaitForSavePackageToFinish() const {
48 ui_test_utils::TestNotificationObserver observer; 67 ui_test_utils::TestNotificationObserver observer;
49 ui_test_utils::RegisterAndWait(&observer, 68 ui_test_utils::RegisterAndWait(&observer,
50 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED, 69 content::NOTIFICATION_SAVE_PACKAGE_SUCCESSFULLY_FINISHED,
51 NotificationService::AllSources()); 70 NotificationService::AllSources());
52 return Details<DownloadItem>(observer.details()).ptr()->original_url(); 71 return Details<DownloadItem>(observer.details()).ptr()->original_url();
53 } 72 }
54 73
55 #if defined(OS_CHROMEOS) 74 #if defined(OS_CHROMEOS)
56 const ActiveDownloadsUI::DownloadList& GetDownloads() const { 75 const ActiveDownloadsUI::DownloadList& GetDownloads() const {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 std::vector<DownloadHistoryInfo> history_entries_; 164 std::vector<DownloadHistoryInfo> history_entries_;
146 165
147 // Path to directory containing test data. 166 // Path to directory containing test data.
148 FilePath test_dir_; 167 FilePath test_dir_;
149 168
150 // Temporary directory we will save pages to. 169 // Temporary directory we will save pages to.
151 ScopedTempDir save_dir_; 170 ScopedTempDir save_dir_;
152 }; 171 };
153 172
154 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) { 173 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) {
155 FilePath file_name(FILE_PATH_LITERAL("a.htm")); 174 GURL url;
156 GURL url = URLRequestMockHTTPJob::GetMockUrl( 175 FilePath full_file_name, dir;
157 FilePath(kTestDir).Append(file_name)); 176 GetPaths("a", &url, &full_file_name, &dir);
158 ui_test_utils::NavigateToURL(browser(), url); 177 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir,
159
160 TabContents* current_tab = browser()->GetSelectedTabContents();
161 ASSERT_TRUE(current_tab);
162
163 FilePath full_file_name = save_dir_.path().Append(file_name);
164 FilePath dir = save_dir_.path().AppendASCII("a_files");
165 ASSERT_TRUE(current_tab->SavePage(full_file_name, dir,
166 SavePackage::SAVE_AS_ONLY_HTML)); 178 SavePackage::SAVE_AS_ONLY_HTML));
Paweł Hajdan Jr. 2011/08/11 17:26:40 nit: Isn't this line misaligned now?
achuithb 2011/08/11 23:21:59 Done.
167 179
168 EXPECT_EQ(url, WaitForSavePackageToFinish()); 180 EXPECT_EQ(url, WaitForSavePackageToFinish());
169 181
170 CheckDownloadUI(full_file_name); 182 CheckDownloadUI(full_file_name);
171 CheckDownloadHistory(url, full_file_name, 1); // a.htm is 1 file. 183 CheckDownloadHistory(url, full_file_name, 1); // a.htm is 1 file.
172 184
173 EXPECT_TRUE(file_util::PathExists(full_file_name)); 185 EXPECT_TRUE(file_util::PathExists(full_file_name));
174 EXPECT_FALSE(file_util::PathExists(dir)); 186 EXPECT_FALSE(file_util::PathExists(dir));
175 EXPECT_TRUE(file_util::ContentsEqual( 187 EXPECT_TRUE(file_util::ContentsEqual(
176 test_dir_.Append(FilePath(kTestDir)).Append(file_name), 188 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")),
177 full_file_name)); 189 full_file_name));
178 } 190 }
179 191
180 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveViewSourceHTMLOnly) { 192 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveViewSourceHTMLOnly) {
181 FilePath file_name(FILE_PATH_LITERAL("a.htm")); 193 FilePath file_name(FILE_PATH_LITERAL("a.htm"));
182 GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl( 194 GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl(
183 FilePath(kTestDir).Append(file_name)); 195 FilePath(kTestDir).Append(file_name));
184 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl( 196 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl(
185 FilePath(kTestDir).Append(file_name)); 197 FilePath(kTestDir).Append(file_name));
186 ui_test_utils::NavigateToURL(browser(), view_source_url); 198 ui_test_utils::NavigateToURL(browser(), view_source_url);
187 199
188 TabContents* current_tab = browser()->GetSelectedTabContents();
189 ASSERT_TRUE(current_tab);
190
191 FilePath full_file_name = save_dir_.path().Append(file_name); 200 FilePath full_file_name = save_dir_.path().Append(file_name);
192 FilePath dir = save_dir_.path().AppendASCII("a_files"); 201 FilePath dir = save_dir_.path().AppendASCII("a_files");
193 202
194 ASSERT_TRUE(current_tab->SavePage(full_file_name, dir, 203 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir,
195 SavePackage::SAVE_AS_ONLY_HTML)); 204 SavePackage::SAVE_AS_ONLY_HTML));
196 205
197 EXPECT_EQ(actual_page_url, WaitForSavePackageToFinish()); 206 EXPECT_EQ(actual_page_url, WaitForSavePackageToFinish());
198 207
199 CheckDownloadUI(full_file_name); 208 CheckDownloadUI(full_file_name);
200 CheckDownloadHistory(actual_page_url, full_file_name, 1); // a.htm is 1 file. 209 CheckDownloadHistory(actual_page_url, full_file_name, 1); // a.htm is 1 file.
201 210
202 EXPECT_TRUE(file_util::PathExists(full_file_name)); 211 EXPECT_TRUE(file_util::PathExists(full_file_name));
203 EXPECT_FALSE(file_util::PathExists(dir)); 212 EXPECT_FALSE(file_util::PathExists(dir));
204 EXPECT_TRUE(file_util::ContentsEqual( 213 EXPECT_TRUE(file_util::ContentsEqual(
205 test_dir_.Append(FilePath(kTestDir)).Append(file_name), 214 test_dir_.Append(FilePath(kTestDir)).Append(file_name),
206 full_file_name)); 215 full_file_name));
207 } 216 }
208 217
209 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { 218 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) {
210 FilePath file_name(FILE_PATH_LITERAL("b.htm")); 219 GURL url;
211 GURL url = URLRequestMockHTTPJob::GetMockUrl( 220 FilePath full_file_name, dir;
212 FilePath(kTestDir).Append(file_name)); 221 GetPaths("b", &url, &full_file_name, &dir);
213 ui_test_utils::NavigateToURL(browser(), url); 222 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir,
214
215 TabContents* current_tab = browser()->GetSelectedTabContents();
216 ASSERT_TRUE(current_tab);
217
218 FilePath full_file_name = save_dir_.path().Append(file_name);
219 FilePath dir = save_dir_.path().AppendASCII("b_files");
220 ASSERT_TRUE(current_tab->SavePage(full_file_name, dir,
221 SavePackage::SAVE_AS_COMPLETE_HTML)); 223 SavePackage::SAVE_AS_COMPLETE_HTML));
Paweł Hajdan Jr. 2011/08/11 17:26:40 nit: Isn't this line misaligned now?
achuithb 2011/08/11 23:21:59 Done.
222 224
223 EXPECT_EQ(url, WaitForSavePackageToFinish()); 225 EXPECT_EQ(url, WaitForSavePackageToFinish());
224 226
225 CheckDownloadUI(full_file_name); 227 CheckDownloadUI(full_file_name);
226 CheckDownloadHistory(url, full_file_name, 3); // b.htm is 3 files. 228 CheckDownloadHistory(url, full_file_name, 3); // b.htm is 3 files.
227 229
228 EXPECT_TRUE(file_util::PathExists(full_file_name)); 230 EXPECT_TRUE(file_util::PathExists(full_file_name));
229 EXPECT_TRUE(file_util::PathExists(dir)); 231 EXPECT_TRUE(file_util::PathExists(dir));
230 EXPECT_TRUE(file_util::TextContentsEqual( 232 EXPECT_TRUE(file_util::TextContentsEqual(
231 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"), 233 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"),
(...skipping 17 matching lines...) Expand all
249 251
250 GURL url = URLRequestMockHTTPJob::GetMockUrl( 252 GURL url = URLRequestMockHTTPJob::GetMockUrl(
251 FilePath(kTestDir).Append(file_name)); 253 FilePath(kTestDir).Append(file_name));
252 ui_test_utils::NavigateToURL(browser(), url); 254 ui_test_utils::NavigateToURL(browser(), url);
253 255
254 FilePath full_file_name = save_dir_.path().AppendASCII( 256 FilePath full_file_name = save_dir_.path().AppendASCII(
255 std::string("Test page for saving page feature") + kAppendedExtension); 257 std::string("Test page for saving page feature") + kAppendedExtension);
256 FilePath dir = save_dir_.path().AppendASCII( 258 FilePath dir = save_dir_.path().AppendASCII(
257 "Test page for saving page feature_files"); 259 "Test page for saving page feature_files");
258 260
259 TabContents* current_tab = browser()->GetSelectedTabContents(); 261 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir,
260 ASSERT_TRUE(current_tab);
261
262 ASSERT_TRUE(current_tab->SavePage(full_file_name, dir,
263 SavePackage::SAVE_AS_COMPLETE_HTML)); 262 SavePackage::SAVE_AS_COMPLETE_HTML));
Paweł Hajdan Jr. 2011/08/11 17:26:40 nit: Isn't this line misaligned now?
achuithb 2011/08/11 23:21:59 Done.
264 263
265 EXPECT_EQ(url, WaitForSavePackageToFinish()); 264 EXPECT_EQ(url, WaitForSavePackageToFinish());
266 265
267 CheckDownloadUI(full_file_name); 266 CheckDownloadUI(full_file_name);
268 CheckDownloadHistory(url, full_file_name, 3); // b.htm is 3 files. 267 CheckDownloadHistory(url, full_file_name, 3); // b.htm is 3 files.
269 268
270 EXPECT_TRUE(file_util::PathExists(full_file_name)); 269 EXPECT_TRUE(file_util::PathExists(full_file_name));
271 EXPECT_TRUE(file_util::PathExists(dir)); 270 EXPECT_TRUE(file_util::PathExists(dir));
272 EXPECT_TRUE(file_util::TextContentsEqual( 271 EXPECT_TRUE(file_util::TextContentsEqual(
273 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"), 272 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"),
274 full_file_name)); 273 full_file_name));
275 EXPECT_TRUE(file_util::ContentsEqual( 274 EXPECT_TRUE(file_util::ContentsEqual(
276 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), 275 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"),
277 dir.AppendASCII("1.png"))); 276 dir.AppendASCII("1.png")));
278 EXPECT_TRUE(file_util::ContentsEqual( 277 EXPECT_TRUE(file_util::ContentsEqual(
279 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), 278 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"),
280 dir.AppendASCII("1.css"))); 279 dir.AppendASCII("1.css")));
281 } 280 }
282 281
283 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, RemoveFromList) { 282 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, RemoveFromList) {
284 FilePath file_name(FILE_PATH_LITERAL("a.htm")); 283 GURL url;
285 GURL url = URLRequestMockHTTPJob::GetMockUrl( 284 FilePath full_file_name, dir;
286 FilePath(kTestDir).Append(file_name)); 285 GetPaths("a", &url, &full_file_name, &dir);
287 ui_test_utils::NavigateToURL(browser(), url); 286 ASSERT_TRUE(GetCurrentTab()->SavePage(full_file_name, dir,
288
289 TabContents* current_tab = browser()->GetSelectedTabContents();
290 ASSERT_TRUE(current_tab);
291
292 FilePath full_file_name = save_dir_.path().Append(file_name);
293 FilePath dir = save_dir_.path().AppendASCII("a_files");
294 ASSERT_TRUE(current_tab->SavePage(full_file_name, dir,
295 SavePackage::SAVE_AS_ONLY_HTML)); 287 SavePackage::SAVE_AS_ONLY_HTML));
Paweł Hajdan Jr. 2011/08/11 17:26:40 nit: Isn't this line misaligned now?
achuithb 2011/08/11 23:21:59 Done.
296 288
297 EXPECT_EQ(url, WaitForSavePackageToFinish()); 289 EXPECT_EQ(url, WaitForSavePackageToFinish());
298 290
299 CheckDownloadUI(full_file_name); 291 CheckDownloadUI(full_file_name);
300 CheckDownloadHistory(url, full_file_name, 1); // a.htm is 1 file. 292 CheckDownloadHistory(url, full_file_name, 1); // a.htm is 1 file.
301 293
302 EXPECT_EQ(GetDownloadManager()->RemoveAllDownloads(), 1); 294 EXPECT_EQ(GetDownloadManager()->RemoveAllDownloads(), 1);
303 295
304 #if defined(OS_CHROMEOS) 296 #if defined(OS_CHROMEOS)
305 EXPECT_EQ(GetDownloads().size(), 0U); 297 EXPECT_EQ(GetDownloads().size(), 0U);
306 #endif 298 #endif
307 299
308 // Should not be in history. 300 // Should not be in history.
309 QueryDownloadHistory(); 301 QueryDownloadHistory();
310 EXPECT_EQ(std::find_if(history_entries_.begin(), history_entries_.end(), 302 EXPECT_EQ(std::find_if(history_entries_.begin(), history_entries_.end(),
311 DownloadHistoryInfoMatch(url, full_file_name, 1)), 303 DownloadHistoryInfoMatch(url, full_file_name, 1)),
312 history_entries_.end()); 304 history_entries_.end());
313 305
314 EXPECT_TRUE(file_util::PathExists(full_file_name)); 306 EXPECT_TRUE(file_util::PathExists(full_file_name));
315 EXPECT_FALSE(file_util::PathExists(dir)); 307 EXPECT_FALSE(file_util::PathExists(dir));
316 EXPECT_TRUE(file_util::ContentsEqual( 308 EXPECT_TRUE(file_util::ContentsEqual(
317 test_dir_.Append(FilePath(kTestDir)).Append(file_name), 309 test_dir_.Append(FilePath(kTestDir)).Append(FILE_PATH_LITERAL("a.htm")),
318 full_file_name)); 310 full_file_name));
319 } 311 }
320 312
313 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, Cancel) {
Paweł Hajdan Jr. 2011/08/11 17:26:40 nit: Add comment what this is testing.
achuithb 2011/08/11 23:21:59 Done.
314 GURL url;
315 FilePath full_file_name, dir;
316 GetPaths("a", &url, &full_file_name, &dir);
317 scoped_refptr<SavePackage> save_package(new SavePackage(GetCurrentTab(),
318 SavePackage::SAVE_AS_ONLY_HTML, full_file_name, dir));
321 } 319 }
320
321 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, ExplicitCancel) {
322 GURL url;
323 FilePath full_file_name, dir;
324 GetPaths("a", &url, &full_file_name, &dir);
325 scoped_refptr<SavePackage> save_package(new SavePackage(GetCurrentTab(),
326 SavePackage::SAVE_AS_ONLY_HTML, full_file_name, dir));
327 save_package->Cancel(true);
328 }
329
330 } // namespace
Paweł Hajdan Jr. 2011/08/11 17:26:40 nit: Two spaces between } and //
achuithb 2011/08/11 23:21:59 Done.
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698