sync_util_unittest.cc 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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.
  4. #include "components/sync/base/sync_util.h"
  5. #include "base/command_line.h"
  6. #include "base/strings/string_util.h"
  7. #include "components/sync/base/command_line_switches.h"
  8. #include "testing/gtest/include/gtest/gtest.h"
  9. #include "url/gurl.h"
  10. namespace syncer {
  11. TEST(SyncUtilTest, GetSyncServiceURLWithoutCommandLineSwitch) {
  12. // If the command line is not set the url is one of two constants chosen based
  13. // on the channel (e.g. beta).
  14. base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
  15. std::string url =
  16. GetSyncServiceURL(command_line, version_info::Channel::BETA).spec();
  17. ASSERT_TRUE(internal::kSyncServerUrl == url ||
  18. internal::kSyncDevServerUrl == url);
  19. }
  20. TEST(SyncUtilTest, GetSyncServiceURLWithCommandLineSwitch) {
  21. // See that we can set the URL via the command line.
  22. base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
  23. command_line.AppendSwitchASCII(kSyncServiceURL, "https://foo/bar");
  24. ASSERT_EQ(
  25. "https://foo/bar",
  26. GetSyncServiceURL(command_line, version_info::Channel::UNKNOWN).spec());
  27. }
  28. TEST(SyncUtilTest, GetSyncServiceURLWithBadCommandLineSwitch) {
  29. // If the command line value is not a valid url it is ignored.
  30. base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
  31. command_line.AppendSwitchASCII(kSyncServiceURL, "invalid_url");
  32. std::string url =
  33. GetSyncServiceURL(command_line, version_info::Channel::UNKNOWN).spec();
  34. ASSERT_TRUE(internal::kSyncServerUrl == url ||
  35. internal::kSyncDevServerUrl == url);
  36. }
  37. TEST(SyncUtilTest, FormatUserAgentForSync) {
  38. std::string user_agent =
  39. internal::FormatUserAgentForSync("TEST", version_info::Channel::UNKNOWN);
  40. ASSERT_TRUE(base::StartsWith(user_agent, "Chrome TEST",
  41. base::CompareCase::SENSITIVE));
  42. }
  43. } // namespace syncer