OLD | NEW |
---|---|
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 Loading... | |
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)); | |
amit
2010/12/13 23:45:27
nit: spacing around &
ananta
2010/12/14 00:36:27
Done.
| |
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()), | |
258 url_prefix, false)) | |
amit
2010/12/13 23:45:27
nit: fits on the line above
ananta
2010/12/14 00:36:27
Done.
| |
259 return zone != URLZONE_UNTRUSTED; | |
260 return false; | |
261 } | |
262 | |
231 TEST_F(UtilTests, CanNavigateTest) { | 263 TEST_F(UtilTests, CanNavigateTest) { |
232 MockIInternetSecurityManager mock; | 264 MockNavigationConstraintsZoneOverride mock; |
233 | 265 |
234 struct Zones { | 266 struct Zones { |
235 const wchar_t* url_prefix; | 267 const wchar_t* url_prefix; |
236 URLZONE zone; | 268 URLZONE zone; |
237 } test_zones[] = { | 269 } test_zones[] = { |
238 { L"http://blah", URLZONE_INTERNET }, | 270 { L"http://blah", URLZONE_INTERNET }, |
239 { L"http://untrusted", URLZONE_UNTRUSTED }, | 271 { L"http://untrusted", URLZONE_UNTRUSTED }, |
240 { L"about:", URLZONE_TRUSTED }, | 272 { L"about:", URLZONE_TRUSTED }, |
241 { L"view-source:", URLZONE_TRUSTED }, | 273 { L"view-source:", URLZONE_TRUSTED }, |
242 { L"chrome-extension:", URLZONE_TRUSTED }, | 274 { L"chrome-extension:", URLZONE_TRUSTED }, |
243 { L"ftp:", URLZONE_UNTRUSTED }, | 275 { L"ftp:", URLZONE_UNTRUSTED }, |
244 { L"file:", URLZONE_LOCAL_MACHINE }, | 276 { L"file:", URLZONE_LOCAL_MACHINE }, |
245 { L"sip:", URLZONE_UNTRUSTED }, | 277 { L"sip:", URLZONE_UNTRUSTED }, |
246 }; | 278 }; |
247 | 279 |
248 for (int i = 0; i < arraysize(test_zones); ++i) { | 280 for (int i = 0; i < arraysize(test_zones); ++i) { |
249 const Zones& zone = test_zones[i]; | 281 const Zones& zone = test_zones[i]; |
250 EXPECT_CALL(mock, MapUrlToZone(testing::StartsWith(zone.url_prefix), | 282 EXPECT_CALL(mock, IsZoneAllowed(UrlPathStartsWith(zone.url_prefix))) |
251 testing::_, testing::_)) | 283 .WillRepeatedly(testing::Return(zone.zone != URLZONE_UNTRUSTED)); |
252 .WillRepeatedly(testing::DoAll( | |
253 testing::SetArgumentPointee<1>(zone.zone), | |
254 testing::Return(S_OK))); | |
255 } | 284 } |
256 | 285 |
257 struct Cases { | 286 struct Cases { |
258 const char* url; | 287 const char* url; |
259 bool is_privileged; | |
260 bool default_expected; | 288 bool default_expected; |
261 bool unsafe_expected; | 289 bool unsafe_expected; |
262 } test_cases[] = { | 290 } test_cases[] = { |
263 // Invalid URL | 291 // Invalid URL |
264 { " ", false, false, false }, | 292 { " ", false, false }, |
265 { "foo bar", true, false, false }, | 293 { "foo bar", false, false }, |
266 | 294 |
267 // non-privileged test cases | 295 // non-privileged test cases |
268 { "http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore", false, | 296 { "http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore", true, |
269 true, true }, | 297 true }, |
270 { "http://untrusted/bar.html", false, false, true }, | 298 { "http://untrusted/bar.html", false, true }, |
271 { "http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore", false, | 299 { "http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore", true, |
272 true, true }, | 300 true }, |
273 { "view-source:http://www.google.ca", false, true, true }, | 301 { "view-source:http://www.google.ca", true, true }, |
274 { "view-source:javascript:alert('foo');", false, false, true }, | 302 { "view-source:javascript:alert('foo');", false, true }, |
275 { "about:blank", false, true, true }, | 303 { "about:blank", true, true }, |
276 { "About:Version", false, true, true }, | 304 { "About:Version", true, true }, |
277 { "about:config", false, false, true }, | 305 { "about:config", false, true }, |
278 { "chrome-extension://aaaaaaaaaaaaaaaaaaa/toolstrip.html", false, false, | 306 { "chrome-extension://aaaaaaaaaaaaaaaaaaa/toolstrip.html", false, true }, |
279 true }, | 307 { "ftp://www.google.ca", false, true }, |
280 { "ftp://www.google.ca", false, false, true }, | 308 { "file://www.google.ca", false, true }, |
281 { "file://www.google.ca", false, false, true }, | 309 { "file://C:\boot.ini", false, true }, |
282 { "file://C:\boot.ini", false, false, true }, | 310 { "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 }; | 311 }; |
303 | 312 |
304 for (int i = 0; i < arraysize(test_cases); ++i) { | 313 for (int i = 0; i < arraysize(test_cases); ++i) { |
305 const Cases& test = test_cases[i]; | 314 const Cases& test = test_cases[i]; |
306 bool actual = CanNavigate(GURL(test.url), &mock, test.is_privileged); | 315 bool actual = CanNavigate(GURL(test.url), &mock); |
307 EXPECT_EQ(test.default_expected, actual) << "Failure url: " << test.url; | 316 EXPECT_EQ(test.default_expected, actual) << "Failure url: " << test.url; |
308 } | 317 } |
318 } | |
309 | 319 |
310 bool enable_gcf = GetConfigBool(false, kAllowUnsafeURLs); | 320 TEST_F(UtilTests, CanNavigateTestDenyAll) { |
311 SetConfigBool(kAllowUnsafeURLs, true); | 321 MockNavigationConstraints mock; |
312 | 322 |
313 for (int i = 0; i < arraysize(test_cases); ++i) { | 323 EXPECT_CALL(mock, IsZoneAllowed(testing::_)) |
314 const Cases& test = test_cases[i]; | 324 .Times(testing::AnyNumber()) |
315 bool actual = CanNavigate(GURL(test.url), &mock, test.is_privileged); | 325 .WillRepeatedly(testing::Return(false)); |
316 EXPECT_EQ(test.unsafe_expected, actual) << "Failure url: " << test.url; | 326 |
327 EXPECT_CALL(mock, IsSchemeAllowed(testing::_)) | |
328 .Times(testing::AnyNumber()) | |
329 .WillRepeatedly(testing::Return(false)); | |
330 | |
331 EXPECT_CALL(mock, AllowUnsafeUrls()) | |
332 .Times(testing::AnyNumber()) | |
333 .WillRepeatedly(testing::Return(false)); | |
334 | |
335 char *urls[] = { | |
amit
2010/12/13 23:45:27
would it make sense to use the same 'test_cases' l
ananta
2010/12/14 00:36:27
Done.
| |
336 {"http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore"}, | |
337 {"http://untrusted/bar.html"}, | |
338 {"http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore"}, | |
339 {"view-source:http://www.google.ca"}, | |
340 {"view-source:javascript:alert('foo');"}, | |
341 {"about:blank"}, | |
342 {"About:Version"}, | |
343 }; | |
344 | |
345 for (int i = 0; i < arraysize(urls); ++i) { | |
346 EXPECT_FALSE(CanNavigate(GURL(urls[i]), &mock)); | |
317 } | 347 } |
348 } | |
318 | 349 |
319 SetConfigBool(kAllowUnsafeURLs, enable_gcf); | 350 TEST_F(UtilTests, CanNavigateTestAllowAll) { |
351 MockNavigationConstraints mock; | |
352 | |
353 EXPECT_CALL(mock, AllowUnsafeUrls()) | |
354 .Times(testing::AnyNumber()) | |
355 .WillRepeatedly(testing::Return(false)); | |
356 | |
357 EXPECT_CALL(mock, IsSchemeAllowed(testing::_)) | |
358 .Times(testing::AnyNumber()) | |
359 .WillRepeatedly(testing::Return(true)); | |
360 | |
361 EXPECT_CALL(mock, IsZoneAllowed(testing::_)) | |
362 .Times(testing::AnyNumber()) | |
363 .WillRepeatedly(testing::Return(true)); | |
364 | |
365 char *urls[] = { | |
366 {"gcf:about:cache"}, | |
367 {"gcf:http://www.google.com"}, | |
368 {"view-source:javascript:alert('foo');"}, | |
369 {"http://www.google.com"}, | |
370 }; | |
371 | |
372 for (int i = 0; i < arraysize(urls); ++i) { | |
373 EXPECT_TRUE(CanNavigate(GURL(urls[i]), &mock)); | |
374 } | |
375 } | |
376 | |
377 TEST_F(UtilTests, CanNavigateTestAllowAllUnsafeUrs) { | |
amit
2010/12/13 23:45:27
nit:CanNavigateTestAllowAllUnsafeUr'l's
ananta
2010/12/14 00:36:27
Done.
| |
378 MockNavigationConstraints mock; | |
379 | |
380 EXPECT_CALL(mock, AllowUnsafeUrls()) | |
381 .Times(testing::AnyNumber()) | |
382 .WillRepeatedly(testing::Return(true)); | |
383 | |
384 char *urls[] = { | |
385 {"gcf:about:cache"}, | |
386 {"gcf:http://www.google.com"}, | |
387 {"view-source:javascript:alert('foo');"}, | |
388 {"http://www.google.com"}, | |
389 }; | |
390 | |
391 for (int i = 0; i < arraysize(urls); ++i) { | |
392 EXPECT_TRUE(CanNavigate(GURL(urls[i]), &mock)); | |
393 } | |
320 } | 394 } |
321 | 395 |
322 TEST_F(UtilTests, IsDefaultRendererTest) { | 396 TEST_F(UtilTests, IsDefaultRendererTest) { |
323 RegKey config_key(HKEY_CURRENT_USER, kChromeFrameConfigKey, KEY_ALL_ACCESS); | 397 RegKey config_key(HKEY_CURRENT_USER, kChromeFrameConfigKey, KEY_ALL_ACCESS); |
324 EXPECT_TRUE(config_key.Valid()); | 398 EXPECT_TRUE(config_key.Valid()); |
325 | 399 |
326 DWORD saved_default_renderer = 0; // NOLINT | 400 DWORD saved_default_renderer = 0; // NOLINT |
327 config_key.ReadValueDW(kEnableGCFRendererByDefault, &saved_default_renderer); | 401 config_key.ReadValueDW(kEnableGCFRendererByDefault, &saved_default_renderer); |
328 | 402 |
329 config_key.DeleteValue(kEnableGCFRendererByDefault); | 403 config_key.DeleteValue(kEnableGCFRendererByDefault); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
440 | 514 |
441 ASSERT_EQ(expect_match, | 515 ASSERT_EQ(expect_match, |
442 CheckXUaCompatibleDirective(test.header_value, | 516 CheckXUaCompatibleDirective(test.header_value, |
443 all_versions[version_index])) | 517 all_versions[version_index])) |
444 << "Expect '" << test.header_value << "' to " | 518 << "Expect '" << test.header_value << "' to " |
445 << (expect_match ? "match" : "not match") << " IE major version " | 519 << (expect_match ? "match" : "not match") << " IE major version " |
446 << all_versions[version_index]; | 520 << all_versions[version_index]; |
447 } | 521 } |
448 } | 522 } |
449 } | 523 } |
OLD | NEW |