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

Side by Side Diff: content/browser/download/download_browsertest.cc

Issue 10913015: Reland DownloadManager::GetAllDownloads actually does now (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 3 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // This file contains download browser tests that are known to be runnable 5 // This file contains download browser tests that are known to be runnable
6 // in a pure content context. Over time tests should be migrated here. 6 // in a pure content context. Over time tests should be migrated here.
7 7
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/scoped_temp_dir.h" 10 #include "base/scoped_temp_dir.h"
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 // DownloadItem, and wait for the state that indicates the item has been 143 // DownloadItem, and wait for the state that indicates the item has been
144 // entered in the history and made visible in the UI. 144 // entered in the history and made visible in the UI.
145 145
146 // Create a download, wait until it's started, and confirm 146 // Create a download, wait until it's started, and confirm
147 // we're in the expected state. 147 // we're in the expected state.
148 scoped_ptr<DownloadTestObserver> observer(CreateInProgressWaiter(shell(), 1)); 148 scoped_ptr<DownloadTestObserver> observer(CreateInProgressWaiter(shell(), 1));
149 NavigateToURL(shell(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); 149 NavigateToURL(shell(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl));
150 observer->WaitForFinished(); 150 observer->WaitForFinished();
151 151
152 std::vector<DownloadItem*> downloads; 152 std::vector<DownloadItem*> downloads;
153 DownloadManagerForShell(shell())->SearchDownloads(string16(), &downloads); 153 DownloadManagerForShell(shell())->GetAllDownloads(&downloads);
154 ASSERT_EQ(1u, downloads.size()); 154 ASSERT_EQ(1u, downloads.size());
155 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState()); 155 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState());
156 156
157 // Cancel the download and wait for download system quiesce. 157 // Cancel the download and wait for download system quiesce.
158 downloads[0]->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD); 158 downloads[0]->Delete(DownloadItem::DELETE_DUE_TO_USER_DISCARD);
159 scoped_refptr<DownloadTestFlushObserver> flush_observer( 159 scoped_refptr<DownloadTestFlushObserver> flush_observer(
160 new DownloadTestFlushObserver(DownloadManagerForShell(shell()))); 160 new DownloadTestFlushObserver(DownloadManagerForShell(shell())));
161 flush_observer->WaitForFlush(); 161 flush_observer->WaitForFlush();
162 162
163 // Get the important info from other threads and check it. 163 // Get the important info from other threads and check it.
164 EXPECT_TRUE(EnsureNoPendingDownloads()); 164 EXPECT_TRUE(EnsureNoPendingDownloads());
165 } 165 }
166 166
167 // Check that downloading multiple (in this case, 2) files does not result in 167 // Check that downloading multiple (in this case, 2) files does not result in
168 // corrupted files. 168 // corrupted files.
169 IN_PROC_BROWSER_TEST_F(DownloadContentTest, MultiDownload) { 169 IN_PROC_BROWSER_TEST_F(DownloadContentTest, MultiDownload) {
170 // Create a download, wait until it's started, and confirm 170 // Create a download, wait until it's started, and confirm
171 // we're in the expected state. 171 // we're in the expected state.
172 scoped_ptr<DownloadTestObserver> observer1( 172 scoped_ptr<DownloadTestObserver> observer1(
173 CreateInProgressWaiter(shell(), 1)); 173 CreateInProgressWaiter(shell(), 1));
174 NavigateToURL(shell(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl)); 174 NavigateToURL(shell(), GURL(URLRequestSlowDownloadJob::kUnknownSizeUrl));
175 observer1->WaitForFinished(); 175 observer1->WaitForFinished();
176 176
177 std::vector<DownloadItem*> downloads; 177 std::vector<DownloadItem*> downloads;
178 DownloadManagerForShell(shell())->SearchDownloads(string16(), &downloads); 178 DownloadManagerForShell(shell())->GetAllDownloads(&downloads);
179 ASSERT_EQ(1u, downloads.size()); 179 ASSERT_EQ(1u, downloads.size());
180 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState()); 180 ASSERT_EQ(DownloadItem::IN_PROGRESS, downloads[0]->GetState());
181 DownloadItem* download1 = downloads[0]; // The only download. 181 DownloadItem* download1 = downloads[0]; // The only download.
182 182
183 // Start the second download and wait until it's done. 183 // Start the second download and wait until it's done.
184 FilePath file(FILE_PATH_LITERAL("download-test.lib")); 184 FilePath file(FILE_PATH_LITERAL("download-test.lib"));
185 GURL url(URLRequestMockHTTPJob::GetMockUrl(file)); 185 GURL url(URLRequestMockHTTPJob::GetMockUrl(file));
186 // Download the file and wait. 186 // Download the file and wait.
187 DownloadAndWait(shell(), url); 187 DownloadAndWait(shell(), url);
188 188
189 // Should now have 2 items on the manager. 189 // Should now have 2 items on the manager.
190 downloads.clear(); 190 downloads.clear();
191 DownloadManagerForShell(shell())->SearchDownloads(string16(), &downloads); 191 DownloadManagerForShell(shell())->GetAllDownloads(&downloads);
192 ASSERT_EQ(2u, downloads.size()); 192 ASSERT_EQ(2u, downloads.size());
193 // We don't know the order of the downloads. 193 // We don't know the order of the downloads.
194 DownloadItem* download2 = downloads[(download1 == downloads[0]) ? 1 : 0]; 194 DownloadItem* download2 = downloads[(download1 == downloads[0]) ? 1 : 0];
195 195
196 ASSERT_EQ(DownloadItem::IN_PROGRESS, download1->GetState()); 196 ASSERT_EQ(DownloadItem::IN_PROGRESS, download1->GetState());
197 ASSERT_EQ(DownloadItem::COMPLETE, download2->GetState()); 197 ASSERT_EQ(DownloadItem::COMPLETE, download2->GetState());
198 198
199 // Allow the first request to finish. 199 // Allow the first request to finish.
200 scoped_ptr<DownloadTestObserver> observer2(CreateWaiter(shell(), 1)); 200 scoped_ptr<DownloadTestObserver> observer2(CreateWaiter(shell(), 1));
201 NavigateToURL(shell(), GURL(URLRequestSlowDownloadJob::kFinishDownloadUrl)); 201 NavigateToURL(shell(), GURL(URLRequestSlowDownloadJob::kFinishDownloadUrl));
(...skipping 12 matching lines...) Expand all
214 URLRequestSlowDownloadJob::kSecondDownloadSize; 214 URLRequestSlowDownloadJob::kSecondDownloadSize;
215 std::string expected_contents(file_size1, '*'); 215 std::string expected_contents(file_size1, '*');
216 ASSERT_TRUE(VerifyFile(file1, expected_contents, file_size1)); 216 ASSERT_TRUE(VerifyFile(file1, expected_contents, file_size1));
217 217
218 FilePath file2(download2->GetFullPath()); 218 FilePath file2(download2->GetFullPath());
219 ASSERT_TRUE(file_util::ContentsEqual( 219 ASSERT_TRUE(file_util::ContentsEqual(
220 file2, GetTestFilePath("download", "download-test.lib"))); 220 file2, GetTestFilePath("download", "download-test.lib")));
221 } 221 }
222 222
223 } // namespace content 223 } // namespace content
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/downloads/downloads_api_unittest.cc ('k') | content/browser/download/download_manager_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698