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

Side by Side Diff: chrome_frame/test/util_unittests.cc

Issue 218019: Initial import of the Chrome Frame codebase. Integration in chrome.gyp coming... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « chrome_frame/test/test_server_test.cc ('k') | chrome_frame/test_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2006-2009 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.h"
6 #include "chrome_frame/test/chrome_frame_unittests.h"
7 #include "chrome_frame/utils.h"
8
9 const wchar_t kChannelName[] = L"-dev";
10 const wchar_t kSuffix[] = L"-fix";
11
12 TEST(UtilTests, AppendSuffixToChannelNameTest) {
13 std::wstring str_base;
14 std::wstring channel_name(kChannelName);
15 std::wstring suffix(kSuffix);
16
17 str_base = L"2.0-dev-bar";
18 EXPECT_TRUE(AppendSuffixToChannelName(&str_base, channel_name, suffix));
19 EXPECT_STREQ(L"2.0-dev-fix-bar", str_base.c_str());
20
21 str_base = L"2.0-dev-fix-bar";
22 EXPECT_FALSE(AppendSuffixToChannelName(&str_base, channel_name, suffix));
23 EXPECT_STREQ(L"2.0-dev-fix-bar", str_base.c_str());
24
25 str_base = L"2.0-dev-bar-dev-bar";
26 EXPECT_TRUE(AppendSuffixToChannelName(&str_base, channel_name, suffix));
27 EXPECT_STREQ(L"2.0-dev-fix-bar-dev-bar", str_base.c_str());
28
29 str_base = L"2.0";
30 EXPECT_FALSE(AppendSuffixToChannelName(&str_base, channel_name, suffix));
31 EXPECT_STREQ(L"2.0", str_base.c_str());
32
33 str_base = L"2.0-devvvv";
34 EXPECT_TRUE(AppendSuffixToChannelName(&str_base, channel_name, suffix));
35 EXPECT_STREQ(L"2.0-dev-fixvvv", str_base.c_str());
36 }
37
38 TEST(UtilTests, RemoveSuffixFromStringTest) {
39 std::wstring str_base;
40 std::wstring channel_name(kChannelName);
41 std::wstring suffix(kSuffix);
42
43 str_base = L"2.0-dev-fix";
44 EXPECT_TRUE(RemoveSuffixFromChannelName(&str_base, channel_name, suffix));
45 EXPECT_STREQ(L"2.0-dev", str_base.c_str());
46
47 str_base = L"2.0-dev-fix-full";
48 EXPECT_TRUE(RemoveSuffixFromChannelName(&str_base, channel_name, suffix));
49 EXPECT_STREQ(L"2.0-dev-full", str_base.c_str());
50
51 str_base = L"2.0";
52 EXPECT_FALSE(RemoveSuffixFromChannelName(&str_base, channel_name, suffix));
53 EXPECT_STREQ(L"2.0", str_base.c_str());
54
55 str_base = L"2.0-dev";
56 EXPECT_FALSE(RemoveSuffixFromChannelName(&str_base, channel_name, suffix));
57 EXPECT_STREQ(L"2.0-dev", str_base.c_str());
58
59 str_base = L"2.0-fix";
60 EXPECT_FALSE(RemoveSuffixFromChannelName(&str_base, channel_name, suffix));
61 EXPECT_STREQ(L"2.0-fix", str_base.c_str());
62
63 str_base = L"2.0-full-fix";
64 EXPECT_FALSE(RemoveSuffixFromChannelName(&str_base, channel_name, suffix));
65 EXPECT_STREQ(L"2.0-full-fix", str_base.c_str());
66
67 str_base = L"2.0-dev-dev-fix";
68 EXPECT_TRUE(RemoveSuffixFromChannelName(&str_base, channel_name, suffix));
69 EXPECT_STREQ(L"2.0-dev-dev", str_base.c_str());
70 }
71
72 TEST(UtilTests, GetModuleVersionTest) {
73 HMODULE mod = GetModuleHandle(L"kernel32.dll");
74 EXPECT_NE(mod, static_cast<HMODULE>(NULL));
75 wchar_t path[MAX_PATH] = {0};
76 GetModuleFileName(mod, path, arraysize(path));
77
78 // Use the method that goes to disk
79 scoped_ptr<FileVersionInfo> base_info(
80 FileVersionInfo::CreateFileVersionInfo(path));
81 EXPECT_TRUE(base_info.get() != NULL);
82
83 // Use the method that doesn't go to disk
84 uint32 low = 0, high = 0;
85 EXPECT_TRUE(GetModuleVersion(mod, &high, &low));
86 EXPECT_NE(high, 0);
87 EXPECT_NE(low, 0);
88
89 // Make sure they give the same results.
90 VS_FIXEDFILEINFO* fixed_info = base_info->fixed_file_info();
91 EXPECT_TRUE(fixed_info != NULL);
92
93 EXPECT_EQ(fixed_info->dwFileVersionMS, static_cast<DWORD>(high));
94 EXPECT_EQ(fixed_info->dwFileVersionLS, static_cast<DWORD>(low));
95 }
96
97 TEST(UtilTests, HaveSameOrigin) {
98 struct OriginCompare {
99 const char* a;
100 const char* b;
101 bool same_origin;
102 } test_cases[] = {
103 { "", "", true },
104 { "*", "*", true },
105 { "*", "+", false },
106 { "http://www.google.com/", "http://www.google.com/", true },
107 { "http://www.google.com", "http://www.google.com/", true },
108 { "http://www.google.com:80/", "http://www.google.com/", true },
109 { "http://www.google.com:8080/", "http://www.google.com/", false },
110 { "https://www.google.com/", "http://www.google.com/", false },
111 { "http://docs.google.com/", "http://www.google.com/", false },
112 { "https://www.google.com/", "https://www.google.com:443/", true },
113 { "https://www.google.com/", "https://www.google.com:443", true },
114 };
115
116 for (int i = 0; i < arraysize(test_cases); ++i) {
117 const OriginCompare& test = test_cases[i];
118 EXPECT_EQ(test.same_origin, HaveSameOrigin(test.a, test.b));
119 }
120 }
OLDNEW
« no previous file with comments | « chrome_frame/test/test_server_test.cc ('k') | chrome_frame/test_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698