summaryrefslogtreecommitdiffstats
path: root/chrome_frame/test/html_util_unittests.cc
diff options
context:
space:
mode:
authorrobertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-14 20:57:55 +0000
committerrobertshield@chromium.org <robertshield@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-14 20:57:55 +0000
commit9f2c80205e234968f2519f60a6bc9fa6528148f7 (patch)
tree9dd9ba83425bc07558c212d8b9ff7e68d437e04d /chrome_frame/test/html_util_unittests.cc
parent1e7b72d0b63349e8d3876cf46226ec3ce5feb5fa (diff)
downloadchromium_src-9f2c80205e234968f2519f60a6bc9fa6528148f7.zip
chromium_src-9f2c80205e234968f2519f60a6bc9fa6528148f7.tar.gz
chromium_src-9f2c80205e234968f2519f60a6bc9fa6528148f7.tar.bz2
Have Chrome Frame "support" IE conditional comment tags (of the downlevel-hidden variety) by ignoring them (rather than treating them as comment start/end) when parsing HTML streams.
BUG=65627 TEST=chrome_frame_unittests.exe, also syntax like <!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><![endif]--> will now activate CF. Offtopic: I wonder what happens if I paste HTML into CL comments. Heh. Review URL: http://codereview.chromium.org/5708007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@69177 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome_frame/test/html_util_unittests.cc')
-rw-r--r--chrome_frame/test/html_util_unittests.cc102
1 files changed, 101 insertions, 1 deletions
diff --git a/chrome_frame/test/html_util_unittests.cc b/chrome_frame/test/html_util_unittests.cc
index 02b54a4..b182519 100644
--- a/chrome_frame/test/html_util_unittests.cc
+++ b/chrome_frame/test/html_util_unittests.cc
@@ -213,12 +213,112 @@ TEST_F(HtmlUtilUnittest, CloseTagInsideHTMLCommentTest) {
HTMLScanner scanner(test_data.c_str());
- // Grab the meta tag from the document and ensure that we get exactly one.
+ // Ensure that the the meta tag is NOT detected.
+ HTMLScanner::StringRangeList tag_list;
+ scanner.GetTagsByName(L"meta", &tag_list, L"body");
+ ASSERT_TRUE(tag_list.empty());
+}
+
+TEST_F(HtmlUtilUnittest, IEConditionalCommentTest) {
+ std::wstring test_data(
+ L"<!--[if lte IE 8]><META http-equiv=X-UA-Compatible content='chrome=1'/>"
+ L"<![endif]-->");
+
+ HTMLScanner scanner(test_data.c_str());
+
+ // Ensure that the the meta tag IS detected.
+ HTMLScanner::StringRangeList tag_list;
+ scanner.GetTagsByName(L"meta", &tag_list, L"body");
+ ASSERT_EQ(1, tag_list.size());
+}
+
+TEST_F(HtmlUtilUnittest, IEConditionalCommentWithNestedCommentTest) {
+ std::wstring test_data(
+ L"<!--[if IE]><!--<META http-equiv=X-UA-Compatible content='chrome=1'/>"
+ L"--><![endif]-->");
+
+ HTMLScanner scanner(test_data.c_str());
+
+ // Ensure that the the meta tag IS NOT detected.
HTMLScanner::StringRangeList tag_list;
scanner.GetTagsByName(L"meta", &tag_list, L"body");
ASSERT_TRUE(tag_list.empty());
}
+TEST_F(HtmlUtilUnittest, IEConditionalCommentWithMultipleNestedTagsTest) {
+ std::wstring test_data(
+ L"<!--[if lte IE 8]> <META http-equiv=X-UA-Compatible "
+ L"content='chrome=1'/><foo bar></foo><foo baz/><![endif]-->"
+ L"<boo hoo><boo hah>");
+
+ HTMLScanner scanner(test_data.c_str());
+
+ // Ensure that the the meta tag IS detected.
+ HTMLScanner::StringRangeList meta_tag_list;
+ scanner.GetTagsByName(L"meta", &meta_tag_list, L"body");
+ ASSERT_EQ(1, meta_tag_list.size());
+
+ // Ensure that the foo tags are also detected.
+ HTMLScanner::StringRangeList foo_tag_list;
+ scanner.GetTagsByName(L"foo", &foo_tag_list, L"body");
+ ASSERT_EQ(2, foo_tag_list.size());
+
+ // Ensure that the boo tags are also detected.
+ HTMLScanner::StringRangeList boo_tag_list;
+ scanner.GetTagsByName(L"boo", &boo_tag_list, L"body");
+ ASSERT_EQ(2, boo_tag_list.size());
+}
+
+TEST_F(HtmlUtilUnittest, IEConditionalCommentWithAlternateEndingTest) {
+ std::wstring test_data(
+ L"<!--[if lte IE 8]> <META http-equiv=X-UA-Compatible "
+ L"content='chrome=1'/><foo bar></foo><foo baz/><![endif]>"
+ L"<boo hoo><!--><boo hah>");
+
+ HTMLScanner scanner(test_data.c_str());
+
+ // Ensure that the the meta tag IS detected.
+ HTMLScanner::StringRangeList meta_tag_list;
+ scanner.GetTagsByName(L"meta", &meta_tag_list, L"body");
+ ASSERT_EQ(1, meta_tag_list.size());
+
+ // Ensure that the foo tags are also detected.
+ HTMLScanner::StringRangeList foo_tag_list;
+ scanner.GetTagsByName(L"foo", &foo_tag_list, L"body");
+ ASSERT_EQ(2, foo_tag_list.size());
+
+ // Ensure that the boo tags are also detected.
+ HTMLScanner::StringRangeList boo_tag_list;
+ scanner.GetTagsByName(L"boo", &boo_tag_list, L"body");
+ ASSERT_EQ(2, boo_tag_list.size());
+}
+
+TEST_F(HtmlUtilUnittest, IEConditionalCommentNonTerminatedTest) {
+ // This test shouldn't detect any tags up until the end of the conditional
+ // comment tag.
+ std::wstring test_data(
+ L"<!--[if lte IE 8> <META http-equiv=X-UA-Compatible "
+ L"content='chrome=1'/><foo bar></foo><foo baz/><![endif]>"
+ L"<boo hoo><!--><boo hah>");
+
+ HTMLScanner scanner(test_data.c_str());
+
+ // Ensure that the the meta tag IS NOT detected.
+ HTMLScanner::StringRangeList meta_tag_list;
+ scanner.GetTagsByName(L"meta", &meta_tag_list, L"body");
+ ASSERT_TRUE(meta_tag_list.empty());
+
+ // Ensure that the foo tags are NOT detected.
+ HTMLScanner::StringRangeList foo_tag_list;
+ scanner.GetTagsByName(L"foo", &foo_tag_list, L"body");
+ ASSERT_TRUE(foo_tag_list.empty());
+
+ // Ensure that the boo tags are detected.
+ HTMLScanner::StringRangeList boo_tag_list;
+ scanner.GetTagsByName(L"boo", &boo_tag_list, L"body");
+ ASSERT_EQ(2, boo_tag_list.size());
+}
+
TEST_F(HtmlUtilUnittest, AddChromeFrameToUserAgentValue) {
struct TestCase {
std::string input_;