OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
387 | 387 |
388 void loadHTML(const WebData& html) | 388 void loadHTML(const WebData& html) |
389 { | 389 { |
390 m_frame->loadHTMLString(html, toKURL("about:blank")); | 390 m_frame->loadHTMLString(html, toKURL("about:blank")); |
391 runPendingTasks(); | 391 runPendingTasks(); |
392 } | 392 } |
393 | 393 |
394 void executeScript(const WebString& code) | 394 void executeScript(const WebString& code) |
395 { | 395 { |
396 m_frame->executeScript(WebScriptSource(code)); | 396 m_frame->executeScript(WebScriptSource(code)); |
| 397 m_frame->view()->layout(); |
397 runPendingTasks(); | 398 runPendingTasks(); |
398 } | 399 } |
399 | 400 |
400 CSSCallbackWebFrameClient m_client; | 401 CSSCallbackWebFrameClient m_client; |
401 FrameTestHelpers::WebViewHelper m_helper; | 402 FrameTestHelpers::WebViewHelper m_helper; |
402 WebFrame* m_frame; | 403 WebFrame* m_frame; |
403 }; | 404 }; |
404 | 405 |
405 TEST_F(WebFrameCSSCallbackTest, AuthorStyleSheet) | 406 TEST_F(WebFrameCSSCallbackTest, AuthorStyleSheet) |
406 { | 407 { |
407 loadHTML( | 408 loadHTML( |
408 "<style>" | 409 "<style>" |
409 // This stylesheet checks that the internal property and value can't be | 410 // This stylesheet checks that the internal property and value can't be |
410 // set by a stylesheet, only WebDocument::watchCSSSelectors(). | 411 // set by a stylesheet, only WebDocument::watchCSSSelectors(). |
411 "div.initial_on { -internal-callback: none; }" | 412 "div.initial_on { -internal-callback: none; }" |
412 "div.initial_off { -internal-callback: -internal-presence; }" | 413 "div.initial_off { -internal-callback: -internal-presence; }" |
413 "</style>" | 414 "</style>" |
414 "<div class=\"initial_on\"></div>" | 415 "<div class=\"initial_on\"></div>" |
415 "<div class=\"initial_off\"></div>"); | 416 "<div class=\"initial_off\"></div>"); |
416 | 417 |
417 std::vector<WebString> selectors; | 418 std::vector<WebString> selectors; |
418 selectors.push_back(WebString::fromUTF8("div.initial_on")); | 419 selectors.push_back(WebString::fromUTF8("div.initial_on")); |
419 m_frame->document().watchCSSSelectors(WebVector<WebString>(selectors)); | 420 m_frame->document().watchCSSSelectors(WebVector<WebString>(selectors)); |
| 421 m_frame->view()->layout(); |
420 runPendingTasks(); | 422 runPendingTasks(); |
421 EXPECT_EQ(1, updateCount()); | 423 EXPECT_EQ(1, updateCount()); |
422 EXPECT_THAT(matchedSelectors(), testing::ElementsAre("div.initial_on")); | 424 EXPECT_THAT(matchedSelectors(), testing::ElementsAre("div.initial_on")); |
423 | 425 |
424 // Check that adding a watched selector calls back for already-present nodes
. | 426 // Check that adding a watched selector calls back for already-present nodes
. |
425 selectors.push_back(WebString::fromUTF8("div.initial_off")); | 427 selectors.push_back(WebString::fromUTF8("div.initial_off")); |
426 doc().watchCSSSelectors(WebVector<WebString>(selectors)); | 428 doc().watchCSSSelectors(WebVector<WebString>(selectors)); |
| 429 m_frame->view()->layout(); |
427 runPendingTasks(); | 430 runPendingTasks(); |
428 EXPECT_EQ(2, updateCount()); | 431 EXPECT_EQ(2, updateCount()); |
429 EXPECT_THAT(matchedSelectors(), testing::ElementsAre("div.initial_off", "div
.initial_on")); | 432 EXPECT_THAT(matchedSelectors(), testing::ElementsAre("div.initial_off", "div
.initial_on")); |
430 | 433 |
431 // Check that we can turn off callbacks for certain selectors. | 434 // Check that we can turn off callbacks for certain selectors. |
432 doc().watchCSSSelectors(WebVector<WebString>()); | 435 doc().watchCSSSelectors(WebVector<WebString>()); |
| 436 m_frame->view()->layout(); |
433 runPendingTasks(); | 437 runPendingTasks(); |
434 EXPECT_EQ(3, updateCount()); | 438 EXPECT_EQ(3, updateCount()); |
435 EXPECT_THAT(matchedSelectors(), testing::ElementsAre()); | 439 EXPECT_THAT(matchedSelectors(), testing::ElementsAre()); |
436 } | 440 } |
437 | 441 |
438 TEST_F(WebFrameCSSCallbackTest, SharedRenderStyle) | 442 TEST_F(WebFrameCSSCallbackTest, SharedRenderStyle) |
439 { | 443 { |
440 // Check that adding an element calls back when it matches an existing rule. | 444 // Check that adding an element calls back when it matches an existing rule. |
441 std::vector<WebString> selectors; | 445 std::vector<WebString> selectors; |
442 selectors.push_back(WebString::fromUTF8("span")); | 446 selectors.push_back(WebString::fromUTF8("span")); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
541 | 545 |
542 TEST_F(WebFrameCSSCallbackTest, Reparenting) | 546 TEST_F(WebFrameCSSCallbackTest, Reparenting) |
543 { | 547 { |
544 loadHTML( | 548 loadHTML( |
545 "<div id='d1'><span></span></div>" | 549 "<div id='d1'><span></span></div>" |
546 "<div id='d2'></div>"); | 550 "<div id='d2'></div>"); |
547 | 551 |
548 std::vector<WebString> selectors; | 552 std::vector<WebString> selectors; |
549 selectors.push_back(WebString::fromUTF8("span")); | 553 selectors.push_back(WebString::fromUTF8("span")); |
550 doc().watchCSSSelectors(WebVector<WebString>(selectors)); | 554 doc().watchCSSSelectors(WebVector<WebString>(selectors)); |
| 555 m_frame->view()->layout(); |
551 runPendingTasks(); | 556 runPendingTasks(); |
552 | 557 |
553 EXPECT_EQ(1, updateCount()); | 558 EXPECT_EQ(1, updateCount()); |
554 EXPECT_THAT(matchedSelectors(), testing::ElementsAre("span")); | 559 EXPECT_THAT(matchedSelectors(), testing::ElementsAre("span")); |
555 | 560 |
556 executeScript( | 561 executeScript( |
557 "s = document.querySelector('span');" | 562 "s = document.querySelector('span');" |
558 "d2 = document.getElementById('d2');" | 563 "d2 = document.getElementById('d2');" |
559 "d2.appendChild(s);"); | 564 "d2.appendChild(s);"); |
560 EXPECT_EQ(1, updateCount()) << "Just moving an element that continues to mat
ch shouldn't send a spurious callback."; | 565 EXPECT_EQ(1, updateCount()) << "Just moving an element that continues to mat
ch shouldn't send a spurious callback."; |
561 EXPECT_THAT(matchedSelectors(), testing::ElementsAre("span")); | 566 EXPECT_THAT(matchedSelectors(), testing::ElementsAre("span")); |
562 } | 567 } |
563 | 568 |
564 TEST_F(WebFrameCSSCallbackTest, MultiSelector) | 569 TEST_F(WebFrameCSSCallbackTest, MultiSelector) |
565 { | 570 { |
566 loadHTML("<span></span>"); | 571 loadHTML("<span></span>"); |
567 | 572 |
568 // Check that selector lists match as the whole list, not as each element | 573 // Check that selector lists match as the whole list, not as each element |
569 // independently. | 574 // independently. |
570 std::vector<WebString> selectors; | 575 std::vector<WebString> selectors; |
571 selectors.push_back(WebString::fromUTF8("span")); | 576 selectors.push_back(WebString::fromUTF8("span")); |
572 selectors.push_back(WebString::fromUTF8("span,p")); | 577 selectors.push_back(WebString::fromUTF8("span,p")); |
573 doc().watchCSSSelectors(WebVector<WebString>(selectors)); | 578 doc().watchCSSSelectors(WebVector<WebString>(selectors)); |
| 579 m_frame->view()->layout(); |
| 580 runPendingTasks(); |
574 | 581 |
575 runPendingTasks(); | |
576 EXPECT_EQ(1, updateCount()); | 582 EXPECT_EQ(1, updateCount()); |
577 EXPECT_THAT(matchedSelectors(), testing::ElementsAre("span", "span, p")); | 583 EXPECT_THAT(matchedSelectors(), testing::ElementsAre("span", "span, p")); |
578 } | 584 } |
579 | 585 |
580 TEST_F(WebFrameCSSCallbackTest, InvalidSelector) | 586 TEST_F(WebFrameCSSCallbackTest, InvalidSelector) |
581 { | 587 { |
582 loadHTML("<p><span></span></p>"); | 588 loadHTML("<p><span></span></p>"); |
583 | 589 |
584 // Build a list with one valid selector and one invalid. | 590 // Build a list with one valid selector and one invalid. |
585 std::vector<WebString> selectors; | 591 std::vector<WebString> selectors; |
586 selectors.push_back(WebString::fromUTF8("span")); | 592 selectors.push_back(WebString::fromUTF8("span")); |
587 selectors.push_back(WebString::fromUTF8("[")); // Invalid. | 593 selectors.push_back(WebString::fromUTF8("[")); // Invalid. |
588 selectors.push_back(WebString::fromUTF8("p span")); // Not compound. | 594 selectors.push_back(WebString::fromUTF8("p span")); // Not compound. |
589 doc().watchCSSSelectors(WebVector<WebString>(selectors)); | 595 doc().watchCSSSelectors(WebVector<WebString>(selectors)); |
| 596 m_frame->view()->layout(); |
| 597 runPendingTasks(); |
590 | 598 |
591 runPendingTasks(); | |
592 EXPECT_EQ(1, updateCount()); | 599 EXPECT_EQ(1, updateCount()); |
593 EXPECT_THAT(matchedSelectors(), testing::ElementsAre("span")) | 600 EXPECT_THAT(matchedSelectors(), testing::ElementsAre("span")) |
594 << "An invalid selector shouldn't prevent other selectors from matching.
"; | 601 << "An invalid selector shouldn't prevent other selectors from matching.
"; |
595 } | 602 } |
596 | 603 |
597 TEST_F(WebFrameTest, DispatchMessageEventWithOriginCheck) | 604 TEST_F(WebFrameTest, DispatchMessageEventWithOriginCheck) |
598 { | 605 { |
599 registerMockedHttpURLLoad("postmessage_test.html"); | 606 registerMockedHttpURLLoad("postmessage_test.html"); |
600 | 607 |
601 // Pass true to enable JavaScript. | 608 // Pass true to enable JavaScript. |
(...skipping 4439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5041 { | 5048 { |
5042 registerMockedHttpURLLoad("create_child_frame_fail.html"); | 5049 registerMockedHttpURLLoad("create_child_frame_fail.html"); |
5043 FailCreateChildFrame client; | 5050 FailCreateChildFrame client; |
5044 FrameTestHelpers::WebViewHelper webViewHelper; | 5051 FrameTestHelpers::WebViewHelper webViewHelper; |
5045 webViewHelper.initializeAndLoad(m_baseURL + "create_child_frame_fail.html",
true, &client); | 5052 webViewHelper.initializeAndLoad(m_baseURL + "create_child_frame_fail.html",
true, &client); |
5046 | 5053 |
5047 EXPECT_EQ(1, client.callCount()); | 5054 EXPECT_EQ(1, client.callCount()); |
5048 } | 5055 } |
5049 | 5056 |
5050 } // namespace | 5057 } // namespace |
OLD | NEW |