| 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" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "base/win/registry.h" | 10 #include "base/win/registry.h" |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 | 264 |
| 265 struct Zones { | 265 struct Zones { |
| 266 const wchar_t* url_prefix; | 266 const wchar_t* url_prefix; |
| 267 URLZONE zone; | 267 URLZONE zone; |
| 268 } test_zones[] = { | 268 } test_zones[] = { |
| 269 { L"http://blah", URLZONE_INTERNET }, | 269 { L"http://blah", URLZONE_INTERNET }, |
| 270 { L"http://untrusted", URLZONE_UNTRUSTED }, | 270 { L"http://untrusted", URLZONE_UNTRUSTED }, |
| 271 { L"about:", URLZONE_TRUSTED }, | 271 { L"about:", URLZONE_TRUSTED }, |
| 272 { L"view-source:", URLZONE_TRUSTED }, | 272 { L"view-source:", URLZONE_TRUSTED }, |
| 273 { L"chrome-extension:", URLZONE_TRUSTED }, | 273 { L"chrome-extension:", URLZONE_TRUSTED }, |
| 274 { L"data:", URLZONE_INTERNET }, |
| 274 { L"ftp:", URLZONE_UNTRUSTED }, | 275 { L"ftp:", URLZONE_UNTRUSTED }, |
| 275 { L"file:", URLZONE_LOCAL_MACHINE }, | 276 { L"file:", URLZONE_LOCAL_MACHINE }, |
| 276 { L"sip:", URLZONE_UNTRUSTED }, | 277 { L"sip:", URLZONE_UNTRUSTED }, |
| 277 }; | 278 }; |
| 278 | 279 |
| 279 for (int i = 0; i < arraysize(test_zones); ++i) { | 280 for (int i = 0; i < arraysize(test_zones); ++i) { |
| 280 const Zones& zone = test_zones[i]; | 281 const Zones& zone = test_zones[i]; |
| 281 EXPECT_CALL(mock, IsZoneAllowed(UrlPathStartsWith(zone.url_prefix))) | 282 EXPECT_CALL(mock, IsZoneAllowed(UrlPathStartsWith(zone.url_prefix))) |
| 282 .WillRepeatedly(testing::Return(zone.zone != URLZONE_UNTRUSTED)); | 283 .WillRepeatedly(testing::Return(zone.zone != URLZONE_UNTRUSTED)); |
| 283 } | 284 } |
| 284 | 285 |
| 285 struct Cases { | 286 struct Cases { |
| 286 const char* url; | 287 const char* url; |
| 287 bool default_expected; | 288 bool default_expected; |
| 288 bool unsafe_expected; | 289 bool unsafe_expected; |
| 290 bool is_privileged; |
| 289 } test_cases[] = { | 291 } test_cases[] = { |
| 290 // Invalid URL | 292 // Invalid URL |
| 291 { " ", false, false }, | 293 { " ", false, false, false }, |
| 292 { "foo bar", false, false }, | 294 { "foo bar", false, false, false }, |
| 293 | 295 |
| 294 // non-privileged test cases | 296 // non-privileged test cases |
| 295 { "http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore", true, | 297 { "http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore", true, |
| 298 true, false }, |
| 299 { "http://untrusted/bar.html", false, true, false }, |
| 300 { "http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore", true, |
| 301 true, false }, |
| 302 { "view-source:http://www.google.ca", true, true, false }, |
| 303 { "view-source:javascript:alert('foo');", false, true, false }, |
| 304 { "about:blank", true, true, false }, |
| 305 { "About:Version", true, true, false }, |
| 306 { "about:config", false, true, false }, |
| 307 { "chrome-extension://aaaaaaaaaaaaaaaaaaa/toolstrip.html", false, true, |
| 308 false }, |
| 309 { "ftp://www.google.ca", false, true, false }, |
| 310 { "file://www.google.ca", false, true, false }, |
| 311 { "file://C:\boot.ini", false, true, false }, |
| 312 { "SIP:someone@10.1.2.3", false, true, false }, |
| 313 |
| 314 // privileged test cases |
| 315 { "chrome-extension://aaaaaaaaaaaaaaaaaaa/toolstrip.html", true, true, |
| 296 true }, | 316 true }, |
| 297 { "http://untrusted/bar.html", false, true }, | 317 { "data://aaaaaaaaaaaaaaaaaaa/toolstrip.html", true, true, true }, |
| 298 { "http://blah/?attach_external_tab&10&1&0&0&100&100&iexplore", true, | |
| 299 true }, | |
| 300 { "view-source:http://www.google.ca", true, true }, | |
| 301 { "view-source:javascript:alert('foo');", false, true }, | |
| 302 { "about:blank", true, true }, | |
| 303 { "About:Version", true, true }, | |
| 304 { "about:config", false, true }, | |
| 305 { "chrome-extension://aaaaaaaaaaaaaaaaaaa/toolstrip.html", false, true }, | |
| 306 { "ftp://www.google.ca", false, true }, | |
| 307 { "file://www.google.ca", false, true }, | |
| 308 { "file://C:\boot.ini", false, true }, | |
| 309 { "SIP:someone@10.1.2.3", false, true }, | |
| 310 }; | 318 }; |
| 311 | 319 |
| 312 for (int i = 0; i < arraysize(test_cases); ++i) { | 320 for (int i = 0; i < arraysize(test_cases); ++i) { |
| 313 const Cases& test = test_cases[i]; | 321 const Cases& test = test_cases[i]; |
| 322 mock.set_is_privileged(test.is_privileged); |
| 314 bool actual = CanNavigate(GURL(test.url), &mock); | 323 bool actual = CanNavigate(GURL(test.url), &mock); |
| 315 EXPECT_EQ(test.default_expected, actual) << "Failure url: " << test.url; | 324 EXPECT_EQ(test.default_expected, actual) << "Failure url: " << test.url; |
| 316 } | 325 } |
| 317 } | 326 } |
| 318 | 327 |
| 319 TEST_F(UtilTests, CanNavigateTestDenyAll) { | 328 TEST_F(UtilTests, CanNavigateTestDenyAll) { |
| 320 MockNavigationConstraints mock; | 329 MockNavigationConstraints mock; |
| 321 | 330 |
| 322 EXPECT_CALL(mock, IsZoneAllowed(testing::_)) | 331 EXPECT_CALL(mock, IsZoneAllowed(testing::_)) |
| 323 .Times(testing::AnyNumber()) | 332 .Times(testing::AnyNumber()) |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 | 543 |
| 535 ASSERT_EQ(expect_match, | 544 ASSERT_EQ(expect_match, |
| 536 CheckXUaCompatibleDirective(test.header_value, | 545 CheckXUaCompatibleDirective(test.header_value, |
| 537 all_versions[version_index])) | 546 all_versions[version_index])) |
| 538 << "Expect '" << test.header_value << "' to " | 547 << "Expect '" << test.header_value << "' to " |
| 539 << (expect_match ? "match" : "not match") << " IE major version " | 548 << (expect_match ? "match" : "not match") << " IE major version " |
| 540 << all_versions[version_index]; | 549 << all_versions[version_index]; |
| 541 } | 550 } |
| 542 } | 551 } |
| 543 } | 552 } |
| OLD | NEW |