Skip to content

Commit

Permalink
[Deduplication] Test with binary proto data.
Browse files Browse the repository at this point in the history
This CL adds a binary proto data for testing with some real apps.

BUG=b/238394602

Change-Id: I604958b498e6231790ab207104f04abaa6f40c82
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3817428
Commit-Queue: Maggie Cai <mxcai@chromium.org>
Reviewed-by: Dominick Ng <dominickn@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1034395}
  • Loading branch information
Maggie Cai authored and Chromium LUCI CQ committed Aug 12, 2022
1 parent f546e7d commit 35ae3db
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 25 deletions.
Expand Up @@ -65,14 +65,16 @@ void AppDeduplicationService::OnDuplicatedAppsMapUpdated(
for (auto const& app : group.second.apps()) {
const std::string& app_id = app.app_id_for_platform();
const std::string& source = app.source_name();
AppType app_type = AppType::kUnknown;
EntryId entry_id;
// TODO(b/238394602): Add more data type when real data is ready.
if (source == "arc") {
app_type = AppType::kArc;
entry_id = EntryId(app_id, AppType::kArc);
} else if (source == "web") {
app_type = AppType::kWeb;
entry_id = EntryId(app_id, AppType::kWeb);
} else if (source == "phonehub") {
entry_id = EntryId(app_id);
}
EntryId entry_id(app_id, app_type);

entry_to_group_map_[entry_id] = group.first;

Entry entry(std::move(entry_id));
Expand Down
Expand Up @@ -34,6 +34,7 @@ class AppDeduplicationService : public KeyedService,
friend class AppDeduplicationServiceTest;
FRIEND_TEST_ALL_PREFIXES(AppDeduplicationServiceTest,
OnDuplicatedAppsMapUpdated);
FRIEND_TEST_ALL_PREFIXES(AppDeduplicationServiceTest, ExactDuplicate);

// AppProvisioningDataManager::Observer:
void OnDuplicatedAppsMapUpdated(
Expand Down
Expand Up @@ -4,10 +4,15 @@

#include "chrome/browser/apps/app_deduplication_service/app_deduplication_service.h"

#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/path_service.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/browser/apps/app_deduplication_service/app_deduplication_service_factory.h"
#include "chrome/browser/apps/app_provisioning_service/app_provisioning_data_manager.h"
#include "chrome/browser/apps/app_provisioning_service/proto/app_data.pb.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gmock/include/gmock/gmock.h"
Expand Down Expand Up @@ -74,39 +79,178 @@ TEST_F(AppDeduplicationServiceTest, ServiceAccessPerProfile) {
}

TEST_F(AppDeduplicationServiceTest, OnDuplicatedAppsMapUpdated) {
base::FilePath path;
EXPECT_TRUE(base::PathService::Get(chrome::DIR_TEST_DATA, &path));
path = path.AppendASCII("app_deduplication_service/binary_test_data.pb");

std::string dedupe_pb;
ASSERT_TRUE(base::ReadFileToString(path, &dedupe_pb));

proto::DuplicatedAppsMap duplicated_apps_map;
ASSERT_TRUE(duplicated_apps_map.ParseFromString(dedupe_pb));

TestingProfile::Builder profile_builder;
auto profile = profile_builder.Build();
ASSERT_TRUE(AppDeduplicationServiceFactory::
IsAppDeduplicationServiceAvailableForProfile(profile.get()));
auto* service = AppDeduplicationServiceFactory::GetForProfile(profile.get());
EXPECT_NE(nullptr, service);

std::string binary_pb = "";
base::FilePath install_dir("/");
apps::AppProvisioningDataManager::Get()->PopulateFromDynamicUpdate(
binary_pb, install_dir);
service->OnDuplicatedAppsMapUpdated(duplicated_apps_map);

std::string test_key = "test_key";
std::string arc_app_id = "test_arc_app_id";
auto it =
service->entry_to_group_map_.find(EntryId(arc_app_id, AppType::kArc));
std::string skype_test_key = "Skype";
std::string skype_arc_app_id = "com.skype.raider";
auto it = service->entry_to_group_map_.find(
EntryId(skype_arc_app_id, AppType::kArc));
ASSERT_NE(it, service->entry_to_group_map_.end());
EXPECT_EQ(test_key, it->second);
EXPECT_EQ(skype_test_key, it->second);

std::string web_app_id = "test_web_app_id";
it = service->entry_to_group_map_.find(EntryId(web_app_id, AppType::kWeb));
std::string skype_web_app_id = "http://web.skype.com/";
it = service->entry_to_group_map_.find(
EntryId(skype_web_app_id, AppType::kWeb));
ASSERT_NE(it, service->entry_to_group_map_.end());
EXPECT_EQ(test_key, it->second);
EXPECT_EQ(skype_test_key, it->second);

auto map_it = service->duplication_map_.find(test_key);
std::string skype_phonehub_app_id = "com.skype.raider";
it = service->entry_to_group_map_.find(EntryId(skype_phonehub_app_id));
ASSERT_NE(it, service->entry_to_group_map_.end());
EXPECT_EQ(skype_test_key, it->second);

auto map_it = service->duplication_map_.find(skype_test_key);
ASSERT_FALSE(map_it == service->duplication_map_.end());
EXPECT_THAT(map_it->second.entries,
ElementsAre(Entry(EntryId(arc_app_id, AppType::kArc)),
Entry(EntryId(web_app_id, AppType::kWeb))));
ElementsAre(Entry(EntryId(skype_phonehub_app_id)),
Entry(EntryId(skype_arc_app_id, AppType::kArc)),
Entry(EntryId(skype_web_app_id, AppType::kWeb))));

std::string whatsapp_test_key = "WhatsApp";
std::string whatsapp_arc_app_id = "com.whatsapp";
it = service->entry_to_group_map_.find(
EntryId(whatsapp_arc_app_id, AppType::kArc));
ASSERT_NE(it, service->entry_to_group_map_.end());
EXPECT_EQ(whatsapp_test_key, it->second);

std::string whatsapp_web_app_id = "http://web.whatsapp.com/";
it = service->entry_to_group_map_.find(
EntryId(whatsapp_web_app_id, AppType::kWeb));
ASSERT_NE(it, service->entry_to_group_map_.end());
EXPECT_EQ(whatsapp_test_key, it->second);

std::string whatsapp_phonehub_app_id = "com.whatsapp";
it = service->entry_to_group_map_.find(EntryId(whatsapp_phonehub_app_id));
ASSERT_NE(it, service->entry_to_group_map_.end());
EXPECT_EQ(whatsapp_test_key, it->second);

map_it = service->duplication_map_.find(whatsapp_test_key);
ASSERT_FALSE(map_it == service->duplication_map_.end());
EXPECT_THAT(map_it->second.entries,
ElementsAre(Entry(EntryId(whatsapp_phonehub_app_id)),
Entry(EntryId(whatsapp_arc_app_id, AppType::kArc)),
Entry(EntryId(whatsapp_web_app_id, AppType::kWeb))));
}

// Test exact match entry ids.
TEST_F(AppDeduplicationServiceTest, ExactDuplicate) {
base::FilePath path;
EXPECT_TRUE(base::PathService::Get(chrome::DIR_TEST_DATA, &path));
path = path.AppendASCII("app_deduplication_service/binary_test_data.pb");

std::string dedupe_pb;
ASSERT_TRUE(base::ReadFileToString(path, &dedupe_pb));

proto::DuplicatedAppsMap duplicated_apps_map;
ASSERT_TRUE(duplicated_apps_map.ParseFromString(dedupe_pb));

TestingProfile::Builder profile_builder;
auto profile = profile_builder.Build();
ASSERT_TRUE(AppDeduplicationServiceFactory::
IsAppDeduplicationServiceAvailableForProfile(profile.get()));
auto* service = AppDeduplicationServiceFactory::GetForProfile(profile.get());
EXPECT_NE(nullptr, service);

service->OnDuplicatedAppsMapUpdated(duplicated_apps_map);

EntryId skype_arc_entry_id("com.skype.raider", apps::AppType::kArc);
EntryId skype_web_entry_id("http://web.skype.com/", apps::AppType::kWeb);
EntryId skype_phonehub_entry_id("com.skype.raider");
EntryId whatsapp_arc_entry_id("com.whatsapp", apps::AppType::kArc);
EntryId whatsapp_web_entry_id("http://web.whatsapp.com/",
apps::AppType::kWeb);
EntryId whatsapp_phonehub_entry_id("com.whatsapp");

EXPECT_THAT(
service->GetDuplicates(skype_arc_entry_id),
ElementsAre(Entry(skype_phonehub_entry_id), Entry(skype_arc_entry_id),
Entry(skype_web_entry_id)));
EXPECT_THAT(
service->GetDuplicates(skype_web_entry_id),
ElementsAre(Entry(skype_phonehub_entry_id), Entry(skype_arc_entry_id),
Entry(skype_web_entry_id)));
EXPECT_THAT(
service->GetDuplicates(skype_phonehub_entry_id),
ElementsAre(Entry(skype_phonehub_entry_id), Entry(skype_arc_entry_id),
Entry(skype_web_entry_id)));
EXPECT_THAT(
service->GetDuplicates(whatsapp_web_entry_id),
ElementsAre(Entry(whatsapp_phonehub_entry_id),
Entry(whatsapp_arc_entry_id), Entry(whatsapp_web_entry_id)));
EXPECT_THAT(
service->GetDuplicates(whatsapp_arc_entry_id),
ElementsAre(Entry(whatsapp_phonehub_entry_id),
Entry(whatsapp_arc_entry_id), Entry(whatsapp_web_entry_id)));
EXPECT_THAT(
service->GetDuplicates(whatsapp_phonehub_entry_id),
ElementsAre(Entry(whatsapp_phonehub_entry_id),
Entry(whatsapp_arc_entry_id), Entry(whatsapp_web_entry_id)));

EXPECT_TRUE(service->AreDuplicates(skype_arc_entry_id, skype_web_entry_id));
EXPECT_TRUE(
service->AreDuplicates(skype_arc_entry_id, skype_phonehub_entry_id));
EXPECT_TRUE(
service->AreDuplicates(skype_phonehub_entry_id, skype_web_entry_id));
EXPECT_TRUE(
service->AreDuplicates(whatsapp_arc_entry_id, whatsapp_web_entry_id));
EXPECT_TRUE(service->AreDuplicates(whatsapp_arc_entry_id,
whatsapp_phonehub_entry_id));
EXPECT_TRUE(service->AreDuplicates(whatsapp_web_entry_id,
whatsapp_phonehub_entry_id));

EXPECT_FALSE(
service->AreDuplicates(skype_arc_entry_id, whatsapp_arc_entry_id));
EXPECT_FALSE(
service->AreDuplicates(skype_arc_entry_id, whatsapp_web_entry_id));
EXPECT_FALSE(
service->AreDuplicates(skype_arc_entry_id, whatsapp_phonehub_entry_id));
EXPECT_FALSE(
service->AreDuplicates(skype_web_entry_id, whatsapp_arc_entry_id));
EXPECT_FALSE(
service->AreDuplicates(skype_web_entry_id, whatsapp_web_entry_id));
EXPECT_FALSE(
service->AreDuplicates(skype_web_entry_id, whatsapp_phonehub_entry_id));
EXPECT_FALSE(
service->AreDuplicates(skype_phonehub_entry_id, whatsapp_arc_entry_id));
EXPECT_FALSE(
service->AreDuplicates(skype_phonehub_entry_id, whatsapp_web_entry_id));
EXPECT_FALSE(service->AreDuplicates(skype_phonehub_entry_id,
whatsapp_phonehub_entry_id));

EntryId not_duplicate_app_id("not_duplicate_app_id", apps::AppType::kWeb);
EXPECT_TRUE(service->GetDuplicates(not_duplicate_app_id).empty());
EXPECT_FALSE(
service->AreDuplicates(not_duplicate_app_id, skype_arc_entry_id));
EXPECT_FALSE(
service->AreDuplicates(not_duplicate_app_id, skype_web_entry_id));
EXPECT_FALSE(
service->AreDuplicates(not_duplicate_app_id, skype_phonehub_entry_id));
EXPECT_FALSE(
service->AreDuplicates(not_duplicate_app_id, whatsapp_arc_entry_id));
EXPECT_FALSE(
service->AreDuplicates(not_duplicate_app_id, whatsapp_web_entry_id));
EXPECT_FALSE(
service->AreDuplicates(not_duplicate_app_id, whatsapp_phonehub_entry_id));
}

// Test updating duplication data from app provisioning data manager.
TEST_F(AppDeduplicationServiceTest, AppPromisioningDataManagerUpdate) {
TestingProfile::Builder profile_builder;
auto profile = profile_builder.Build();
ASSERT_TRUE(AppDeduplicationServiceFactory::
Expand All @@ -116,13 +260,13 @@ TEST_F(AppDeduplicationServiceTest, ExactDuplicate) {

std::string binary_pb = "";
base::FilePath install_dir("/");
// TODO(b/238394602): Move the fake data population to test only when real
// data feeds in.
apps::AppProvisioningDataManager::Get()->PopulateFromDynamicUpdate(
binary_pb, install_dir);

std::string arc_app_id = "test_arc_app_id";
std::string web_app_id = "test_web_app_id";
EntryId arc_entry_id(arc_app_id, apps::AppType::kArc);
EntryId web_entry_id(web_app_id, apps::AppType::kWeb);
EntryId arc_entry_id("test_arc_app_id", apps::AppType::kArc);
EntryId web_entry_id("test_web_app_id", apps::AppType::kWeb);

EXPECT_THAT(service->GetDuplicates(arc_entry_id),
ElementsAre(Entry(arc_entry_id), Entry(web_entry_id)));
Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/apps/app_deduplication_service/entry_types.h
Expand Up @@ -19,8 +19,9 @@ enum class EntryType {
};

struct EntryId {
EntryId() = default;
// Constructor for apps.
EntryId(std::string app_id, apps::AppType app_type);
EntryId(std::string app_id, AppType app_type);

// Constructor for web pages.
explicit EntryId(const GURL& url);
Expand Down
17 changes: 17 additions & 0 deletions chrome/test/data/app_deduplication_service/binary_test_data.pb
@@ -0,0 +1,17 @@

^
SkypeU

com.skype.raiderJphonehub

com.skype.raiderJarc

http://web.skype.com/Jweb
\
WhatsAppP

com.whatsappJphonehub

com.whatsappJarc

http://web.whatsapp.com/Jweb

0 comments on commit 35ae3db

Please sign in to comment.