summaryrefslogtreecommitdiffstats
path: root/chrome_frame/test/simple_resource_loader_test.cc
blob: bf881c0efe4f75705d9cabf4a9073d147f02106a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome_frame/simple_resource_loader.h"

#include "base/file_path.h"
#include "base/win/windows_version.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/resource/data_pack.h"

TEST(SimpleResourceLoaderTest, LoadLocaleDll) {
  std::vector<std::wstring> language_tags;
  FilePath locales_path;
  FilePath file_path;
  HMODULE dll_handle = NULL;

  SimpleResourceLoader::DetermineLocalesDirectory(&locales_path);

  // Test valid language-region string:
  language_tags.clear();
  language_tags.push_back(L"en-GB");
  language_tags.push_back(L"en");
  ui::DataPack* data_pack = NULL;

  std::wstring language;

  EXPECT_TRUE(
      SimpleResourceLoader::LoadLocalePack(language_tags, locales_path,
                                           &dll_handle, &data_pack,
                                           &language));
  if (NULL != dll_handle) {
    FreeLibrary(dll_handle);
    dll_handle = NULL;
  }
  EXPECT_TRUE(data_pack != NULL);
  delete data_pack;
  data_pack = NULL;

  EXPECT_EQ(language, L"en-GB");
  language.clear();

  // Test valid language-region string for which we only have a language dll:
  language_tags.clear();
  language_tags.push_back(L"fr-FR");
  language_tags.push_back(L"fr");
  EXPECT_TRUE(
      SimpleResourceLoader::LoadLocalePack(language_tags, locales_path,
                                           &dll_handle, &data_pack,
                                           &language));
  if (NULL != dll_handle) {
    FreeLibrary(dll_handle);
    dll_handle = NULL;
  }
  EXPECT_TRUE(data_pack != NULL);
  delete data_pack;
  data_pack = NULL;

  EXPECT_EQ(language, L"fr");
  language.clear();

  // Test invalid language-region string, make sure fallback works:
  language_tags.clear();
  language_tags.push_back(L"xx-XX");
  language_tags.push_back(L"en-US");
  EXPECT_TRUE(
      SimpleResourceLoader::LoadLocalePack(language_tags, locales_path,
                                           &dll_handle, &data_pack,
                                           &language));
  if (NULL != dll_handle) {
    FreeLibrary(dll_handle);
    dll_handle = NULL;
  }

  EXPECT_TRUE(data_pack != NULL);
  delete data_pack;
  data_pack = NULL;

  EXPECT_EQ(language, L"en-US");
  language.clear();
}

TEST(SimpleResourceLoaderTest, InstanceTest) {
  SimpleResourceLoader* loader = SimpleResourceLoader::GetInstance();

  ASSERT_TRUE(NULL != loader);
  ASSERT_TRUE(NULL != loader->GetResourceModuleHandle());
}