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

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

Issue 6312027: Add files saved using 'Save page as' to the download history.... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 10 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/browser_window.h" 10 #include "chrome/browser/browser_window.h"
11 #include "chrome/browser/download/download_manager.h"
11 #include "chrome/browser/net/url_request_mock_http_job.h" 12 #include "chrome/browser/net/url_request_mock_http_job.h"
13 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/tab_contents/tab_contents.h" 14 #include "chrome/browser/tab_contents/tab_contents.h"
13 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
14 #include "chrome/common/chrome_paths.h" 16 #include "chrome/common/chrome_paths.h"
15 #include "chrome/common/notification_service.h" 17 #include "chrome/common/notification_service.h"
16 #include "chrome/common/url_constants.h" 18 #include "chrome/common/url_constants.h"
17 #include "chrome/test/in_process_browser_test.h" 19 #include "chrome/test/in_process_browser_test.h"
18 #include "chrome/test/ui_test_utils.h" 20 #include "chrome/test/ui_test_utils.h"
19 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
20 22
21 namespace {
22
23 static const FilePath::CharType* kTestDir = FILE_PATH_LITERAL("save_page"); 23 static const FilePath::CharType* kTestDir = FILE_PATH_LITERAL("save_page");
24 24
25 static const char* kAppendedExtension = 25 static const char* kAppendedExtension =
26 #if defined(OS_WIN) 26 #if defined(OS_WIN)
27 ".htm"; 27 ".htm";
28 #else 28 #else
29 ".html"; 29 ".html";
30 #endif 30 #endif
31 31
32 class SavePageBrowserTest : public InProcessBrowserTest { 32 class SavePageBrowserTest : public InProcessBrowserTest {
33 protected: 33 protected:
34 void SetUp() { 34 void SetUp() {
35 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir_)); 35 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir_));
36 ASSERT_TRUE(save_dir_.CreateUniqueTempDir()); 36 ASSERT_TRUE(save_dir_.CreateUniqueTempDir());
37 InProcessBrowserTest::SetUp(); 37 InProcessBrowserTest::SetUp();
38 } 38 }
39 39
40 GURL WaitForSavePackageToFinish() { 40 GURL WaitForSavePackageToFinish() {
41 ui_test_utils::TestNotificationObserver observer; 41 ui_test_utils::TestNotificationObserver observer;
42 ui_test_utils::RegisterAndWait(&observer, 42 ui_test_utils::RegisterAndWait(&observer,
43 NotificationType::SAVE_PACKAGE_SUCCESSFULLY_FINISHED, 43 NotificationType::SAVE_PACKAGE_SUCCESSFULLY_FINISHED,
44 NotificationService::AllSources()); 44 NotificationService::AllSources());
45 return *Details<GURL>(observer.details()).ptr(); 45 return *Details<GURL>(observer.details()).ptr();
46 } 46 }
47 47
48 // Make sure the DownloadItem was added to the download history.
49 void ValidateDownloadHistory(TabContents* current_tab) {
50 DownloadManager* download_manager =
51 current_tab->profile()->GetDownloadManager();
52 EXPECT_EQ(1u, download_manager->history_downloads_.size());
Paweł Hajdan Jr. 2011/02/14 09:35:53 This is not enough. I'd like to query the history
53 }
54
48 // Path to directory containing test data. 55 // Path to directory containing test data.
49 FilePath test_dir_; 56 FilePath test_dir_;
50 57
51 // Temporary directory we will save pages to. 58 // Temporary directory we will save pages to.
52 ScopedTempDir save_dir_; 59 ScopedTempDir save_dir_;
53 }; 60 };
54 61
55 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) { 62 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) {
56 FilePath file_name(FILE_PATH_LITERAL("a.htm")); 63 FilePath file_name(FILE_PATH_LITERAL("a.htm"));
57 GURL url = URLRequestMockHTTPJob::GetMockUrl( 64 GURL url = URLRequestMockHTTPJob::GetMockUrl(
58 FilePath(kTestDir).Append(file_name)); 65 FilePath(kTestDir).Append(file_name));
59 ui_test_utils::NavigateToURL(browser(), url); 66 ui_test_utils::NavigateToURL(browser(), url);
60 67
61 TabContents* current_tab = browser()->GetSelectedTabContents(); 68 TabContents* current_tab = browser()->GetSelectedTabContents();
62 ASSERT_TRUE(current_tab); 69 ASSERT_TRUE(current_tab);
63 70
64 FilePath full_file_name = save_dir_.path().Append(file_name); 71 FilePath full_file_name = save_dir_.path().Append(file_name);
65 FilePath dir = save_dir_.path().AppendASCII("a_files"); 72 FilePath dir = save_dir_.path().AppendASCII("a_files");
66 ASSERT_TRUE(current_tab->SavePage(full_file_name, dir, 73 ASSERT_TRUE(current_tab->SavePage(full_file_name, dir,
67 SavePackage::SAVE_AS_ONLY_HTML)); 74 SavePackage::SAVE_AS_ONLY_HTML));
68 75
69 EXPECT_EQ(url, WaitForSavePackageToFinish()); 76 EXPECT_EQ(url, WaitForSavePackageToFinish());
70 77
71 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF)) 78 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF))
72 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 79 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
73 80
81 ValidateDownloadHistory(current_tab);
82
74 EXPECT_TRUE(file_util::PathExists(full_file_name)); 83 EXPECT_TRUE(file_util::PathExists(full_file_name));
75 EXPECT_FALSE(file_util::PathExists(dir)); 84 EXPECT_FALSE(file_util::PathExists(dir));
76 EXPECT_TRUE(file_util::ContentsEqual( 85 EXPECT_TRUE(file_util::ContentsEqual(
77 test_dir_.Append(FilePath(kTestDir)).Append(file_name), 86 test_dir_.Append(FilePath(kTestDir)).Append(file_name),
78 full_file_name)); 87 full_file_name));
79 } 88 }
80 89
81 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveViewSourceHTMLOnly) { 90 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveViewSourceHTMLOnly) {
82 FilePath file_name(FILE_PATH_LITERAL("a.htm")); 91 FilePath file_name(FILE_PATH_LITERAL("a.htm"));
83 GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl( 92 GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl(
84 FilePath(kTestDir).Append(file_name)); 93 FilePath(kTestDir).Append(file_name));
85 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl( 94 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl(
86 FilePath(kTestDir).Append(file_name)); 95 FilePath(kTestDir).Append(file_name));
87 ui_test_utils::NavigateToURL(browser(), view_source_url); 96 ui_test_utils::NavigateToURL(browser(), view_source_url);
88 97
89 TabContents* current_tab = browser()->GetSelectedTabContents(); 98 TabContents* current_tab = browser()->GetSelectedTabContents();
90 ASSERT_TRUE(current_tab); 99 ASSERT_TRUE(current_tab);
91 100
92 FilePath full_file_name = save_dir_.path().Append(file_name); 101 FilePath full_file_name = save_dir_.path().Append(file_name);
93 FilePath dir = save_dir_.path().AppendASCII("a_files"); 102 FilePath dir = save_dir_.path().AppendASCII("a_files");
94 103
95 ASSERT_TRUE(current_tab->SavePage(full_file_name, dir, 104 ASSERT_TRUE(current_tab->SavePage(full_file_name, dir,
96 SavePackage::SAVE_AS_ONLY_HTML)); 105 SavePackage::SAVE_AS_ONLY_HTML));
97 106
98 EXPECT_EQ(actual_page_url, WaitForSavePackageToFinish()); 107 EXPECT_EQ(actual_page_url, WaitForSavePackageToFinish());
99 108
100 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF)) 109 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF))
101 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 110 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
102 111
112 ValidateDownloadHistory(current_tab);
113
103 EXPECT_TRUE(file_util::PathExists(full_file_name)); 114 EXPECT_TRUE(file_util::PathExists(full_file_name));
104 EXPECT_FALSE(file_util::PathExists(dir)); 115 EXPECT_FALSE(file_util::PathExists(dir));
105 EXPECT_TRUE(file_util::ContentsEqual( 116 EXPECT_TRUE(file_util::ContentsEqual(
106 test_dir_.Append(FilePath(kTestDir)).Append(file_name), 117 test_dir_.Append(FilePath(kTestDir)).Append(file_name),
107 full_file_name)); 118 full_file_name));
108 } 119 }
109 120
110 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { 121 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) {
111 FilePath file_name(FILE_PATH_LITERAL("b.htm")); 122 FilePath file_name(FILE_PATH_LITERAL("b.htm"));
112 GURL url = URLRequestMockHTTPJob::GetMockUrl( 123 GURL url = URLRequestMockHTTPJob::GetMockUrl(
113 FilePath(kTestDir).Append(file_name)); 124 FilePath(kTestDir).Append(file_name));
114 ui_test_utils::NavigateToURL(browser(), url); 125 ui_test_utils::NavigateToURL(browser(), url);
115 126
116 TabContents* current_tab = browser()->GetSelectedTabContents(); 127 TabContents* current_tab = browser()->GetSelectedTabContents();
117 ASSERT_TRUE(current_tab); 128 ASSERT_TRUE(current_tab);
118 129
119 FilePath full_file_name = save_dir_.path().Append(file_name); 130 FilePath full_file_name = save_dir_.path().Append(file_name);
120 FilePath dir = save_dir_.path().AppendASCII("b_files"); 131 FilePath dir = save_dir_.path().AppendASCII("b_files");
121 ASSERT_TRUE(current_tab->SavePage(full_file_name, dir, 132 ASSERT_TRUE(current_tab->SavePage(full_file_name, dir,
122 SavePackage::SAVE_AS_COMPLETE_HTML)); 133 SavePackage::SAVE_AS_COMPLETE_HTML));
123 134
124 EXPECT_EQ(url, WaitForSavePackageToFinish()); 135 EXPECT_EQ(url, WaitForSavePackageToFinish());
125 136
126 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF)) 137 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF))
127 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 138 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
128 139
140 ValidateDownloadHistory(current_tab);
141
129 EXPECT_TRUE(file_util::PathExists(full_file_name)); 142 EXPECT_TRUE(file_util::PathExists(full_file_name));
130 EXPECT_TRUE(file_util::PathExists(dir)); 143 EXPECT_TRUE(file_util::PathExists(dir));
131 EXPECT_TRUE(file_util::TextContentsEqual( 144 EXPECT_TRUE(file_util::TextContentsEqual(
132 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"), 145 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"),
133 full_file_name)); 146 full_file_name));
134 EXPECT_TRUE(file_util::ContentsEqual( 147 EXPECT_TRUE(file_util::ContentsEqual(
135 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), 148 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"),
136 dir.AppendASCII("1.png"))); 149 dir.AppendASCII("1.png")));
137 EXPECT_TRUE(file_util::ContentsEqual( 150 EXPECT_TRUE(file_util::ContentsEqual(
138 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), 151 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"),
(...skipping 22 matching lines...) Expand all
161 ASSERT_TRUE(current_tab); 174 ASSERT_TRUE(current_tab);
162 175
163 ASSERT_TRUE(current_tab->SavePage(full_file_name, dir, 176 ASSERT_TRUE(current_tab->SavePage(full_file_name, dir,
164 SavePackage::SAVE_AS_COMPLETE_HTML)); 177 SavePackage::SAVE_AS_COMPLETE_HTML));
165 178
166 EXPECT_EQ(url, WaitForSavePackageToFinish()); 179 EXPECT_EQ(url, WaitForSavePackageToFinish());
167 180
168 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF)) 181 if (browser()->SupportsWindowFeature(Browser::FEATURE_DOWNLOADSHELF))
169 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); 182 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible());
170 183
184 ValidateDownloadHistory(current_tab);
185
171 EXPECT_TRUE(file_util::PathExists(full_file_name)); 186 EXPECT_TRUE(file_util::PathExists(full_file_name));
172 EXPECT_TRUE(file_util::PathExists(dir)); 187 EXPECT_TRUE(file_util::PathExists(dir));
173 EXPECT_TRUE(file_util::TextContentsEqual( 188 EXPECT_TRUE(file_util::TextContentsEqual(
174 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"), 189 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"),
175 full_file_name)); 190 full_file_name));
176 EXPECT_TRUE(file_util::ContentsEqual( 191 EXPECT_TRUE(file_util::ContentsEqual(
177 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), 192 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"),
178 dir.AppendASCII("1.png"))); 193 dir.AppendASCII("1.png")));
179 EXPECT_TRUE(file_util::ContentsEqual( 194 EXPECT_TRUE(file_util::ContentsEqual(
180 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), 195 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"),
181 dir.AppendASCII("1.css"))); 196 dir.AppendASCII("1.css")));
182 } 197 }
183 198
184 } // namespace
OLDNEW
« chrome/browser/download/download_manager.cc ('K') | « chrome/browser/download/save_package.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698