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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
// Copyright (c) 2006-2009 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 "base/file_version_info.h"
#include "chrome_frame/utils.h"
#include "testing/gtest/include/gtest/gtest.h"
const wchar_t kChannelName[] = L"-dev";
const wchar_t kSuffix[] = L"-fix";
TEST(UtilTests, GetModuleVersionTest) {
HMODULE mod = GetModuleHandle(L"kernel32.dll");
EXPECT_NE(mod, static_cast<HMODULE>(NULL));
wchar_t path[MAX_PATH] = {0};
GetModuleFileName(mod, path, arraysize(path));
// Use the method that goes to disk
scoped_ptr<FileVersionInfo> base_info(
FileVersionInfo::CreateFileVersionInfo(path));
EXPECT_TRUE(base_info.get() != NULL);
// Use the method that doesn't go to disk
uint32 low = 0, high = 0;
EXPECT_TRUE(GetModuleVersion(mod, &high, &low));
EXPECT_NE(high, 0);
EXPECT_NE(low, 0);
// Make sure they give the same results.
VS_FIXEDFILEINFO* fixed_info = base_info->fixed_file_info();
EXPECT_TRUE(fixed_info != NULL);
EXPECT_EQ(fixed_info->dwFileVersionMS, static_cast<DWORD>(high));
EXPECT_EQ(fixed_info->dwFileVersionLS, static_cast<DWORD>(low));
}
TEST(UtilTests, HaveSameOrigin) {
struct OriginCompare {
const char* a;
const char* b;
bool same_origin;
} test_cases[] = {
{ "", "", true },
{ "*", "*", true },
{ "*", "+", false },
{ "http://www.google.com/", "http://www.google.com/", true },
{ "http://www.google.com", "http://www.google.com/", true },
{ "http://www.google.com:80/", "http://www.google.com/", true },
{ "http://www.google.com:8080/", "http://www.google.com/", false },
{ "https://www.google.com/", "http://www.google.com/", false },
{ "http://docs.google.com/", "http://www.google.com/", false },
{ "https://www.google.com/", "https://www.google.com:443/", true },
{ "https://www.google.com/", "https://www.google.com:443", true },
};
for (int i = 0; i < arraysize(test_cases); ++i) {
const OriginCompare& test = test_cases[i];
EXPECT_EQ(test.same_origin, HaveSameOrigin(test.a, test.b));
}
}
TEST(UtilTests, IsValidUrlScheme) {
struct Cases {
const wchar_t* url;
bool is_privileged;
bool expected;
} test_cases[] = {
// non-privileged test cases
{ L"http://www.google.ca", false, true },
{ L"https://www.google.ca", false, true },
{ L"about:config", false, true },
{ L"view-source:http://www.google.ca", false, true },
{ L"chrome-extension://aaaaaaaaaaaaaaaaaaa/toolstrip.html", false, false },
{ L"ftp://www.google.ca", false, false },
{ L"file://www.google.ca", false, false },
{ L"file://C:\boot.ini", false, false },
// privileged test cases
{ L"http://www.google.ca", true, true },
{ L"https://www.google.ca", true, true },
{ L"about:config", true, true },
{ L"view-source:http://www.google.ca", true, true },
{ L"chrome-extension://aaaaaaaaaaaaaaaaaaa/toolstrip.html", true, true },
{ L"ftp://www.google.ca", true, false },
{ L"file://www.google.ca", true, false },
{ L"file://C:\boot.ini", true, false },
};
for (int i = 0; i < arraysize(test_cases); ++i) {
const Cases& test = test_cases[i];
EXPECT_EQ(test.expected, IsValidUrlScheme(test.url, test.is_privileged));
}
}
TEST(UtilTests, GuidToString) {
// {3C5E2125-35BA-48df-A841-5F669B9D69FC}
const GUID test_guid = { 0x3c5e2125, 0x35ba, 0x48df,
{ 0xa8, 0x41, 0x5f, 0x66, 0x9b, 0x9d, 0x69, 0xfc } };
wchar_t compare[64] = {0};
::StringFromGUID2(test_guid, compare, arraysize(compare));
std::wstring str_guid(GuidToString(test_guid));
EXPECT_EQ(0, str_guid.compare(compare));
EXPECT_EQ(static_cast<size_t>(lstrlenW(compare)), str_guid.length());
}
TEST(UtilTests, GetTempInternetFiles) {
FilePath path = GetIETemporaryFilesFolder();
EXPECT_FALSE(path.empty());
}
|