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

Unified Diff: chrome/browser/component_updater/test/cld_component_installer_unittest.cc

Issue 280753003: Add unit tests for the CLD component installer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unused import Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/component_updater/cld_component_installer.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/component_updater/test/cld_component_installer_unittest.cc
diff --git a/chrome/browser/component_updater/test/cld_component_installer_unittest.cc b/chrome/browser/component_updater/test/cld_component_installer_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b12eed57b80e7cebcc74794e73661503309a11bc
--- /dev/null
+++ b/chrome/browser/component_updater/test/cld_component_installer_unittest.cc
@@ -0,0 +1,105 @@
+// Copyright 2014 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 <vector>
+
+#include "base/file_util.h"
+#include "base/files/file_path.h"
+#include "base/files/scoped_temp_dir.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/run_loop.h"
+#include "base/strings/string_util.h"
+#include "base/strings/utf_string_conversions.h"
+#include "base/values.h"
+#include "base/version.h"
+#include "chrome/browser/component_updater/cld_component_installer.h"
+#include "chrome/common/chrome_constants.h"
+#include "chrome/common/chrome_paths.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/platform_test.h"
+
+namespace component_updater {
+
+class CldComponentInstallerTest : public PlatformTest {
+ public:
+ virtual void SetUp() {
+ PlatformTest::SetUp();
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
Sorin Jianu 2014/05/14 10:46:19 Is the temp_dir_ cleaned up somewhere?
Andrew Hayden (chromium.org) 2014/05/14 16:17:29 The destructor of scoped_temp_dir does perform a r
+ }
+
+ base::ScopedTempDir temp_dir_;
+ component_updater::CldComponentInstallerTraits traits;
+};
+
+TEST_F(CldComponentInstallerTest, SetLatestCldDataFile) {
+ traits.SetLatestCldDataFile(base::FilePath()); // static state, yuck.
Sorin Jianu 2014/05/14 10:46:19 Please make the comment more specific if there is
Andrew Hayden (chromium.org) 2014/05/14 16:17:29 Done and moved into SetUp.
+ ASSERT_FALSE(component_updater::GetLatestCldDataFile(
+ static_cast<base::FilePath*>(NULL)));
Sorin Jianu 2014/05/14 10:46:19 static cast is not needed here most likely. Does t
Andrew Hayden (chromium.org) 2014/05/14 16:17:29 I chatted with Marcus about this and we considered
+ const base::FilePath expected(FILE_PATH_LITERAL("test/foo.test"));
+ traits.SetLatestCldDataFile(expected);
+
+ base::FilePath result;
+ ASSERT_TRUE(component_updater::GetLatestCldDataFile(&result));
+ ASSERT_EQ(expected, result);
+}
+
+TEST_F(CldComponentInstallerTest, VerifyInstallation) {
+ ASSERT_FALSE(traits.VerifyInstallation(temp_dir_.path()));
+ const base::FilePath data_file_dir = temp_dir_.path()
+ .Append(FILE_PATH_LITERAL("_platform_specific"))
+ .Append(FILE_PATH_LITERAL("all"));
+ ASSERT_TRUE(base::CreateDirectory(data_file_dir));
Sorin Jianu 2014/05/14 10:46:19 Is data_file_dir cleaned up? In general, are thes
Andrew Hayden (chromium.org) 2014/05/14 16:17:29 Yes, see earlier comment about the temp dir. I'll
+ const base::FilePath data_file = data_file_dir
+ .Append(chrome::kCLDDataFilename);
+ const char test_data[] = "fake cld2 data file content here :)";
Sorin Jianu 2014/05/14 10:46:19 we can use a std::string and don't bother with the
Andrew Hayden (chromium.org) 2014/05/14 16:17:29 Done.
+ const size_t length = arraysize(test_data) - 1;
+ ASSERT_EQ(static_cast<int>(length),
+ base::WriteFile(data_file, test_data, length));
+ ASSERT_TRUE(traits.VerifyInstallation(temp_dir_.path()));
+}
+
+TEST_F(CldComponentInstallerTest, OnCustomInstall) {
+ const base::DictionaryValue manifest;
+ const base::FilePath install_dir;
+ // Sanity: shouldn't crash.
+ ASSERT_TRUE(traits.OnCustomInstall(manifest, install_dir));
+}
+
+TEST_F(CldComponentInstallerTest, GetInstalledPath) {
+ const base::FilePath base_dir;
+ const base::FilePath result = traits.GetInstalledPath(base_dir);
+ ASSERT_TRUE(EndsWith(result.value(), chrome::kCLDDataFilename, true));
+}
+
+TEST_F(CldComponentInstallerTest, GetBaseDirectory) {
+ const base::FilePath result = traits.GetBaseDirectory();
+ ASSERT_FALSE(result.empty());
+}
+
+TEST_F(CldComponentInstallerTest, GetHash) {
+ std::vector<uint8> hash;
+ traits.GetHash(&hash);
+ ASSERT_EQ(static_cast<size_t>(32), hash.size());
+}
+
+TEST_F(CldComponentInstallerTest, GetName) {
+ ASSERT_FALSE(traits.GetName().empty());
+}
+
+TEST_F(CldComponentInstallerTest, ComponentReady) {
+ traits.SetLatestCldDataFile(base::FilePath()); // static state, yuck.
Sorin Jianu 2014/05/14 10:46:19 What is it being tested at lines 91-93?
Andrew Hayden (chromium.org) 2014/05/14 16:17:29 I needed to reset the latest cld file information
+ ASSERT_FALSE(component_updater::GetLatestCldDataFile(
+ static_cast<base::FilePath*>(NULL)));
+ scoped_ptr<base::DictionaryValue> manifest;
+ const base::FilePath install_dir(FILE_PATH_LITERAL("/foo"));
+ const base::Version version("1.2.3.4");
+ traits.ComponentReady(version, install_dir, manifest.Pass());
+ base::FilePath result;
+ ASSERT_TRUE(component_updater::GetLatestCldDataFile(&result));
+ ASSERT_TRUE(StartsWith(base::ASCIIToUTF16(result.value()),
+ base::ASCIIToUTF16(install_dir.value()), true));
+ ASSERT_TRUE(EndsWith(result.value(), chrome::kCLDDataFilename, true));
+}
+
+} // namespace component_updater
« no previous file with comments | « chrome/browser/component_updater/cld_component_installer.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698