[M85 Dev][EFL] Fix crashes at webview launch
[platform/framework/web/chromium-efl.git] / base / file_version_info_win_unittest.cc
1 // Copyright (c) 2011 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 "base/file_version_info_win.h"
6
7 #include <windows.h>
8
9 #include <stddef.h>
10
11 #include <memory>
12
13 #include "base/file_version_info.h"
14 #include "base/files/file_path.h"
15 #include "base/macros.h"
16 #include "base/path_service.h"
17 #include "base/scoped_native_library.h"
18 #include "base/strings/string_util.h"
19 #include "testing/gtest/include/gtest/gtest.h"
20
21 using base::FilePath;
22
23 namespace {
24
25 FilePath GetTestDataPath() {
26   FilePath path;
27   base::PathService::Get(base::DIR_SOURCE_ROOT, &path);
28   path = path.AppendASCII("base");
29   path = path.AppendASCII("test");
30   path = path.AppendASCII("data");
31   path = path.AppendASCII("file_version_info_unittest");
32   return path;
33 }
34
35 class FileVersionInfoFactory {
36  public:
37   explicit FileVersionInfoFactory(const FilePath& path) : path_(path) {}
38
39   std::unique_ptr<FileVersionInfo> Create() const {
40     return FileVersionInfo::CreateFileVersionInfo(path_);
41   }
42
43  private:
44   const FilePath path_;
45
46   DISALLOW_COPY_AND_ASSIGN(FileVersionInfoFactory);
47 };
48
49 class FileVersionInfoForModuleFactory {
50  public:
51   explicit FileVersionInfoForModuleFactory(const FilePath& path)
52       // Load the library with LOAD_LIBRARY_AS_IMAGE_RESOURCE since it shouldn't
53       // be executed.
54       : library_(::LoadLibraryEx(path.value().c_str(),
55                                  nullptr,
56                                  LOAD_LIBRARY_AS_IMAGE_RESOURCE)) {
57     EXPECT_TRUE(library_.is_valid());
58   }
59
60   std::unique_ptr<FileVersionInfo> Create() const {
61     return FileVersionInfo::CreateFileVersionInfoForModule(library_.get());
62   }
63
64  private:
65   const base::ScopedNativeLibrary library_;
66
67   DISALLOW_COPY_AND_ASSIGN(FileVersionInfoForModuleFactory);
68 };
69
70 template <typename T>
71 class FileVersionInfoTest : public testing::Test {};
72
73 using FileVersionInfoFactories =
74     ::testing::Types<FileVersionInfoFactory, FileVersionInfoForModuleFactory>;
75
76 }  // namespace
77
78 TYPED_TEST_SUITE(FileVersionInfoTest, FileVersionInfoFactories);
79
80 TYPED_TEST(FileVersionInfoTest, HardCodedProperties) {
81   const base::FilePath::CharType kDLLName[] =
82       FILE_PATH_LITERAL("FileVersionInfoTest1.dll");
83
84   const wchar_t* const kExpectedValues[15] = {
85       // FileVersionInfoTest.dll
86       L"Goooooogle",                      // company_name
87       L"Google",                          // company_short_name
88       L"This is the product name",        // product_name
89       L"This is the product short name",  // product_short_name
90       L"The Internal Name",               // internal_name
91       L"4.3.2.1",                         // product_version
92       L"Special build property",          // special_build
93       L"This is the original filename",   // original_filename
94       L"This is my file description",     // file_description
95       L"1.2.3.4",                         // file_version
96   };
97
98   FilePath dll_path = GetTestDataPath();
99   dll_path = dll_path.Append(kDLLName);
100
101   TypeParam factory(dll_path);
102   std::unique_ptr<FileVersionInfo> version_info(factory.Create());
103   ASSERT_TRUE(version_info);
104
105   int j = 0;
106   EXPECT_EQ(kExpectedValues[j++],
107             base::AsWStringPiece(version_info->company_name()));
108   EXPECT_EQ(kExpectedValues[j++],
109             base::AsWStringPiece(version_info->company_short_name()));
110   EXPECT_EQ(kExpectedValues[j++],
111             base::AsWStringPiece(version_info->product_name()));
112   EXPECT_EQ(kExpectedValues[j++],
113             base::AsWStringPiece(version_info->product_short_name()));
114   EXPECT_EQ(kExpectedValues[j++],
115             base::AsWStringPiece(version_info->internal_name()));
116   EXPECT_EQ(kExpectedValues[j++],
117             base::AsWStringPiece(version_info->product_version()));
118   EXPECT_EQ(kExpectedValues[j++],
119             base::AsWStringPiece(version_info->special_build()));
120   EXPECT_EQ(kExpectedValues[j++],
121             base::AsWStringPiece(version_info->original_filename()));
122   EXPECT_EQ(kExpectedValues[j++],
123             base::AsWStringPiece(version_info->file_description()));
124   EXPECT_EQ(kExpectedValues[j++],
125             base::AsWStringPiece(version_info->file_version()));
126 }
127
128 TYPED_TEST(FileVersionInfoTest, CustomProperties) {
129   FilePath dll_path = GetTestDataPath();
130   dll_path = dll_path.AppendASCII("FileVersionInfoTest1.dll");
131
132   TypeParam factory(dll_path);
133   std::unique_ptr<FileVersionInfo> version_info(factory.Create());
134   ASSERT_TRUE(version_info);
135
136   // Test few existing properties.
137   base::string16 str;
138   FileVersionInfoWin* version_info_win =
139       static_cast<FileVersionInfoWin*>(version_info.get());
140   EXPECT_TRUE(
141       version_info_win->GetValue(STRING16_LITERAL("Custom prop 1"), &str));
142   EXPECT_EQ(STRING16_LITERAL("Un"), str);
143   EXPECT_EQ(STRING16_LITERAL("Un"), version_info_win->GetStringValue(
144                                         STRING16_LITERAL("Custom prop 1")));
145
146   EXPECT_TRUE(
147       version_info_win->GetValue(STRING16_LITERAL("Custom prop 2"), &str));
148   EXPECT_EQ(STRING16_LITERAL("Deux"), str);
149   EXPECT_EQ(STRING16_LITERAL("Deux"), version_info_win->GetStringValue(
150                                           STRING16_LITERAL("Custom prop 2")));
151
152   EXPECT_TRUE(
153       version_info_win->GetValue(STRING16_LITERAL("Custom prop 3"), &str));
154   EXPECT_EQ(
155       STRING16_LITERAL("1600 Amphitheatre Parkway Mountain View, CA 94043"),
156       str);
157   EXPECT_EQ(
158       STRING16_LITERAL("1600 Amphitheatre Parkway Mountain View, CA 94043"),
159       version_info_win->GetStringValue(STRING16_LITERAL("Custom prop 3")));
160
161   // Test an non-existing property.
162   EXPECT_FALSE(
163       version_info_win->GetValue(STRING16_LITERAL("Unknown property"), &str));
164   EXPECT_EQ(base::string16(), version_info_win->GetStringValue(
165                                   STRING16_LITERAL("Unknown property")));
166
167   EXPECT_EQ(base::Version(std::vector<uint32_t>{1, 0, 0, 1}),
168             version_info_win->GetFileVersion());
169 }
170
171 TYPED_TEST(FileVersionInfoTest, NoVersionInfo) {
172   FilePath dll_path = GetTestDataPath();
173   dll_path = dll_path.AppendASCII("no_version_info.dll");
174
175   TypeParam factory(dll_path);
176   ASSERT_FALSE(factory.Create());
177 }