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 <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 |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 EXPECT_TRUE(tag_list[0].GetTagAttribute(L"content", &attribute_value)); | 206 EXPECT_TRUE(tag_list[0].GetTagAttribute(L"content", &attribute_value)); |
207 EXPECT_TRUE(attribute_value.Equals(L"chrome=1")); | 207 EXPECT_TRUE(attribute_value.Equals(L"chrome=1")); |
208 } | 208 } |
209 | 209 |
210 TEST_F(HtmlUtilUnittest, CloseTagInsideHTMLCommentTest) { | 210 TEST_F(HtmlUtilUnittest, CloseTagInsideHTMLCommentTest) { |
211 std::wstring test_data( | 211 std::wstring test_data( |
212 L"<!-- comment> <META http-equiv=X-UA-Compatible content='chrome=1'/>-->"); | 212 L"<!-- comment> <META http-equiv=X-UA-Compatible content='chrome=1'/>-->"); |
213 | 213 |
214 HTMLScanner scanner(test_data.c_str()); | 214 HTMLScanner scanner(test_data.c_str()); |
215 | 215 |
216 // Grab the meta tag from the document and ensure that we get exactly one. | 216 // Ensure that the the meta tag is NOT detected. |
217 HTMLScanner::StringRangeList tag_list; | 217 HTMLScanner::StringRangeList tag_list; |
218 scanner.GetTagsByName(L"meta", &tag_list, L"body"); | 218 scanner.GetTagsByName(L"meta", &tag_list, L"body"); |
219 ASSERT_TRUE(tag_list.empty()); | 219 ASSERT_TRUE(tag_list.empty()); |
220 } | 220 } |
221 | 221 |
| 222 TEST_F(HtmlUtilUnittest, IEConditionalCommentTest) { |
| 223 std::wstring test_data( |
| 224 L"<!--[if lte IE 8]><META http-equiv=X-UA-Compatible content='chrome=1'/>" |
| 225 L"<![endif]-->"); |
| 226 |
| 227 HTMLScanner scanner(test_data.c_str()); |
| 228 |
| 229 // Ensure that the the meta tag IS detected. |
| 230 HTMLScanner::StringRangeList tag_list; |
| 231 scanner.GetTagsByName(L"meta", &tag_list, L"body"); |
| 232 ASSERT_EQ(1, tag_list.size()); |
| 233 } |
| 234 |
| 235 TEST_F(HtmlUtilUnittest, IEConditionalCommentWithNestedCommentTest) { |
| 236 std::wstring test_data( |
| 237 L"<!--[if IE]><!--<META http-equiv=X-UA-Compatible content='chrome=1'/>" |
| 238 L"--><![endif]-->"); |
| 239 |
| 240 HTMLScanner scanner(test_data.c_str()); |
| 241 |
| 242 // Ensure that the the meta tag IS NOT detected. |
| 243 HTMLScanner::StringRangeList tag_list; |
| 244 scanner.GetTagsByName(L"meta", &tag_list, L"body"); |
| 245 ASSERT_TRUE(tag_list.empty()); |
| 246 } |
| 247 |
| 248 TEST_F(HtmlUtilUnittest, IEConditionalCommentWithMultipleNestedTagsTest) { |
| 249 std::wstring test_data( |
| 250 L"<!--[if lte IE 8]> <META http-equiv=X-UA-Compatible " |
| 251 L"content='chrome=1'/><foo bar></foo><foo baz/><![endif]-->" |
| 252 L"<boo hoo><boo hah>"); |
| 253 |
| 254 HTMLScanner scanner(test_data.c_str()); |
| 255 |
| 256 // Ensure that the the meta tag IS detected. |
| 257 HTMLScanner::StringRangeList meta_tag_list; |
| 258 scanner.GetTagsByName(L"meta", &meta_tag_list, L"body"); |
| 259 ASSERT_EQ(1, meta_tag_list.size()); |
| 260 |
| 261 // Ensure that the foo tags are also detected. |
| 262 HTMLScanner::StringRangeList foo_tag_list; |
| 263 scanner.GetTagsByName(L"foo", &foo_tag_list, L"body"); |
| 264 ASSERT_EQ(2, foo_tag_list.size()); |
| 265 |
| 266 // Ensure that the boo tags are also detected. |
| 267 HTMLScanner::StringRangeList boo_tag_list; |
| 268 scanner.GetTagsByName(L"boo", &boo_tag_list, L"body"); |
| 269 ASSERT_EQ(2, boo_tag_list.size()); |
| 270 } |
| 271 |
| 272 TEST_F(HtmlUtilUnittest, IEConditionalCommentWithAlternateEndingTest) { |
| 273 std::wstring test_data( |
| 274 L"<!--[if lte IE 8]> <META http-equiv=X-UA-Compatible " |
| 275 L"content='chrome=1'/><foo bar></foo><foo baz/><![endif]>" |
| 276 L"<boo hoo><!--><boo hah>"); |
| 277 |
| 278 HTMLScanner scanner(test_data.c_str()); |
| 279 |
| 280 // Ensure that the the meta tag IS detected. |
| 281 HTMLScanner::StringRangeList meta_tag_list; |
| 282 scanner.GetTagsByName(L"meta", &meta_tag_list, L"body"); |
| 283 ASSERT_EQ(1, meta_tag_list.size()); |
| 284 |
| 285 // Ensure that the foo tags are also detected. |
| 286 HTMLScanner::StringRangeList foo_tag_list; |
| 287 scanner.GetTagsByName(L"foo", &foo_tag_list, L"body"); |
| 288 ASSERT_EQ(2, foo_tag_list.size()); |
| 289 |
| 290 // Ensure that the boo tags are also detected. |
| 291 HTMLScanner::StringRangeList boo_tag_list; |
| 292 scanner.GetTagsByName(L"boo", &boo_tag_list, L"body"); |
| 293 ASSERT_EQ(2, boo_tag_list.size()); |
| 294 } |
| 295 |
| 296 TEST_F(HtmlUtilUnittest, IEConditionalCommentNonTerminatedTest) { |
| 297 // This test shouldn't detect any tags up until the end of the conditional |
| 298 // comment tag. |
| 299 std::wstring test_data( |
| 300 L"<!--[if lte IE 8> <META http-equiv=X-UA-Compatible " |
| 301 L"content='chrome=1'/><foo bar></foo><foo baz/><![endif]>" |
| 302 L"<boo hoo><!--><boo hah>"); |
| 303 |
| 304 HTMLScanner scanner(test_data.c_str()); |
| 305 |
| 306 // Ensure that the the meta tag IS NOT detected. |
| 307 HTMLScanner::StringRangeList meta_tag_list; |
| 308 scanner.GetTagsByName(L"meta", &meta_tag_list, L"body"); |
| 309 ASSERT_TRUE(meta_tag_list.empty()); |
| 310 |
| 311 // Ensure that the foo tags are NOT detected. |
| 312 HTMLScanner::StringRangeList foo_tag_list; |
| 313 scanner.GetTagsByName(L"foo", &foo_tag_list, L"body"); |
| 314 ASSERT_TRUE(foo_tag_list.empty()); |
| 315 |
| 316 // Ensure that the boo tags are detected. |
| 317 HTMLScanner::StringRangeList boo_tag_list; |
| 318 scanner.GetTagsByName(L"boo", &boo_tag_list, L"body"); |
| 319 ASSERT_EQ(2, boo_tag_list.size()); |
| 320 } |
| 321 |
222 TEST_F(HtmlUtilUnittest, AddChromeFrameToUserAgentValue) { | 322 TEST_F(HtmlUtilUnittest, AddChromeFrameToUserAgentValue) { |
223 struct TestCase { | 323 struct TestCase { |
224 std::string input_; | 324 std::string input_; |
225 std::string expected_; | 325 std::string expected_; |
226 } test_cases[] = { | 326 } test_cases[] = { |
227 { | 327 { |
228 "", "" | 328 "", "" |
229 }, { | 329 }, { |
230 "Mozilla/4.7 [en] (WinNT; U)", | 330 "Mozilla/4.7 [en] (WinNT; U)", |
231 "Mozilla/4.7 [en] (WinNT; U) chromeframe/0.0.0.0" | 331 "Mozilla/4.7 [en] (WinNT; U) chromeframe/0.0.0.0" |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
370 "Content-Length: 42\r\n" | 470 "Content-Length: 42\r\n" |
371 "X-Frame-Options: SAMEORIGIN\r\n")); | 471 "X-Frame-Options: SAMEORIGIN\r\n")); |
372 EXPECT_TRUE(http_utils::HasFrameBustingHeader( | 472 EXPECT_TRUE(http_utils::HasFrameBustingHeader( |
373 "X-Frame-Options: deny\r\n" | 473 "X-Frame-Options: deny\r\n" |
374 "X-Frame-Options: ALLOWall\r\n" | 474 "X-Frame-Options: ALLOWall\r\n" |
375 "Content-Length: 42\r\n")); | 475 "Content-Length: 42\r\n")); |
376 EXPECT_TRUE(http_utils::HasFrameBustingHeader( | 476 EXPECT_TRUE(http_utils::HasFrameBustingHeader( |
377 "X-Frame-Options: SAMEORIGIN\r\n" | 477 "X-Frame-Options: SAMEORIGIN\r\n" |
378 "X-Frame-Options: ALLOWall\r\n")); | 478 "X-Frame-Options: ALLOWall\r\n")); |
379 } | 479 } |
OLD | NEW |