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

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

Issue 3051018: Ensure that window.open requests issued by ChromeFrame carry the correct cook... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 4 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/protocol_sink_wrap.cc ('k') | chrome_frame/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
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/file_version_info.h" 5 #include "base/file_version_info.h"
6 #include "base/file_version_info_win.h" 6 #include "base/file_version_info_win.h"
7 #include "chrome_frame/utils.h" 7 #include "chrome_frame/utils.h"
8
8 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "testing/gmock/include/gmock/gmock.h"
9 11
10 const wchar_t kChannelName[] = L"-dev"; 12 const wchar_t kChannelName[] = L"-dev";
11 const wchar_t kSuffix[] = L"-fix"; 13 const wchar_t kSuffix[] = L"-fix";
12 14
13 TEST(UtilTests, GetModuleVersionTest) { 15 TEST(UtilTests, GetModuleVersionTest) {
14 HMODULE mod = GetModuleHandle(L"kernel32.dll"); 16 HMODULE mod = GetModuleHandle(L"kernel32.dll");
15 EXPECT_NE(mod, static_cast<HMODULE>(NULL)); 17 EXPECT_NE(mod, static_cast<HMODULE>(NULL));
16 wchar_t path[MAX_PATH] = {0}; 18 wchar_t path[MAX_PATH] = {0};
17 GetModuleFileName(mod, path, arraysize(path)); 19 GetModuleFileName(mod, path, arraysize(path));
18 20
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 EXPECT_EQ(0, str_guid.compare(compare)); 109 EXPECT_EQ(0, str_guid.compare(compare));
108 EXPECT_EQ(static_cast<size_t>(lstrlenW(compare)), str_guid.length()); 110 EXPECT_EQ(static_cast<size_t>(lstrlenW(compare)), str_guid.length());
109 } 111 }
110 112
111 TEST(UtilTests, GetTempInternetFiles) { 113 TEST(UtilTests, GetTempInternetFiles) {
112 FilePath path = GetIETemporaryFilesFolder(); 114 FilePath path = GetIETemporaryFilesFolder();
113 EXPECT_FALSE(path.empty()); 115 EXPECT_FALSE(path.empty());
114 } 116 }
115 117
116 TEST(UtilTests, ParseAttachTabUrlTest) { 118 TEST(UtilTests, ParseAttachTabUrlTest) {
117 std::wstring url = L"attach_external_tab&10&1&0&0&100&100"; 119 ChromeFrameUrl cf_url;
118 120
119 uint64 cookie = 0; 121 EXPECT_TRUE(cf_url.Parse(L"http://f/?attach_external_tab&10&1&0&0&100&100"));
120 gfx::Rect dimensions;
121 int disposition = 0;
122 122
123 EXPECT_TRUE(ParseAttachExternalTabUrl(url, &cookie, &dimensions, 123 EXPECT_TRUE(cf_url.attach_to_external_tab());
124 &disposition)); 124 EXPECT_FALSE(cf_url.is_chrome_protocol());
125 EXPECT_EQ(10, cookie);
126 EXPECT_EQ(1, disposition);
127 EXPECT_EQ(0, dimensions.x());
128 EXPECT_EQ(0, dimensions.y());
129 EXPECT_EQ(100, dimensions.width());
130 EXPECT_EQ(100, dimensions.height());
131 125
132 url = L"http://www.foobar.com?&10&1&0&0&100&100"; 126 EXPECT_EQ(10, cf_url.cookie());
133 EXPECT_FALSE(ParseAttachExternalTabUrl(url, &cookie, &dimensions, 127 EXPECT_EQ(1, cf_url.disposition());
134 &disposition)); 128 EXPECT_EQ(0, cf_url.dimensions().x());
135 url = L"attach_external_tab&10&1"; 129 EXPECT_EQ(0, cf_url.dimensions().y());
136 EXPECT_FALSE(ParseAttachExternalTabUrl(url, &cookie, &dimensions, 130 EXPECT_EQ(100, cf_url.dimensions().width());
137 &disposition)); 131 EXPECT_EQ(100, cf_url.dimensions().height());
132
133 EXPECT_TRUE(cf_url.Parse(L"http://www.foobar.com?&10&1&0&0&100&100"));
134 EXPECT_FALSE(cf_url.attach_to_external_tab());
135
136 EXPECT_FALSE(cf_url.Parse(L"attach_external_tab&10&1"));
137 EXPECT_TRUE(cf_url.attach_to_external_tab());
138
139 EXPECT_TRUE(cf_url.Parse(L"gcf:http://f/?attach_tab&10&1&0&0&100&100"));
140 EXPECT_FALSE(cf_url.attach_to_external_tab());
141 EXPECT_TRUE(cf_url.is_chrome_protocol());
142 }
143
144 // Mock for the IInternetSecurityManager interface
145 class MockIInternetSecurityManager : public IInternetSecurityManager {
146 public:
147 MOCK_METHOD2_WITH_CALLTYPE(__stdcall, QueryInterface,
148 HRESULT(REFIID iid, void** object));
149
150 MOCK_METHOD0_WITH_CALLTYPE(__stdcall, AddRef, ULONG());
151 MOCK_METHOD0_WITH_CALLTYPE(__stdcall, Release, ULONG());
152
153 MOCK_METHOD1_WITH_CALLTYPE(__stdcall, SetSecuritySite,
154 HRESULT(IInternetSecurityMgrSite* site));
155 MOCK_METHOD1_WITH_CALLTYPE(__stdcall, GetSecuritySite,
156 HRESULT(IInternetSecurityMgrSite** site));
157 MOCK_METHOD3_WITH_CALLTYPE(__stdcall, MapUrlToZone,
158 HRESULT(LPCWSTR url, DWORD* zone, DWORD flags));
159 MOCK_METHOD4_WITH_CALLTYPE(__stdcall, GetSecurityId,
160 HRESULT(LPCWSTR url, BYTE* security_id, DWORD* security_size,
161 DWORD_PTR reserved));
162 MOCK_METHOD8_WITH_CALLTYPE(__stdcall, ProcessUrlAction,
163 HRESULT(LPCWSTR url, DWORD action, BYTE* policy, DWORD cb_policy,
164 BYTE* context, DWORD context_size, DWORD flags,
165 DWORD reserved));
166 MOCK_METHOD7_WITH_CALLTYPE(__stdcall, QueryCustomPolicy,
167 HRESULT(LPCWSTR url, REFGUID guid, BYTE** policy, DWORD* cb_policy,
168 BYTE* context, DWORD cb_context, DWORD reserved));
169 MOCK_METHOD3_WITH_CALLTYPE(__stdcall, SetZoneMapping,
170 HRESULT(DWORD zone, LPCWSTR pattern, DWORD flags));
171 MOCK_METHOD3_WITH_CALLTYPE(__stdcall, GetZoneMappings,
172 HRESULT(DWORD zone, IEnumString** enum_string, DWORD flags));
173 };
174
175 TEST(UtilTests, CanNavigateFullTabModeTest) {
176 ChromeFrameUrl cf_url;
177
178 MockIInternetSecurityManager mock;
179 EXPECT_CALL(mock, MapUrlToZone(testing::StartsWith(L"http://blah"),
180 testing::_, testing::_))
181 .WillRepeatedly(testing::DoAll(
182 testing::SetArgumentPointee<1>(URLZONE_INTERNET),
183 testing::Return(S_OK)));
184
185 EXPECT_CALL(mock, MapUrlToZone(testing::StartsWith(L"http://untrusted"),
186 testing::_, testing::_))
187 .WillRepeatedly(testing::DoAll(
188 testing::SetArgumentPointee<1>(URLZONE_UNTRUSTED),
189 testing::Return(S_OK)));
190
191 EXPECT_CALL(mock, MapUrlToZone(testing::StartsWith(L"about:"),
192 testing::_, testing::_))
193 .WillRepeatedly(testing::DoAll(
194 testing::SetArgumentPointee<1>(URLZONE_TRUSTED),
195 testing::Return(S_OK)));
196
197 EXPECT_CALL(mock, MapUrlToZone(testing::StartsWith(L"view-source:"),
198 testing::_, testing::_))
199 .WillRepeatedly(testing::DoAll(
200 testing::SetArgumentPointee<1>(URLZONE_TRUSTED),
201 testing::Return(S_OK)));
202
203 EXPECT_TRUE(cf_url.Parse(
204 L"http://blah/?attach_external_tab&10&1&0&0&100&100"));
205 EXPECT_TRUE(CanNavigateInFullTabMode(cf_url, &mock));
206
207 EXPECT_TRUE(cf_url.Parse(
208 L"http://untrusted/bar.html"));
209 EXPECT_FALSE(CanNavigateInFullTabMode(cf_url, &mock));
210
211 EXPECT_TRUE(cf_url.Parse(
212 L"http://blah/?attach_external_tab&10&1&0&0&100&100"));
213 EXPECT_TRUE(CanNavigateInFullTabMode(cf_url, &mock));
214
215 EXPECT_TRUE(cf_url.Parse(L"gcf:about:blank"));
216 EXPECT_TRUE(CanNavigateInFullTabMode(cf_url, &mock));
217
218 EXPECT_TRUE(cf_url.Parse(L"gcf:view-source:http://www.foo.com"));
219 EXPECT_TRUE(CanNavigateInFullTabMode(cf_url, &mock));
220
221 EXPECT_TRUE(cf_url.Parse(L"gcf:about:version"));
222 EXPECT_TRUE(CanNavigateInFullTabMode(cf_url, &mock));
223
224 EXPECT_TRUE(cf_url.Parse(L"gcf:about:bar"));
225 EXPECT_TRUE(CanNavigateInFullTabMode(cf_url, &mock));
226
227 bool enable_gcf = GetConfigBool(false, kEnableGCFProtocol);
228
229 SetConfigBool(kEnableGCFProtocol, false);
230
231 EXPECT_TRUE(cf_url.Parse(L"gcf:http://blah"));
232 EXPECT_FALSE(CanNavigateInFullTabMode(cf_url, &mock));
233
234 SetConfigBool(kEnableGCFProtocol, true);
235
236 EXPECT_TRUE(cf_url.Parse(L"gcf:http://blah"));
237 EXPECT_TRUE(CanNavigateInFullTabMode(cf_url, &mock));
238
239 EXPECT_TRUE(cf_url.Parse(L"gcf:http://untrusted/bar"));
240 EXPECT_FALSE(CanNavigateInFullTabMode(cf_url, &mock));
241
242 SetConfigBool(kEnableGCFProtocol, enable_gcf);
138 } 243 }
139 244
140 TEST(UtilTests, ParseVersionTest) { 245 TEST(UtilTests, ParseVersionTest) {
141 uint32 high = 0, low = 0; 246 uint32 high = 0, low = 0;
142 EXPECT_FALSE(ParseVersion(L"", &high, &low)); 247 EXPECT_FALSE(ParseVersion(L"", &high, &low));
143 EXPECT_TRUE(ParseVersion(L"1", &high, &low) && high == 1 && low == 0); 248 EXPECT_TRUE(ParseVersion(L"1", &high, &low) && high == 1 && low == 0);
144 EXPECT_TRUE(ParseVersion(L"1.", &high, &low) && high == 1 && low == 0); 249 EXPECT_TRUE(ParseVersion(L"1.", &high, &low) && high == 1 && low == 0);
145 EXPECT_TRUE(ParseVersion(L"1.2", &high, &low) && high == 1 && low == 2); 250 EXPECT_TRUE(ParseVersion(L"1.2", &high, &low) && high == 1 && low == 2);
146 EXPECT_TRUE(ParseVersion(L"1.2.3.4", &high, &low) && high == 1 && low == 2); 251 EXPECT_TRUE(ParseVersion(L"1.2.3.4", &high, &low) && high == 1 && low == 2);
147 EXPECT_TRUE(ParseVersion(L"10.20", &high, &low) && high == 10 && low == 20); 252 EXPECT_TRUE(ParseVersion(L"10.20", &high, &low) && high == 10 && low == 20);
148 } 253 }
149 254
OLDNEW
« no previous file with comments | « chrome_frame/protocol_sink_wrap.cc ('k') | chrome_frame/utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698