Commit 3447899f authored by Hesen Zhang's avatar Hesen Zhang Committed by Commit Bot

Fixed unintialized warning in clang.


Reland "[Video Tutorials] Add internal tutorial group."

This is a reland of a96793a7

Original change's description:
> [Video Tutorials] Add internal tutorial group.
>
> Bug: 1115755
> Change-Id: I481a8f6498188681216d13df32ee41436cd1306c
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2358056
> Reviewed-by: David Trainor <dtrainor@chromium.org>
> Commit-Queue: Hesen Zhang <hesen@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#800642}

Bug: 1115755
Change-Id: I0960fef750bba2e37fc0d36574376e9c4de44c7c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2372883
Commit-Queue: Hesen Zhang <hesen@chromium.org>
Reviewed-by: default avatarDavid Trainor <dtrainor@chromium.org>
Cr-Commit-Position: refs/heads/master@{#801868}
parent e03f5b3e
......@@ -11,6 +11,8 @@ source_set("internal") {
sources = [
"proto_conversions.cc",
"proto_conversions.h",
"tutorial_group.cc",
"tutorial_group.h",
"tutorial_service_impl.cc",
"tutorial_service_impl.h",
]
......@@ -74,7 +76,10 @@ if (is_android) {
source_set("unit_tests") {
testonly = true
sources = [ "proto_conversions_unittest.cc" ]
sources = [
"proto_conversions_unittest.cc",
"tutorial_group_unittest.cc",
]
deps = [
":internal",
......
......@@ -71,4 +71,25 @@ void TutorialFromProto(TutorialProto* proto, Tutorial* tutorial) {
tutorial->video_length = proto->video_length();
}
void TutorialGroupToProto(TutorialGroup* group, TutorialGroupProto* proto) {
DCHECK(group);
DCHECK(proto);
proto->set_locale(group->locale);
proto->clear_tutorials();
for (auto& tutorial : group->tutorials)
TutorialToProto(&tutorial, proto->add_tutorials());
}
void TutorialGroupFromProto(TutorialGroupProto* proto, TutorialGroup* group) {
DCHECK(group);
DCHECK(proto);
group->locale = proto->locale();
group->tutorials.clear();
for (auto tutorial_proto : proto->tutorials()) {
Tutorial tutorial;
TutorialFromProto(&tutorial_proto, &tutorial);
group->tutorials.emplace_back(std::move(tutorial));
}
}
} // namespace video_tutorials
......@@ -5,19 +5,26 @@
#ifndef CHROME_BROWSER_VIDEO_TUTORIALS_INTERNAL_PROTO_CONVERSIONS_H_
#define CHROME_BROWSER_VIDEO_TUTORIALS_INTERNAL_PROTO_CONVERSIONS_H_
#include "chrome/browser/video_tutorials/internal/tutorial_group.h"
#include "chrome/browser/video_tutorials/proto/video_tutorials.pb.h"
#include "chrome/browser/video_tutorials/tutorial.h"
namespace video_tutorials {
using TutorialProto = video_tutorials::proto::VideoTutorial;
using TutorialGroupProto = video_tutorials::proto::VideoTutorialGroup;
// Convert in-memory struct Tutorial to proto::VideoTutorial.
void TutorialToProto(Tutorial* tutorial, TutorialProto* proto);
// Convert proto::VideoTutorial to in-memory struct Tutorial.
// Convert proto::VideoTutorial to in-memory struct Tutorial.
void TutorialFromProto(TutorialProto* proto, Tutorial* tutorial);
// Convert in-memory struct TutorialGroup to proto::VideoTutorialGroup.
void TutorialGroupToProto(TutorialGroup* group, TutorialGroupProto* proto);
// Convert proto::VideoTutorialGroup to in-memory struct TutorialGroup.
void TutorialGroupFromProto(TutorialGroupProto* proto, TutorialGroup* group);
} // namespace video_tutorials
#endif // CHROME_BROWSER_VIDEO_TUTORIALS_INTERNAL_PROTO_CONVERSIONS_H_
......@@ -17,6 +17,15 @@ void ResetTutorialEntry(Tutorial* entry) {
kTestURL, kTestURL, 60);
}
void ResetTutorialGroup(TutorialGroup* group) {
*group = TutorialGroup("cn");
group->tutorials.clear();
Tutorial entry1;
ResetTutorialEntry(&entry1);
group->tutorials.emplace_back(entry1);
group->tutorials.emplace_back(entry1);
}
// Verify round-way conversion of Tutorial struct.
TEST(VideoTutorialsProtoConversionsTest, TutorialConversion) {
Tutorial expected, actual;
......@@ -27,5 +36,15 @@ TEST(VideoTutorialsProtoConversionsTest, TutorialConversion) {
EXPECT_EQ(expected, actual);
}
// Verify round-way conversion of TutorialGroup struct.
TEST(VideoTutorialsProtoConversionsTest, TutorialGroupConversion) {
TutorialGroup expected, actual;
ResetTutorialGroup(&expected);
TutorialGroupProto intermediate;
TutorialGroupToProto(&expected, &intermediate);
TutorialGroupFromProto(&intermediate, &actual);
EXPECT_EQ(expected, actual);
}
} // namespace
} // namespace video_tutorials
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/video_tutorials/internal/tutorial_group.h"
namespace video_tutorials {
TutorialGroup::TutorialGroup() = default;
TutorialGroup::TutorialGroup(const std::string& locale) : locale(locale) {}
bool TutorialGroup::operator==(const TutorialGroup& other) const {
return locale == other.locale && tutorials == other.tutorials;
}
bool TutorialGroup::operator!=(const TutorialGroup& other) const {
return !(*this == other);
}
TutorialGroup::~TutorialGroup() = default;
TutorialGroup::TutorialGroup(const TutorialGroup& other) = default;
TutorialGroup& TutorialGroup::operator=(const TutorialGroup& other) = default;
} // namespace video_tutorials
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_VIDEO_TUTORIALS_INTERNAL_TUTORIAL_GROUP_H_
#define CHROME_BROWSER_VIDEO_TUTORIALS_INTERNAL_TUTORIAL_GROUP_H_
#include "chrome/browser/video_tutorials/tutorial.h"
namespace video_tutorials {
// In memory struct of a group of video tutorials with same language .
struct TutorialGroup {
TutorialGroup();
explicit TutorialGroup(const std::string& locale);
~TutorialGroup();
bool operator==(const TutorialGroup& other) const;
bool operator!=(const TutorialGroup& other) const;
TutorialGroup(const TutorialGroup& other);
TutorialGroup& operator=(const TutorialGroup& other);
// Language of this group.
std::string locale;
// A list of tutorials.
std::vector<Tutorial> tutorials;
};
} // namespace video_tutorials
#endif // CHROME_BROWSER_VIDEO_TUTORIALS_INTERNAL_TUTORIAL_GROUP_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/video_tutorials/internal/tutorial_group.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace video_tutorials {
namespace {
void ResetTutorialGroup(TutorialGroup* group) {
*group = TutorialGroup("en");
group->tutorials.resize(3, Tutorial());
group->tutorials.front().feature = FeatureType::kDownload;
group->tutorials.back().feature = FeatureType::kSearch;
}
// Verify the copy/assign and compare operators for TutorialGroup struct.
TEST(VideoTutorialGroupTest, CopyAndCompareOperators) {
TutorialGroup lhs, rhs;
ResetTutorialGroup(&lhs);
ResetTutorialGroup(&rhs);
EXPECT_EQ(lhs, rhs);
rhs.locale = "jp";
EXPECT_NE(lhs, rhs);
ResetTutorialGroup(&rhs);
std::reverse(rhs.tutorials.begin(), rhs.tutorials.end());
EXPECT_NE(lhs, rhs);
ResetTutorialGroup(&rhs);
rhs.tutorials.pop_back();
EXPECT_NE(lhs, rhs);
ResetTutorialGroup(&rhs);
}
} // namespace
} // namespace video_tutorials
......@@ -6,7 +6,7 @@
namespace video_tutorials {
Tutorial::Tutorial() = default;
Tutorial::Tutorial() : feature(FeatureType::kInvalid), video_length(0) {}
Tutorial::Tutorial(FeatureType feature,
const std::string& title,
......
......@@ -43,7 +43,7 @@ struct Tutorial {
Tutorial& operator=(const Tutorial& other);
// Type of feature where this video tutorial targeted.
FeatureType feature{FeatureType::kInvalid};
FeatureType feature;
// The title of the video.
std::string title;
......
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