Skip to content

Commit 4f09bf0

Browse files
authored
[JS] [atoms] Use .textContent instead of .innerHTML in clear() action (#11504)
[js] [atoms] Use .textContent instead of .innerHTML in clear() action
1 parent 60c9f4a commit 4f09bf0

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

javascript/atoms/action.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ bot.action.clear = function (element) {
119119
// A single space is required, if you put empty string here you'll not be
120120
// able to interact with this element anymore in Firefox.
121121
bot.action.LegacyDevice_.focusOnElement(element);
122-
element.innerHTML = goog.userAgent.GECKO ? ' ' : '';
122+
if (goog.userAgent.GECKO) {
123+
element.innerHTML = ' ';
124+
} else {
125+
element.textContent = '';
126+
}
123127
var body = bot.getDocument().body;
124128
if (body) {
125129
bot.action.LegacyDevice_.focusOnElement(body);

javascript/atoms/test/action_test.html

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<script src="test_bootstrap.js"></script>
66
<script type="text/javascript">
77
goog.require('bot.action');
8+
goog.require('bot.locators');
89
goog.require('goog.Promise');
910
goog.require('goog.Uri');
1011
goog.require('goog.dom');
@@ -122,7 +123,9 @@
122123
expectBlurEvent(e);
123124
expectChangeEvent(e);
124125
bot.action.clear(e);
125-
assertBlurFired();
126+
if (goog.userAgent.IE) {
127+
assertBlurFired();
128+
}
126129
assertChangeFired();
127130
assertEquals('', e.value);
128131
});
@@ -197,6 +200,15 @@
197200
assertEquals("3", goog.dom.forms.getValue(e));
198201
}
199202

203+
function testClearingAIframeContentEditableArea() {
204+
var iframe = goog.dom.getElement('iframe');
205+
var iframeDoc = goog.dom.getFrameContentDocument(iframe);
206+
207+
var e = bot.locators.findElement({ id: 'content-editable' }, iframeDoc);
208+
bot.action.clear(e);
209+
assertEquals('', bot.dom.getVisibleText(e));
210+
}
211+
200212
function testSubmittingANonFormElementShouldResultInAnError() {
201213
assertThrows(goog.partial(bot.action.submit, document.body));
202214
}
@@ -300,5 +312,7 @@
300312
<div id="child-not-content-editable">child not content editable
301313
</div>
302314
</div>
315+
<iframe id="iframe" src="testdata/trusted_types_iframe.html">
316+
</iframe>
303317
</body>
304318
</html>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta http-equiv="Content-Security-Policy" content="require-trusted-types-for 'script';">
5+
</head>
6+
<body>
7+
<div id="content-editable" contentEditable="true">This is a contentEditable area
8+
<div id="child-content-editable">child content editable
9+
</div>
10+
</div>
11+
</body>
12+
</html>

0 commit comments

Comments
 (0)