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 <stdint.h> | 5 #include <stdint.h> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "base/version.h" | 16 #include "base/version.h" |
17 #include "chrome/browser/component_updater/cld_component_installer.h" | 17 #include "chrome/browser/component_updater/cld_component_installer.h" |
18 #include "components/translate/content/browser/browser_cld_data_provider.h" | 18 #include "components/translate/content/browser/browser_cld_data_provider.h" |
| 19 #include "components/translate/content/common/cld_data_source.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
20 #include "testing/platform_test.h" | 21 #include "testing/platform_test.h" |
21 | 22 |
22 using component_updater::CldComponentInstallerTraits; | 23 using component_updater::CldComponentInstallerTraits; |
23 | 24 |
24 namespace { | 25 namespace { |
25 // This has to match what's in cld_component_installer.cc. | 26 // This has to match what's in cld_component_installer.cc. |
26 const base::FilePath::CharType kTestCldDataFileName[] = | 27 const base::FilePath::CharType kTestCldDataFileName[] = |
27 FILE_PATH_LITERAL("cld2_data.bin"); | 28 FILE_PATH_LITERAL("cld2_data.bin"); |
28 | 29 |
29 } // namespace | 30 } // namespace |
30 | 31 |
31 namespace component_updater { | 32 namespace component_updater { |
32 | 33 |
33 class CldComponentInstallerTest : public PlatformTest { | 34 class CldComponentInstallerTest : public PlatformTest { |
34 public: | 35 public: |
35 CldComponentInstallerTest() {} | 36 CldComponentInstallerTest() {} |
36 void SetUp() override { | 37 void SetUp() override { |
37 PlatformTest::SetUp(); | 38 PlatformTest::SetUp(); |
| 39 translate::CldDataSource::DisableSanityChecksForTest(); |
38 | 40 |
39 // ScopedTempDir automatically does a recursive delete on the entire | 41 // ScopedTempDir automatically does a recursive delete on the entire |
40 // directory in its destructor, so no cleanup is required in TearDown. | 42 // directory in its destructor, so no cleanup is required in TearDown. |
41 // Note that all files created by this test case are created within the | 43 // Note that all files created by this test case are created within the |
42 // directory that is created here, so even though they are not explicitly | 44 // directory that is created here, so even though they are not explicitly |
43 // created *as temp files*, they will still get cleaned up automagically. | 45 // created *as temp files*, they will still get cleaned up automagically. |
44 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 46 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
45 | 47 |
46 // The "latest CLD data file" is a static piece of information, and thus | 48 // The "latest CLD data file" is a static piece of information, and thus |
47 // for correctness we empty it before each test. | 49 // for correctness we empty it before each test. |
48 CldComponentInstallerTraits::SetLatestCldDataFile(base::FilePath()); | 50 CldComponentInstallerTraits::SetLatestCldDataFile(base::FilePath()); |
49 base::FilePath path_now = | 51 base::FilePath path_now = |
50 CldComponentInstallerTraits::GetLatestCldDataFile(); | 52 CldComponentInstallerTraits::GetLatestCldDataFile(); |
51 ASSERT_TRUE(path_now.empty()); | 53 ASSERT_TRUE(path_now.empty()); |
52 } | 54 } |
53 | 55 |
| 56 void TearDown() override { |
| 57 // Restore sanity checks. |
| 58 translate::CldDataSource::EnableSanityChecksForTest(); |
| 59 } |
54 protected: | 60 protected: |
55 base::ScopedTempDir temp_dir_; | 61 base::ScopedTempDir temp_dir_; |
56 CldComponentInstallerTraits traits_; | 62 CldComponentInstallerTraits traits_; |
57 | 63 |
58 private: | 64 private: |
59 DISALLOW_COPY_AND_ASSIGN(CldComponentInstallerTest); | 65 DISALLOW_COPY_AND_ASSIGN(CldComponentInstallerTest); |
60 }; | 66 }; |
61 | 67 |
62 TEST_F(CldComponentInstallerTest, SetLatestCldDataFile) { | 68 TEST_F(CldComponentInstallerTest, SetLatestCldDataFile) { |
63 const base::FilePath expected(FILE_PATH_LITERAL("test/foo.test")); | 69 const base::FilePath expected(FILE_PATH_LITERAL("test/foo.test")); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 traits_.ComponentReady(version, install_dir, manifest.Pass()); | 125 traits_.ComponentReady(version, install_dir, manifest.Pass()); |
120 base::FilePath result = | 126 base::FilePath result = |
121 CldComponentInstallerTraits::GetLatestCldDataFile(); | 127 CldComponentInstallerTraits::GetLatestCldDataFile(); |
122 ASSERT_TRUE(StartsWith(result.AsUTF16Unsafe(), | 128 ASSERT_TRUE(StartsWith(result.AsUTF16Unsafe(), |
123 install_dir.AsUTF16Unsafe(), | 129 install_dir.AsUTF16Unsafe(), |
124 true)); | 130 true)); |
125 ASSERT_TRUE(EndsWith(result.value(), kTestCldDataFileName, true)); | 131 ASSERT_TRUE(EndsWith(result.value(), kTestCldDataFileName, true)); |
126 } | 132 } |
127 | 133 |
128 } // namespace component_updater | 134 } // namespace component_updater |
OLD | NEW |