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

Side by Side Diff: third_party/WebKit/Source/core/html/HTMLFormControlElementTest.cpp

Issue 2851123002: Merge "Form validation: Do not show validation bubble during printing." to M59. (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLFormControlElement.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "core/html/HTMLFormControlElement.h" 5 #include "core/html/HTMLFormControlElement.h"
6 6
7 #include <memory>
7 #include "core/dom/Document.h" 8 #include "core/dom/Document.h"
8 #include "core/frame/FrameView.h" 9 #include "core/frame/FrameView.h"
9 #include "core/html/HTMLInputElement.h" 10 #include "core/html/HTMLInputElement.h"
10 #include "core/layout/LayoutObject.h" 11 #include "core/layout/LayoutObject.h"
11 #include "core/loader/EmptyClients.h" 12 #include "core/loader/EmptyClients.h"
13 #include "core/page/ValidationMessageClient.h"
12 #include "core/testing/DummyPageHolder.h" 14 #include "core/testing/DummyPageHolder.h"
13 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
14 #include <memory>
15 16
16 namespace blink { 17 namespace blink {
17 18
19 namespace {
20 class MockValidationMessageClient
21 : public GarbageCollectedFinalized<MockValidationMessageClient>,
22 public ValidationMessageClient {
23 USING_GARBAGE_COLLECTED_MIXIN(MockValidationMessageClient);
24
25 public:
26 void ShowValidationMessage(const Element& anchor,
27 const String&,
28 TextDirection,
29 const String&,
30 TextDirection) override {
31 anchor_ = anchor;
32 }
33
34 void HideValidationMessage(const Element& anchor) override {
35 if (anchor_ == &anchor)
36 anchor_ = nullptr;
37 }
38
39 bool IsValidationMessageVisible(const Element& anchor) override {
40 return anchor_ == &anchor;
41 }
42
43 void WillUnloadDocument(const Document&) override {}
44 void DocumentDetached(const Document&) override {}
45 void WillBeDestroyed() override {}
46 DEFINE_INLINE_VIRTUAL_TRACE() {
47 visitor->Trace(anchor_);
48 ValidationMessageClient::Trace(visitor);
49 }
50
51 private:
52 Member<const Element> anchor_;
53 };
54 }
55
18 class HTMLFormControlElementTest : public ::testing::Test { 56 class HTMLFormControlElementTest : public ::testing::Test {
19 protected: 57 protected:
20 void SetUp() override; 58 void SetUp() override;
21 59
22 DummyPageHolder& Page() const { return *dummy_page_holder_; } 60 DummyPageHolder& Page() const { return *dummy_page_holder_; }
23 Document& GetDocument() const { return *document_; } 61 Document& GetDocument() const { return *document_; }
24 62
25 private: 63 private:
26 std::unique_ptr<DummyPageHolder> dummy_page_holder_; 64 std::unique_ptr<DummyPageHolder> dummy_page_holder_;
27 Persistent<Document> document_; 65 Persistent<Document> document_;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 115
78 input->setCustomValidity(String()); 116 input->setCustomValidity(String());
79 message = input->validationMessage().StripWhiteSpace(); 117 message = input->validationMessage().StripWhiteSpace();
80 sub_message = input->ValidationSubMessage().StripWhiteSpace(); 118 sub_message = input->ValidationSubMessage().StripWhiteSpace();
81 input->FindCustomValidationMessageTextDirection(message, message_dir, 119 input->FindCustomValidationMessageTextDirection(message, message_dir,
82 sub_message, sub_message_dir); 120 sub_message, sub_message_dir);
83 EXPECT_EQ(TextDirection::kLtr, message_dir); 121 EXPECT_EQ(TextDirection::kLtr, message_dir);
84 EXPECT_EQ(TextDirection::kRtl, sub_message_dir); 122 EXPECT_EQ(TextDirection::kRtl, sub_message_dir);
85 } 123 }
86 124
125 TEST_F(HTMLFormControlElementTest, UpdateValidationMessageSkippedIfPrinting) {
126 GetDocument().documentElement()->setInnerHTML(
127 "<body><input required id=input></body>");
128 GetDocument().View()->UpdateAllLifecyclePhases();
129 ValidationMessageClient* validation_message_client =
130 new MockValidationMessageClient();
131 GetDocument().GetPage()->SetValidationMessageClient(
132 validation_message_client);
133
134 HTMLInputElement* input =
135 toHTMLInputElement(GetDocument().getElementById("input"));
136 GetDocument().GetFrame()->SetPrinting(true, FloatSize(800, 600),
137 FloatSize(800, 600), 1);
138 input->reportValidity();
139 EXPECT_FALSE(validation_message_client->IsValidationMessageVisible(*input));
140 }
141
87 } // namespace blink 142 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/HTMLFormControlElement.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698