Index: chrome/browser/component_updater/cros_component_installer_unittest.cc |
diff --git a/chrome/browser/component_updater/cros_component_installer_unittest.cc b/chrome/browser/component_updater/cros_component_installer_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e9ac1f5762c721106a12641439c81453178ef218 |
--- /dev/null |
+++ b/chrome/browser/component_updater/cros_component_installer_unittest.cc |
@@ -0,0 +1,145 @@ |
+// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "base/metrics/field_trial.h" |
+#include "base/run_loop.h" |
+#include "base/test/test_simple_task_runner.h" |
+#include "base/threading/thread_task_runner_handle.h" |
+#include "chrome/browser/component_updater/cros_component_installer.h" |
+#include "chrome/test/base/testing_browser_process.h" |
+#include "components/component_updater/mock_component_updater_service.h" |
+#include "content/public/test/test_browser_thread_bundle.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+#include "testing/platform_test.h" |
+ |
+namespace component_updater { |
+ |
+class CrOSMockComponentUpdateService |
+ : public component_updater::MockComponentUpdateService { |
+ public: |
+ CrOSMockComponentUpdateService() {} |
+ ~CrOSMockComponentUpdateService() override {} |
+ |
+ scoped_refptr<base::SequencedTaskRunner> GetSequencedTaskRunner() override { |
+ return base::ThreadTaskRunnerHandle::Get(); |
+ } |
+ |
+ private: |
+ content::TestBrowserThreadBundle thread_bundle_; |
+ DISALLOW_COPY_AND_ASSIGN(CrOSMockComponentUpdateService); |
+}; |
+ |
+class CrOSComponentInstallerTest : public PlatformTest { |
+ public: |
+ CrOSComponentInstallerTest() {} |
+ |
+ void SetUp() override { PlatformTest::SetUp(); } |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(CrOSComponentInstallerTest); |
+}; |
+TEST_F(CrOSComponentInstallerTest, ParseValidConfig) { |
+ ConfigParser parser; |
+ std::vector<ConfigParser::Result> result; |
+ std::string content = |
+ "<components>" |
+ " <component name='cups' dir_name='cups' " |
+ "sha2hashstr='" |
+ "00001111222233334444555566667777000011112222333344445555AAAAFFFF'></" |
+ "component>" |
+ " <component name='samba' dir_name='samba' " |
+ "sha2hashstr='" |
+ "0000111122223333444455556666777700001111222233334444555566667777'></" |
+ "component>" |
+ "</components>"; |
+ parser.Parse(content, result); |
+ EXPECT_EQ(2, (int)result.size()); |
+ EXPECT_EQ("cups", result[0].dir_name); |
+ EXPECT_EQ("cups", result[0].name); |
+ EXPECT_EQ("samba", result[1].dir_name); |
+ EXPECT_EQ("samba", result[1].name); |
+ EXPECT_EQ("FFFF", result[0].sha2hashstr.substr(60)); |
+ EXPECT_EQ("7777", result[1].sha2hashstr.substr(60)); |
+} |
+ |
+TEST_F(CrOSComponentInstallerTest, ParseInValid1Config) { |
+ ConfigParser parser; |
+ std::vector<ConfigParser::Result> result; |
+ std::string content = |
+ "<components>" |
+ " <component name='cups' dir_name='cups'></component>" |
+ " <component name='samba' dir_name='samba' " |
+ "sha2hashstr='" |
+ "0000111122223333444455556666777700001111222233334444555566667777'></" |
+ "component>" |
+ "</components>"; |
+ parser.Parse(content, result); |
+ EXPECT_EQ(0, (int)result.size()); |
+} |
+ |
+TEST_F(CrOSComponentInstallerTest, ParseInValid2Config) { |
+ ConfigParser parser; |
+ std::vector<ConfigParser::Result> result; |
+ std::string content = |
+ "<components>" |
+ " <component name='' dir_name='cups' " |
+ "sha2hashstr='" |
+ "00001111222233334444555566667777000011112222333344445555AAAAFFFF'></" |
+ "component>" |
+ " <component name='samba' dir_name='samba' " |
+ "sha2hashstr='" |
+ "0000111122223333444455556666777700001111222233334444555566667777'></" |
+ "component>" |
+ "</components>"; |
+ parser.Parse(content, result); |
+ EXPECT_EQ(0, (int)result.size()); |
+} |
+TEST_F(CrOSComponentInstallerTest, ParseInValid3Config) { |
+ ConfigParser parser; |
+ std::vector<ConfigParser::Result> result; |
+ std::string content = |
+ "<components>" |
+ " component name='cups' dir_name='cups' " |
+ "sha2hashstr='" |
+ "00001111222233334444555566667777000011112222333344445555AAAAFFFF'></" |
+ "component>" |
+ " <component name='samba' dir_name='samba' " |
+ "sha2hashstr='" |
+ "0000111122223333444455556666777700001111222233334444555566667777'></" |
+ "component>" |
+ "</components>"; |
+ parser.Parse(content, result); |
+ EXPECT_EQ(0, (int)result.size()); |
+} |
+TEST_F(CrOSComponentInstallerTest, ParseInValid4Config) { |
+ ConfigParser parser; |
+ std::vector<ConfigParser::Result> result; |
+ std::string content = |
+ "<components>" |
+ " <component name='cups' dir_name='cups' " |
+ "sha2hashstr='" |
+ "00001111222233334444555566667777000011112222333344445555AAAAFFFG'></" |
+ "component>" |
+ " <component name='samba' dir_name='samba' " |
+ "sha2hashstr='" |
+ "0000111122223333444455556666777700001111222233334444555566667777'></" |
+ "component>" |
+ "</components>"; |
+ parser.Parse(content, result); |
+ EXPECT_EQ(0, (int)result.size()); |
+} |
+TEST_F(CrOSComponentInstallerTest, ComponentUpdateService) { |
+ std::unique_ptr<CrOSMockComponentUpdateService> cus( |
+ new CrOSMockComponentUpdateService()); |
+ EXPECT_CALL(*cus, RegisterComponent(testing::_)).Times(1); |
+ |
+ ConfigParser::Result result; |
+ result.name = "cups"; |
+ result.dir_name = "cups"; |
+ result.sha2hashstr = |
+ "00001111222233334444555566667777000011112222333344445555AAAAFFFF"; |
+ RegisterCrOSComponent(cus.get(), result); |
+ base::RunLoop().RunUntilIdle(); |
+} |
+} // namespace component_updater |