OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <windows.h> | 5 #include <windows.h> |
6 #include <atlsecurity.h> | 6 #include <atlsecurity.h> |
7 #include <shellapi.h> | 7 #include <shellapi.h> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 HTMLScanner::StringRangeList foo_tag_list; | 312 HTMLScanner::StringRangeList foo_tag_list; |
313 scanner.GetTagsByName(L"foo", &foo_tag_list, L"body"); | 313 scanner.GetTagsByName(L"foo", &foo_tag_list, L"body"); |
314 ASSERT_TRUE(foo_tag_list.empty()); | 314 ASSERT_TRUE(foo_tag_list.empty()); |
315 | 315 |
316 // Ensure that the boo tags are detected. | 316 // Ensure that the boo tags are detected. |
317 HTMLScanner::StringRangeList boo_tag_list; | 317 HTMLScanner::StringRangeList boo_tag_list; |
318 scanner.GetTagsByName(L"boo", &boo_tag_list, L"body"); | 318 scanner.GetTagsByName(L"boo", &boo_tag_list, L"body"); |
319 ASSERT_EQ(2, boo_tag_list.size()); | 319 ASSERT_EQ(2, boo_tag_list.size()); |
320 } | 320 } |
321 | 321 |
| 322 struct UserAgentTestCase { |
| 323 std::string input_; |
| 324 std::string expected_; |
| 325 } user_agent_test_cases[] = { |
| 326 { |
| 327 "", "" |
| 328 }, { |
| 329 "Mozilla/4.7 [en] (WinNT; U)", |
| 330 "Mozilla/4.7 [en] (WinNT; U; chromeframe/0.0.0.0)" |
| 331 }, { |
| 332 "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT)", |
| 333 "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT; chromeframe/0.0.0.0)" |
| 334 }, { |
| 335 "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; T312461; " |
| 336 ".NET CLR 1.1.4322)", |
| 337 "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; T312461; " |
| 338 ".NET CLR 1.1.4322; chromeframe/0.0.0.0)" |
| 339 }, { |
| 340 "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT 4.0) Opera 5.11 [en]", |
| 341 "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT 4.0; chromeframe/0.0.0.0) " |
| 342 "Opera 5.11 [en]" |
| 343 }, { |
| 344 "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)", |
| 345 "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; " |
| 346 "chromeframe/0.0.0.0)" |
| 347 }, { |
| 348 "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) " |
| 349 "Gecko/20030208 Netscape/7.02", |
| 350 "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2; " |
| 351 "chromeframe/0.0.0.0) Gecko/20030208 Netscape/7.02" |
| 352 }, { |
| 353 "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040612 " |
| 354 "Firefox/0.8", |
| 355 "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6; chromeframe/0.0.0.0) " |
| 356 "Gecko/20040612 Firefox/0.8" |
| 357 }, { |
| 358 "Mozilla/5.0 (compatible; Konqueror/3.2; Linux) (KHTML, like Gecko)", |
| 359 "Mozilla/5.0 (compatible; Konqueror/3.2; Linux; chromeframe/0.0.0.0) " |
| 360 "(KHTML, like Gecko)" |
| 361 }, { |
| 362 "Lynx/2.8.4rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.6h", |
| 363 "Lynx/2.8.4rel.1 libwww-FM/2.14 SSL-MM/1.4.1 " |
| 364 "OpenSSL/0.9.6h chromeframe/0.0.0.0", |
| 365 }, { |
| 366 "Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.7.10) " |
| 367 "Gecko/20050716 Firefox/1.0.6", |
| 368 "Mozilla/5.0 (X11; U; Linux i686 (x86_64; chromeframe/0.0.0.0); en-US; " |
| 369 "rv:1.7.10) Gecko/20050716 Firefox/1.0.6" |
| 370 }, { |
| 371 "Invalid/1.1 ((((((", |
| 372 "Invalid/1.1 (((((( chromeframe/0.0.0.0", |
| 373 }, { |
| 374 "Invalid/1.1 ()))))", |
| 375 "Invalid/1.1 ( chromeframe/0.0.0.0)))))", |
| 376 }, { |
| 377 "Strange/1.1 ()", |
| 378 "Strange/1.1 ( chromeframe/0.0.0.0)", |
| 379 } |
| 380 }; |
| 381 |
322 TEST_F(HtmlUtilUnittest, AddChromeFrameToUserAgentValue) { | 382 TEST_F(HtmlUtilUnittest, AddChromeFrameToUserAgentValue) { |
323 struct TestCase { | 383 for (int i = 0; i < arraysize(user_agent_test_cases); ++i) { |
324 std::string input_; | |
325 std::string expected_; | |
326 } test_cases[] = { | |
327 { | |
328 "", "" | |
329 }, { | |
330 "Mozilla/4.7 [en] (WinNT; U)", | |
331 "Mozilla/4.7 [en] (WinNT; U; chromeframe/0.0.0.0)" | |
332 }, { | |
333 "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT)", | |
334 "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT; chromeframe/0.0.0.0)" | |
335 }, { | |
336 "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; T312461; " | |
337 ".NET CLR 1.1.4322)", | |
338 "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; T312461; " | |
339 ".NET CLR 1.1.4322; chromeframe/0.0.0.0)" | |
340 }, { | |
341 "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT 4.0) Opera 5.11 [en]", | |
342 "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT 4.0; chromeframe/0.0.0.0) " | |
343 "Opera 5.11 [en]" | |
344 }, { | |
345 "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)", | |
346 "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; " | |
347 "chromeframe/0.0.0.0)" | |
348 }, { | |
349 "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) " | |
350 "Gecko/20030208 Netscape/7.02", | |
351 "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2; " | |
352 "chromeframe/0.0.0.0) Gecko/20030208 Netscape/7.02" | |
353 }, { | |
354 "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040612 " | |
355 "Firefox/0.8", | |
356 "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6; chromeframe/0.0.0.0) " | |
357 "Gecko/20040612 Firefox/0.8" | |
358 }, { | |
359 "Mozilla/5.0 (compatible; Konqueror/3.2; Linux) (KHTML, like Gecko)", | |
360 "Mozilla/5.0 (compatible; Konqueror/3.2; Linux; chromeframe/0.0.0.0) " | |
361 "(KHTML, like Gecko)" | |
362 }, { | |
363 "Lynx/2.8.4rel.1 libwww-FM/2.14 SSL-MM/1.4.1 OpenSSL/0.9.6h", | |
364 "Lynx/2.8.4rel.1 libwww-FM/2.14 SSL-MM/1.4.1 " | |
365 "OpenSSL/0.9.6h chromeframe/0.0.0.0", | |
366 }, { | |
367 "Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.7.10) " | |
368 "Gecko/20050716 Firefox/1.0.6", | |
369 "Mozilla/5.0 (X11; U; Linux i686 (x86_64; chromeframe/0.0.0.0); en-US; " | |
370 "rv:1.7.10) Gecko/20050716 Firefox/1.0.6" | |
371 }, { | |
372 "Invalid/1.1 ((((((", | |
373 "Invalid/1.1 (((((( chromeframe/0.0.0.0", | |
374 }, { | |
375 "Invalid/1.1 ()))))", | |
376 "Invalid/1.1 ( chromeframe/0.0.0.0)))))", | |
377 }, { | |
378 "Strange/1.1 ()", | |
379 "Strange/1.1 ( chromeframe/0.0.0.0)", | |
380 } | |
381 }; | |
382 | |
383 for (int i = 0; i < arraysize(test_cases); ++i) { | |
384 std::string new_ua( | 384 std::string new_ua( |
385 http_utils::AddChromeFrameToUserAgentValue(test_cases[i].input_)); | 385 http_utils::AddChromeFrameToUserAgentValue( |
386 EXPECT_EQ(test_cases[i].expected_, new_ua); | 386 user_agent_test_cases[i].input_)); |
| 387 EXPECT_EQ(user_agent_test_cases[i].expected_, new_ua); |
387 } | 388 } |
388 | 389 |
389 // Now do the same test again, but test that we don't add the chromeframe | 390 // Now do the same test again, but test that we don't add the chromeframe |
390 // tag if we've already added it. | 391 // tag if we've already added it. |
391 for (int i = 0; i < arraysize(test_cases); ++i) { | 392 for (int i = 0; i < arraysize(user_agent_test_cases); ++i) { |
392 std::string ua(test_cases[i].expected_); | 393 std::string ua(user_agent_test_cases[i].expected_); |
393 std::string new_ua(http_utils::AddChromeFrameToUserAgentValue(ua)); | 394 std::string new_ua(http_utils::AddChromeFrameToUserAgentValue(ua)); |
394 EXPECT_EQ(test_cases[i].expected_, new_ua); | 395 EXPECT_EQ(user_agent_test_cases[i].expected_, new_ua); |
395 } | 396 } |
396 } | 397 } |
397 | 398 |
| 399 TEST_F(HtmlUtilUnittest, RemoveChromeFrameFromUserAgentValue) { |
| 400 for (int i = 0; i < arraysize(user_agent_test_cases); ++i) { |
| 401 std::string new_ua( |
| 402 http_utils::RemoveChromeFrameFromUserAgentValue( |
| 403 user_agent_test_cases[i].expected_)); |
| 404 EXPECT_EQ(user_agent_test_cases[i].input_, new_ua); |
| 405 } |
| 406 |
| 407 // Also test that we don't modify the UA if chromeframe is not present. |
| 408 for (int i = 0; i < arraysize(user_agent_test_cases); ++i) { |
| 409 std::string ua(user_agent_test_cases[i].input_); |
| 410 std::string new_ua(http_utils::RemoveChromeFrameFromUserAgentValue(ua)); |
| 411 EXPECT_EQ(user_agent_test_cases[i].input_, new_ua); |
| 412 } |
| 413 } |
| 414 |
398 TEST_F(HtmlUtilUnittest, GetDefaultUserAgentHeaderWithCFTag) { | 415 TEST_F(HtmlUtilUnittest, GetDefaultUserAgentHeaderWithCFTag) { |
399 std::string ua(http_utils::GetDefaultUserAgentHeaderWithCFTag()); | 416 std::string ua(http_utils::GetDefaultUserAgentHeaderWithCFTag()); |
400 EXPECT_NE(0u, ua.length()); | 417 EXPECT_NE(0u, ua.length()); |
401 EXPECT_NE(std::string::npos, ua.find("Mozilla")); | 418 EXPECT_NE(std::string::npos, ua.find("Mozilla")); |
402 EXPECT_NE(std::string::npos, ua.find(kChromeFrameUserAgent)); | 419 EXPECT_NE(std::string::npos, ua.find(kChromeFrameUserAgent)); |
403 } | 420 } |
404 | 421 |
405 TEST_F(HtmlUtilUnittest, GetChromeUserAgent) { | 422 TEST_F(HtmlUtilUnittest, GetChromeUserAgent) { |
406 // This code is duplicated from chrome_content_client.cc to avoid | 423 // This code is duplicated from chrome_content_client.cc to avoid |
407 // introducing a link-time dependency on chrome_common. | 424 // introducing a link-time dependency on chrome_common. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 "Content-Length: 42\r\n" | 495 "Content-Length: 42\r\n" |
479 "X-Frame-Options: SAMEORIGIN\r\n")); | 496 "X-Frame-Options: SAMEORIGIN\r\n")); |
480 EXPECT_TRUE(http_utils::HasFrameBustingHeader( | 497 EXPECT_TRUE(http_utils::HasFrameBustingHeader( |
481 "X-Frame-Options: deny\r\n" | 498 "X-Frame-Options: deny\r\n" |
482 "X-Frame-Options: ALLOWall\r\n" | 499 "X-Frame-Options: ALLOWall\r\n" |
483 "Content-Length: 42\r\n")); | 500 "Content-Length: 42\r\n")); |
484 EXPECT_TRUE(http_utils::HasFrameBustingHeader( | 501 EXPECT_TRUE(http_utils::HasFrameBustingHeader( |
485 "X-Frame-Options: SAMEORIGIN\r\n" | 502 "X-Frame-Options: SAMEORIGIN\r\n" |
486 "X-Frame-Options: ALLOWall\r\n")); | 503 "X-Frame-Options: ALLOWall\r\n")); |
487 } | 504 } |
OLD | NEW |