Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: components/component_updater/default_component_installer_unittest.cc

Issue 2102083002: Allow component installers to specify a map of installer attributes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <iterator> 5 #include <iterator>
6 #include <string> 6 #include <string>
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 24 matching lines...) Expand all
35 namespace { 35 namespace {
36 36
37 // This hash corresponds to jebgalgnebhfojomionfpkfelancnnkf.crx. 37 // This hash corresponds to jebgalgnebhfojomionfpkfelancnnkf.crx.
38 const uint8_t kSha256Hash[] = {0x94, 0x16, 0x0b, 0x6d, 0x41, 0x75, 0xe9, 0xec, 38 const uint8_t kSha256Hash[] = {0x94, 0x16, 0x0b, 0x6d, 0x41, 0x75, 0xe9, 0xec,
39 0x8e, 0xd5, 0xfa, 0x54, 0xb0, 0xd2, 0xdd, 0xa5, 39 0x8e, 0xd5, 0xfa, 0x54, 0xb0, 0xd2, 0xdd, 0xa5,
40 0x6e, 0x05, 0x6b, 0xe8, 0x73, 0x47, 0xf6, 0xc4, 40 0x6e, 0x05, 0x6b, 0xe8, 0x73, 0x47, 0xf6, 0xc4,
41 0x11, 0x9f, 0xbc, 0xb3, 0x09, 0xb3, 0x5b, 0x40}; 41 0x11, 0x9f, 0xbc, 0xb3, 0x09, 0xb3, 0x5b, 0x40};
42 42
43 class MockUpdateClient : public UpdateClient { 43 class MockUpdateClient : public UpdateClient {
44 public: 44 public:
45 MockUpdateClient() {}; 45 MockUpdateClient() {}
46 MOCK_METHOD1(AddObserver, void(Observer* observer)); 46 MOCK_METHOD1(AddObserver, void(Observer* observer));
47 MOCK_METHOD1(RemoveObserver, void(Observer* observer)); 47 MOCK_METHOD1(RemoveObserver, void(Observer* observer));
48 MOCK_METHOD3(Install, 48 MOCK_METHOD3(Install,
49 void(const std::string& id, 49 void(const std::string& id,
50 const CrxDataCallback& crx_data_callback, 50 const CrxDataCallback& crx_data_callback,
51 const CompletionCallback& completion_callback)); 51 const CompletionCallback& completion_callback));
52 MOCK_METHOD3(Update, 52 MOCK_METHOD3(Update,
53 void(const std::vector<std::string>& ids, 53 void(const std::vector<std::string>& ids,
54 const CrxDataCallback& crx_data_callback, 54 const CrxDataCallback& crx_data_callback,
55 const CompletionCallback& completion_callback)); 55 const CompletionCallback& completion_callback));
56 MOCK_CONST_METHOD2(GetCrxUpdateState, 56 MOCK_CONST_METHOD2(GetCrxUpdateState,
57 bool(const std::string& id, CrxUpdateItem* update_item)); 57 bool(const std::string& id, CrxUpdateItem* update_item));
58 MOCK_CONST_METHOD1(IsUpdating, bool(const std::string& id)); 58 MOCK_CONST_METHOD1(IsUpdating, bool(const std::string& id));
59 MOCK_METHOD0(Stop, void()); 59 MOCK_METHOD0(Stop, void());
60 MOCK_METHOD3(SendUninstallPing, 60 MOCK_METHOD3(SendUninstallPing,
61 void(const std::string& id, const Version& version, int reason)); 61 void(const std::string& id, const Version& version, int reason));
62 62
63 private: 63 private:
64 ~MockUpdateClient() override {}; 64 ~MockUpdateClient() override {}
65 }; 65 };
66 66
67 class FakeInstallerTraits : public ComponentInstallerTraits { 67 class FakeInstallerTraits : public ComponentInstallerTraits {
68 public: 68 public:
69 ~FakeInstallerTraits() override {} 69 ~FakeInstallerTraits() override {}
70 70
71 bool VerifyInstallation(const base::DictionaryValue& manifest, 71 bool VerifyInstallation(const base::DictionaryValue& manifest,
72 const base::FilePath& dir) const override { 72 const base::FilePath& dir) const override {
73 return true; 73 return true;
74 } 74 }
(...skipping 13 matching lines...) Expand all
88 std::unique_ptr<base::DictionaryValue> manifest) override {} 88 std::unique_ptr<base::DictionaryValue> manifest) override {}
89 89
90 base::FilePath GetRelativeInstallDir() const override { 90 base::FilePath GetRelativeInstallDir() const override {
91 return base::FilePath(FILE_PATH_LITERAL("fake")); 91 return base::FilePath(FILE_PATH_LITERAL("fake"));
92 } 92 }
93 93
94 void GetHash(std::vector<uint8_t>* hash) const override { GetPkHash(hash); } 94 void GetHash(std::vector<uint8_t>* hash) const override { GetPkHash(hash); }
95 95
96 std::string GetName() const override { return "fake name"; } 96 std::string GetName() const override { return "fake name"; }
97 97
98 std::string GetAp() const override { return "fake-ap"; } 98 update_client::InstallerAttributes GetInstallerAttributes() const override {
99 update_client::InstallerAttributes installer_attributes;
100 installer_attributes["ap"] = "fake-ap";
101 installer_attributes["is-enterprise"] = "1";
102 return installer_attributes;
103 }
99 104
100 private: 105 private:
101 static void GetPkHash(std::vector<uint8_t>* hash) { 106 static void GetPkHash(std::vector<uint8_t>* hash) {
102 hash->assign(std::begin(kSha256Hash), std::end(kSha256Hash)); 107 hash->assign(std::begin(kSha256Hash), std::end(kSha256Hash));
103 } 108 }
104 }; 109 };
105 110
106 class DefaultComponentInstallerTest : public testing::Test { 111 class DefaultComponentInstallerTest : public testing::Test {
107 public: 112 public:
108 DefaultComponentInstallerTest(); 113 DefaultComponentInstallerTest();
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 201
197 DefaultComponentInstaller* installer = 202 DefaultComponentInstaller* installer =
198 new DefaultComponentInstaller(std::move(traits)); 203 new DefaultComponentInstaller(std::move(traits));
199 installer->Register(component_updater(), base::Closure()); 204 installer->Register(component_updater(), base::Closure());
200 205
201 RunThreads(); 206 RunThreads();
202 207
203 CrxUpdateItem item; 208 CrxUpdateItem item;
204 EXPECT_TRUE(component_updater()->GetComponentDetails(id, &item)); 209 EXPECT_TRUE(component_updater()->GetComponentDetails(id, &item));
205 const CrxComponent& component(item.component); 210 const CrxComponent& component(item.component);
211
212 update_client::InstallerAttributes expected_attrs;
213 expected_attrs["ap"] = "fake-ap";
214 expected_attrs["is-enterprise"] = "1";
215
206 EXPECT_EQ( 216 EXPECT_EQ(
207 std::vector<uint8_t>(std::begin(kSha256Hash), std::end(kSha256Hash)), 217 std::vector<uint8_t>(std::begin(kSha256Hash), std::end(kSha256Hash)),
208 component.pk_hash); 218 component.pk_hash);
209 EXPECT_EQ(base::Version("0.0.0.0"), component.version); 219 EXPECT_EQ(base::Version("0.0.0.0"), component.version);
210 EXPECT_TRUE(component.fingerprint.empty()); 220 EXPECT_TRUE(component.fingerprint.empty());
211 EXPECT_STREQ("fake name", component.name.c_str()); 221 EXPECT_STREQ("fake name", component.name.c_str());
212 EXPECT_STREQ("fake-ap", component.ap.c_str()); 222 EXPECT_EQ(expected_attrs, component.installer_attributes);
213 EXPECT_TRUE(component.requires_network_encryption); 223 EXPECT_TRUE(component.requires_network_encryption);
214 } 224 }
215 225
216 } // namespace component_updater 226 } // namespace component_updater
OLDNEW
« no previous file with comments | « components/component_updater/default_component_installer.cc ('k') | components/update_client/update_checker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698