OLD | NEW |
---|---|
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_item.h" | 11 #include "chrome/browser/download/download_item.h" |
12 #include "chrome/browser/download/download_manager.h" | |
13 #include "chrome/browser/history/download_history_info.h" | |
14 #include "chrome/browser/profiles/profile.h" | |
11 #include "chrome/browser/ui/browser.h" | 15 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
13 #include "chrome/browser/ui/download/download_tab_helper.h" | 17 #include "chrome/browser/ui/download/download_tab_helper.h" |
14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
15 #include "chrome/browser/ui/webui/active_downloads_ui.h" | 19 #include "chrome/browser/ui/webui/active_downloads_ui.h" |
16 #include "chrome/common/chrome_paths.h" | 20 #include "chrome/common/chrome_paths.h" |
17 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
18 #include "chrome/test/in_process_browser_test.h" | 22 #include "chrome/test/in_process_browser_test.h" |
19 #include "chrome/test/ui_test_utils.h" | 23 #include "chrome/test/ui_test_utils.h" |
20 #include "content/browser/net/url_request_mock_http_job.h" | 24 #include "content/browser/net/url_request_mock_http_job.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 found = true; | 70 found = true; |
67 break; | 71 break; |
68 } | 72 } |
69 } | 73 } |
70 EXPECT_TRUE(found); | 74 EXPECT_TRUE(found); |
71 #else | 75 #else |
72 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); | 76 EXPECT_TRUE(browser()->window()->IsDownloadShelfVisible()); |
73 #endif | 77 #endif |
74 } | 78 } |
75 | 79 |
80 void QueryDownloadHistory() { | |
81 DownloadManager* download_manager = | |
82 browser()->profile()->GetDownloadManager(); | |
83 ASSERT_TRUE(download_manager); | |
84 | |
85 // Query the history system. | |
86 download_manager->download_history()->Load( | |
87 NewCallback(this, | |
88 &SavePageBrowserTest::OnQueryDownloadEntriesComplete)); | |
89 | |
90 // Run message loop until a quit message is sent from | |
91 // OnQueryDownloadEntriesComplete(). | |
92 ui_test_utils::RunMessageLoop(); | |
93 } | |
94 | |
95 void OnQueryDownloadEntriesComplete( | |
96 std::vector<DownloadHistoryInfo>* entries) { | |
97 // Make a copy of the URLs returned by the history system. | |
98 history_urls_.clear(); | |
99 for (size_t i = 0; i < entries->size(); ++i) { | |
100 history_urls_.push_back(entries->at(i).url); | |
101 } | |
102 | |
103 // Indicate thet we have received the history and can continue. | |
104 MessageLoopForUI::current()->Quit(); | |
105 } | |
106 | |
107 void CheckDownloadHistory(const GURL& url) { | |
108 QueryDownloadHistory(); | |
109 | |
110 EXPECT_NE(std::find(history_urls_.begin(), history_urls_.end(), url), | |
111 history_urls_.end()); | |
Randy Smith (Not in Mondays)
2011/07/06 20:04:04
I'm inclined to think that we should have a lot mo
| |
112 } | |
113 | |
114 // URLs found in the history. | |
115 std::vector<GURL> history_urls_; | |
116 | |
76 // Path to directory containing test data. | 117 // Path to directory containing test data. |
77 FilePath test_dir_; | 118 FilePath test_dir_; |
78 | 119 |
79 // Temporary directory we will save pages to. | 120 // Temporary directory we will save pages to. |
80 ScopedTempDir save_dir_; | 121 ScopedTempDir save_dir_; |
81 }; | 122 }; |
82 | 123 |
83 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) { | 124 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveHTMLOnly) { |
84 FilePath file_name(FILE_PATH_LITERAL("a.htm")); | 125 FilePath file_name(FILE_PATH_LITERAL("a.htm")); |
85 GURL url = URLRequestMockHTTPJob::GetMockUrl( | 126 GURL url = URLRequestMockHTTPJob::GetMockUrl( |
86 FilePath(kTestDir).Append(file_name)); | 127 FilePath(kTestDir).Append(file_name)); |
87 ui_test_utils::NavigateToURL(browser(), url); | 128 ui_test_utils::NavigateToURL(browser(), url); |
88 | 129 |
89 TabContentsWrapper* current_tab = browser()->GetSelectedTabContentsWrapper(); | 130 TabContentsWrapper* current_tab = browser()->GetSelectedTabContentsWrapper(); |
90 ASSERT_TRUE(current_tab); | 131 ASSERT_TRUE(current_tab); |
91 | 132 |
92 FilePath full_file_name = save_dir_.path().Append(file_name); | 133 FilePath full_file_name = save_dir_.path().Append(file_name); |
93 FilePath dir = save_dir_.path().AppendASCII("a_files"); | 134 FilePath dir = save_dir_.path().AppendASCII("a_files"); |
94 ASSERT_TRUE(current_tab->download_tab_helper()->SavePage( | 135 ASSERT_TRUE(current_tab->download_tab_helper()->SavePage( |
95 full_file_name, dir, SavePackage::SAVE_AS_ONLY_HTML)); | 136 full_file_name, dir, SavePackage::SAVE_AS_ONLY_HTML)); |
96 | 137 |
97 EXPECT_EQ(url, WaitForSavePackageToFinish()); | 138 EXPECT_EQ(url, WaitForSavePackageToFinish()); |
98 | 139 |
99 CheckDownloadUI(full_file_name); | 140 CheckDownloadUI(full_file_name); |
141 CheckDownloadHistory(url); | |
100 | 142 |
101 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 143 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
102 EXPECT_FALSE(file_util::PathExists(dir)); | 144 EXPECT_FALSE(file_util::PathExists(dir)); |
103 EXPECT_TRUE(file_util::ContentsEqual( | 145 EXPECT_TRUE(file_util::ContentsEqual( |
104 test_dir_.Append(FilePath(kTestDir)).Append(file_name), | 146 test_dir_.Append(FilePath(kTestDir)).Append(file_name), |
105 full_file_name)); | 147 full_file_name)); |
106 } | 148 } |
107 | 149 |
108 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveViewSourceHTMLOnly) { | 150 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveViewSourceHTMLOnly) { |
109 FilePath file_name(FILE_PATH_LITERAL("a.htm")); | 151 FilePath file_name(FILE_PATH_LITERAL("a.htm")); |
110 GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl( | 152 GURL view_source_url = URLRequestMockHTTPJob::GetMockViewSourceUrl( |
111 FilePath(kTestDir).Append(file_name)); | 153 FilePath(kTestDir).Append(file_name)); |
112 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl( | 154 GURL actual_page_url = URLRequestMockHTTPJob::GetMockUrl( |
113 FilePath(kTestDir).Append(file_name)); | 155 FilePath(kTestDir).Append(file_name)); |
114 ui_test_utils::NavigateToURL(browser(), view_source_url); | 156 ui_test_utils::NavigateToURL(browser(), view_source_url); |
115 | 157 |
116 TabContentsWrapper* current_tab = browser()->GetSelectedTabContentsWrapper(); | 158 TabContentsWrapper* current_tab = browser()->GetSelectedTabContentsWrapper(); |
117 ASSERT_TRUE(current_tab); | 159 ASSERT_TRUE(current_tab); |
118 | 160 |
119 FilePath full_file_name = save_dir_.path().Append(file_name); | 161 FilePath full_file_name = save_dir_.path().Append(file_name); |
120 FilePath dir = save_dir_.path().AppendASCII("a_files"); | 162 FilePath dir = save_dir_.path().AppendASCII("a_files"); |
121 | 163 |
122 ASSERT_TRUE(current_tab->download_tab_helper()->SavePage( | 164 ASSERT_TRUE(current_tab->download_tab_helper()->SavePage( |
123 full_file_name, dir, SavePackage::SAVE_AS_ONLY_HTML)); | 165 full_file_name, dir, SavePackage::SAVE_AS_ONLY_HTML)); |
124 | 166 |
125 EXPECT_EQ(actual_page_url, WaitForSavePackageToFinish()); | 167 EXPECT_EQ(actual_page_url, WaitForSavePackageToFinish()); |
126 | 168 |
127 CheckDownloadUI(full_file_name); | 169 CheckDownloadUI(full_file_name); |
170 CheckDownloadHistory(actual_page_url); | |
128 | 171 |
129 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 172 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
130 EXPECT_FALSE(file_util::PathExists(dir)); | 173 EXPECT_FALSE(file_util::PathExists(dir)); |
131 EXPECT_TRUE(file_util::ContentsEqual( | 174 EXPECT_TRUE(file_util::ContentsEqual( |
132 test_dir_.Append(FilePath(kTestDir)).Append(file_name), | 175 test_dir_.Append(FilePath(kTestDir)).Append(file_name), |
133 full_file_name)); | 176 full_file_name)); |
134 } | 177 } |
135 | 178 |
136 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { | 179 IN_PROC_BROWSER_TEST_F(SavePageBrowserTest, SaveCompleteHTML) { |
137 FilePath file_name(FILE_PATH_LITERAL("b.htm")); | 180 FilePath file_name(FILE_PATH_LITERAL("b.htm")); |
138 GURL url = URLRequestMockHTTPJob::GetMockUrl( | 181 GURL url = URLRequestMockHTTPJob::GetMockUrl( |
139 FilePath(kTestDir).Append(file_name)); | 182 FilePath(kTestDir).Append(file_name)); |
140 ui_test_utils::NavigateToURL(browser(), url); | 183 ui_test_utils::NavigateToURL(browser(), url); |
141 | 184 |
142 TabContentsWrapper* current_tab = browser()->GetSelectedTabContentsWrapper(); | 185 TabContentsWrapper* current_tab = browser()->GetSelectedTabContentsWrapper(); |
143 ASSERT_TRUE(current_tab); | 186 ASSERT_TRUE(current_tab); |
144 | 187 |
145 FilePath full_file_name = save_dir_.path().Append(file_name); | 188 FilePath full_file_name = save_dir_.path().Append(file_name); |
146 FilePath dir = save_dir_.path().AppendASCII("b_files"); | 189 FilePath dir = save_dir_.path().AppendASCII("b_files"); |
147 ASSERT_TRUE(current_tab->download_tab_helper()->SavePage( | 190 ASSERT_TRUE(current_tab->download_tab_helper()->SavePage( |
148 full_file_name, dir, SavePackage::SAVE_AS_COMPLETE_HTML)); | 191 full_file_name, dir, SavePackage::SAVE_AS_COMPLETE_HTML)); |
149 | 192 |
150 EXPECT_EQ(url, WaitForSavePackageToFinish()); | 193 EXPECT_EQ(url, WaitForSavePackageToFinish()); |
151 | 194 |
152 CheckDownloadUI(full_file_name); | 195 CheckDownloadUI(full_file_name); |
196 CheckDownloadHistory(url); | |
153 | 197 |
154 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 198 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
155 EXPECT_TRUE(file_util::PathExists(dir)); | 199 EXPECT_TRUE(file_util::PathExists(dir)); |
156 EXPECT_TRUE(file_util::TextContentsEqual( | 200 EXPECT_TRUE(file_util::TextContentsEqual( |
157 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"), | 201 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved1.htm"), |
158 full_file_name)); | 202 full_file_name)); |
159 EXPECT_TRUE(file_util::ContentsEqual( | 203 EXPECT_TRUE(file_util::ContentsEqual( |
160 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), | 204 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), |
161 dir.AppendASCII("1.png"))); | 205 dir.AppendASCII("1.png"))); |
162 EXPECT_TRUE(file_util::ContentsEqual( | 206 EXPECT_TRUE(file_util::ContentsEqual( |
(...skipping 21 matching lines...) Expand all Loading... | |
184 | 228 |
185 TabContentsWrapper* current_tab = browser()->GetSelectedTabContentsWrapper(); | 229 TabContentsWrapper* current_tab = browser()->GetSelectedTabContentsWrapper(); |
186 ASSERT_TRUE(current_tab); | 230 ASSERT_TRUE(current_tab); |
187 | 231 |
188 ASSERT_TRUE(current_tab->download_tab_helper()->SavePage( | 232 ASSERT_TRUE(current_tab->download_tab_helper()->SavePage( |
189 full_file_name, dir, SavePackage::SAVE_AS_COMPLETE_HTML)); | 233 full_file_name, dir, SavePackage::SAVE_AS_COMPLETE_HTML)); |
190 | 234 |
191 EXPECT_EQ(url, WaitForSavePackageToFinish()); | 235 EXPECT_EQ(url, WaitForSavePackageToFinish()); |
192 | 236 |
193 CheckDownloadUI(full_file_name); | 237 CheckDownloadUI(full_file_name); |
238 CheckDownloadHistory(url); | |
194 | 239 |
195 EXPECT_TRUE(file_util::PathExists(full_file_name)); | 240 EXPECT_TRUE(file_util::PathExists(full_file_name)); |
196 EXPECT_TRUE(file_util::PathExists(dir)); | 241 EXPECT_TRUE(file_util::PathExists(dir)); |
197 EXPECT_TRUE(file_util::TextContentsEqual( | 242 EXPECT_TRUE(file_util::TextContentsEqual( |
198 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"), | 243 test_dir_.Append(FilePath(kTestDir)).AppendASCII("b.saved2.htm"), |
199 full_file_name)); | 244 full_file_name)); |
200 EXPECT_TRUE(file_util::ContentsEqual( | 245 EXPECT_TRUE(file_util::ContentsEqual( |
201 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), | 246 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.png"), |
202 dir.AppendASCII("1.png"))); | 247 dir.AppendASCII("1.png"))); |
203 EXPECT_TRUE(file_util::ContentsEqual( | 248 EXPECT_TRUE(file_util::ContentsEqual( |
204 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), | 249 test_dir_.Append(FilePath(kTestDir)).AppendASCII("1.css"), |
205 dir.AppendASCII("1.css"))); | 250 dir.AppendASCII("1.css"))); |
206 } | 251 } |
207 | 252 |
208 } // namespace | 253 } // namespace |
OLD | NEW |