aw_package_names_allowlist_component_installer_policy_unittest.cc 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Copyright 2021 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 "android_webview/nonembedded/component_updater/installer_policies/aw_package_names_allowlist_component_installer_policy.h"
  5. #include <vector>
  6. #include "android_webview/common/aw_switches.h"
  7. #include "base/memory/ref_counted.h"
  8. #include "base/memory/scoped_refptr.h"
  9. #include "base/test/task_environment.h"
  10. #include "base/values.h"
  11. #include "base/version.h"
  12. #include "components/update_client/utils.h"
  13. #include "testing/gtest/include/gtest/gtest.h"
  14. namespace android_webview {
  15. const uint8_t kWebViewAppsPackageNamesAllowlistPublicKeySHA256[32] = {
  16. 0x04, 0xcb, 0xb8, 0xd5, 0xf9, 0x36, 0x2b, 0x36, 0x04, 0xb2, 0x60,
  17. 0xaf, 0x9c, 0x04, 0xa1, 0x08, 0xa3, 0xe9, 0xdc, 0x92, 0x46, 0xe7,
  18. 0xae, 0xc8, 0x3e, 0x32, 0x6f, 0x74, 0x43, 0x02, 0xf3, 0x7e};
  19. class AwPackageNamesAllowlistComponentInstallerPolicyTest
  20. : public ::testing::Test {
  21. public:
  22. AwPackageNamesAllowlistComponentInstallerPolicyTest() = default;
  23. protected:
  24. base::test::TaskEnvironment env_;
  25. };
  26. // TODO(crbug.com/1202702): Add a test that calls
  27. // RegisterWebViewAppsPackageNamesAllowlistComponent() and checks that
  28. // registration_finished is called.
  29. TEST_F(AwPackageNamesAllowlistComponentInstallerPolicyTest, ComponentHash) {
  30. auto policy =
  31. std::make_unique<AwPackageNamesAllowlistComponentInstallerPolicy>();
  32. std::vector<uint8_t> expected;
  33. expected.assign(
  34. kWebViewAppsPackageNamesAllowlistPublicKeySHA256,
  35. kWebViewAppsPackageNamesAllowlistPublicKeySHA256 +
  36. std::size(kWebViewAppsPackageNamesAllowlistPublicKeySHA256));
  37. std::vector<uint8_t> actual;
  38. policy->GetHash(&actual);
  39. EXPECT_EQ(expected, actual);
  40. std::string expected_id = "aemllinfpjdgcldgaelcgakpjmaekbai";
  41. std::string actual_id = update_client::GetCrxIdFromPublicKeyHash(actual);
  42. EXPECT_EQ(expected_id, actual_id);
  43. }
  44. } // namespace android_webview