1 // Copyright 2015 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.
5 #include "components/sync_driver/sync_util.h"
7 #include "base/command_line.h"
8 #include "base/strings/string_util.h"
9 #include "components/sync_driver/sync_driver_switches.h"
10 #include "testing/gtest/include/gtest/gtest.h"
15 TEST(SyncUtilTest
, GetSyncServiceURLWithoutCommandLineSwitch
) {
16 // If the command line is not set the url is one of two constants chosen based
17 // on the channel (e.g. beta).
18 base::CommandLine
command_line(base::CommandLine::NO_PROGRAM
);
20 GetSyncServiceURL(command_line
, version_info::Channel::BETA
).spec();
21 ASSERT_TRUE(internal::kSyncServerUrl
== url
||
22 internal::kSyncDevServerUrl
== url
);
25 TEST(SyncUtilTest
, GetSyncServiceURLWithCommandLineSwitch
) {
26 // See that we can set the URL via the command line.
27 base::CommandLine
command_line(base::CommandLine::NO_PROGRAM
);
28 command_line
.AppendSwitchASCII(switches::kSyncServiceURL
, "https://foo/bar");
31 GetSyncServiceURL(command_line
, version_info::Channel::UNKNOWN
).spec());
34 TEST(SyncUtilTest
, GetSyncServiceURLWithBadCommandLineSwitch
) {
35 // If the command line value is not a valid url it is ignored.
36 base::CommandLine
command_line(base::CommandLine::NO_PROGRAM
);
37 command_line
.AppendSwitchASCII(switches::kSyncServiceURL
, "invalid_url");
39 GetSyncServiceURL(command_line
, version_info::Channel::UNKNOWN
).spec();
40 ASSERT_TRUE(internal::kSyncServerUrl
== url
||
41 internal::kSyncDevServerUrl
== url
);
44 TEST(SyncUtilTest
, MakeUserAgentForSync
) {
45 std::string user_agent
=
46 MakeUserAgentForSync("TEST", version_info::Channel::UNKNOWN
);
47 ASSERT_TRUE(base::StartsWith(user_agent
, "Chrome TEST",
48 base::CompareCase::SENSITIVE
));