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

Side by Side Diff: chrome/browser/download/download_extension_apitest.cc

Issue 9110042: Re-enable DownloadsApiTest.Downloads (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 11 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) 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 "chrome/browser/download/download_service.h"
6 #include "chrome/browser/download/download_service_factory.h"
5 #include "chrome/browser/extensions/extension_apitest.h" 7 #include "chrome/browser/extensions/extension_apitest.h"
6 #include "chrome/browser/prefs/pref_service.h" 8 #include "chrome/browser/prefs/pref_service.h"
7 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/ui/browser.h" 10 #include "chrome/browser/ui/browser.h"
9 #include "chrome/common/chrome_switches.h" 11 #include "chrome/common/chrome_switches.h"
10 #include "chrome/common/pref_names.h" 12 #include "chrome/common/pref_names.h"
13 #include "content/public/browser/download_manager.h"
11 14
12 class DownloadsApiTest : public ExtensionApiTest { 15 class DownloadsApiTest : public ExtensionApiTest {
13 public: 16 public:
14 void SetUpCommandLine(CommandLine* command_line) OVERRIDE { 17 void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
15 ExtensionApiTest::SetUpCommandLine(command_line); 18 ExtensionApiTest::SetUpCommandLine(command_line);
16 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); 19 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
17 } 20 }
18 21
19 void SetUpTempDownloadsDir() { 22 void SetUpTempDownloadsDir() {
20 ASSERT_TRUE(tmpdir.CreateUniqueTempDir()); 23 ASSERT_TRUE(tmpdir.CreateUniqueTempDir());
21 browser()->profile()->GetPrefs()->SetFilePath( 24 browser()->profile()->GetPrefs()->SetFilePath(
22 prefs::kDownloadDefaultDirectory, tmpdir.path()); 25 prefs::kDownloadDefaultDirectory, tmpdir.path());
23 } 26 }
24 27
28 void CleanUpDownloads() {
29 // Clean up any remaining downloads so the browser can quit without
30 // prompting about in-progress downloads. Ideally this would be done in the
31 // extension itself, but currently we don't expose enough through the
32 // extension API to make this possible.
33 DownloadService* download_service = DownloadServiceFactory::GetForProfile(
34 browser()->profile());
35 ASSERT_TRUE(download_service != NULL);
36 if (!download_service->HasCreatedDownloadManager())
37 return;
38 content::DownloadManager* download_manager =
39 download_service->GetDownloadManager();
40 ASSERT_TRUE(download_manager != NULL);
41 if (download_manager->InProgressCount() == 0)
42 return;
43 typedef content::DownloadManager::DownloadVector DownloadVector;
44 DownloadVector all_downloads;
45 download_manager->GetAllDownloads(FilePath(), &all_downloads);
asanka 2012/01/09 17:22:17 There's a race here where the download item might
Randy Smith (Not in Mondays) 2012/01/09 19:05:45 Chris: Can you get ahold of the list of downloads
cbentzel 2012/01/09 19:16:41 Thanks for the explanation of when this could happ
cbentzel 2012/01/09 19:16:41 It doesn't look there is a way to get to this from
Randy Smith (Not in Mondays) 2012/01/09 19:20:32 Oh, goodness, please don't do that; an interface o
46 for (DownloadVector::const_iterator it = all_downloads.begin();
47 it != all_downloads.end();
48 ++it) {
49 content::DownloadItem* download_item = *it;
50 download_manager->CancelDownload(download_item->GetId());
51 }
52 }
53
25 private: 54 private:
26 ScopedTempDir tmpdir; 55 ScopedTempDir tmpdir;
27 }; 56 };
28 57
29 IN_PROC_BROWSER_TEST_F(DownloadsApiTest, DISABLED_Downloads) { 58 IN_PROC_BROWSER_TEST_F(DownloadsApiTest, Downloads) {
30 SetUpTempDownloadsDir(); 59 SetUpTempDownloadsDir();
31 ASSERT_TRUE(StartTestServer()); 60 ASSERT_TRUE(StartTestServer());
32 ASSERT_TRUE(RunExtensionTest("downloads")) << message_; 61 ASSERT_TRUE(RunExtensionTest("downloads")) << message_;
62 CleanUpDownloads();
33 } 63 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698