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

Side by Side Diff: chrome/browser/component_updater/cld_component_installer_unittest.cc

Issue 1102103002: Move the unit tests files side-by-side with the corresponding .cc files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 8 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 unified diff | Download patch
OLDNEW
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 "components/translate/content/common/cld_data_source.h"
20 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "testing/platform_test.h" 21 #include "testing/platform_test.h"
22 22
23 using component_updater::CldComponentInstallerTraits; 23 using component_updater::CldComponentInstallerTraits;
24 24
25 namespace { 25 namespace {
26
26 // This has to match what's in cld_component_installer.cc. 27 // This has to match what's in cld_component_installer.cc.
27 const base::FilePath::CharType kTestCldDataFileName[] = 28 const base::FilePath::CharType kTestCldDataFileName[] =
28 FILE_PATH_LITERAL("cld2_data.bin"); 29 FILE_PATH_LITERAL("cld2_data.bin");
29 30
30 } // namespace 31 } // namespace
31 32
32 namespace component_updater { 33 namespace component_updater {
33 34
34 class CldComponentInstallerTest : public PlatformTest { 35 class CldComponentInstallerTest : public PlatformTest {
35 public: 36 public:
(...skipping 14 matching lines...) Expand all
50 CldComponentInstallerTraits::SetLatestCldDataFile(base::FilePath()); 51 CldComponentInstallerTraits::SetLatestCldDataFile(base::FilePath());
51 base::FilePath path_now = 52 base::FilePath path_now =
52 CldComponentInstallerTraits::GetLatestCldDataFile(); 53 CldComponentInstallerTraits::GetLatestCldDataFile();
53 ASSERT_TRUE(path_now.empty()); 54 ASSERT_TRUE(path_now.empty());
54 } 55 }
55 56
56 void TearDown() override { 57 void TearDown() override {
57 // Restore sanity checks. 58 // Restore sanity checks.
58 translate::CldDataSource::EnableSanityChecksForTest(); 59 translate::CldDataSource::EnableSanityChecksForTest();
59 } 60 }
61
60 protected: 62 protected:
61 base::ScopedTempDir temp_dir_; 63 base::ScopedTempDir temp_dir_;
62 CldComponentInstallerTraits traits_; 64 CldComponentInstallerTraits traits_;
63 65
64 private: 66 private:
65 DISALLOW_COPY_AND_ASSIGN(CldComponentInstallerTest); 67 DISALLOW_COPY_AND_ASSIGN(CldComponentInstallerTest);
66 }; 68 };
67 69
68 TEST_F(CldComponentInstallerTest, SetLatestCldDataFile) { 70 TEST_F(CldComponentInstallerTest, SetLatestCldDataFile) {
69 const base::FilePath expected(FILE_PATH_LITERAL("test/foo.test")); 71 const base::FilePath expected(FILE_PATH_LITERAL("test/foo.test"));
70 CldComponentInstallerTraits::SetLatestCldDataFile(expected); 72 CldComponentInstallerTraits::SetLatestCldDataFile(expected);
71 base::FilePath result = 73 base::FilePath result = CldComponentInstallerTraits::GetLatestCldDataFile();
72 CldComponentInstallerTraits::GetLatestCldDataFile();
73 ASSERT_EQ(expected, result); 74 ASSERT_EQ(expected, result);
74 } 75 }
75 76
76 TEST_F(CldComponentInstallerTest, VerifyInstallation) { 77 TEST_F(CldComponentInstallerTest, VerifyInstallation) {
77 // All files are created within a ScopedTempDir, which deletes all 78 // All files are created within a ScopedTempDir, which deletes all
78 // children when its destructor is called (at the end of each test). 79 // children when its destructor is called (at the end of each test).
79 const base::DictionaryValue manifest; 80 const base::DictionaryValue manifest;
80 ASSERT_FALSE(traits_.VerifyInstallation(manifest, temp_dir_.path())); 81 ASSERT_FALSE(traits_.VerifyInstallation(manifest, temp_dir_.path()));
81 const base::FilePath data_file_dir = 82 const base::FilePath data_file_dir =
82 temp_dir_.path().Append(FILE_PATH_LITERAL("_platform_specific")).Append( 83 temp_dir_.path()
83 FILE_PATH_LITERAL("all")); 84 .Append(FILE_PATH_LITERAL("_platform_specific"))
85 .Append(FILE_PATH_LITERAL("all"));
84 ASSERT_TRUE(base::CreateDirectory(data_file_dir)); 86 ASSERT_TRUE(base::CreateDirectory(data_file_dir));
85 const base::FilePath data_file = data_file_dir.Append(kTestCldDataFileName); 87 const base::FilePath data_file = data_file_dir.Append(kTestCldDataFileName);
86 const std::string test_data("fake cld2 data file content here :)"); 88 const std::string test_data("fake cld2 data file content here :)");
87 ASSERT_EQ(static_cast<int32>(test_data.length()), 89 ASSERT_EQ(static_cast<int32>(test_data.length()),
88 base::WriteFile(data_file, test_data.c_str(), test_data.length())); 90 base::WriteFile(data_file, test_data.c_str(), test_data.length()));
89 ASSERT_TRUE(traits_.VerifyInstallation(manifest, temp_dir_.path())); 91 ASSERT_TRUE(traits_.VerifyInstallation(manifest, temp_dir_.path()));
90 } 92 }
91 93
92 TEST_F(CldComponentInstallerTest, OnCustomInstall) { 94 TEST_F(CldComponentInstallerTest, OnCustomInstall) {
93 const base::DictionaryValue manifest; 95 const base::DictionaryValue manifest;
(...skipping 22 matching lines...) Expand all
116 118
117 TEST_F(CldComponentInstallerTest, GetName) { 119 TEST_F(CldComponentInstallerTest, GetName) {
118 ASSERT_FALSE(traits_.GetName().empty()); 120 ASSERT_FALSE(traits_.GetName().empty());
119 } 121 }
120 122
121 TEST_F(CldComponentInstallerTest, ComponentReady) { 123 TEST_F(CldComponentInstallerTest, ComponentReady) {
122 scoped_ptr<base::DictionaryValue> manifest; 124 scoped_ptr<base::DictionaryValue> manifest;
123 const base::FilePath install_dir(FILE_PATH_LITERAL("/foo")); 125 const base::FilePath install_dir(FILE_PATH_LITERAL("/foo"));
124 const base::Version version("1.2.3.4"); 126 const base::Version version("1.2.3.4");
125 traits_.ComponentReady(version, install_dir, manifest.Pass()); 127 traits_.ComponentReady(version, install_dir, manifest.Pass());
126 base::FilePath result = 128 base::FilePath result = CldComponentInstallerTraits::GetLatestCldDataFile();
127 CldComponentInstallerTraits::GetLatestCldDataFile(); 129 ASSERT_TRUE(
128 ASSERT_TRUE(StartsWith(result.AsUTF16Unsafe(), 130 StartsWith(result.AsUTF16Unsafe(), install_dir.AsUTF16Unsafe(), true));
129 install_dir.AsUTF16Unsafe(),
130 true));
131 ASSERT_TRUE(EndsWith(result.value(), kTestCldDataFileName, true)); 131 ASSERT_TRUE(EndsWith(result.value(), kTestCldDataFileName, true));
132 } 132 }
133 133
134 } // namespace component_updater 134 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698