OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 /** @const */ var TOTAL_RESULT_COUNT = 25; | 5 /** @const */ var TOTAL_RESULT_COUNT = 25; |
6 | 6 |
7 /** | 7 /** |
8 * Test C++ fixture for downloads WebUI testing. | 8 * Test C++ fixture for downloads WebUI testing. |
9 * @constructor | 9 * @constructor |
10 * @extends {testing.Test} | 10 * @extends {testing.Test} |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 /** | 43 /** |
44 * Sends TOTAL_RESULT_COUNT fake downloads to the page. This can't be called | 44 * Sends TOTAL_RESULT_COUNT fake downloads to the page. This can't be called |
45 * in the preLoad, because it requires the global Download object to have | 45 * in the preLoad, because it requires the global Download object to have |
46 * been created by the page. | 46 * been created by the page. |
47 * @override | 47 * @override |
48 */ | 48 */ |
49 setUp: function() { | 49 setUp: function() { |
50 // The entries will begin at 1:00 AM on Sept 2, 2008, and will be spaced | 50 // The entries will begin at 1:00 AM on Sept 2, 2008, and will be spaced |
51 // two minutes apart. | 51 // two minutes apart. |
52 var timestamp = new Date(2008, 9, 2, 1, 0).getTime(); | 52 var timestamp = new Date(2008, 9, 2, 1, 0).getTime(); |
| 53 var list = []; |
53 for (var i = 0; i < TOTAL_RESULT_COUNT; ++i) { | 54 for (var i = 0; i < TOTAL_RESULT_COUNT; ++i) { |
54 downloads.updated(this.createDownload_(i, timestamp)); | 55 list.push(this.createDownload_(i, timestamp)); |
55 timestamp += 2 * 60 * 1000; // Next visit is two minutes later. | 56 timestamp += 2 * 60 * 1000; // Next visit is two minutes later. |
56 } | 57 } |
57 expectEquals(downloads.size(), TOTAL_RESULT_COUNT); | 58 downloads.Manager.updateAll(list); |
| 59 expectEquals(downloads.Manager.size(), TOTAL_RESULT_COUNT); |
58 }, | 60 }, |
59 | 61 |
60 /** | 62 /** |
61 * Creates a download object to be passed to the page, following the expected | 63 * Creates a download object to be passed to the page, following the expected |
62 * backend format (see downloads_dom_handler.cc). | 64 * backend format (see downloads_dom_handler.cc). |
63 * @param {number} A unique ID for the download. | 65 * @param {number} A unique ID for the download. |
64 * @param {number} The time the download purportedly started. | 66 * @param {number} The time the download purportedly started. |
65 * @return {!Object} A fake download object. | 67 * @return {!Object} A fake download object. |
66 * @private | 68 * @private |
67 */ | 69 */ |
68 createDownload_: function(id, timestamp) { | 70 createDownload_: function(id, timestamp) { |
69 return { | 71 return { |
70 id: id, | 72 id: id, |
71 started: timestamp, | 73 started: timestamp, |
72 otr: false, | 74 otr: false, |
73 state: Download.States.COMPLETE, | 75 state: downloads.Item.States.COMPLETE, |
74 retry: false, | 76 retry: false, |
75 file_path: '/path/to/file', | 77 file_path: '/path/to/file', |
76 file_url: 'http://google.com/' + timestamp, | 78 file_url: 'http://google.com/' + timestamp, |
77 file_name: 'download_' + timestamp, | 79 file_name: 'download_' + timestamp, |
78 url: 'http://google.com/' + timestamp, | 80 url: 'http://google.com/' + timestamp, |
79 file_externally_removed: false, | 81 file_externally_removed: false, |
80 danger_type: Download.DangerType.NOT_DANGEROUS, | 82 danger_type: downloads.Item.DangerType.NOT_DANGEROUS, |
81 last_reason_text: '', | 83 last_reason_text: '', |
82 since_string: 'today', | 84 since_string: 'today', |
83 date_string: 'today', | 85 date_string: 'today', |
84 percent: 100, | 86 percent: 100, |
85 progress_status_text: 'done', | 87 progress_status_text: 'done', |
86 received: 128, | 88 received: 128, |
87 }; | 89 }; |
88 }, | 90 }, |
89 | 91 |
90 /** | 92 /** |
91 * Simulates getting no results from C++. | 93 * Simulates getting no results from C++. |
92 */ | 94 */ |
93 sendEmptyList: function() { | 95 sendEmptyList: function() { |
94 downloadsList([]); | 96 downloads.Manager.updateAll([]); |
95 assertEquals(0, downloads.size()); | 97 assertEquals(0, downloads.Manager.size()); |
96 }, | 98 }, |
97 | 99 |
98 /** | 100 /** |
99 * Check that |element| is showing and contains |text|. | 101 * Check that |element| is showing and contains |text|. |
100 * @param {Element} element | 102 * @param {Element} element |
101 * @param {string} text | 103 * @param {string} text |
102 */ | 104 */ |
103 checkShowing: function(element, text) { | 105 checkShowing: function(element, text) { |
104 expectFalse(element.hidden); | 106 expectFalse(element.hidden); |
105 expectNotEquals(-1, element.textContent.indexOf(text)); | 107 expectNotEquals(-1, element.textContent.indexOf(text)); |
106 }, | 108 }, |
107 | 109 |
108 /** | 110 /** |
109 * Asserts the correctness of the state of the UI elements that delete the | 111 * Asserts the correctness of the state of the UI elements that delete the |
110 * download history. | 112 * download history. |
111 * @param {boolean} visible True if download deletion UI should be visible. | 113 * @param {boolean} visible True if download deletion UI should be visible. |
112 */ | 114 */ |
113 expectDeleteControlsVisible: function(visible) { | 115 expectDeleteControlsVisible: function(visible) { |
114 // "Clear all" should only be showing when deletions are allowed. | 116 // "Clear all" should only be showing when deletions are allowed. |
115 expectEquals(!visible, $('clear-all').hidden); | 117 expectEquals(!visible, $('clear-all').hidden); |
116 | 118 |
117 // "Remove from list" links should only exist when deletions are allowed. | 119 // "Remove from list" links should only exist when deletions are allowed. |
118 expectEquals(visible ? TOTAL_RESULT_COUNT : 0, | 120 var query = '#downloads-display .safe .remove'; |
119 document.querySelectorAll('.control-remove-link').length); | 121 if (!visible) |
| 122 query += '[hidden]'; |
| 123 expectEquals(TOTAL_RESULT_COUNT, document.querySelectorAll(query).length); |
120 }, | 124 }, |
121 }; | 125 }; |
OLD | NEW |