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

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

Issue 5698005: Add support for gcf:about:plugins in chrome frame full tab mode. The URL vali... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years 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
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_path.h" 5 #include "base/file_path.h"
6 #include "base/file_version_info.h" 6 #include "base/file_version_info.h"
7 #include "base/file_version_info_win.h" 7 #include "base/file_version_info_win.h"
8 #include "base/utf_string_conversions.h"
8 #include "base/win/registry.h" 9 #include "base/win/registry.h"
10
11 #include "chrome_frame/chrome_frame_delegate.h"
9 #include "chrome_frame/utils.h" 12 #include "chrome_frame/utils.h"
10 13
11 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
12 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
13 16
14 using base::win::RegKey; 17 using base::win::RegKey;
15 18
16 const wchar_t kChannelName[] = L"-dev"; 19 const wchar_t kChannelName[] = L"-dev";
17 const wchar_t kSuffix[] = L"-fix"; 20 const wchar_t kSuffix[] = L"-fix";
18 21
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 DWORD reserved)); 198 DWORD reserved));
196 MOCK_METHOD7_WITH_CALLTYPE(__stdcall, QueryCustomPolicy, 199 MOCK_METHOD7_WITH_CALLTYPE(__stdcall, QueryCustomPolicy,
197 HRESULT(LPCWSTR url, REFGUID guid, BYTE** policy, DWORD* cb_policy, 200 HRESULT(LPCWSTR url, REFGUID guid, BYTE** policy, DWORD* cb_policy,
198 BYTE* context, DWORD cb_context, DWORD reserved)); 201 BYTE* context, DWORD cb_context, DWORD reserved));
199 MOCK_METHOD3_WITH_CALLTYPE(__stdcall, SetZoneMapping, 202 MOCK_METHOD3_WITH_CALLTYPE(__stdcall, SetZoneMapping,
200 HRESULT(DWORD zone, LPCWSTR pattern, DWORD flags)); 203 HRESULT(DWORD zone, LPCWSTR pattern, DWORD flags));
201 MOCK_METHOD3_WITH_CALLTYPE(__stdcall, GetZoneMappings, 204 MOCK_METHOD3_WITH_CALLTYPE(__stdcall, GetZoneMappings,
202 HRESULT(DWORD zone, IEnumString** enum_string, DWORD flags)); 205 HRESULT(DWORD zone, IEnumString** enum_string, DWORD flags));
203 }; 206 };
204 207
208 // This class provides a partial mock for the NavigationConstraints
209 // interface by providing specialized zone overrides.
210 class MockNavigationConstraintsZoneOverride
211 : public NavigationConstraintsImpl {
212 public:
213 MOCK_METHOD1(IsZoneAllowed, bool(const GURL&url));
214 };
215
216 // Mock NavigationConstraints
217 class MockNavigationConstraints : public NavigationConstraints {
218 public:
219 MOCK_METHOD0(AllowUnsafeUrls, bool());
220 MOCK_METHOD1(IsSchemeAllowed, bool(const GURL&url));
221 MOCK_METHOD1(IsZoneAllowed, bool(const GURL&url));
222 };
223
224 // Matcher which returns true if the URL passed in starts with the prefix
225 // specified.
226 MATCHER_P(UrlPathStartsWith, url_prefix, "url starts with prefix") {
227 return StartsWith(UTF8ToWide(arg.spec()), url_prefix, false);
228 }
229
230 ACTION_P3(HandleZone, mock, url_prefix, zone) {
231 if (StartsWith(UTF8ToWide(arg0.spec()),
232 url_prefix, false))
233 return zone != URLZONE_UNTRUSTED;
234 return false;
235 }
236
205 TEST(UtilTests, CanNavigateTest) { 237 TEST(UtilTests, CanNavigateTest) {
206 MockIInternetSecurityManager mock; 238 MockNavigationConstraintsZoneOverride mock;
207 239
208 struct Zones { 240 struct Zones {
209 const wchar_t* url_prefix; 241 const wchar_t* url_prefix;
210 URLZONE zone; 242 URLZONE zone;
211 } test_zones[] = { 243 } test_zones[] = {
212 { L"http://blah", URLZONE_INTERNET }, 244 { L"http://blah", URLZONE_INTERNET },
213 { L"http://untrusted", URLZONE_UNTRUSTED }, 245 { L"http://untrusted", URLZONE_UNTRUSTED },
214 { L"about:", URLZONE_TRUSTED }, 246 { L"about:", URLZONE_TRUSTED },
215 { L"view-source:", URLZONE_TRUSTED }, 247 { L"view-source:", URLZONE_TRUSTED },
216 { L"chrome-extension:", URLZONE_TRUSTED }, 248 { L"chrome-extension:", URLZONE_TRUSTED },
217 { L"ftp:", URLZONE_UNTRUSTED }, 249 { L"ftp:", URLZONE_UNTRUSTED },
218 { L"file:", URLZONE_LOCAL_MACHINE }, 250 { L"file:", URLZONE_LOCAL_MACHINE },
219 { L"sip:", URLZONE_UNTRUSTED }, 251 { L"sip:", URLZONE_UNTRUSTED },
220 }; 252 };
221 253
222 for (int i = 0; i < arraysize(test_zones); ++i) { 254 for (int i = 0; i < arraysize(test_zones); ++i) {
223 const Zones& zone = test_zones[i]; 255 const Zones& zone = test_zones[i];
224 EXPECT_CALL(mock, MapUrlToZone(testing::StartsWith(zone.url_prefix), 256 EXPECT_CALL(mock, IsZoneAllowed(UrlPathStartsWith(zone.url_prefix)))
225 testing::_, testing::_)) 257 .WillRepeatedly(testing::Return(zone.zone != URLZONE_UNTRUSTED));
226 .WillRepeatedly(testing::DoAll(
227 testing::SetArgumentPointee<1>(zone.zone),
228 testing::Return(S_OK)));
229 } 258 }
230 259
231 struct Cases { 260 struct Cases {
232 const char* url; 261 const char* url;
233 bool is_privileged;
234 bool default_expected; 262 bool default_expected;
235 bool unsafe_expected; 263 bool unsafe_expected;
236 } test_cases[] = { 264 } test_cases[] = {
237 // Invalid URL 265 // Invalid URL
238 { " ", false, false, false }, 266 { " ", false, false },
239 { "foo bar", true, false, false }, 267 { "foo bar", false, false },
240 268
241 // non-privileged test cases 269 // non-privileged test cases
242 { "http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore", false, 270 { "http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore", true,
243 true, true }, 271 true },
244 { "http://untrusted/bar.html", false, false, true }, 272 { "http://untrusted/bar.html", false, true },
245 { "http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore", false, 273 { "http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore", true,
246 true, true }, 274 true },
247 { "view-source:http://www.google.ca", false, true, true }, 275 { "view-source:http://www.google.ca", true, true },
248 { "view-source:javascript:alert('foo');", false, false, true }, 276 { "view-source:javascript:alert('foo');", false, true },
249 { "about:blank", false, true, true }, 277 { "about:blank", true, true },
250 { "About:Version", false, true, true }, 278 { "About:Version", true, true },
251 { "about:config", false, false, true }, 279 { "about:config", false, true },
252 { "chrome-extension://aaaaaaaaaaaaaaaaaaa/toolstrip.html", false, false, 280 { "chrome-extension://aaaaaaaaaaaaaaaaaaa/toolstrip.html", false, true },
253 true }, 281 { "ftp://www.google.ca", false, true },
254 { "ftp://www.google.ca", false, false, true }, 282 { "file://www.google.ca", false, true },
255 { "file://www.google.ca", false, false, true }, 283 { "file://C:\boot.ini", false, true },
256 { "file://C:\boot.ini", false, false, true }, 284 { "SIP:someone@10.1.2.3", false, true },
257 { "SIP:someone@10.1.2.3", false, false, true },
258
259 // privileged test cases
260 { "http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore", true, true,
261 true },
262 { "http://untrusted/bar.html", true, false, true },
263 { "http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore", true, true,
264 true },
265 { "view-source:http://www.google.ca", true, true, true },
266 { "view-source:javascript:alert('foo');", true, false, true },
267 { "about:blank", true, true, true },
268 { "About:Version", true, true, true },
269 { "about:config", true, false, true },
270 { "chrome-extension://aaaaaaaaaaaaaaaaaaa/toolstrip.html", true, true,
271 true },
272 { "ftp://www.google.ca", true, false, true },
273 { "file://www.google.ca", true, false, true },
274 { "file://C:\boot.ini", true, false, true },
275 { "sip:someone@10.1.2.3", false, false, true },
276 }; 285 };
277 286
278 for (int i = 0; i < arraysize(test_cases); ++i) { 287 for (int i = 0; i < arraysize(test_cases); ++i) {
279 const Cases& test = test_cases[i]; 288 const Cases& test = test_cases[i];
280 bool actual = CanNavigate(GURL(test.url), &mock, test.is_privileged); 289 bool actual = CanNavigate(GURL(test.url), &mock);
281 EXPECT_EQ(test.default_expected, actual) << "Failure url: " << test.url; 290 EXPECT_EQ(test.default_expected, actual) << "Failure url: " << test.url;
282 } 291 }
283 292
284 bool enable_gcf = GetConfigBool(false, kAllowUnsafeURLs); 293 bool enable_gcf = GetConfigBool(false, kAllowUnsafeURLs);
285 SetConfigBool(kAllowUnsafeURLs, true); 294 SetConfigBool(kAllowUnsafeURLs, true);
amit 2010/12/10 23:56:17 not needed anymore! please get rid of other instan
ananta 2010/12/11 02:11:11 Done.
286 295
287 for (int i = 0; i < arraysize(test_cases); ++i) { 296 for (int i = 0; i < arraysize(test_cases); ++i) {
288 const Cases& test = test_cases[i]; 297 const Cases& test = test_cases[i];
289 bool actual = CanNavigate(GURL(test.url), &mock, test.is_privileged); 298 bool actual = CanNavigate(GURL(test.url), &mock);
290 EXPECT_EQ(test.unsafe_expected, actual) << "Failure url: " << test.url; 299 EXPECT_EQ(test.unsafe_expected, actual) << "Failure url: " << test.url;
291 } 300 }
292 301
293 SetConfigBool(kAllowUnsafeURLs, enable_gcf); 302 SetConfigBool(kAllowUnsafeURLs, enable_gcf);
294 } 303 }
295 304
305 TEST(UtilTests, CanNavigateTestDenyAll) {
amit 2010/12/10 23:56:17 nice new tests
306 MockNavigationConstraints mock;
307
308 EXPECT_CALL(mock, IsZoneAllowed(testing::_))
309 .Times(testing::AnyNumber())
310 .WillRepeatedly(testing::Return(false));
311
312 EXPECT_CALL(mock, IsSchemeAllowed(testing::_))
313 .Times(testing::AnyNumber())
314 .WillRepeatedly(testing::Return(false));
315
316 EXPECT_CALL(mock, AllowUnsafeUrls())
317 .Times(testing::AnyNumber())
318 .WillRepeatedly(testing::Return(false));
319
320 char *urls[] = {
321 {"http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore"},
322 {"http://untrusted/bar.html"},
323 {"http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore"},
324 {"view-source:http://www.google.ca"},
325 {"view-source:javascript:alert('foo');"},
326 {"about:blank"},
327 {"About:Version"},
328 };
329
330 for (int i = 0; i < arraysize(urls); ++i) {
331 EXPECT_FALSE(CanNavigate(GURL(urls[i]), &mock));
332 }
333 }
334
335 TEST(UtilTests, CanNavigateTestAllowAll) {
336 MockNavigationConstraints mock;
337
338 EXPECT_CALL(mock, AllowUnsafeUrls())
339 .Times(testing::AnyNumber())
340 .WillRepeatedly(testing::Return(false));
341
342 EXPECT_CALL(mock, IsSchemeAllowed(testing::_))
343 .Times(testing::AnyNumber())
344 .WillRepeatedly(testing::Return(true));
345
346 EXPECT_CALL(mock, IsZoneAllowed(testing::_))
347 .Times(testing::AnyNumber())
348 .WillRepeatedly(testing::Return(true));
349
350 char *urls[] = {
351 {"gcf:about:cache"},
352 {"gcf:http://www.google.com"},
353 {"view-source:javascript:alert('foo');"},
354 {"http://www.google.com"},
355 };
356
357 for (int i = 0; i < arraysize(urls); ++i) {
358 EXPECT_TRUE(CanNavigate(GURL(urls[i]), &mock));
359 }
360 }
361
362 TEST(UtilTests, CanNavigateTestAllowAllUnsafeUrs) {
363 MockNavigationConstraints mock;
364
365 EXPECT_CALL(mock, AllowUnsafeUrls())
366 .Times(testing::AnyNumber())
367 .WillRepeatedly(testing::Return(true));
368
369 char *urls[] = {
370 {"gcf:about:cache"},
371 {"gcf:http://www.google.com"},
372 {"view-source:javascript:alert('foo');"},
373 {"http://www.google.com"},
374 };
375
376 for (int i = 0; i < arraysize(urls); ++i) {
377 EXPECT_TRUE(CanNavigate(GURL(urls[i]), &mock));
378 }
379 }
380
296 TEST(UtilTests, IsDefaultRendererTest) { 381 TEST(UtilTests, IsDefaultRendererTest) {
297 RegKey config_key(HKEY_CURRENT_USER, kChromeFrameConfigKey, KEY_ALL_ACCESS); 382 RegKey config_key(HKEY_CURRENT_USER, kChromeFrameConfigKey, KEY_ALL_ACCESS);
298 EXPECT_TRUE(config_key.Valid()); 383 EXPECT_TRUE(config_key.Valid());
299 384
300 DWORD saved_default_renderer = 0; // NOLINT 385 DWORD saved_default_renderer = 0; // NOLINT
301 config_key.ReadValueDW(kEnableGCFRendererByDefault, &saved_default_renderer); 386 config_key.ReadValueDW(kEnableGCFRendererByDefault, &saved_default_renderer);
302 387
303 config_key.DeleteValue(kEnableGCFRendererByDefault); 388 config_key.DeleteValue(kEnableGCFRendererByDefault);
304 EXPECT_FALSE(IsGcfDefaultRenderer()); 389 EXPECT_FALSE(IsGcfDefaultRenderer());
305 390
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 499
415 ASSERT_EQ(expect_match, 500 ASSERT_EQ(expect_match,
416 CheckXUaCompatibleDirective(test.header_value, 501 CheckXUaCompatibleDirective(test.header_value,
417 all_versions[version_index])) 502 all_versions[version_index]))
418 << "Expect '" << test.header_value << "' to " 503 << "Expect '" << test.header_value << "' to "
419 << (expect_match ? "match" : "not match") << " IE major version " 504 << (expect_match ? "match" : "not match") << " IE major version "
420 << all_versions[version_index]; 505 << all_versions[version_index];
421 } 506 }
422 } 507 }
423 } 508 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698