Commit bff0b67e authored by Xing Liu's avatar Xing Liu Committed by Commit Bot

Download later: Don't load download schedule when feature is disabled.

It's possible that we may rollback download later feature. We should
not load the download schedule data when the feature is disabled.

Bug: 1114855
Change-Id: Iaca2998a85296f3a16f0b23d14215425356a4895
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2346932Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Reviewed-by: default avatarHesen Zhang <hesen@chromium.org>
Reviewed-by: default avatarShakti Sahu <shaktisahu@chromium.org>
Commit-Queue: Xing Liu <xingliu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796912}
parent 40e519df
...@@ -5,8 +5,10 @@ ...@@ -5,8 +5,10 @@
#include "components/download/database/download_db_conversions.h" #include "components/download/database/download_db_conversions.h"
#include <utility> #include <utility>
#include "base/notreached.h" #include "base/notreached.h"
#include "base/pickle.h" #include "base/pickle.h"
#include "components/download/public/common/download_features.h"
namespace download { namespace download {
namespace { namespace {
...@@ -207,7 +209,8 @@ download_pb::InProgressInfo DownloadDBConversions::InProgressInfoToProto( ...@@ -207,7 +209,8 @@ download_pb::InProgressInfo DownloadDBConversions::InProgressInfoToProto(
proto.set_metered(in_progress_info.metered); proto.set_metered(in_progress_info.metered);
proto.set_bytes_wasted(in_progress_info.bytes_wasted); proto.set_bytes_wasted(in_progress_info.bytes_wasted);
proto.set_auto_resume_count(in_progress_info.auto_resume_count); proto.set_auto_resume_count(in_progress_info.auto_resume_count);
if (in_progress_info.download_schedule.has_value()) { if (base::FeatureList::IsEnabled(download::features::kDownloadLater) &&
in_progress_info.download_schedule.has_value()) {
DCHECK_NE(in_progress_info.download_schedule->only_on_wifi(), DCHECK_NE(in_progress_info.download_schedule->only_on_wifi(),
in_progress_info.metered); in_progress_info.metered);
auto download_schedule_proto = auto download_schedule_proto =
...@@ -266,7 +269,8 @@ InProgressInfo DownloadDBConversions::InProgressInfoFromProto( ...@@ -266,7 +269,8 @@ InProgressInfo DownloadDBConversions::InProgressInfoFromProto(
info.metered = proto.metered(); info.metered = proto.metered();
info.bytes_wasted = proto.bytes_wasted(); info.bytes_wasted = proto.bytes_wasted();
info.auto_resume_count = proto.auto_resume_count(); info.auto_resume_count = proto.auto_resume_count();
if (proto.has_download_schedule()) { if (base::FeatureList::IsEnabled(download::features::kDownloadLater) &&
proto.has_download_schedule()) {
info.download_schedule = DownloadScheduleFromProto( info.download_schedule = DownloadScheduleFromProto(
proto.download_schedule(), !proto.metered() /*only_on_wifi*/); proto.download_schedule(), !proto.metered() /*only_on_wifi*/);
DCHECK_NE(info.download_schedule->only_on_wifi(), info.metered); DCHECK_NE(info.download_schedule->only_on_wifi(), info.metered);
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#include "components/download/database/download_db_conversions.h" #include "components/download/database/download_db_conversions.h"
#include "base/optional.h" #include "base/optional.h"
#include "base/test/scoped_feature_list.h"
#include "components/download/public/common/download_features.h"
#include "components/download/public/common/download_schedule.h" #include "components/download/public/common/download_schedule.h"
#include "components/download/public/common/download_url_parameters.h" #include "components/download/public/common/download_url_parameters.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -67,7 +69,19 @@ DownloadInfo CreateDownloadInfo() { ...@@ -67,7 +69,19 @@ DownloadInfo CreateDownloadInfo() {
class DownloadDBConversionsTest : public testing::Test, class DownloadDBConversionsTest : public testing::Test,
public DownloadDBConversions { public DownloadDBConversions {
public: public:
~DownloadDBConversionsTest() override {} ~DownloadDBConversionsTest() override = default;
void SetUp() override {
scoped_feature_list_.InitAndEnableFeature(features::kDownloadLater);
}
protected:
base::test::ScopedFeatureList* scoped_feature_list() {
return &scoped_feature_list_;
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
}; };
TEST_F(DownloadDBConversionsTest, DownloadEntry) { TEST_F(DownloadDBConversionsTest, DownloadEntry) {
...@@ -185,4 +199,20 @@ TEST_F(DownloadDBConversionsTest, DownloadSchedule) { ...@@ -185,4 +199,20 @@ TEST_F(DownloadDBConversionsTest, DownloadSchedule) {
EXPECT_EQ(persisted_download_schedule, download_schedule); EXPECT_EQ(persisted_download_schedule, download_schedule);
} }
// Test to verify that when download later feature is disabled, download
// schedule will not be loaded.
TEST_F(DownloadDBConversionsTest, DownloadLaterDisabled) {
scoped_feature_list()->Reset();
scoped_feature_list()->InitAndDisableFeature(features::kDownloadLater);
DownloadDBEntry entry;
entry.download_info = CreateDownloadInfo();
EXPECT_TRUE(
entry.download_info->in_progress_info->download_schedule.has_value());
auto new_entry = DownloadDBEntryFromProto(DownloadDBEntryToProto(entry));
EXPECT_FALSE(
new_entry.download_info->in_progress_info->download_schedule.has_value());
}
} // namespace download } // namespace download
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment