1 // Copyright 2020 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/supervised_user/supervised_user_sync_model_type_controller.h"
6
7 #include "base/callback_helpers.h"
8 #include "chrome/browser/supervised_user/supervised_user_constants.h"
9 #include "chrome/test/base/testing_profile.h"
10 #include "components/sync/base/model_type.h"
11 #include "components/sync/base/sync_mode.h"
12 #include "components/sync/driver/data_type_controller.h"
13 #include "content/public/test/browser_task_environment.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 using syncer::DataTypeController;
17
18 class SupervisedUserSyncModelTypeControllerTest : public testing::Test {
19 private:
20 content::BrowserTaskEnvironment task_environment_;
21 };
22
TEST_F(SupervisedUserSyncModelTypeControllerTest,SupervisedUserMeetsPreconditions)23 TEST_F(SupervisedUserSyncModelTypeControllerTest,
24 SupervisedUserMeetsPreconditions) {
25 TestingProfile::Builder builder;
26 builder.SetSupervisedUserId(supervised_users::kChildAccountSUID);
27 std::unique_ptr<Profile> child_profile = builder.Build();
28 ASSERT_TRUE(child_profile->IsSupervised());
29
30 SupervisedUserSyncModelTypeController controller(
31 syncer::SUPERVISED_USER_SETTINGS, child_profile.get(),
32 /*dump_stack=*/base::DoNothing(),
33 /*store_factory=*/base::DoNothing(),
34 /*syncable_service=*/nullptr);
35 EXPECT_EQ(DataTypeController::PreconditionState::kPreconditionsMet,
36 controller.GetPreconditionState());
37 }
38
TEST_F(SupervisedUserSyncModelTypeControllerTest,NonSupervisedUserDoesNotMeetPreconditions)39 TEST_F(SupervisedUserSyncModelTypeControllerTest,
40 NonSupervisedUserDoesNotMeetPreconditions) {
41 TestingProfile::Builder builder;
42 std::unique_ptr<Profile> non_child_profile = builder.Build();
43 ASSERT_FALSE(non_child_profile->IsSupervised());
44
45 SupervisedUserSyncModelTypeController controller(
46 syncer::SUPERVISED_USER_SETTINGS, non_child_profile.get(),
47 /*dump_stack=*/base::DoNothing(),
48 /*store_factory=*/base::DoNothing(),
49 /*syncable_service=*/nullptr);
50 EXPECT_EQ(DataTypeController::PreconditionState::kMustStopAndClearData,
51 controller.GetPreconditionState());
52 }
53
TEST_F(SupervisedUserSyncModelTypeControllerTest,HasTransportModeDelegate)54 TEST_F(SupervisedUserSyncModelTypeControllerTest, HasTransportModeDelegate) {
55 TestingProfile::Builder builder;
56 builder.SetSupervisedUserId(supervised_users::kChildAccountSUID);
57 std::unique_ptr<Profile> child_profile = builder.Build();
58 ASSERT_TRUE(child_profile->IsSupervised());
59
60 SupervisedUserSyncModelTypeController controller(
61 syncer::SUPERVISED_USER_SETTINGS, child_profile.get(),
62 /*dump_stack=*/base::DoNothing(),
63 /*store_factory=*/base::DoNothing(),
64 /*syncable_service=*/nullptr);
65 EXPECT_TRUE(
66 controller.GetDelegateForTesting(syncer::SyncMode::kTransportOnly));
67 }
68