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

Side by Side Diff: chrome/browser/android/download/download_manager_service_unittest.cc

Issue 1809203006: Switch to use download GUID to indentify download items (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix merge error Created 4 years, 9 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/android/download/download_manager_service.h" 5 #include "chrome/browser/android/download/download_manager_service.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_string.h" 8 #include "base/android/jni_string.h"
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 18 matching lines...) Expand all
29 29
30 class DownloadManagerServiceTest : public testing::Test { 30 class DownloadManagerServiceTest : public testing::Test {
31 public: 31 public:
32 DownloadManagerServiceTest() 32 DownloadManagerServiceTest()
33 : service_( 33 : service_(
34 new DownloadManagerService(base::android::AttachCurrentThread(), 34 new DownloadManagerService(base::android::AttachCurrentThread(),
35 nullptr, 35 nullptr,
36 &manager_)), 36 &manager_)),
37 finished_(false), 37 finished_(false),
38 success_(false) { 38 success_(false) {
39 ON_CALL(manager_, GetDownload(_)) 39 ON_CALL(manager_, GetDownloadByGuid(_))
40 .WillByDefault( 40 .WillByDefault(
41 ::testing::Invoke(this, &DownloadManagerServiceTest::GetDownload)); 41 ::testing::Invoke(this,
42 &DownloadManagerServiceTest::GetDownloadByGuid));
42 } 43 }
43 44
44 void OnResumptionDone(bool success) { 45 void OnResumptionDone(bool success) {
45 finished_ = true; 46 finished_ = true;
46 success_ = success; 47 success_ = success;
47 } 48 }
48 49
49 void StartDownload(int download_id) { 50 void StartDownload(const std::string& download_guid) {
50 JNIEnv* env = base::android::AttachCurrentThread(); 51 JNIEnv* env = base::android::AttachCurrentThread();
51 service_->set_resume_callback_for_testing(base::Bind( 52 service_->set_resume_callback_for_testing(base::Bind(
52 &DownloadManagerServiceTest::OnResumptionDone, base::Unretained(this))); 53 &DownloadManagerServiceTest::OnResumptionDone, base::Unretained(this)));
53 service_->ResumeDownload( 54 service_->ResumeDownload(
54 env, nullptr, download_id, 55 env, nullptr, 0, JavaParamRef<jstring>(
56 env, base::android::ConvertUTF8ToJavaString(
57 env, download_guid).obj()),
55 base::android::ConvertUTF8ToJavaString(env, "test").obj()); 58 base::android::ConvertUTF8ToJavaString(env, "test").obj());
56 while (!finished_) 59 while (!finished_)
57 message_loop_.RunUntilIdle(); 60 message_loop_.RunUntilIdle();
58 } 61 }
59 62
60 void CreateDownloadItem(bool can_resume) { 63 void CreateDownloadItem(bool can_resume) {
61 download_.reset(new content::MockDownloadItem()); 64 download_.reset(new content::MockDownloadItem());
62 ON_CALL(*download_, CanResume()) 65 ON_CALL(*download_, CanResume())
63 .WillByDefault(::testing::Return(can_resume)); 66 .WillByDefault(::testing::Return(can_resume));
64 } 67 }
65 68
66 protected: 69 protected:
67 content::DownloadItem* GetDownload(uint32_t) { return download_.get(); } 70 content::DownloadItem* GetDownloadByGuid(const std::string&) {
71 return download_.get();
72 }
68 73
69 base::MessageLoop message_loop_; 74 base::MessageLoop message_loop_;
70 scoped_ptr<content::MockDownloadItem> download_; 75 scoped_ptr<content::MockDownloadItem> download_;
71 content::MockDownloadManager manager_; 76 content::MockDownloadManager manager_;
72 DownloadManagerService* service_; 77 DownloadManagerService* service_;
73 bool finished_; 78 bool finished_;
74 bool success_; 79 bool success_;
75 80
76 DISALLOW_COPY_AND_ASSIGN(DownloadManagerServiceTest); 81 DISALLOW_COPY_AND_ASSIGN(DownloadManagerServiceTest);
77 }; 82 };
78 83
79 // Test that resumption will fail if no download item is found before times out. 84 // Test that resumption will fail if no download item is found before times out.
80 TEST_F(DownloadManagerServiceTest, ResumptionTimeOut) { 85 TEST_F(DownloadManagerServiceTest, ResumptionTimeOut) {
81 StartDownload(1); 86 StartDownload("0000");
82 EXPECT_FALSE(success_); 87 EXPECT_FALSE(success_);
83 } 88 }
84 89
85 // Test that resumption succeeds if the download item is found and can be 90 // Test that resumption succeeds if the download item is found and can be
86 // resumed. 91 // resumed.
87 TEST_F(DownloadManagerServiceTest, ResumptionWithResumableItem) { 92 TEST_F(DownloadManagerServiceTest, ResumptionWithResumableItem) {
88 CreateDownloadItem(true); 93 CreateDownloadItem(true);
89 StartDownload(1); 94 StartDownload("0000");
90 EXPECT_TRUE(success_); 95 EXPECT_TRUE(success_);
91 } 96 }
92 97
93 // Test that resumption fails if the target download item is not resumable. 98 // Test that resumption fails if the target download item is not resumable.
94 TEST_F(DownloadManagerServiceTest, ResumptionWithNonResumableItem) { 99 TEST_F(DownloadManagerServiceTest, ResumptionWithNonResumableItem) {
95 CreateDownloadItem(false); 100 CreateDownloadItem(false);
96 StartDownload(1); 101 StartDownload("0000");
97 EXPECT_FALSE(success_); 102 EXPECT_FALSE(success_);
98 } 103 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698