| OLD | NEW |
| 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 <sstream> | 5 #include <sstream> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 #if defined(OS_WIN) | 9 #if defined(OS_WIN) |
| 10 #include <shlwapi.h> | 10 #include <shlwapi.h> |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 | 124 |
| 125 // Complete sending the request. We do this by loading a second URL in a | 125 // Complete sending the request. We do this by loading a second URL in a |
| 126 // separate tab. | 126 // separate tab. |
| 127 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); | 127 scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0)); |
| 128 EXPECT_TRUE(window->AppendTab(GURL( | 128 EXPECT_TRUE(window->AppendTab(GURL( |
| 129 URLRequestSlowDownloadJob::kFinishDownloadUrl))); | 129 URLRequestSlowDownloadJob::kFinishDownloadUrl))); |
| 130 EXPECT_EQ(2, GetTabCount()); | 130 EXPECT_EQ(2, GetTabCount()); |
| 131 // TODO(tc): check download status text | 131 // TODO(tc): check download status text |
| 132 | 132 |
| 133 // Make sure the download shelf is showing. | 133 // Make sure the download shelf is showing. |
| 134 scoped_refptr<TabProxy> dl_tab(window->GetTab(0)); | 134 EXPECT_TRUE(WaitForDownloadShelfVisible(window.get())); |
| 135 ASSERT_TRUE(dl_tab.get()); | |
| 136 EXPECT_TRUE(WaitForDownloadShelfVisible(dl_tab.get())); | |
| 137 } | 135 } |
| 138 | 136 |
| 139 FilePath filename; | 137 FilePath filename; |
| 140 net::FileURLToFilePath(url, &filename); | 138 net::FileURLToFilePath(url, &filename); |
| 141 filename = filename.BaseName(); | 139 filename = filename.BaseName(); |
| 142 FilePath download_path = download_prefix_.Append(filename); | 140 FilePath download_path = download_prefix_.Append(filename); |
| 143 EXPECT_TRUE(file_util::PathExists(download_path)); | 141 EXPECT_TRUE(file_util::PathExists(download_path)); |
| 144 | 142 |
| 145 // Delete the file we just downloaded. | 143 // Delete the file we just downloaded. |
| 146 for (int i = 0; i < 10; ++i) { | 144 for (int i = 0; i < 10; ++i) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 163 | 161 |
| 164 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(file.ToWStringHack())); | 162 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(file.ToWStringHack())); |
| 165 // No new tabs created, downloads appear in the current tab's download shelf. | 163 // No new tabs created, downloads appear in the current tab's download shelf. |
| 166 WaitUntilTabCount(1); | 164 WaitUntilTabCount(1); |
| 167 | 165 |
| 168 // Wait until the file is downloaded. | 166 // Wait until the file is downloaded. |
| 169 PlatformThread::Sleep(action_timeout_ms()); | 167 PlatformThread::Sleep(action_timeout_ms()); |
| 170 | 168 |
| 171 CleanUpDownload(file); | 169 CleanUpDownload(file); |
| 172 | 170 |
| 173 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); | 171 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
| 174 ASSERT_TRUE(tab_proxy.get()); | 172 ASSERT_TRUE(browser.get()); |
| 175 EXPECT_TRUE(WaitForDownloadShelfVisible(tab_proxy.get())); | 173 EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get())); |
| 176 } | 174 } |
| 177 | 175 |
| 178 // Access a file with a viewable mime-type, verify that a download | 176 // Access a file with a viewable mime-type, verify that a download |
| 179 // did not initiate. | 177 // did not initiate. |
| 180 TEST_F(DownloadTest, NoDownload) { | 178 TEST_F(DownloadTest, NoDownload) { |
| 181 FilePath file(FILE_PATH_LITERAL("download-test2.html")); | 179 FilePath file(FILE_PATH_LITERAL("download-test2.html")); |
| 182 FilePath file_path = download_prefix_.Append(file); | 180 FilePath file_path = download_prefix_.Append(file); |
| 183 | 181 |
| 184 if (file_util::PathExists(file_path)) | 182 if (file_util::PathExists(file_path)) |
| 185 ASSERT_TRUE(file_util::Delete(file_path, false)); | 183 ASSERT_TRUE(file_util::Delete(file_path, false)); |
| 186 | 184 |
| 187 EXPECT_EQ(1, GetTabCount()); | 185 EXPECT_EQ(1, GetTabCount()); |
| 188 | 186 |
| 189 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(file.ToWStringHack())); | 187 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(file.ToWStringHack())); |
| 190 WaitUntilTabCount(1); | 188 WaitUntilTabCount(1); |
| 191 | 189 |
| 192 // Wait to see if the file will be downloaded. | 190 // Wait to see if the file will be downloaded. |
| 193 PlatformThread::Sleep(action_timeout_ms()); | 191 PlatformThread::Sleep(action_timeout_ms()); |
| 194 | 192 |
| 195 EXPECT_FALSE(file_util::PathExists(file_path)); | 193 EXPECT_FALSE(file_util::PathExists(file_path)); |
| 196 if (file_util::PathExists(file_path)) | 194 if (file_util::PathExists(file_path)) |
| 197 ASSERT_TRUE(file_util::Delete(file_path, false)); | 195 ASSERT_TRUE(file_util::Delete(file_path, false)); |
| 198 | 196 |
| 199 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); | 197 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
| 200 ASSERT_TRUE(tab_proxy.get()); | 198 ASSERT_TRUE(browser.get()); |
| 201 EXPECT_FALSE(WaitForDownloadShelfVisible(tab_proxy.get())); | 199 EXPECT_FALSE(WaitForDownloadShelfVisible(browser.get())); |
| 202 } | 200 } |
| 203 | 201 |
| 204 // Download a 0-size file with a content-disposition header, verify that the | 202 // Download a 0-size file with a content-disposition header, verify that the |
| 205 // download tab opened and the file exists as the filename specified in the | 203 // download tab opened and the file exists as the filename specified in the |
| 206 // header. This also ensures we properly handle empty file downloads. | 204 // header. This also ensures we properly handle empty file downloads. |
| 207 TEST_F(DownloadTest, ContentDisposition) { | 205 TEST_F(DownloadTest, ContentDisposition) { |
| 208 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); | 206 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); |
| 209 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); | 207 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); |
| 210 | 208 |
| 211 EXPECT_EQ(1, GetTabCount()); | 209 EXPECT_EQ(1, GetTabCount()); |
| 212 | 210 |
| 213 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(file.ToWStringHack())); | 211 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(file.ToWStringHack())); |
| 214 WaitUntilTabCount(1); | 212 WaitUntilTabCount(1); |
| 215 | 213 |
| 216 // Wait until the file is downloaded. | 214 // Wait until the file is downloaded. |
| 217 PlatformThread::Sleep(action_timeout_ms()); | 215 PlatformThread::Sleep(action_timeout_ms()); |
| 218 | 216 |
| 219 CleanUpDownload(download_file, file); | 217 CleanUpDownload(download_file, file); |
| 220 | 218 |
| 221 // Ensure the download shelf is visible on the current tab. | 219 // Ensure the download shelf is visible on the window. |
| 222 scoped_refptr<TabProxy> tab_proxy(GetActiveTab()); | 220 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
| 223 ASSERT_TRUE(tab_proxy.get()); | 221 ASSERT_TRUE(browser.get()); |
| 224 EXPECT_TRUE(WaitForDownloadShelfVisible(tab_proxy.get())); | 222 EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get())); |
| 225 } | 223 } |
| 226 | 224 |
| 225 // Test that the download shelf is per-window by starting a download in one |
| 226 // tab, opening a second tab, closing the shelf, going back to the first tab, |
| 227 // and checking that the shelf is closed. |
| 228 TEST_F(DownloadTest, PerWindowShelf) { |
| 229 FilePath file(FILE_PATH_LITERAL("download-test3.gif")); |
| 230 FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif")); |
| 231 |
| 232 EXPECT_EQ(1, GetTabCount()); |
| 233 |
| 234 NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(file.ToWStringHack())); |
| 235 WaitUntilTabCount(1); |
| 236 |
| 237 // Wait until the file is downloaded. |
| 238 PlatformThread::Sleep(action_timeout_ms()); |
| 239 |
| 240 CleanUpDownload(download_file, file); |
| 241 |
| 242 // Ensure the download shelf is visible on the window. |
| 243 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
| 244 ASSERT_TRUE(browser.get()); |
| 245 EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get())); |
| 246 |
| 247 // Open a second tab |
| 248 browser->AppendTab(GURL("")); |
| 249 WaitUntilTabCount(2); |
| 250 |
| 251 // Hide shelf |
| 252 browser->SetShelfVisible(false); |
| 253 EXPECT_TRUE(WaitForDownloadShelfInvisible(browser.get())); |
| 254 |
| 255 // Go to first tab |
| 256 EXPECT_TRUE(browser->ActivateTab(0)); |
| 257 int tab_count; |
| 258 EXPECT_TRUE(browser->GetTabCount(&tab_count)); |
| 259 ASSERT_EQ(2, tab_count); |
| 260 |
| 261 bool shelf_visible; |
| 262 EXPECT_TRUE(browser->IsShelfVisible(&shelf_visible)); |
| 263 ASSERT_FALSE(shelf_visible); |
| 264 } |
| 265 |
| 266 |
| 227 // UnknownSize and KnownSize are tests which depend on | 267 // UnknownSize and KnownSize are tests which depend on |
| 228 // URLRequestSlowDownloadJob to serve content in a certain way. Data will be | 268 // URLRequestSlowDownloadJob to serve content in a certain way. Data will be |
| 229 // sent in two chunks where the first chunk is 35K and the second chunk is 10K. | 269 // sent in two chunks where the first chunk is 35K and the second chunk is 10K. |
| 230 // The test will first attempt to download a file; but the server will "pause" | 270 // The test will first attempt to download a file; but the server will "pause" |
| 231 // in the middle until the server receives a second request for | 271 // in the middle until the server receives a second request for |
| 232 // "download-finish. At that time, the download will finish. | 272 // "download-finish. At that time, the download will finish. |
| 233 TEST_F(DownloadTest, UnknownSize) { | 273 TEST_F(DownloadTest, UnknownSize) { |
| 234 GURL url(URLRequestSlowDownloadJob::kUnknownSizeUrl); | 274 GURL url(URLRequestSlowDownloadJob::kUnknownSizeUrl); |
| 235 FilePath filename; | 275 FilePath filename; |
| 236 net::FileURLToFilePath(url, &filename); | 276 net::FileURLToFilePath(url, &filename); |
| 237 filename = filename.BaseName(); | 277 filename = filename.BaseName(); |
| 238 RunSizeTest(url, L"32.0 KB - " + filename.ToWStringHack(), | 278 RunSizeTest(url, L"32.0 KB - " + filename.ToWStringHack(), |
| 239 L"100% - " + filename.ToWStringHack()); | 279 L"100% - " + filename.ToWStringHack()); |
| 240 } | 280 } |
| 241 | 281 |
| 242 // http://b/1158253 | 282 // http://b/1158253 |
| 243 TEST_F(DownloadTest, DISABLED_KnownSize) { | 283 TEST_F(DownloadTest, DISABLED_KnownSize) { |
| 244 GURL url(URLRequestSlowDownloadJob::kKnownSizeUrl); | 284 GURL url(URLRequestSlowDownloadJob::kKnownSizeUrl); |
| 245 FilePath filename; | 285 FilePath filename; |
| 246 net::FileURLToFilePath(url, &filename); | 286 net::FileURLToFilePath(url, &filename); |
| 247 filename = filename.BaseName(); | 287 filename = filename.BaseName(); |
| 248 RunSizeTest(url, L"71% - " + filename.ToWStringHack(), | 288 RunSizeTest(url, L"71% - " + filename.ToWStringHack(), |
| 249 L"100% - " + filename.ToWStringHack()); | 289 L"100% - " + filename.ToWStringHack()); |
| 250 } | 290 } |
| 251 | 291 |
| 252 } // namespace | 292 } // namespace |
| OLD | NEW |