Bug 1385873 - <option> should not be deselected in dropdown. r?automatedtester draft
authorAndreas Tolfsen <ato@sny.no>
Mon, 31 Jul 2017 14:08:41 +0100
changeset 618472 ba1a146e2026bc3752386bc7af3eac1be4a71df5
parent 618471 2e9ccc68221718f5bdb7e82774ad16417f953a76
child 618473 16628b9d78c3eea7f7aed3559359de848229c585
push id71347
push userbmo:ato@sny.no
push dateMon, 31 Jul 2017 14:56:01 +0000
reviewersautomatedtester
bugs1385873
milestone56.0a1
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
testing/marionette/harness/marionette_harness/tests/unit/test_select.py
testing/marionette/interaction.js
--- 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.