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

Unified Diff: third_party/WebKit/Source/core/html/forms/PasswordInputTypeTest.cpp

Issue 2468833002: Count visible password fields on a page (Closed)
Patch Set: fix comment wrapping Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/html/forms/PasswordInputTypeTest.cpp
diff --git a/third_party/WebKit/Source/core/html/forms/PasswordInputTypeTest.cpp b/third_party/WebKit/Source/core/html/forms/PasswordInputTypeTest.cpp
index 2b76a67a9ad730f456ec74f03e9235e78d526dad..0cd592b0636df765a7e00482e10878ac30bf6524 100644
--- a/third_party/WebKit/Source/core/html/forms/PasswordInputTypeTest.cpp
+++ b/third_party/WebKit/Source/core/html/forms/PasswordInputTypeTest.cpp
@@ -18,12 +18,14 @@ namespace blink {
class MockInterfaceProvider : public blink::InterfaceProvider {
public:
- MockInterfaceProvider() : m_passwordFieldVisibleCalled(false) {}
+ MockInterfaceProvider()
+ : m_passwordFieldVisibleCalled(false),
+ m_numPasswordFieldsInvisibleCalls(0) {}
virtual ~MockInterfaceProvider() {}
void getInterface(const char* name,
mojo::ScopedMessagePipeHandle handle) override {
- if (!m_mockSensitiveInputVisibilityService) {
+ if (!m_mockSensitiveInputVisibilityService || true) {
m_mockSensitiveInputVisibilityService.reset(
new MockSensitiveInputVisibilityService(
this,
@@ -38,6 +40,14 @@ class MockInterfaceProvider : public blink::InterfaceProvider {
return m_passwordFieldVisibleCalled;
}
+ void incrementPasswordFieldsInvisibleCalled() {
+ ++m_numPasswordFieldsInvisibleCalls;
+ }
+
+ uint32_t numPasswordFieldsInvisibleCalls() const {
+ return m_numPasswordFieldsInvisibleCalls;
+ }
+
private:
class MockSensitiveInputVisibilityService
: public mojom::blink::SensitiveInputVisibilityService {
@@ -54,6 +64,10 @@ class MockInterfaceProvider : public blink::InterfaceProvider {
m_registry->setPasswordFieldVisibleCalled();
}
+ void AllPasswordFieldsInInsecureContextInvisible() override {
+ m_registry->incrementPasswordFieldsInvisibleCalled();
+ }
+
mojo::Binding<SensitiveInputVisibilityService> m_binding;
MockInterfaceProvider* const m_registry;
};
@@ -61,6 +75,7 @@ class MockInterfaceProvider : public blink::InterfaceProvider {
std::unique_ptr<MockSensitiveInputVisibilityService>
m_mockSensitiveInputVisibilityService;
bool m_passwordFieldVisibleCalled;
+ uint32_t m_numPasswordFieldsInvisibleCalls;
};
// Tests that a Mojo message is sent when a visible password field
@@ -161,4 +176,127 @@ TEST(PasswordInputTypeTest,
EXPECT_FALSE(interfaceProvider.passwordFieldVisibleCalled());
}
+// Tests that a Mojo message is sent when the only visible password
+// field becomes invisible.
+TEST(PasswordInputTypeTest, VisiblePasswordFieldBecomesInvisible) {
+ MockInterfaceProvider interfaceProvider;
+ std::unique_ptr<DummyPageHolder> pageHolder = DummyPageHolder::create(
+ IntSize(2000, 2000), nullptr, nullptr, nullptr, &interfaceProvider);
+ pageHolder->document().body()->setInnerHTML("<input type='password'>",
+ ASSERT_NO_EXCEPTION);
+ pageHolder->document().view()->updateAllLifecyclePhases();
+ blink::testing::runPendingTasks();
+ EXPECT_TRUE(interfaceProvider.passwordFieldVisibleCalled());
+ EXPECT_EQ(0u, interfaceProvider.numPasswordFieldsInvisibleCalls());
+
+ // Now make the input invisible.
+ HTMLInputElement* input =
+ toHTMLInputElement(pageHolder->document().body()->firstChild());
+ input->setAttribute("style", "display:none;", ASSERT_NO_EXCEPTION);
+ pageHolder->document().view()->updateAllLifecyclePhases();
+ blink::testing::runPendingTasks();
+ EXPECT_EQ(1u, interfaceProvider.numPasswordFieldsInvisibleCalls());
+}
+
+// Tests that a Mojo message is sent when all visible password fields
+// become invisible.
+TEST(PasswordInputTypeTest, AllVisiblePasswordFieldBecomeInvisible) {
+ MockInterfaceProvider interfaceProvider;
+ std::unique_ptr<DummyPageHolder> pageHolder = DummyPageHolder::create(
+ IntSize(2000, 2000), nullptr, nullptr, nullptr, &interfaceProvider);
+ pageHolder->document().body()->setInnerHTML(
+ "<input type='password'><input type='password'>", ASSERT_NO_EXCEPTION);
+ pageHolder->document().view()->updateAllLifecyclePhases();
+ blink::testing::runPendingTasks();
+ EXPECT_EQ(0u, interfaceProvider.numPasswordFieldsInvisibleCalls());
+
+ // Make the first input invisible. There should be no message because
+ // there is still a visible input.
+ HTMLInputElement* input =
+ toHTMLInputElement(pageHolder->document().body()->firstChild());
+ input->setAttribute("style", "display:none;", ASSERT_NO_EXCEPTION);
+ pageHolder->document().view()->updateAllLifecyclePhases();
+ blink::testing::runPendingTasks();
+ EXPECT_EQ(0u, interfaceProvider.numPasswordFieldsInvisibleCalls());
+
+ // When all inputs are invisible, then a message should be sent.
+ input = toHTMLInputElement(pageHolder->document().body()->lastChild());
+ input->setAttribute("style", "display:none;", ASSERT_NO_EXCEPTION);
+ pageHolder->document().view()->updateAllLifecyclePhases();
+ blink::testing::runPendingTasks();
+ EXPECT_EQ(1u, interfaceProvider.numPasswordFieldsInvisibleCalls());
+
+ // If the count of visible inputs goes positive again and then back to
+ // zero, a message should be sent again.
+ input->setAttribute("style", "", ASSERT_NO_EXCEPTION);
+ pageHolder->document().view()->updateAllLifecyclePhases();
+ blink::testing::runPendingTasks();
+ EXPECT_EQ(1u, interfaceProvider.numPasswordFieldsInvisibleCalls());
+ input->setAttribute("style", "display:none;", ASSERT_NO_EXCEPTION);
+ pageHolder->document().view()->updateAllLifecyclePhases();
+ blink::testing::runPendingTasks();
+ EXPECT_EQ(2u, interfaceProvider.numPasswordFieldsInvisibleCalls());
+}
+
+// Tests that a Mojo message is sent when the containing element of a
+// visible password field becomes invisible.
+TEST(PasswordInputTypeTest, PasswordFieldContainerBecomesInvisible) {
+ MockInterfaceProvider interfaceProvider;
+ std::unique_ptr<DummyPageHolder> pageHolder = DummyPageHolder::create(
+ IntSize(2000, 2000), nullptr, nullptr, nullptr, &interfaceProvider);
+ pageHolder->document().body()->setInnerHTML(
+ "<div><input type='password'></div>", ASSERT_NO_EXCEPTION);
+ pageHolder->document().view()->updateAllLifecyclePhases();
+ blink::testing::runPendingTasks();
+ EXPECT_EQ(0u, interfaceProvider.numPasswordFieldsInvisibleCalls());
+
+ // If the containing div becomes invisible, a message should be sent.
+ HTMLElement* div =
+ toHTMLDivElement(pageHolder->document().body()->firstChild());
+ div->setAttribute("style", "display:none;", ASSERT_NO_EXCEPTION);
+ pageHolder->document().view()->updateAllLifecyclePhases();
+ blink::testing::runPendingTasks();
+ EXPECT_EQ(1u, interfaceProvider.numPasswordFieldsInvisibleCalls());
+
+ // If the containing div becomes visible and then invisible again, a message
+ // should be sent.
+ div->setAttribute("style", "", ASSERT_NO_EXCEPTION);
+ pageHolder->document().view()->updateAllLifecyclePhases();
+ blink::testing::runPendingTasks();
+ EXPECT_EQ(1u, interfaceProvider.numPasswordFieldsInvisibleCalls());
+ div->setAttribute("style", "display:none;", ASSERT_NO_EXCEPTION);
+ pageHolder->document().view()->updateAllLifecyclePhases();
+ blink::testing::runPendingTasks();
+ EXPECT_EQ(2u, interfaceProvider.numPasswordFieldsInvisibleCalls());
+}
+
+// Tests that a Mojo message is sent when all visible password fields
+// become non-password fields.
+TEST(PasswordInputTypeTest, PasswordFieldsBecomeNonPasswordFields) {
+ MockInterfaceProvider interfaceProvider;
+ std::unique_ptr<DummyPageHolder> pageHolder = DummyPageHolder::create(
+ IntSize(2000, 2000), nullptr, nullptr, nullptr, &interfaceProvider);
+ pageHolder->document().body()->setInnerHTML(
+ "<input type='password'><input type='password'>", ASSERT_NO_EXCEPTION);
+ pageHolder->document().view()->updateAllLifecyclePhases();
+ blink::testing::runPendingTasks();
+ EXPECT_EQ(0u, interfaceProvider.numPasswordFieldsInvisibleCalls());
+
+ // Make the first input a non-password input. There should be no
+ // message because there is still a visible password input.
+ HTMLInputElement* input =
+ toHTMLInputElement(pageHolder->document().body()->firstChild());
+ input->setType("text");
+ pageHolder->document().view()->updateAllLifecyclePhases();
+ blink::testing::runPendingTasks();
+ EXPECT_EQ(0u, interfaceProvider.numPasswordFieldsInvisibleCalls());
+
+ // When all inputs are no longer passwords, then a message should be sent.
+ input = toHTMLInputElement(pageHolder->document().body()->lastChild());
+ input->setType("text");
+ pageHolder->document().view()->updateAllLifecyclePhases();
+ blink::testing::runPendingTasks();
+ EXPECT_EQ(1u, interfaceProvider.numPasswordFieldsInvisibleCalls());
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698