Bug 1385873 - <option> should not be deselected in dropdown. r?automatedtester
Marionette deselects <option>s if they are already selected in <select
multiple>, but it should not deselect them if they are in a dropdown
<select>.
MozReview-Commit-ID: 9CHfYrGn7xR
--- a/testing/marionette/harness/marionette_harness/tests/unit/test_select.py
+++ b/testing/marionette/harness/marionette_harness/tests/unit/test_select.py
@@ -36,17 +36,17 @@ class TestSelect(SelectTestCase):
</select>"""))
select = self.marionette.find_element(By.TAG_NAME, "select")
options = self.marionette.find_elements(By.TAG_NAME, "option")
self.assertSelected(options[0])
options[1].click()
self.assertSelected(options[1])
- def test_deselect(self):
+ def test_deselect_others(self):
self.marionette.navigate(inline("""
<select>
<option>first
<option>second
<option>third
</select>"""))
select = self.marionette.find_element(By.TAG_NAME, "select")
options = self.marionette.find_elements(By.TAG_NAME, "option")
@@ -55,16 +55,32 @@ class TestSelect(SelectTestCase):
self.assertSelected(options[0])
options[1].click()
self.assertSelected(options[1])
options[2].click()
self.assertSelected(options[2])
options[0].click()
self.assertSelected(options[0])
+ def test_select_self(self):
+ self.marionette.navigate(inline("""
+ <select>
+ <option>first
+ <option>second
+ </select>"""))
+ select = self.marionette.find_element(By.TAG_NAME, "select")
+ options = self.marionette.find_elements(By.TAG_NAME, "option")
+ self.assertSelected(options[0])
+ self.assertNotSelected(options[1])
+
+ options[1].click()
+ self.assertSelected(options[1])
+ options[1].click()
+ self.assertSelected(options[1])
+
def test_out_of_view(self):
self.marionette.navigate(inline("""
<select>
<option>1
<option>2
<option>3
<option>4
<option>5
--- a/testing/marionette/interaction.js
+++ b/testing/marionette/interaction.js
@@ -291,18 +291,24 @@ interaction.selectOption = function(el)
let containerEl = element.getContainer(el);
event.mouseover(containerEl);
event.mousemove(containerEl);
event.mousedown(containerEl);
event.focus(containerEl);
event.input(containerEl);
- // toggle selectedness the way holding down control works
- el.selected = !el.selected;
+ // Clicking <option> in <select> should not be deselected if selected.
+ // However, clicking one in a <select multiple> should toggle
+ // selectedness the way holding down Control works.
+ if (containerEl.multiple) {
+ el.selected = !el.selected;
+ } else if (!el.selected) {
+ el.selected = true;
+ }
event.change(containerEl);
event.mouseup(containerEl);
event.click(containerEl);
};
/**
* Flushes the event loop by requesting an animation frame.