| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014, Google Inc. All rights reserved. | 2 * Copyright (c) 2014, 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 16 matching lines...) Expand all Loading... |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "core/dom/Document.h" | 31 #include "core/dom/Document.h" |
| 32 | 32 |
| 33 #include "core/dom/NodeWithIndex.h" | 33 #include "core/dom/NodeWithIndex.h" |
| 34 #include "core/dom/SynchronousMutationObserver.h" | 34 #include "core/dom/SynchronousMutationObserver.h" |
| 35 #include "core/dom/Text.h" | 35 #include "core/dom/Text.h" |
| 36 #include "core/frame/FrameView.h" | 36 #include "core/frame/FrameView.h" |
| 37 #include "core/frame/Settings.h" |
| 37 #include "core/html/HTMLHeadElement.h" | 38 #include "core/html/HTMLHeadElement.h" |
| 39 #include "core/html/HTMLInputElement.h" |
| 38 #include "core/html/HTMLLinkElement.h" | 40 #include "core/html/HTMLLinkElement.h" |
| 41 #include "core/page/Page.h" |
| 42 #include "core/page/ValidationMessageClient.h" |
| 39 #include "core/testing/DummyPageHolder.h" | 43 #include "core/testing/DummyPageHolder.h" |
| 40 #include "platform/heap/Handle.h" | 44 #include "platform/heap/Handle.h" |
| 41 #include "platform/weborigin/ReferrerPolicy.h" | 45 #include "platform/weborigin/ReferrerPolicy.h" |
| 42 #include "platform/weborigin/SchemeRegistry.h" | 46 #include "platform/weborigin/SchemeRegistry.h" |
| 43 #include "platform/weborigin/SecurityOrigin.h" | 47 #include "platform/weborigin/SecurityOrigin.h" |
| 44 #include "testing/gmock/include/gmock/gmock.h" | 48 #include "testing/gmock/include/gmock/gmock.h" |
| 45 #include "testing/gtest/include/gtest/gtest.h" | 49 #include "testing/gtest/include/gtest/gtest.h" |
| 46 #include <memory> | 50 #include <memory> |
| 47 | 51 |
| 48 namespace blink { | 52 namespace blink { |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 visitor->trace(m_childrenChangedNodes); | 238 visitor->trace(m_childrenChangedNodes); |
| 235 visitor->trace(m_mergeTextNodesRecords); | 239 visitor->trace(m_mergeTextNodesRecords); |
| 236 visitor->trace(m_moveTreeToNewDocumentNodes); | 240 visitor->trace(m_moveTreeToNewDocumentNodes); |
| 237 visitor->trace(m_removedChildrenNodes); | 241 visitor->trace(m_removedChildrenNodes); |
| 238 visitor->trace(m_removedNodes); | 242 visitor->trace(m_removedNodes); |
| 239 visitor->trace(m_splitTextNodes); | 243 visitor->trace(m_splitTextNodes); |
| 240 visitor->trace(m_updatedCharacterDataRecords); | 244 visitor->trace(m_updatedCharacterDataRecords); |
| 241 SynchronousMutationObserver::trace(visitor); | 245 SynchronousMutationObserver::trace(visitor); |
| 242 } | 246 } |
| 243 | 247 |
| 248 class MockValidationMessageClient |
| 249 : public GarbageCollectedFinalized<MockValidationMessageClient>, |
| 250 public ValidationMessageClient { |
| 251 USING_GARBAGE_COLLECTED_MIXIN(MockValidationMessageClient); |
| 252 |
| 253 public: |
| 254 MockValidationMessageClient() { reset(); } |
| 255 void reset() { |
| 256 showValidationMessageWasCalled = false; |
| 257 willUnloadDocumentWasCalled = false; |
| 258 documentDetachedWasCalled = false; |
| 259 } |
| 260 bool showValidationMessageWasCalled; |
| 261 bool willUnloadDocumentWasCalled; |
| 262 bool documentDetachedWasCalled; |
| 263 |
| 264 // ValidationMessageClient functions. |
| 265 void showValidationMessage(const Element& anchor, |
| 266 const String& mainMessage, |
| 267 TextDirection, |
| 268 const String& subMessage, |
| 269 TextDirection) override { |
| 270 showValidationMessageWasCalled = true; |
| 271 } |
| 272 void hideValidationMessage(const Element& anchor) override {} |
| 273 bool isValidationMessageVisible(const Element& anchor) override { |
| 274 return true; |
| 275 } |
| 276 void willUnloadDocument(const Document&) override { |
| 277 willUnloadDocumentWasCalled = true; |
| 278 } |
| 279 void documentDetached(const Document&) override { |
| 280 documentDetachedWasCalled = true; |
| 281 } |
| 282 void willBeDestroyed() override {} |
| 283 |
| 284 // DEFINE_INLINE_VIRTUAL_TRACE() { ValidationMessageClient::trace(visitor); } |
| 285 }; |
| 286 |
| 244 } // anonymous namespace | 287 } // anonymous namespace |
| 245 | 288 |
| 246 // This tests that we properly resize and re-layout pages for printing in the | 289 // This tests that we properly resize and re-layout pages for printing in the |
| 247 // presence of media queries effecting elements in a subtree layout boundary | 290 // presence of media queries effecting elements in a subtree layout boundary |
| 248 TEST_F(DocumentTest, PrintRelayout) { | 291 TEST_F(DocumentTest, PrintRelayout) { |
| 249 setHtmlInnerHTML( | 292 setHtmlInnerHTML( |
| 250 "<style>" | 293 "<style>" |
| 251 " div {" | 294 " div {" |
| 252 " width: 100px;" | 295 " width: 100px;" |
| 253 " height: 100px;" | 296 " height: 100px;" |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 | 686 |
| 644 { | 687 { |
| 645 setHtmlInnerHTML( | 688 setHtmlInnerHTML( |
| 646 "<body>" | 689 "<body>" |
| 647 "<meta name=\"theme-color\" content=\"#00ff00\">"); | 690 "<meta name=\"theme-color\" content=\"#00ff00\">"); |
| 648 EXPECT_EQ(Color(0, 255, 0), document().themeColor()) | 691 EXPECT_EQ(Color(0, 255, 0), document().themeColor()) |
| 649 << "Theme color should be bright green."; | 692 << "Theme color should be bright green."; |
| 650 } | 693 } |
| 651 } | 694 } |
| 652 | 695 |
| 696 TEST_F(DocumentTest, ValidationMessageCleanup) { |
| 697 ValidationMessageClient* originalClient = &page().validationMessageClient(); |
| 698 MockValidationMessageClient* mockClient = new MockValidationMessageClient(); |
| 699 document().settings()->setScriptEnabled(true); |
| 700 page().setValidationMessageClient(mockClient); |
| 701 // implicitOpen()-implicitClose() makes Document.loadEventFinished() |
| 702 // true. It's necessary to kick unload process. |
| 703 document().implicitOpen(ForceSynchronousParsing); |
| 704 document().implicitClose(); |
| 705 document().appendChild(document().createElement("html")); |
| 706 setHtmlInnerHTML("<body><input required></body>"); |
| 707 Element* script = document().createElement("script"); |
| 708 script->setTextContent( |
| 709 "window.onunload = function() {" |
| 710 "document.querySelector('input').reportValidity(); };"); |
| 711 document().body()->appendChild(script); |
| 712 HTMLInputElement* input = toHTMLInputElement(document().body()->firstChild()); |
| 713 DVLOG(0) << document().body()->outerHTML(); |
| 714 |
| 715 // Sanity check. |
| 716 input->reportValidity(); |
| 717 EXPECT_TRUE(mockClient->showValidationMessageWasCalled); |
| 718 mockClient->reset(); |
| 719 |
| 720 // prepareForCommit() unloads the document, and shutdown. |
| 721 document().frame()->prepareForCommit(); |
| 722 EXPECT_TRUE(mockClient->willUnloadDocumentWasCalled); |
| 723 EXPECT_TRUE(mockClient->documentDetachedWasCalled); |
| 724 // Unload handler tried to show a validation message, but it should fail. |
| 725 EXPECT_FALSE(mockClient->showValidationMessageWasCalled); |
| 726 |
| 727 page().setValidationMessageClient(originalClient); |
| 728 } |
| 729 |
| 653 } // namespace blink | 730 } // namespace blink |
| OLD | NEW |