OLD | NEW |
(Empty) | |
| 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 |
| 5 #include <string> |
| 6 |
| 7 #include "base/files/file_path.h" |
| 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/path_service.h" |
| 10 #include "build/build_config.h" |
| 11 #include "components/update_client/protocol_builder.h" |
| 12 #include "components/update_client/updater_state.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 |
| 15 using std::string; |
| 16 |
| 17 namespace update_client { |
| 18 |
| 19 TEST(UpdateClientUtils, BuildProtocolRequest_ProdIdVersion) { |
| 20 // Verifies that |prod_id| and |version| are serialized. |
| 21 const string request = BuildProtocolRequest("some_prod_id", "1.0", "", "", "", |
| 22 "", "", "", nullptr); |
| 23 EXPECT_NE(string::npos, request.find(" version=\"some_prod_id-1.0\" ")); |
| 24 } |
| 25 |
| 26 TEST(UpdateClientUtils, BuildProtocolRequest_DownloadPreference) { |
| 27 // Verifies that an empty |download_preference| is not serialized. |
| 28 const string request_no_dlpref = |
| 29 BuildProtocolRequest("", "", "", "", "", "", "", "", nullptr); |
| 30 EXPECT_EQ(string::npos, request_no_dlpref.find(" dlpref=")); |
| 31 |
| 32 // Verifies that |download_preference| is serialized. |
| 33 const string request_with_dlpref = |
| 34 BuildProtocolRequest("", "", "", "", "", "some pref", "", "", nullptr); |
| 35 EXPECT_NE(string::npos, request_with_dlpref.find(" dlpref=\"some pref\"")); |
| 36 } |
| 37 |
| 38 TEST(UpdateClientUtils, BuildProtocolRequestUpdaterStateAttributes) { |
| 39 // When no updater state is provided, then check that the elements and |
| 40 // attributes related to the updater state are not serialized. |
| 41 std::string request = |
| 42 BuildProtocolRequest("", "", "", "", "", "", "", "", nullptr).c_str(); |
| 43 EXPECT_EQ(std::string::npos, request.find(" domainjoined")); |
| 44 EXPECT_EQ(std::string::npos, request.find("<updater")); |
| 45 |
| 46 UpdaterState::Attributes attributes; |
| 47 attributes["domainjoined"] = "1"; |
| 48 attributes["name"] = "Omaha"; |
| 49 attributes["version"] = "1.2.3.4"; |
| 50 attributes["laststarted"] = "1"; |
| 51 attributes["lastchecked"] = "2"; |
| 52 attributes["autoupdatecheckenabled"] = "0"; |
| 53 attributes["updatepolicy"] = "-1"; |
| 54 request = BuildProtocolRequest( |
| 55 "", "", "", "", "", "", "", "", |
| 56 base::MakeUnique<UpdaterState::Attributes>(attributes)); |
| 57 EXPECT_NE(std::string::npos, request.find(" domainjoined=\"1\"")); |
| 58 const std::string updater_element = |
| 59 "<updater autoupdatecheckenabled=\"0\" " |
| 60 "lastchecked=\"2\" laststarted=\"1\" name=\"Omaha\" " |
| 61 "updatepolicy=\"-1\" version=\"1.2.3.4\"/>"; |
| 62 #if defined(GOOGLE_CHROME_BUILD) |
| 63 EXPECT_NE(std::string::npos, request.find(updater_element)); |
| 64 #else |
| 65 EXPECT_EQ(std::string::npos, request.find(updater_element)); |
| 66 #endif // GOOGLE_CHROME_BUILD |
| 67 } |
| 68 |
| 69 } // namespace update_client |
OLD | NEW |