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

Side by Side Diff: chrome/browser/component_updater/cros_component_installer_unittest.cc

Issue 2898063002: Hold cros_component_installers in browser_process. (Closed)
Patch Set: address comments from waffles Created 3 years, 7 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
(Empty)
1 // Copyright 2017 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 "chrome/browser/component_updater/cros_component_installer.h"
6
7 #include "base/memory/ptr_util.h"
8 #include "base/run_loop.h"
9 #include "base/test/test_simple_task_runner.h"
10 #include "base/threading/thread_task_runner_handle.h"
11 #include "chrome/browser/browser_process_platform_part_chromeos.h"
12 #include "chrome/test/base/testing_browser_process.h"
13 #include "components/component_updater/mock_component_updater_service.h"
14 #include "content/public/test/test_browser_thread_bundle.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "testing/platform_test.h"
17
18 namespace component_updater {
19
20 class CrOSMockComponentUpdateService
21 : public component_updater::MockComponentUpdateService {
22 public:
23 CrOSMockComponentUpdateService() {}
24 ~CrOSMockComponentUpdateService() override {}
25 scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() override {
26 return base::ThreadTaskRunnerHandle::Get();
27 }
28
29 private:
30 DISALLOW_COPY_AND_ASSIGN(CrOSMockComponentUpdateService);
31 };
32
33 class CrOSComponentInstallerTest : public PlatformTest {
34 public:
35 CrOSComponentInstallerTest() {}
36 void SetUp() override { PlatformTest::SetUp(); }
37
38 private:
39 content::TestBrowserThreadBundle thread_bundle_;
40 DISALLOW_COPY_AND_ASSIGN(CrOSComponentInstallerTest);
41 };
42
43 class FakeInstallerTraits : public ComponentInstallerTraits {
44 public:
45 ~FakeInstallerTraits() override {}
46
47 bool VerifyInstallation(const base::DictionaryValue& manifest,
48 const base::FilePath& dir) const override {
49 return true;
50 }
51
52 bool SupportsGroupPolicyEnabledComponentUpdates() const override {
53 return true;
54 }
55
56 bool RequiresNetworkEncryption() const override { return true; }
57
58 update_client::CrxInstaller::Result OnCustomInstall(
59 const base::DictionaryValue& manifest,
60 const base::FilePath& install_dir) override {
61 return update_client::CrxInstaller::Result(0);
62 }
63
64 void ComponentReady(
65 const base::Version& version,
66 const base::FilePath& install_dir,
67 std::unique_ptr<base::DictionaryValue> manifest) override {}
68
69 base::FilePath GetRelativeInstallDir() const override {
70 return base::FilePath(FILE_PATH_LITERAL("fake"));
71 }
72
73 void GetHash(std::vector<uint8_t>* hash) const override {}
74
75 std::string GetName() const override { return "fake name"; }
76
77 update_client::InstallerAttributes GetInstallerAttributes() const override {
78 update_client::InstallerAttributes installer_attributes;
79 return installer_attributes;
80 }
81
82 std::vector<std::string> GetMimeTypes() const override {
83 return std::vector<std::string>();
84 }
85 };
86 TEST_F(CrOSComponentInstallerTest, BPPPComponentManifest) {
87 auto bppp = new BrowserProcessPlatformPart();
88 ASSERT_EQ(bppp->IsCompatibleCrOSComponent("a"), false);
89 bppp->AddCompatibleCrOSComponent("a");
90 ASSERT_EQ(bppp->IsCompatibleCrOSComponent("a"), true);
91 }
92 TEST_F(CrOSComponentInstallerTest, RegisterComponentSuccess) {
93 std::unique_ptr<CrOSMockComponentUpdateService> cus =
94 base::MakeUnique<CrOSMockComponentUpdateService>();
95 EXPECT_CALL(*cus, RegisterComponent(testing::_)).Times(1);
96 component_updater::CrOSComponent::InstallCrOSComponent(
97 "epson-inkjet-printer-escpr", update_client::Callback());
98 base::RunLoop().RunUntilIdle();
99 }
100 TEST_F(CrOSComponentInstallerTest, RegisterComponentFail) {
101 std::unique_ptr<CrOSMockComponentUpdateService> cus =
102 base::MakeUnique<CrOSMockComponentUpdateService>();
103 EXPECT_CALL(*cus, RegisterComponent(testing::_)).Times(0);
104 component_updater::CrOSComponent::InstallCrOSComponent(
105 "a-component-not-exist", update_client::Callback());
106 base::RunLoop().RunUntilIdle();
107 }
108
109 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698