Skip to content

Commit

Permalink
[JS] [atoms] Use .textContent instead of .innerHTML in clear() action (
Browse files Browse the repository at this point in the history
…#11504)

[js] [atoms] Use .textContent instead of .innerHTML in clear() action
  • Loading branch information
tosmolka authored Feb 15, 2023
1 parent 60c9f4a commit 4f09bf0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
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>

0 comments on commit 4f09bf0

Please sign in to comment.