| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "core/html/parser/HTMLPreloadScanner.h" | 5 #include "core/html/parser/HTMLPreloadScanner.h" |
| 6 | 6 |
| 7 #include "core/MediaTypeNames.h" | 7 #include "core/MediaTypeNames.h" |
| 8 #include "core/css/MediaValuesCached.h" | 8 #include "core/css/MediaValuesCached.h" |
| 9 #include "core/fetch/ClientHintsPreferences.h" | 9 #include "core/fetch/ClientHintsPreferences.h" |
| 10 #include "core/frame/Settings.h" | 10 #include "core/frame/Settings.h" |
| (...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 {"http://example.test", "<img src='data:text/html,<p>data</data>'>", | 733 {"http://example.test", "<img src='data:text/html,<p>data</data>'>", |
| 734 nullptr, "http://example.test/", Resource::Image, 0}, | 734 nullptr, "http://example.test/", Resource::Image, 0}, |
| 735 {"data:text/html,<a>anchor</a>", "<img src='#anchor'>", nullptr, | 735 {"data:text/html,<a>anchor</a>", "<img src='#anchor'>", nullptr, |
| 736 "http://example.test/", Resource::Image, 0}, | 736 "http://example.test/", Resource::Image, 0}, |
| 737 }; | 737 }; |
| 738 | 738 |
| 739 for (const auto& testCase : testCases) | 739 for (const auto& testCase : testCases) |
| 740 test(testCase); | 740 test(testCase); |
| 741 } | 741 } |
| 742 | 742 |
| 743 // The preload scanner should follow the same policy that the ScriptLoader does |
| 744 // with regard to the type and language attribute. |
| 745 TEST_F(HTMLPreloadScannerTest, testScriptTypeAndLanguage) { |
| 746 TestCase testCases[] = { |
| 747 // Allow empty src and language attributes. |
| 748 {"http://example.test", "<script src='test.js'></script>", "test.js", |
| 749 "http://example.test/", Resource::Script, 0}, |
| 750 {"http://example.test", |
| 751 "<script type='' language='' src='test.js'></script>", "test.js", |
| 752 "http://example.test/", Resource::Script, 0}, |
| 753 // Allow standard language and type attributes. |
| 754 {"http://example.test", |
| 755 "<script type='text/javascript' src='test.js'></script>", "test.js", |
| 756 "http://example.test/", Resource::Script, 0}, |
| 757 {"http://example.test", |
| 758 "<script type='text/javascript' language='javascript' " |
| 759 "src='test.js'></script>", |
| 760 "test.js", "http://example.test/", Resource::Script, 0}, |
| 761 // Allow legacy languages in the "language" attribute with an empty |
| 762 // type. |
| 763 {"http://example.test", |
| 764 "<script language='javascript1.1' src='test.js'></script>", "test.js", |
| 765 "http://example.test/", Resource::Script, 0}, |
| 766 // Allow legacy languages in the "type" attribute. |
| 767 {"http://example.test", |
| 768 "<script type='javascript' src='test.js'></script>", "test.js", |
| 769 "http://example.test/", Resource::Script, 0}, |
| 770 {"http://example.test", |
| 771 "<script type='javascript1.7' src='test.js'></script>", "test.js", |
| 772 "http://example.test/", Resource::Script, 0}, |
| 773 // Do not allow invalid types in the "type" attribute. |
| 774 {"http://example.test", "<script type='invalid' src='test.js'></script>", |
| 775 nullptr, "http://example.test/", Resource::Script, 0}, |
| 776 {"http://example.test", "<script type='asdf' src='test.js'></script>", |
| 777 nullptr, "http://example.test/", Resource::Script, 0}, |
| 778 // Do not allow invalid languages. |
| 779 {"http://example.test", |
| 780 "<script language='french' src='test.js'></script>", nullptr, |
| 781 "http://example.test/", Resource::Script, 0}, |
| 782 {"http://example.test", |
| 783 "<script language='python' src='test.js'></script>", nullptr, |
| 784 "http://example.test/", Resource::Script, 0}, |
| 785 }; |
| 786 |
| 787 for (const auto& testCase : testCases) |
| 788 test(testCase); |
| 789 } |
| 790 |
| 743 } // namespace blink | 791 } // namespace blink |
| OLD | NEW |