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

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
« no previous file with comments | « chrome_frame/test/automation_client_mock.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_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/string_util.h"
9 #include "base/utf_string_conversions.h"
8 #include "base/win/registry.h" 10 #include "base/win/registry.h"
11 #include "chrome_frame/navigation_constraints.h"
9 #include "chrome_frame/test/chrome_frame_test_utils.h" 12 #include "chrome_frame/test/chrome_frame_test_utils.h"
10 #include "chrome_frame/utils.h" 13 #include "chrome_frame/utils.h"
11 14
12 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
13 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
14 17
15 using base::win::RegKey; 18 using base::win::RegKey;
16 using chrome_frame_test::TempRegKeyOverride; 19 using chrome_frame_test::TempRegKeyOverride;
17 20
18 const wchar_t kChannelName[] = L"-dev"; 21 const wchar_t kChannelName[] = L"-dev";
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 DWORD reserved)); 224 DWORD reserved));
222 MOCK_METHOD7_WITH_CALLTYPE(__stdcall, QueryCustomPolicy, 225 MOCK_METHOD7_WITH_CALLTYPE(__stdcall, QueryCustomPolicy,
223 HRESULT(LPCWSTR url, REFGUID guid, BYTE** policy, DWORD* cb_policy, 226 HRESULT(LPCWSTR url, REFGUID guid, BYTE** policy, DWORD* cb_policy,
224 BYTE* context, DWORD cb_context, DWORD reserved)); 227 BYTE* context, DWORD cb_context, DWORD reserved));
225 MOCK_METHOD3_WITH_CALLTYPE(__stdcall, SetZoneMapping, 228 MOCK_METHOD3_WITH_CALLTYPE(__stdcall, SetZoneMapping,
226 HRESULT(DWORD zone, LPCWSTR pattern, DWORD flags)); 229 HRESULT(DWORD zone, LPCWSTR pattern, DWORD flags));
227 MOCK_METHOD3_WITH_CALLTYPE(__stdcall, GetZoneMappings, 230 MOCK_METHOD3_WITH_CALLTYPE(__stdcall, GetZoneMappings,
228 HRESULT(DWORD zone, IEnumString** enum_string, DWORD flags)); 231 HRESULT(DWORD zone, IEnumString** enum_string, DWORD flags));
229 }; 232 };
230 233
234 // This class provides a partial mock for the NavigationConstraints
235 // interface by providing specialized zone overrides.
236 class MockNavigationConstraintsZoneOverride
237 : public NavigationConstraintsImpl {
238 public:
239 MOCK_METHOD1(IsZoneAllowed, bool(const GURL&url));
240 };
241
242 // Mock NavigationConstraints
243 class MockNavigationConstraints : public NavigationConstraints {
244 public:
245 MOCK_METHOD0(AllowUnsafeUrls, bool());
246 MOCK_METHOD1(IsSchemeAllowed, bool(const GURL& url));
247 MOCK_METHOD1(IsZoneAllowed, bool(const GURL& url));
248 };
249
250 // Matcher which returns true if the URL passed in starts with the prefix
251 // specified.
252 MATCHER_P(UrlPathStartsWith, url_prefix, "url starts with prefix") {
253 return StartsWith(UTF8ToWide(arg.spec()), url_prefix, false);
254 }
255
256 ACTION_P3(HandleZone, mock, url_prefix, zone) {
257 if (StartsWith(UTF8ToWide(arg0.spec()), url_prefix, false))
258 return zone != URLZONE_UNTRUSTED;
259 return false;
260 }
261
231 TEST_F(UtilTests, CanNavigateTest) { 262 TEST_F(UtilTests, CanNavigateTest) {
232 MockIInternetSecurityManager mock; 263 MockNavigationConstraintsZoneOverride mock;
233 264
234 struct Zones { 265 struct Zones {
235 const wchar_t* url_prefix; 266 const wchar_t* url_prefix;
236 URLZONE zone; 267 URLZONE zone;
237 } test_zones[] = { 268 } test_zones[] = {
238 { L"http://blah", URLZONE_INTERNET }, 269 { L"http://blah", URLZONE_INTERNET },
239 { L"http://untrusted", URLZONE_UNTRUSTED }, 270 { L"http://untrusted", URLZONE_UNTRUSTED },
240 { L"about:", URLZONE_TRUSTED }, 271 { L"about:", URLZONE_TRUSTED },
241 { L"view-source:", URLZONE_TRUSTED }, 272 { L"view-source:", URLZONE_TRUSTED },
242 { L"chrome-extension:", URLZONE_TRUSTED }, 273 { L"chrome-extension:", URLZONE_TRUSTED },
243 { L"ftp:", URLZONE_UNTRUSTED }, 274 { L"ftp:", URLZONE_UNTRUSTED },
244 { L"file:", URLZONE_LOCAL_MACHINE }, 275 { L"file:", URLZONE_LOCAL_MACHINE },
245 { L"sip:", URLZONE_UNTRUSTED }, 276 { L"sip:", URLZONE_UNTRUSTED },
246 }; 277 };
247 278
248 for (int i = 0; i < arraysize(test_zones); ++i) { 279 for (int i = 0; i < arraysize(test_zones); ++i) {
249 const Zones& zone = test_zones[i]; 280 const Zones& zone = test_zones[i];
250 EXPECT_CALL(mock, MapUrlToZone(testing::StartsWith(zone.url_prefix), 281 EXPECT_CALL(mock, IsZoneAllowed(UrlPathStartsWith(zone.url_prefix)))
251 testing::_, testing::_)) 282 .WillRepeatedly(testing::Return(zone.zone != URLZONE_UNTRUSTED));
252 .WillRepeatedly(testing::DoAll(
253 testing::SetArgumentPointee<1>(zone.zone),
254 testing::Return(S_OK)));
255 } 283 }
256 284
257 struct Cases { 285 struct Cases {
258 const char* url; 286 const char* url;
259 bool is_privileged;
260 bool default_expected; 287 bool default_expected;
261 bool unsafe_expected; 288 bool unsafe_expected;
262 } test_cases[] = { 289 } test_cases[] = {
263 // Invalid URL 290 // Invalid URL
264 { " ", false, false, false }, 291 { " ", false, false },
265 { "foo bar", true, false, false }, 292 { "foo bar", false, false },
266 293
267 // non-privileged test cases 294 // non-privileged test cases
268 { "http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore", false, 295 { "http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore", true,
269 true, true }, 296 true },
270 { "http://untrusted/bar.html", false, false, true }, 297 { "http://untrusted/bar.html", false, true },
271 { "http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore", false, 298 { "http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore", true,
272 true, true }, 299 true },
273 { "view-source:http://www.google.ca", false, true, true }, 300 { "view-source:http://www.google.ca", true, true },
274 { "view-source:javascript:alert('foo');", false, false, true }, 301 { "view-source:javascript:alert('foo');", false, true },
275 { "about:blank", false, true, true }, 302 { "about:blank", true, true },
276 { "About:Version", false, true, true }, 303 { "About:Version", true, true },
277 { "about:config", false, false, true }, 304 { "about:config", false, true },
278 { "chrome-extension://aaaaaaaaaaaaaaaaaaa/toolstrip.html", false, false, 305 { "chrome-extension://aaaaaaaaaaaaaaaaaaa/toolstrip.html", false, true },
279 true }, 306 { "ftp://www.google.ca", false, true },
280 { "ftp://www.google.ca", false, false, true }, 307 { "file://www.google.ca", false, true },
281 { "file://www.google.ca", false, false, true }, 308 { "file://C:\boot.ini", false, true },
282 { "file://C:\boot.ini", false, false, true }, 309 { "SIP:someone@10.1.2.3", false, true },
283 { "SIP:someone@10.1.2.3", false, false, true },
284
285 // privileged test cases
286 { "http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore", true, true,
287 true },
288 { "http://untrusted/bar.html", true, false, true },
289 { "http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore", true, true,
290 true },
291 { "view-source:http://www.google.ca", true, true, true },
292 { "view-source:javascript:alert('foo');", true, false, true },
293 { "about:blank", true, true, true },
294 { "About:Version", true, true, true },
295 { "about:config", true, false, true },
296 { "chrome-extension://aaaaaaaaaaaaaaaaaaa/toolstrip.html", true, true,
297 true },
298 { "ftp://www.google.ca", true, false, true },
299 { "file://www.google.ca", true, false, true },
300 { "file://C:\boot.ini", true, false, true },
301 { "sip:someone@10.1.2.3", false, false, true },
302 }; 310 };
303 311
304 for (int i = 0; i < arraysize(test_cases); ++i) { 312 for (int i = 0; i < arraysize(test_cases); ++i) {
305 const Cases& test = test_cases[i]; 313 const Cases& test = test_cases[i];
306 bool actual = CanNavigate(GURL(test.url), &mock, test.is_privileged); 314 bool actual = CanNavigate(GURL(test.url), &mock);
307 EXPECT_EQ(test.default_expected, actual) << "Failure url: " << test.url; 315 EXPECT_EQ(test.default_expected, actual) << "Failure url: " << test.url;
308 } 316 }
317 }
309 318
310 bool enable_gcf = GetConfigBool(false, kAllowUnsafeURLs); 319 TEST_F(UtilTests, CanNavigateTestDenyAll) {
311 SetConfigBool(kAllowUnsafeURLs, true); 320 MockNavigationConstraints mock;
312 321
313 for (int i = 0; i < arraysize(test_cases); ++i) { 322 EXPECT_CALL(mock, IsZoneAllowed(testing::_))
314 const Cases& test = test_cases[i]; 323 .Times(testing::AnyNumber())
315 bool actual = CanNavigate(GURL(test.url), &mock, test.is_privileged); 324 .WillRepeatedly(testing::Return(false));
316 EXPECT_EQ(test.unsafe_expected, actual) << "Failure url: " << test.url; 325
326 EXPECT_CALL(mock, IsSchemeAllowed(testing::_))
327 .Times(testing::AnyNumber())
328 .WillRepeatedly(testing::Return(false));
329
330 EXPECT_CALL(mock, AllowUnsafeUrls())
331 .Times(testing::AnyNumber())
332 .WillRepeatedly(testing::Return(false));
333
334 char *urls[] = {
335 { " "},
336 { "foo bar"},
337 // non-privileged test cases
338 { "http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore"},
339 { "http://untrusted/bar.html"},
340 { "http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore"},
341 { "view-source:http://www.google.ca"},
342 { "view-source:javascript:alert('foo');"},
343 { "about:blank"},
344 { "About:Version"},
345 { "about:config"},
346 { "chrome-extension://aaaaaaaaaaaaaaaaaaa/toolstrip.html"},
347 { "ftp://www.google.ca"},
348 { "file://www.google.ca"},
349 { "file://C:\boot.ini"},
350 { "SIP:someone@10.1.2.3"},
351 };
352
353 for (int i = 0; i < arraysize(urls); ++i) {
354 EXPECT_FALSE(CanNavigate(GURL(urls[i]), &mock));
317 } 355 }
356 }
318 357
319 SetConfigBool(kAllowUnsafeURLs, enable_gcf); 358 TEST_F(UtilTests, CanNavigateTestAllowAll) {
359 MockNavigationConstraints mock;
360
361 EXPECT_CALL(mock, AllowUnsafeUrls())
362 .Times(testing::AnyNumber())
363 .WillRepeatedly(testing::Return(false));
364
365 EXPECT_CALL(mock, IsSchemeAllowed(testing::_))
366 .Times(testing::AnyNumber())
367 .WillRepeatedly(testing::Return(true));
368
369 EXPECT_CALL(mock, IsZoneAllowed(testing::_))
370 .Times(testing::AnyNumber())
371 .WillRepeatedly(testing::Return(true));
372
373 char *urls[] = {
374 // non-privileged test cases
375 { "http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore"},
376 { "http://untrusted/bar.html"},
377 { "http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore"},
378 { "view-source:http://www.google.ca"},
379 { "view-source:javascript:alert('foo');"},
380 { "about:blank"},
381 { "About:Version"},
382 { "about:config"},
383 { "chrome-extension://aaaaaaaaaaaaaaaaaaa/toolstrip.html"},
384 { "ftp://www.google.ca"},
385 { "file://www.google.ca"},
386 { "file://C:\boot.ini"},
387 { "SIP:someone@10.1.2.3"},
388 { "gcf:about:cache"},
389 { "gcf:about:plugins"},
390 };
391
392 for (int i = 0; i < arraysize(urls); ++i) {
393 EXPECT_TRUE(CanNavigate(GURL(urls[i]), &mock));
394 }
395 }
396
397 TEST_F(UtilTests, CanNavigateTestAllowAllUnsafeUrls) {
398 MockNavigationConstraints mock;
399
400 EXPECT_CALL(mock, AllowUnsafeUrls())
401 .Times(testing::AnyNumber())
402 .WillRepeatedly(testing::Return(true));
403
404 char *urls[] = {
405 {"gcf:about:cache"},
406 {"gcf:http://www.google.com"},
407 {"view-source:javascript:alert('foo');"},
408 {"http://www.google.com"},
409 };
410
411 for (int i = 0; i < arraysize(urls); ++i) {
412 EXPECT_TRUE(CanNavigate(GURL(urls[i]), &mock));
413 }
320 } 414 }
321 415
322 TEST_F(UtilTests, IsDefaultRendererTest) { 416 TEST_F(UtilTests, IsDefaultRendererTest) {
323 RegKey config_key(HKEY_CURRENT_USER, kChromeFrameConfigKey, KEY_ALL_ACCESS); 417 RegKey config_key(HKEY_CURRENT_USER, kChromeFrameConfigKey, KEY_ALL_ACCESS);
324 EXPECT_TRUE(config_key.Valid()); 418 EXPECT_TRUE(config_key.Valid());
325 419
326 DWORD saved_default_renderer = 0; // NOLINT 420 DWORD saved_default_renderer = 0; // NOLINT
327 config_key.ReadValueDW(kEnableGCFRendererByDefault, &saved_default_renderer); 421 config_key.ReadValueDW(kEnableGCFRendererByDefault, &saved_default_renderer);
328 422
329 config_key.DeleteValue(kEnableGCFRendererByDefault); 423 config_key.DeleteValue(kEnableGCFRendererByDefault);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 534
441 ASSERT_EQ(expect_match, 535 ASSERT_EQ(expect_match,
442 CheckXUaCompatibleDirective(test.header_value, 536 CheckXUaCompatibleDirective(test.header_value,
443 all_versions[version_index])) 537 all_versions[version_index]))
444 << "Expect '" << test.header_value << "' to " 538 << "Expect '" << test.header_value << "' to "
445 << (expect_match ? "match" : "not match") << " IE major version " 539 << (expect_match ? "match" : "not match") << " IE major version "
446 << all_versions[version_index]; 540 << all_versions[version_index];
447 } 541 }
448 } 542 }
449 } 543 }
OLDNEW
« no previous file with comments | « chrome_frame/test/automation_client_mock.cc ('k') | chrome_frame/utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698