1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
|
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/data_sharing/public/data_sharing_service.h"
#include "base/run_loop.h"
#include "base/test/scoped_feature_list.h"
#include "build/branding_buildflags.h"
#include "chrome/browser/data_sharing/data_sharing_service_factory.h"
#include "chrome/browser/data_sharing/desktop/data_sharing_sdk_delegate_desktop.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "components/data_sharing/public/features.h"
#include "content/public/test/browser_test.h"
#include "google_apis/gaia/gaia_id.h"
class DataSharingServiceBrowserTest : public InProcessBrowserTest {
public:
DataSharingServiceBrowserTest() {
scoped_feature_list_.InitWithFeatures(
{data_sharing::features::kDataSharingFeature}, {});
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
};
IN_PROC_BROWSER_TEST_F(DataSharingServiceBrowserTest, ReadGroup) {
// In branded build, tests are skipped since it fetches data from the server.
// In non-branded build, fake data are returned from a dummy implementation.
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
GTEST_SKIP() << "N/A for Google Chrome Branding Build";
#else
base::RunLoop run_loop;
auto* service = data_sharing::DataSharingServiceFactory::GetForProfile(
browser()->profile());
// TODO(crbug.com/338431049): This test should use synchronous ReadGroup()
// instead of ReadGroupDeprecated(). Note that this will require receiving a
// GroupId from the sync server first (as part of COLLABORATION_GROUP
// datatype) -> simplest way to achieve this is to derive test from SyncTest
// and inject COLLABORATION_GROUP into fake sync server.
service->ReadGroupDeprecated(
data_sharing::GroupId("12345"),
base::BindOnce(
[](base::RunLoop* run_loop,
const data_sharing::DataSharingService::GroupDataOrFailureOutcome&
result) {
EXPECT_EQ(data_sharing::GroupId("12345"),
result->group_token.group_id);
EXPECT_EQ("GROUP_NAME", result->display_name);
EXPECT_EQ(1u, result->members.size());
data_sharing::GroupMember member = result->members[0];
EXPECT_EQ("GAIA_ID", member.gaia_id.ToString());
EXPECT_EQ("MEMBER_NAME", member.display_name);
EXPECT_EQ("test@gmail.com", member.email);
EXPECT_EQ(data_sharing::MemberRole::kMember, member.role);
EXPECT_EQ(GURL("http://example.com"), member.avatar_url);
data_sharing::GroupMember former_member = result->former_members[0];
EXPECT_EQ("GAIA_ID2", former_member.gaia_id.ToString());
EXPECT_EQ("MEMBER_NAME2", former_member.display_name);
EXPECT_EQ("test2@gmail.com", former_member.email);
EXPECT_EQ(data_sharing::MemberRole::kFormerMember,
former_member.role);
EXPECT_EQ(GURL("http://example2.com"), former_member.avatar_url);
run_loop->Quit();
},
&run_loop));
run_loop.Run();
#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
}
IN_PROC_BROWSER_TEST_F(DataSharingServiceBrowserTest, ReadGroupWithToken) {
// In branded build, tests are skipped since it fetches data from the server.
// In non-branded build, fake data are returned from a dummy implementation.
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
GTEST_SKIP() << "N/A for Google Chrome Branding Build";
#else
base::RunLoop run_loop;
auto* service = data_sharing::DataSharingServiceFactory::GetForProfile(
browser()->profile());
service->ReadNewGroup(
data_sharing::GroupToken(data_sharing::GroupId("12345"), "access_token"),
base::BindOnce(
[](base::RunLoop* run_loop,
const data_sharing::DataSharingService::GroupDataOrFailureOutcome&
result) {
EXPECT_EQ(data_sharing::GroupId("12345"),
result->group_token.group_id);
EXPECT_EQ("GROUP_NAME", result->display_name);
EXPECT_EQ(1u, result->members.size());
data_sharing::GroupMember member = result->members[0];
EXPECT_EQ("GAIA_ID", member.gaia_id.ToString());
EXPECT_EQ("MEMBER_NAME", member.display_name);
EXPECT_EQ("test@gmail.com", member.email);
EXPECT_EQ(data_sharing::MemberRole::kMember, member.role);
EXPECT_EQ(GURL("http://example.com"), member.avatar_url);
data_sharing::GroupMember former_member = result->former_members[0];
EXPECT_EQ("GAIA_ID2", former_member.gaia_id.ToString());
EXPECT_EQ("MEMBER_NAME2", former_member.display_name);
EXPECT_EQ("test2@gmail.com", former_member.email);
EXPECT_EQ(data_sharing::MemberRole::kFormerMember,
former_member.role);
EXPECT_EQ(GURL("http://example2.com"), former_member.avatar_url);
run_loop->Quit();
},
&run_loop));
run_loop.Run();
#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
}
IN_PROC_BROWSER_TEST_F(DataSharingServiceBrowserTest, DeleteGroup) {
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
GTEST_SKIP() << "N/A for Google Chrome Branding Build";
#else
base::RunLoop run_loop;
auto* service = data_sharing::DataSharingServiceFactory::GetForProfile(
browser()->profile());
service->DeleteGroup(
data_sharing::GroupId("12345"),
base::BindOnce(
[](base::RunLoop* run_loop,
data_sharing::DataSharingService::PeopleGroupActionOutcome
result) {
EXPECT_EQ(result, data_sharing::DataSharingService::
PeopleGroupActionOutcome::kPersistentFailure);
run_loop->Quit();
},
&run_loop));
run_loop.Run();
#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
}
IN_PROC_BROWSER_TEST_F(DataSharingServiceBrowserTest, LeaveGroup) {
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
GTEST_SKIP() << "N/A for Google Chrome Branding Build";
#else
base::RunLoop run_loop;
auto* service = data_sharing::DataSharingServiceFactory::GetForProfile(
browser()->profile());
service->LeaveGroup(
data_sharing::GroupId("12345"),
base::BindOnce(
[](base::RunLoop* run_loop,
data_sharing::DataSharingService::PeopleGroupActionOutcome
result) {
EXPECT_EQ(result, data_sharing::DataSharingService::
PeopleGroupActionOutcome::kPersistentFailure);
run_loop->Quit();
},
&run_loop));
run_loop.Run();
#endif // BUILDFLAG(GOOGLE_CHROME_BRANDING)
}
|