Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: third_party/WebKit/Source/core/dom/DocumentTest.cpp

Issue 2771193002: Form validation: Validation bubble should be closed on document unload process. (Closed)
Patch Set: . Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 18 matching lines...) Expand all
29 */ 29 */
30 30
31 #include "core/dom/Document.h" 31 #include "core/dom/Document.h"
32 32
33 #include <memory> 33 #include <memory>
34 #include "bindings/core/v8/V8BindingForTesting.h" 34 #include "bindings/core/v8/V8BindingForTesting.h"
35 #include "core/dom/NodeWithIndex.h" 35 #include "core/dom/NodeWithIndex.h"
36 #include "core/dom/SynchronousMutationObserver.h" 36 #include "core/dom/SynchronousMutationObserver.h"
37 #include "core/dom/Text.h" 37 #include "core/dom/Text.h"
38 #include "core/frame/FrameView.h" 38 #include "core/frame/FrameView.h"
39 #include "core/frame/Settings.h"
39 #include "core/html/HTMLHeadElement.h" 40 #include "core/html/HTMLHeadElement.h"
41 #include "core/html/HTMLInputElement.h"
40 #include "core/html/HTMLLinkElement.h" 42 #include "core/html/HTMLLinkElement.h"
43 #include "core/page/Page.h"
44 #include "core/page/ValidationMessageClient.h"
41 #include "core/testing/DummyPageHolder.h" 45 #include "core/testing/DummyPageHolder.h"
42 #include "platform/heap/Handle.h" 46 #include "platform/heap/Handle.h"
43 #include "platform/weborigin/ReferrerPolicy.h" 47 #include "platform/weborigin/ReferrerPolicy.h"
44 #include "platform/weborigin/SchemeRegistry.h" 48 #include "platform/weborigin/SchemeRegistry.h"
45 #include "platform/weborigin/SecurityOrigin.h" 49 #include "platform/weborigin/SecurityOrigin.h"
46 #include "testing/gmock/include/gmock/gmock.h" 50 #include "testing/gmock/include/gmock/gmock.h"
47 #include "testing/gtest/include/gtest/gtest.h" 51 #include "testing/gtest/include/gtest/gtest.h"
48 52
49 namespace blink { 53 namespace blink {
50 54
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 visitor->trace(m_childrenChangedNodes); 239 visitor->trace(m_childrenChangedNodes);
236 visitor->trace(m_mergeTextNodesRecords); 240 visitor->trace(m_mergeTextNodesRecords);
237 visitor->trace(m_moveTreeToNewDocumentNodes); 241 visitor->trace(m_moveTreeToNewDocumentNodes);
238 visitor->trace(m_removedChildrenNodes); 242 visitor->trace(m_removedChildrenNodes);
239 visitor->trace(m_removedNodes); 243 visitor->trace(m_removedNodes);
240 visitor->trace(m_splitTextNodes); 244 visitor->trace(m_splitTextNodes);
241 visitor->trace(m_updatedCharacterDataRecords); 245 visitor->trace(m_updatedCharacterDataRecords);
242 SynchronousMutationObserver::trace(visitor); 246 SynchronousMutationObserver::trace(visitor);
243 } 247 }
244 248
249 class MockValidationMessageClient
250 : public GarbageCollectedFinalized<MockValidationMessageClient>,
251 public ValidationMessageClient {
252 USING_GARBAGE_COLLECTED_MIXIN(MockValidationMessageClient);
253
254 public:
255 MockValidationMessageClient() { reset(); }
256 void reset() {
257 showValidationMessageWasCalled = false;
258 willUnloadDocumentWasCalled = false;
259 documentDetachedWasCalled = false;
260 }
261 bool showValidationMessageWasCalled;
262 bool willUnloadDocumentWasCalled;
263 bool documentDetachedWasCalled;
264
265 // ValidationMessageClient functions.
266 void showValidationMessage(const Element& anchor,
267 const String& mainMessage,
268 TextDirection,
269 const String& subMessage,
270 TextDirection) override {
271 showValidationMessageWasCalled = true;
272 }
273 void hideValidationMessage(const Element& anchor) override {}
274 bool isValidationMessageVisible(const Element& anchor) override {
275 return true;
276 }
277 void willUnloadDocument(const Document&) override {
278 willUnloadDocumentWasCalled = true;
279 }
280 void documentDetached(const Document&) override {
281 documentDetachedWasCalled = true;
282 }
283 void willBeDestroyed() override {}
284
285 // DEFINE_INLINE_VIRTUAL_TRACE() { ValidationMessageClient::trace(visitor); }
286 };
287
245 } // anonymous namespace 288 } // anonymous namespace
246 289
247 // This tests that we properly resize and re-layout pages for printing in the 290 // This tests that we properly resize and re-layout pages for printing in the
248 // presence of media queries effecting elements in a subtree layout boundary 291 // presence of media queries effecting elements in a subtree layout boundary
249 TEST_F(DocumentTest, PrintRelayout) { 292 TEST_F(DocumentTest, PrintRelayout) {
250 setHtmlInnerHTML( 293 setHtmlInnerHTML(
251 "<style>" 294 "<style>"
252 " div {" 295 " div {"
253 " width: 100px;" 296 " width: 100px;"
254 " height: 100px;" 297 " height: 100px;"
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 688
646 { 689 {
647 setHtmlInnerHTML( 690 setHtmlInnerHTML(
648 "<body>" 691 "<body>"
649 "<meta name=\"theme-color\" content=\"#00ff00\">"); 692 "<meta name=\"theme-color\" content=\"#00ff00\">");
650 EXPECT_EQ(Color(0, 255, 0), document().themeColor()) 693 EXPECT_EQ(Color(0, 255, 0), document().themeColor())
651 << "Theme color should be bright green."; 694 << "Theme color should be bright green.";
652 } 695 }
653 } 696 }
654 697
698 TEST_F(DocumentTest, ValidationMessageCleanup) {
699 ValidationMessageClient* originalClient = &page().validationMessageClient();
700 MockValidationMessageClient* mockClient = new MockValidationMessageClient();
701 document().settings()->setScriptEnabled(true);
702 page().setValidationMessageClient(mockClient);
703 // implicitOpen()-implicitClose() makes Document.loadEventFinished()
704 // true. It's necessary to kick unload process.
705 document().implicitOpen(ForceSynchronousParsing);
706 document().implicitClose();
707 document().appendChild(document().createElement("html"));
708 setHtmlInnerHTML("<body><input required></body>");
709 Element* script = document().createElement("script");
710 script->setTextContent(
711 "window.onunload = function() {"
712 "document.querySelector('input').reportValidity(); };");
713 document().body()->appendChild(script);
714 HTMLInputElement* input = toHTMLInputElement(document().body()->firstChild());
715 DVLOG(0) << document().body()->outerHTML();
716
717 // Sanity check.
718 input->reportValidity();
719 EXPECT_TRUE(mockClient->showValidationMessageWasCalled);
720 mockClient->reset();
721
722 // prepareForCommit() unloads the document, and shutdown.
723 document().frame()->prepareForCommit();
724 EXPECT_TRUE(mockClient->willUnloadDocumentWasCalled);
725 EXPECT_TRUE(mockClient->documentDetachedWasCalled);
726 // Unload handler tried to show a validation message, but it should fail.
727 EXPECT_FALSE(mockClient->showValidationMessageWasCalled);
728
729 page().setValidationMessageClient(originalClient);
730 }
731
655 } // namespace blink 732 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/dom/Document.cpp ('k') | third_party/WebKit/Source/core/html/HTMLFormControlElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698