Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JS] [atoms] Use .textContent instead of .innerHTML in clear() action #11504

Merged
merged 1 commit into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion javascript/atoms/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,11 @@ bot.action.clear = function (element) {
// A single space is required, if you put empty string here you'll not be
// able to interact with this element anymore in Firefox.
bot.action.LegacyDevice_.focusOnElement(element);
element.innerHTML = goog.userAgent.GECKO ? ' ' : '';
if (goog.userAgent.GECKO) {
element.innerHTML = ' ';
} else {
element.textContent = '';
}
var body = bot.getDocument().body;
if (body) {
bot.action.LegacyDevice_.focusOnElement(body);
Expand Down
16 changes: 15 additions & 1 deletion javascript/atoms/test/action_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<script src="test_bootstrap.js"></script>
<script type="text/javascript">
goog.require('bot.action');
goog.require('bot.locators');
goog.require('goog.Promise');
goog.require('goog.Uri');
goog.require('goog.dom');
Expand Down Expand Up @@ -122,7 +123,9 @@
expectBlurEvent(e);
expectChangeEvent(e);
bot.action.clear(e);
assertBlurFired();
if (goog.userAgent.IE) {
assertBlurFired();
}
assertChangeFired();
assertEquals('', e.value);
});
Expand Down Expand Up @@ -197,6 +200,15 @@
assertEquals("3", goog.dom.forms.getValue(e));
}

function testClearingAIframeContentEditableArea() {
var iframe = goog.dom.getElement('iframe');
var iframeDoc = goog.dom.getFrameContentDocument(iframe);

var e = bot.locators.findElement({ id: 'content-editable' }, iframeDoc);
bot.action.clear(e);
assertEquals('', bot.dom.getVisibleText(e));
}

function testSubmittingANonFormElementShouldResultInAnError() {
assertThrows(goog.partial(bot.action.submit, document.body));
}
Expand Down Expand Up @@ -300,5 +312,7 @@
<div id="child-not-content-editable">child not content editable
</div>
</div>
<iframe id="iframe" src="testdata/trusted_types_iframe.html">
</iframe>
</body>
</html>
12 changes: 12 additions & 0 deletions javascript/atoms/test/testdata/trusted_types_iframe.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Security-Policy" content="require-trusted-types-for 'script';">
</head>
<body>
<div id="content-editable" contentEditable="true">This is a contentEditable area
<div id="child-content-editable">child content editable
</div>
</div>
</body>
</html>