protocol_serializer_unittest.cc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // Copyright 2016 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 <string>
  5. #include "base/strings/string_util.h"
  6. #include "base/version.h"
  7. #include "components/update_client/protocol_serializer.h"
  8. #include "testing/gtest/include/gtest/gtest.h"
  9. using std::string;
  10. namespace update_client {
  11. TEST(BuildProtocolRequest, BuildUpdateCheckExtraRequestHeaders) {
  12. auto headers = BuildUpdateCheckExtraRequestHeaders(
  13. "fake_prodid", base::Version("30.0"), {}, true);
  14. EXPECT_EQ("fake_prodid-30.0", headers["X-Goog-Update-Updater"]);
  15. EXPECT_EQ("fg", headers["X-Goog-Update-Interactivity"]);
  16. EXPECT_TRUE(headers["X-Goog-Update-AppId"].empty());
  17. headers = BuildUpdateCheckExtraRequestHeaders(
  18. "fake_prodid", base::Version("30.0"), {}, false);
  19. EXPECT_EQ("fake_prodid-30.0", headers["X-Goog-Update-Updater"]);
  20. EXPECT_EQ("bg", headers["X-Goog-Update-Interactivity"]);
  21. EXPECT_TRUE(headers["X-Goog-Update-AppId"].empty());
  22. headers = BuildUpdateCheckExtraRequestHeaders(
  23. "fake_prodid", base::Version("30.0"),
  24. {"jebgalgnebhfojomionfpkfelancnnkf"}, true);
  25. EXPECT_EQ("fake_prodid-30.0", headers["X-Goog-Update-Updater"]);
  26. EXPECT_EQ("fg", headers["X-Goog-Update-Interactivity"]);
  27. EXPECT_EQ("jebgalgnebhfojomionfpkfelancnnkf", headers["X-Goog-Update-AppId"]);
  28. headers = BuildUpdateCheckExtraRequestHeaders(
  29. "fake_prodid", base::Version("30.0"),
  30. {"jebgalgnebhfojomionfpkfelancnnkf", "ihfokbkgjpifbbojhneepfflplebdkc"},
  31. true);
  32. EXPECT_EQ("fake_prodid-30.0", headers["X-Goog-Update-Updater"]);
  33. EXPECT_EQ("fg", headers["X-Goog-Update-Interactivity"]);
  34. EXPECT_EQ("jebgalgnebhfojomionfpkfelancnnkf,ihfokbkgjpifbbojhneepfflplebdkc",
  35. headers["X-Goog-Update-AppId"]);
  36. // Test that only 30 extension ids are joined in the headers.
  37. headers = BuildUpdateCheckExtraRequestHeaders(
  38. "fake_prodid", base::Version("30.0"),
  39. std::vector<std::string>(40, "jebgalgnebhfojomionfpkfelancnnkf"), true);
  40. EXPECT_EQ(base::JoinString(std::vector<std::string>(
  41. 30, "jebgalgnebhfojomionfpkfelancnnkf"),
  42. ","),
  43. headers["X-Goog-Update-AppId"]);
  44. }
  45. } // namespace update_client