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 "chrome_frame/simple_resource_loader.h"
6
7#include "base/files/file_path.h"
8#include "base/win/windows_version.h"
9#include "testing/gtest/include/gtest/gtest.h"
10#include "ui/base/resource/data_pack.h"
11
12TEST(SimpleResourceLoaderTest, LoadLocaleDll) {
13  std::vector<std::wstring> language_tags;
14  base::FilePath locales_path;
15  base::FilePath file_path;
16  HMODULE dll_handle = NULL;
17
18  SimpleResourceLoader::DetermineLocalesDirectory(&locales_path);
19
20  // Test valid language-region string:
21  language_tags.clear();
22  language_tags.push_back(L"en-GB");
23  language_tags.push_back(L"en");
24  ui::DataPack* data_pack = NULL;
25
26  std::wstring language;
27
28  EXPECT_TRUE(
29      SimpleResourceLoader::LoadLocalePack(language_tags, locales_path,
30                                           &dll_handle, &data_pack,
31                                           &language));
32  if (NULL != dll_handle) {
33    FreeLibrary(dll_handle);
34    dll_handle = NULL;
35  }
36  EXPECT_TRUE(data_pack != NULL);
37  delete data_pack;
38  data_pack = NULL;
39
40  EXPECT_EQ(language, L"en-GB");
41  language.clear();
42
43  // Test valid language-region string for which we only have a language dll:
44  language_tags.clear();
45  language_tags.push_back(L"fr-FR");
46  language_tags.push_back(L"fr");
47  EXPECT_TRUE(
48      SimpleResourceLoader::LoadLocalePack(language_tags, locales_path,
49                                           &dll_handle, &data_pack,
50                                           &language));
51  if (NULL != dll_handle) {
52    FreeLibrary(dll_handle);
53    dll_handle = NULL;
54  }
55  EXPECT_TRUE(data_pack != NULL);
56  delete data_pack;
57  data_pack = NULL;
58
59  EXPECT_EQ(language, L"fr");
60  language.clear();
61
62  // Test invalid language-region string, make sure fallback works:
63  language_tags.clear();
64  language_tags.push_back(L"xx-XX");
65  language_tags.push_back(L"en-US");
66  EXPECT_TRUE(
67      SimpleResourceLoader::LoadLocalePack(language_tags, locales_path,
68                                           &dll_handle, &data_pack,
69                                           &language));
70  if (NULL != dll_handle) {
71    FreeLibrary(dll_handle);
72    dll_handle = NULL;
73  }
74
75  EXPECT_TRUE(data_pack != NULL);
76  delete data_pack;
77  data_pack = NULL;
78
79  EXPECT_EQ(language, L"en-US");
80  language.clear();
81}
82
83TEST(SimpleResourceLoaderTest, InstanceTest) {
84  SimpleResourceLoader* loader = SimpleResourceLoader::GetInstance();
85
86  ASSERT_TRUE(NULL != loader);
87  ASSERT_TRUE(NULL != loader->GetResourceModuleHandle());
88}
89