1 // Copyright 2018 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 <memory>
6
7 #include "base/command_line.h"
8 #include "base/files/scoped_temp_dir.h"
9 #include "base/macros.h"
10 #include "build/branding_buildflags.h"
11 #include "build/build_config.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/send_tab_to_self/send_tab_to_self_util.h"
14 #include "chrome/browser/sync/profile_sync_service_factory.h"
15 #include "chrome/browser/sync/test/integration/single_client_status_change_checker.h"
16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/test/base/in_process_browser_test.h"
18 #include "components/browser_sync/browser_sync_switches.h"
19 #include "components/sync/base/model_type.h"
20 #include "components/sync/driver/profile_sync_service.h"
21 #include "components/sync/driver/sync_driver_switches.h"
22 #include "content/public/test/browser_test.h"
23 #include "crypto/ec_private_key.h"
24
25 namespace {
26
27 using syncer::ProfileSyncService;
28
29 class SyncTransportActiveChecker : public SingleClientStatusChangeChecker {
30 public:
SyncTransportActiveChecker(ProfileSyncService * service)31 explicit SyncTransportActiveChecker(ProfileSyncService* service)
32 : SingleClientStatusChangeChecker(service) {}
33
IsExitConditionSatisfied(std::ostream * os)34 bool IsExitConditionSatisfied(std::ostream* os) override {
35 *os << "Waiting for sync transport to become active";
36 return service()->GetTransportState() ==
37 syncer::SyncService::TransportState::ACTIVE;
38 }
39 };
40
41 // This test verifies some basic functionality of local sync, used for roaming
42 // profiles (enterprise use-case).
43 class LocalSyncTest : public InProcessBrowserTest {
44 protected:
LocalSyncTest()45 LocalSyncTest() {
46 EXPECT_TRUE(local_sync_backend_dir_.CreateUniqueTempDir());
47 }
48
~LocalSyncTest()49 ~LocalSyncTest() override {}
50
SetUpCommandLine(base::CommandLine * command_line)51 void SetUpCommandLine(base::CommandLine* command_line) override {
52 // By default on Window OS local sync backend uses roaming profile. It can
53 // lead to problems if some tests run simultaneously and use the same
54 // roaming profile.
55 auto file = local_sync_backend_dir_.GetPath().Append(
56 FILE_PATH_LITERAL("profile.pb"));
57 command_line->AppendSwitchASCII(switches::kLocalSyncBackendDir,
58 file.MaybeAsASCII());
59 command_line->AppendSwitch(switches::kEnableLocalSyncBackend);
60 command_line->AppendSwitchASCII(
61 switches::kSyncDeferredStartupTimeoutSeconds, "1");
62 }
63
64 private:
65 base::ScopedTempDir local_sync_backend_dir_;
66 DISALLOW_COPY_AND_ASSIGN(LocalSyncTest);
67 };
68
69 // The local sync backend is currently only supported on Windows, Mac and Linux.
70 #if defined(OS_WIN) || defined(OS_MAC) || defined(OS_LINUX)
IN_PROC_BROWSER_TEST_F(LocalSyncTest,ShouldStart)71 IN_PROC_BROWSER_TEST_F(LocalSyncTest, ShouldStart) {
72 ProfileSyncService* service =
73 ProfileSyncServiceFactory::GetAsProfileSyncServiceForProfile(
74 browser()->profile());
75
76 // Wait until the first sync cycle is completed.
77 ASSERT_TRUE(SyncTransportActiveChecker(service).Wait());
78
79 EXPECT_TRUE(service->IsLocalSyncEnabled());
80 EXPECT_FALSE(service->IsSyncFeatureEnabled());
81 EXPECT_FALSE(service->IsSyncFeatureActive());
82
83 // Verify that the expected set of data types successfully started up.
84 // If this test fails after adding a new data type, carefully consider whether
85 // the type should be enabled in Local Sync mode, i.e. for roaming profiles on
86 // Windows.
87 // TODO(crbug.com/1109640): Consider whether all of these types should really
88 // be enabled in Local Sync mode.
89 syncer::ModelTypeSet expected_active_data_types = syncer::ModelTypeSet(
90 syncer::BOOKMARKS, syncer::PREFERENCES, syncer::PASSWORDS,
91 syncer::AUTOFILL_PROFILE, syncer::AUTOFILL, syncer::AUTOFILL_WALLET_DATA,
92 syncer::AUTOFILL_WALLET_METADATA, syncer::THEMES, syncer::TYPED_URLS,
93 syncer::EXTENSIONS, syncer::SEARCH_ENGINES, syncer::SESSIONS,
94 syncer::APPS, syncer::APP_SETTINGS, syncer::EXTENSION_SETTINGS,
95 syncer::HISTORY_DELETE_DIRECTIVES, syncer::DEVICE_INFO,
96 syncer::PRIORITY_PREFERENCES, syncer::WEB_APPS, syncer::PROXY_TABS,
97 syncer::NIGORI);
98
99 // The dictionary is currently only synced on Windows and Linux.
100 #if defined(OS_WIN) || defined(OS_LINUX)
101 expected_active_data_types.Put(syncer::DICTIONARY);
102 #endif
103
104 EXPECT_EQ(service->GetActiveDataTypes(), expected_active_data_types);
105
106 // Verify certain features are disabled.
107 EXPECT_FALSE(service->GetActiveDataTypes().Has(syncer::USER_CONSENTS));
108 EXPECT_FALSE(service->GetActiveDataTypes().Has(syncer::USER_EVENTS));
109 EXPECT_FALSE(service->GetActiveDataTypes().Has(syncer::SECURITY_EVENTS));
110 EXPECT_FALSE(service->GetActiveDataTypes().Has(syncer::SEND_TAB_TO_SELF));
111 EXPECT_FALSE(service->GetActiveDataTypes().Has(syncer::SHARING_MESSAGE));
112 EXPECT_FALSE(send_tab_to_self::IsUserSyncTypeActive(browser()->profile()));
113 }
114 #endif // defined(OS_WIN) || defined(OS_MAC) || defined(OS_LINUX)
115
116 } // namespace
117