OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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 <vector> | |
6 | |
7 #include "base/file_util.h" | |
8 #include "base/files/file_path.h" | |
9 #include "base/files/scoped_temp_dir.h" | |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "base/run_loop.h" | |
12 #include "base/strings/string_util.h" | |
13 #include "base/strings/utf_string_conversions.h" | |
14 #include "base/values.h" | |
15 #include "base/version.h" | |
16 #include "chrome/browser/component_updater/cld_component_installer.h" | |
17 #include "chrome/common/chrome_constants.h" | |
18 #include "chrome/common/chrome_paths.h" | |
19 #include "testing/gtest/include/gtest/gtest.h" | |
20 #include "testing/platform_test.h" | |
21 | |
22 namespace component_updater { | |
23 | |
24 class CldComponentInstallerTest : public PlatformTest { | |
25 public: | |
26 virtual void SetUp() { | |
27 PlatformTest::SetUp(); | |
28 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
| |
29 } | |
30 | |
31 base::ScopedTempDir temp_dir_; | |
32 component_updater::CldComponentInstallerTraits traits; | |
33 }; | |
34 | |
35 TEST_F(CldComponentInstallerTest, SetLatestCldDataFile) { | |
36 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.
| |
37 ASSERT_FALSE(component_updater::GetLatestCldDataFile( | |
38 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
| |
39 const base::FilePath expected(FILE_PATH_LITERAL("test/foo.test")); | |
40 traits.SetLatestCldDataFile(expected); | |
41 | |
42 base::FilePath result; | |
43 ASSERT_TRUE(component_updater::GetLatestCldDataFile(&result)); | |
44 ASSERT_EQ(expected, result); | |
45 } | |
46 | |
47 TEST_F(CldComponentInstallerTest, VerifyInstallation) { | |
48 ASSERT_FALSE(traits.VerifyInstallation(temp_dir_.path())); | |
49 const base::FilePath data_file_dir = temp_dir_.path() | |
50 .Append(FILE_PATH_LITERAL("_platform_specific")) | |
51 .Append(FILE_PATH_LITERAL("all")); | |
52 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
| |
53 const base::FilePath data_file = data_file_dir | |
54 .Append(chrome::kCLDDataFilename); | |
55 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.
| |
56 const size_t length = arraysize(test_data) - 1; | |
57 ASSERT_EQ(static_cast<int>(length), | |
58 base::WriteFile(data_file, test_data, length)); | |
59 ASSERT_TRUE(traits.VerifyInstallation(temp_dir_.path())); | |
60 } | |
61 | |
62 TEST_F(CldComponentInstallerTest, OnCustomInstall) { | |
63 const base::DictionaryValue manifest; | |
64 const base::FilePath install_dir; | |
65 // Sanity: shouldn't crash. | |
66 ASSERT_TRUE(traits.OnCustomInstall(manifest, install_dir)); | |
67 } | |
68 | |
69 TEST_F(CldComponentInstallerTest, GetInstalledPath) { | |
70 const base::FilePath base_dir; | |
71 const base::FilePath result = traits.GetInstalledPath(base_dir); | |
72 ASSERT_TRUE(EndsWith(result.value(), chrome::kCLDDataFilename, true)); | |
73 } | |
74 | |
75 TEST_F(CldComponentInstallerTest, GetBaseDirectory) { | |
76 const base::FilePath result = traits.GetBaseDirectory(); | |
77 ASSERT_FALSE(result.empty()); | |
78 } | |
79 | |
80 TEST_F(CldComponentInstallerTest, GetHash) { | |
81 std::vector<uint8> hash; | |
82 traits.GetHash(&hash); | |
83 ASSERT_EQ(static_cast<size_t>(32), hash.size()); | |
84 } | |
85 | |
86 TEST_F(CldComponentInstallerTest, GetName) { | |
87 ASSERT_FALSE(traits.GetName().empty()); | |
88 } | |
89 | |
90 TEST_F(CldComponentInstallerTest, ComponentReady) { | |
91 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
| |
92 ASSERT_FALSE(component_updater::GetLatestCldDataFile( | |
93 static_cast<base::FilePath*>(NULL))); | |
94 scoped_ptr<base::DictionaryValue> manifest; | |
95 const base::FilePath install_dir(FILE_PATH_LITERAL("/foo")); | |
96 const base::Version version("1.2.3.4"); | |
97 traits.ComponentReady(version, install_dir, manifest.Pass()); | |
98 base::FilePath result; | |
99 ASSERT_TRUE(component_updater::GetLatestCldDataFile(&result)); | |
100 ASSERT_TRUE(StartsWith(base::ASCIIToUTF16(result.value()), | |
101 base::ASCIIToUTF16(install_dir.value()), true)); | |
102 ASSERT_TRUE(EndsWith(result.value(), chrome::kCLDDataFilename, true)); | |
103 } | |
104 | |
105 } // namespace component_updater | |
OLD | NEW |