1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
|
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <sstream>
#include <string>
#include "build/build_config.h"
#if defined(OS_WIN)
#include <shlwapi.h>
#endif
#include "base/command_line.h"
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/platform_thread.h"
#include "base/string_util.h"
#include "base/test/test_file_util.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/download/download_util.h"
#include "chrome/browser/net/url_request_mock_http_job.h"
#include "chrome/browser/net/url_request_slow_download_job.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/ui/ui_test.h"
#include "chrome/test/automation/tab_proxy.h"
#include "chrome/test/automation/browser_proxy.h"
#include "net/base/net_util.h"
#include "net/url_request/url_request_unittest.h"
namespace {
const wchar_t kDocRoot[] = L"chrome/test/data";
class DownloadTest : public UITest {
protected:
DownloadTest() : UITest() {}
void CheckDownload(const FilePath& client_filename,
const FilePath& server_filename) {
// Find the path on the client.
FilePath file_on_client = download_prefix_.Append(client_filename);
// Find the path on the server.
FilePath file_on_server;
ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA,
&file_on_server));
file_on_server = file_on_server.Append(server_filename);
ASSERT_TRUE(file_util::PathExists(file_on_server));
WaitForGeneratedFileAndCheck(file_on_client, file_on_server,
true, true, false);
#if defined(OS_WIN)
// Check if the Zone Identifier is correctly set.
if (file_util::VolumeSupportsADS(file_on_client))
EXPECT_TRUE(file_util::HasInternetZoneIdentifier(file_on_client));
#endif
// Delete the client copy of the file.
EXPECT_TRUE(file_util::Delete(file_on_client, false));
}
void CheckDownload(const FilePath& file) {
CheckDownload(file, file);
}
void CleanupDownloadFiles(const FilePath& prefix) {
FilePath path_prefix(download_prefix_);
path_prefix = path_prefix.Append(prefix);
download_util::EraseUniqueDownloadFiles(path_prefix);
}
virtual void SetUp() {
UITest::SetUp();
download_prefix_ = GetDownloadDirectory();
}
protected:
void RunSizeTest(const GURL& url,
const std::wstring& expected_title_in_progress,
const std::wstring& expected_title_finished) {
FilePath filename;
net::FileURLToFilePath(url, &filename);
filename = filename.BaseName();
CleanupDownloadFiles(filename);
{
EXPECT_EQ(1, GetTabCount());
NavigateToURL(url);
// Downloads appear in the shelf
WaitUntilTabCount(1);
// TODO(tc): check download status text
// Complete sending the request. We do this by loading a second URL in a
// separate tab.
scoped_refptr<BrowserProxy> window(automation()->GetBrowserWindow(0));
ASSERT_TRUE(window.get());
EXPECT_TRUE(window->AppendTab(GURL(
URLRequestSlowDownloadJob::kFinishDownloadUrl)));
EXPECT_EQ(2, GetTabCount());
// TODO(tc): check download status text
// Make sure the download shelf is showing.
EXPECT_TRUE(WaitForDownloadShelfVisible(window.get()));
}
FilePath download_path = download_prefix_.Append(filename);
EXPECT_TRUE(file_util::PathExists(download_path));
// Delete the file we just downloaded.
EXPECT_TRUE(file_util::DieFileDie(download_path, true));
EXPECT_FALSE(file_util::PathExists(download_path));
}
FilePath download_prefix_;
};
// Download a file with non-viewable content, verify that the
// download tab opened and the file exists.
// All download tests are flaky on all platforms, http://crbug.com/35275,
// http://crbug.com/48913.
// Additionally, there is Windows-specific flake, http://crbug.com/20809.
TEST_F(DownloadTest, DISABLED_DownloadMimeType) {
FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
CleanupDownloadFiles(file);
EXPECT_EQ(1, GetTabCount());
NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(file));
// No new tabs created, downloads appear in the current tab's download shelf.
WaitUntilTabCount(1);
CheckDownload(file);
scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
ASSERT_TRUE(browser.get());
EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get()));
}
// Access a file with a viewable mime-type, verify that a download
// did not initiate.
// All download tests are flaky on all platforms, http://crbug.com/35275,
// http://crbug.com/48913.
// Additionally, there is Windows-specific flake, http://crbug.com/20809.
TEST_F(DownloadTest, FLAKY_NoDownload) {
FilePath file(FILE_PATH_LITERAL("download-test2.html"));
FilePath file_path = download_prefix_.Append(file);
CleanupDownloadFiles(file);
NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(file));
WaitUntilTabCount(1);
// Wait to see if the file will be downloaded.
PlatformThread::Sleep(sleep_timeout_ms());
EXPECT_FALSE(file_util::PathExists(file_path));
if (file_util::PathExists(file_path))
ASSERT_TRUE(file_util::Delete(file_path, false));
scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
ASSERT_TRUE(browser.get());
EXPECT_FALSE(WaitForDownloadShelfVisible(browser.get()));
}
// Download a 0-size file with a content-disposition header, verify that the
// download tab opened and the file exists as the filename specified in the
// header. This also ensures we properly handle empty file downloads.
// All download tests are flaky on all platforms, http://crbug.com/35275,
// http://crbug.com/48913.
// Additionally, there is Windows-specific flake, http://crbug.com/20809.
TEST_F(DownloadTest, DISABLED_ContentDisposition) {
FilePath file(FILE_PATH_LITERAL("download-test3.gif"));
FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif"));
CleanupDownloadFiles(file);
NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(file));
WaitUntilTabCount(1);
CheckDownload(download_file, file);
// Ensure the download shelf is visible on the window.
scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
ASSERT_TRUE(browser.get());
EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get()));
}
// Test that the download shelf is per-window by starting a download in one
// tab, opening a second tab, closing the shelf, going back to the first tab,
// and checking that the shelf is closed.
// See bug http://crbug.com/26325
// All download tests are flaky on all platforms, http://crbug.com/35275,
// http://crbug.com/48913.
// Additionally, there is Windows-specific flake, http://crbug.com/20809.
TEST_F(DownloadTest, DISABLED_PerWindowShelf) {
FilePath file(FILE_PATH_LITERAL("download-test3.gif"));
FilePath download_file(FILE_PATH_LITERAL("download-test3-attachment.gif"));
CleanupDownloadFiles(download_file);
NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(file));
WaitUntilTabCount(1);
CheckDownload(download_file, file);
// Ensure the download shelf is visible on the window.
scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
ASSERT_TRUE(browser.get());
EXPECT_TRUE(WaitForDownloadShelfVisible(browser.get()));
// Open a second tab
ASSERT_TRUE(browser->AppendTab(GURL()));
WaitUntilTabCount(2);
// Hide shelf
EXPECT_TRUE(browser->SetShelfVisible(false));
EXPECT_TRUE(WaitForDownloadShelfInvisible(browser.get()));
// Go to first tab
EXPECT_TRUE(browser->ActivateTab(0));
int tab_count;
EXPECT_TRUE(browser->GetTabCount(&tab_count));
ASSERT_EQ(2, tab_count);
bool shelf_visible;
EXPECT_TRUE(browser->IsShelfVisible(&shelf_visible));
ASSERT_FALSE(shelf_visible);
}
// UnknownSize and KnownSize are tests which depend on
// URLRequestSlowDownloadJob to serve content in a certain way. Data will be
// sent in two chunks where the first chunk is 35K and the second chunk is 10K.
// The test will first attempt to download a file; but the server will "pause"
// in the middle until the server receives a second request for
// "download-finish. At that time, the download will finish.
// All download tests are flaky on all platforms, http://crbug.com/35275,
// http://crbug.com/48913.
// Additionally, there is Windows-specific flake, http://crbug.com/20809.
TEST_F(DownloadTest, FLAKY_UnknownSize) {
GURL url(URLRequestSlowDownloadJob::kUnknownSizeUrl);
FilePath filename;
net::FileURLToFilePath(url, &filename);
filename = filename.BaseName();
RunSizeTest(url, L"32.0 KB - " + filename.ToWStringHack(),
L"100% - " + filename.ToWStringHack());
}
// All download tests are flaky on all platforms, http://crbug.com/35275,
// http://crbug.com/48913.
// Additionally, there is Windows-specific flake, http://crbug.com/20809.
TEST_F(DownloadTest, FLAKY_KnownSize) {
GURL url(URLRequestSlowDownloadJob::kKnownSizeUrl);
FilePath filename;
net::FileURLToFilePath(url, &filename);
filename = filename.BaseName();
RunSizeTest(url, L"71% - " + filename.ToWStringHack(),
L"100% - " + filename.ToWStringHack());
}
// Test that when downloading an item in Incognito mode, we don't crash when
// closing the last Incognito window (http://crbug.com/13983).
// All download tests are flaky on all platforms, http://crbug.com/35275,
// http://crbug.com/48913.
// Additionally, there is Windows-specific flake, http://crbug.com/20809.
TEST_F(DownloadTest, DISABLED_IncognitoDownload) {
// Open a regular window and sanity check default values for window / tab
// count and shelf visibility.
scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
ASSERT_TRUE(browser.get());
int window_count = 0;
ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count));
ASSERT_EQ(1, window_count);
EXPECT_EQ(1, GetTabCount());
bool is_shelf_visible;
EXPECT_TRUE(browser->IsShelfVisible(&is_shelf_visible));
EXPECT_FALSE(is_shelf_visible);
// Open an Incognito window.
ASSERT_TRUE(browser->RunCommand(IDC_NEW_INCOGNITO_WINDOW));
ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count));
ASSERT_EQ(2, window_count);
scoped_refptr<BrowserProxy> incognito(automation()->GetBrowserWindow(1));
ASSERT_TRUE(incognito.get());
// Wait for the new tab UI to load.
int load_time;
ASSERT_TRUE(automation()->WaitForInitialNewTabUILoad(&load_time));
// Download something.
FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
CleanupDownloadFiles(file);
scoped_refptr<TabProxy> tab(incognito->GetTab(0));
ASSERT_TRUE(tab.get());
ASSERT_TRUE(tab->NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(file)));
// Verify that the download shelf is showing for the Incognito window.
EXPECT_TRUE(WaitForDownloadShelfVisible(incognito.get()));
// Close the Incognito window and don't crash.
ASSERT_TRUE(incognito->RunCommand(IDC_CLOSE_WINDOW));
ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count));
ASSERT_EQ(1, window_count);
// Verify that the regular window does not have a download shelf.
EXPECT_TRUE(browser->IsShelfVisible(&is_shelf_visible));
EXPECT_FALSE(is_shelf_visible);
CheckDownload(file);
}
// All of the following tests are disabled, see http://crbug.com/43066
// All download tests are flaky on all platforms, http://crbug.com/35275,
// http://crbug.com/48913.
// Additionally, there is Windows-specific flake, http://crbug.com/20809.
TEST_F(DownloadTest, FLAKY_DontCloseNewTab1) {
scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
ASSERT_TRUE(browser.get());
int window_count = 0;
ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count));
ASSERT_EQ(1, window_count);
EXPECT_EQ(1, GetTabCount());
scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
ASSERT_TRUE(tab_proxy.get());
FilePath file1(FILE_PATH_LITERAL("download-test2.html"));
ASSERT_TRUE(tab_proxy->NavigateToURLAsyncWithDisposition(
URLRequestMockHTTPJob::GetMockUrl(file1),
NEW_BACKGROUND_TAB));
// We should have two tabs now.
WaitUntilTabCount(2);
}
// All download tests are flaky on all platforms, http://crbug.com/35275,
// http://crbug.com/48913.
// Additionally, there is Windows-specific flake, http://crbug.com/20809.
TEST_F(DownloadTest, FLAKY_CloseNewTab1) {
scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
ASSERT_TRUE(browser.get());
int window_count = 0;
ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count));
ASSERT_EQ(1, window_count);
EXPECT_EQ(1, GetTabCount());
scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
ASSERT_TRUE(tab_proxy.get());
FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
CleanupDownloadFiles(file);
ASSERT_TRUE(tab_proxy->NavigateToURLAsyncWithDisposition(
URLRequestMockHTTPJob::GetMockUrl(file),
NEW_BACKGROUND_TAB));
// When the download starts, we should still have one tab.
ASSERT_TRUE(WaitForDownloadShelfVisible(browser));
EXPECT_EQ(1, GetTabCount());
CheckDownload(file);
}
// Disabled, see http://crbug.com/43066
// All download tests are flaky on all platforms, http://crbug.com/35275,
// http://crbug.com/48913.
// Additionally, there is Windows-specific flake, http://crbug.com/20809.
TEST_F(DownloadTest, FLAKY_DontCloseNewTab2) {
scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
ASSERT_TRUE(browser.get());
int window_count = 0;
ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count));
ASSERT_EQ(1, window_count);
EXPECT_EQ(1, GetTabCount());
scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
ASSERT_TRUE(tab_proxy.get());
ASSERT_TRUE(tab_proxy->NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
FilePath(FILE_PATH_LITERAL("download_page1.html")))));
FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
CleanupDownloadFiles(file);
ASSERT_TRUE(tab_proxy->NavigateToURLAsync(GURL("javascript:openNew()")));
ASSERT_TRUE(WaitForDownloadShelfVisible(browser));
EXPECT_EQ(2, GetTabCount());
CheckDownload(file);
}
// Flaky, see http://crbug.com/43066
// All download tests are flaky on all platforms, http://crbug.com/35275,
// http://crbug.com/48913.
// Additionally, there is Windows-specific flake, http://crbug.com/20809.
TEST_F(DownloadTest, FLAKY_DontCloseNewTab3) {
scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
ASSERT_TRUE(browser.get());
int window_count = 0;
ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count));
ASSERT_EQ(1, window_count);
EXPECT_EQ(1, GetTabCount());
scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
ASSERT_TRUE(tab_proxy.get());
ASSERT_TRUE(tab_proxy->NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
FilePath(FILE_PATH_LITERAL("download_page2.html")))));
ASSERT_TRUE(tab_proxy->NavigateToURLAsync(GURL("javascript:openNew()")));
FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
CleanupDownloadFiles(file);
ASSERT_TRUE(tab_proxy->NavigateToURLAsync(
URLRequestMockHTTPJob::GetMockUrl(file)));
ASSERT_TRUE(WaitForDownloadShelfVisible(browser));
EXPECT_EQ(2, GetTabCount());
CheckDownload(file);
}
// Flaky, see http://crbug.com/43066
// All download tests are flaky on all platforms, http://crbug.com/35275,
// http://crbug.com/48913.
// Additionally, there is Windows-specific flake, http://crbug.com/20809.
TEST_F(DownloadTest, FLAKY_CloseNewTab2) {
scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
ASSERT_TRUE(browser.get());
int window_count = 0;
ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count));
ASSERT_EQ(1, window_count);
EXPECT_EQ(1, GetTabCount());
scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
ASSERT_TRUE(tab_proxy.get());
ASSERT_TRUE(tab_proxy->NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
FilePath(FILE_PATH_LITERAL("download_page3.html")))));
FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
CleanupDownloadFiles(file);
ASSERT_TRUE(tab_proxy->NavigateToURLAsync(GURL("javascript:openNew()")));
ASSERT_TRUE(WaitForDownloadShelfVisible(browser));
EXPECT_EQ(1, GetTabCount());
CheckDownload(file);
}
// Flaky, see http://crbug.com/43066
// All download tests are flaky on all platforms, http://crbug.com/35275,
// http://crbug.com/48913.
// Additionally, there is Windows-specific flake, http://crbug.com/20809.
TEST_F(DownloadTest, FLAKY_CloseNewTab3) {
scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
ASSERT_TRUE(browser.get());
int window_count = 0;
ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count));
ASSERT_EQ(1, window_count);
EXPECT_EQ(1, GetTabCount());
scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
ASSERT_TRUE(tab_proxy.get());
ASSERT_TRUE(tab_proxy->NavigateToURL(URLRequestMockHTTPJob::GetMockUrl(
FilePath(FILE_PATH_LITERAL("download_page4.html")))));
FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
CleanupDownloadFiles(file);
ASSERT_TRUE(tab_proxy->NavigateToURLAsync(
GURL("javascript:document.getElementById('form').submit()")));
ASSERT_TRUE(WaitForDownloadShelfVisible(browser));
EXPECT_EQ(1, GetTabCount());
CheckDownload(file);
}
// All download tests are flaky on all platforms, http://crbug.com/35275,
// http://crbug.com/48913.
// Additionally, there is Windows-specific flake, http://crbug.com/20809.
TEST_F(DownloadTest, DISABLED_DontCloseNewWindow) {
scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
ASSERT_TRUE(browser.get());
int window_count = 0;
ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count));
ASSERT_EQ(1, window_count);
EXPECT_EQ(1, GetTabCount());
scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
ASSERT_TRUE(tab_proxy.get());
FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
CleanupDownloadFiles(file);
ASSERT_TRUE(tab_proxy->NavigateToURLAsyncWithDisposition(
URLRequestMockHTTPJob::GetMockUrl(file), NEW_WINDOW));
ASSERT_TRUE(automation()->WaitForWindowCountToBecome(2));
CheckDownload(file);
}
// Regression test for http://crbug.com/44454
// All download tests are flaky on all platforms, http://crbug.com/35275,
// http://crbug.com/48913.
// Additionally, there is Windows-specific flake, http://crbug.com/20809.
TEST_F(DownloadTest, DISABLED_NewWindow) {
scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
ASSERT_TRUE(browser.get());
int window_count = 0;
ASSERT_TRUE(automation()->GetBrowserWindowCount(&window_count));
ASSERT_EQ(1, window_count);
EXPECT_EQ(1, GetTabCount());
scoped_refptr<TabProxy> tab_proxy(GetActiveTab());
ASSERT_TRUE(tab_proxy.get());
FilePath file(FILE_PATH_LITERAL("download-test1.lib"));
CleanupDownloadFiles(file);
ASSERT_TRUE(tab_proxy->NavigateToURLAsyncWithDisposition(
URLRequestMockHTTPJob::GetMockUrl(file), NEW_WINDOW));
ASSERT_TRUE(automation()->WaitForWindowCountToBecome(2));
CheckDownload(file);
}
} // namespace
|