OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "base/version.h" | 15 #include "base/version.h" |
16 #include "chrome/browser/component_updater/cld_component_installer.h" | 16 #include "chrome/browser/component_updater/cld_component_installer.h" |
17 #include "components/translate/content/browser/data_file_browser_cld_data_provid
er.h" | 17 #include "components/translate/content/browser/browser_cld_data_provider.h" |
18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
19 #include "testing/platform_test.h" | 19 #include "testing/platform_test.h" |
20 | 20 |
| 21 using component_updater::CldComponentInstallerTraits; |
| 22 |
21 namespace { | 23 namespace { |
22 // This has to match what's in cld_component_installer.cc. | 24 // This has to match what's in cld_component_installer.cc. |
23 const base::FilePath::CharType kTestCldDataFileName[] = | 25 const base::FilePath::CharType kTestCldDataFileName[] = |
24 FILE_PATH_LITERAL("cld2_data.bin"); | 26 FILE_PATH_LITERAL("cld2_data.bin"); |
| 27 |
25 } // namespace | 28 } // namespace |
26 | 29 |
27 namespace component_updater { | 30 namespace component_updater { |
28 | 31 |
29 class CldComponentInstallerTest : public PlatformTest { | 32 class CldComponentInstallerTest : public PlatformTest { |
30 public: | 33 public: |
31 CldComponentInstallerTest() {} | 34 CldComponentInstallerTest() {} |
32 virtual void SetUp() OVERRIDE { | 35 virtual void SetUp() OVERRIDE { |
33 PlatformTest::SetUp(); | 36 PlatformTest::SetUp(); |
34 | 37 |
35 // ScopedTempDir automatically does a recursive delete on the entire | 38 // ScopedTempDir automatically does a recursive delete on the entire |
36 // directory in its destructor, so no cleanup is required in TearDown. | 39 // directory in its destructor, so no cleanup is required in TearDown. |
37 // Note that all files created by this test case are created within the | 40 // Note that all files created by this test case are created within the |
38 // directory that is created here, so even though they are not explicitly | 41 // directory that is created here, so even though they are not explicitly |
39 // created *as temp files*, they will still get cleaned up automagically. | 42 // created *as temp files*, they will still get cleaned up automagically. |
40 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 43 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
41 | 44 |
42 // The "latest CLD data file" is a static piece of information, and thus | 45 // The "latest CLD data file" is a static piece of information, and thus |
43 // for correctness we empty it before each test. | 46 // for correctness we empty it before each test. |
44 component_updater::CldComponentInstallerTraits::SetLatestCldDataFile( | 47 CldComponentInstallerTraits::SetLatestCldDataFile(base::FilePath()); |
45 base::FilePath()); | |
46 base::FilePath path_now = | 48 base::FilePath path_now = |
47 translate::DataFileBrowserCldDataProvider::GetCldDataFilePath(); | 49 CldComponentInstallerTraits::GetLatestCldDataFile(); |
48 ASSERT_TRUE(path_now.empty()); | 50 ASSERT_TRUE(path_now.empty()); |
49 } | 51 } |
50 | 52 |
51 protected: | 53 protected: |
52 base::ScopedTempDir temp_dir_; | 54 base::ScopedTempDir temp_dir_; |
53 component_updater::CldComponentInstallerTraits traits_; | 55 CldComponentInstallerTraits traits_; |
54 | 56 |
55 private: | 57 private: |
56 DISALLOW_COPY_AND_ASSIGN(CldComponentInstallerTest); | 58 DISALLOW_COPY_AND_ASSIGN(CldComponentInstallerTest); |
57 }; | 59 }; |
58 | 60 |
59 TEST_F(CldComponentInstallerTest, SetLatestCldDataFile) { | 61 TEST_F(CldComponentInstallerTest, SetLatestCldDataFile) { |
60 const base::FilePath expected(FILE_PATH_LITERAL("test/foo.test")); | 62 const base::FilePath expected(FILE_PATH_LITERAL("test/foo.test")); |
61 component_updater::CldComponentInstallerTraits::SetLatestCldDataFile( | 63 CldComponentInstallerTraits::SetLatestCldDataFile(expected); |
62 expected); | |
63 base::FilePath result = | 64 base::FilePath result = |
64 translate::DataFileBrowserCldDataProvider::GetCldDataFilePath(); | 65 CldComponentInstallerTraits::GetLatestCldDataFile(); |
65 ASSERT_EQ(expected, result); | 66 ASSERT_EQ(expected, result); |
66 } | 67 } |
67 | 68 |
68 TEST_F(CldComponentInstallerTest, VerifyInstallation) { | 69 TEST_F(CldComponentInstallerTest, VerifyInstallation) { |
69 // All files are created within a ScopedTempDir, which deletes all | 70 // All files are created within a ScopedTempDir, which deletes all |
70 // children when its destructor is called (at the end of each test). | 71 // children when its destructor is called (at the end of each test). |
71 ASSERT_FALSE(traits_.VerifyInstallation(temp_dir_.path())); | 72 ASSERT_FALSE(traits_.VerifyInstallation(temp_dir_.path())); |
72 const base::FilePath data_file_dir = | 73 const base::FilePath data_file_dir = |
73 temp_dir_.path().Append(FILE_PATH_LITERAL("_platform_specific")).Append( | 74 temp_dir_.path().Append(FILE_PATH_LITERAL("_platform_specific")).Append( |
74 FILE_PATH_LITERAL("all")); | 75 FILE_PATH_LITERAL("all")); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 TEST_F(CldComponentInstallerTest, GetName) { | 109 TEST_F(CldComponentInstallerTest, GetName) { |
109 ASSERT_FALSE(traits_.GetName().empty()); | 110 ASSERT_FALSE(traits_.GetName().empty()); |
110 } | 111 } |
111 | 112 |
112 TEST_F(CldComponentInstallerTest, ComponentReady) { | 113 TEST_F(CldComponentInstallerTest, ComponentReady) { |
113 scoped_ptr<base::DictionaryValue> manifest; | 114 scoped_ptr<base::DictionaryValue> manifest; |
114 const base::FilePath install_dir(FILE_PATH_LITERAL("/foo")); | 115 const base::FilePath install_dir(FILE_PATH_LITERAL("/foo")); |
115 const base::Version version("1.2.3.4"); | 116 const base::Version version("1.2.3.4"); |
116 traits_.ComponentReady(version, install_dir, manifest.Pass()); | 117 traits_.ComponentReady(version, install_dir, manifest.Pass()); |
117 base::FilePath result = | 118 base::FilePath result = |
118 translate::DataFileBrowserCldDataProvider::GetCldDataFilePath(); | 119 CldComponentInstallerTraits::GetLatestCldDataFile(); |
119 ASSERT_TRUE(StartsWith(result.AsUTF16Unsafe(), | 120 ASSERT_TRUE(StartsWith(result.AsUTF16Unsafe(), |
120 install_dir.AsUTF16Unsafe(), | 121 install_dir.AsUTF16Unsafe(), |
121 true)); | 122 true)); |
122 ASSERT_TRUE(EndsWith(result.value(), kTestCldDataFileName, true)); | 123 ASSERT_TRUE(EndsWith(result.value(), kTestCldDataFileName, true)); |
123 } | 124 } |
124 | 125 |
125 } // namespace component_updater | 126 } // namespace component_updater |
OLD | NEW |