Bug 1343037 part 19. Add some tests. r=ehsan
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 09 Mar 2017 14:44:06 -0500
changeset 347118 d737e4692b288509f9f95eb98f14402c58247df3
parent 347117 ff3d9260a13210b9dce654420e1089eba98a1eba
child 347119 5df501fbf40d16cc5a23384e189e7ae12e746ea5
push id31491
push usercbook@mozilla.com
push dateMon, 13 Mar 2017 14:24:00 +0000
treeherdermozilla-central@8d9fd089cabd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1343037
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1343037 part 19. Add some tests. r=ehsan MozReview-Commit-ID: L7LNF2Bfwgk
testing/web-platform/mozilla/meta/MANIFEST.json
testing/web-platform/mozilla/tests/html/semantics/forms/textfieldselection/selection-value-interactions.html
--- a/testing/web-platform/mozilla/meta/MANIFEST.json
+++ b/testing/web-platform/mozilla/meta/MANIFEST.json
@@ -346,16 +346,22 @@
   },
   "testharness": {
    "fetch/api/redirect/redirect-referrer.https.html": [
     [
      "/_mozilla/fetch/api/redirect/redirect-referrer.https.html",
      {}
     ]
    ],
+   "html/semantics/forms/textfieldselection/selection-value-interactions.html": [
+    [
+     "/_mozilla/html/semantics/forms/textfieldselection/selection-value-interactions.html",
+     {}
+    ]
+   ],
    "html/semantics/scripting-1/the-script-element/create-module-script.html": [
     [
      "/_mozilla/html/semantics/scripting-1/the-script-element/create-module-script.html",
      {}
     ]
    ],
    "html/semantics/scripting-1/the-script-element/reload-failed-module-script.html": [
     [
@@ -739,16 +745,20 @@
   "fetch/api/redirect/redirect-referrer-mixed-content.js": [
    "f9d7ec9cf9fa8c847e45664b05482e3f8c191385",
    "support"
   ],
   "fetch/api/redirect/redirect-referrer.https.html": [
    "99cbd16b78771f35e075e4012d8dbc5dce3209c0",
    "testharness"
   ],
+  "html/semantics/forms/textfieldselection/selection-value-interactions.html": [
+   "6c5e95a8f2f11d106e669eb82b46ffff73d08335",
+   "testharness"
+  ],
   "html/semantics/scripting-1/the-script-element/create-module-script.html": [
    "3214bced5d81e8001a321aea4c80675b6603b11d",
    "testharness"
   ],
   "html/semantics/scripting-1/the-script-element/reload-failed-module-script.html": [
    "5b8cf6809bd8d0797f4172bf9a01f9085c0abbaf",
    "testharness"
   ],
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/mozilla/tests/html/semantics/forms/textfieldselection/selection-value-interactions.html
@@ -0,0 +1,203 @@
+<!doctype html>
+<meta charset=utf-8>
+<title></title>
+<script src=/resources/testharness.js></script>
+<script src=/resources/testharnessreport.js></script>
+<div id=log></div>
+<div id=target></div>
+<script>
+  var target = document.getElementById("target");
+  var sometext = "something";
+  var shorttext = "abc";
+  var elemData = [
+    {
+      desc: "textarea not in body",
+      factory: () => document.createElement("textarea"),
+    },
+    {
+      desc: "input not in body",
+      factory: () => document.createElement("input"),
+    },
+    {
+      desc: "textarea in body",
+      factory: () => document.body.appendChild(document.createElement("textarea")),
+    },
+    {
+      desc: "input in body",
+      factory: () => document.body.appendChild(document.createElement("input")),
+    },
+    {
+      desc: "textarea in body with parsed default value",
+      factory: () => {
+        target.innerHTML = "<textarea>abcdefghij</textarea>"
+        return target.querySelector("textarea");
+      },
+    },
+    {
+      desc: "input in body with parsed default value",
+      factory: () => {
+        target.innerHTML = "<input value='abcdefghij'>"
+        return target.querySelector("input");
+      },
+    },
+    {
+      desc: "focused textarea",
+      factory: () => {
+        var t = document.body.appendChild(document.createElement("textarea"));
+        t.focus();
+        return t;
+      },
+    },
+    {
+      desc: "focused input",
+      factory: () => {
+        var i = document.body.appendChild(document.createElement("input"));
+        i.focus();
+        return i;
+      },
+    },
+    {
+      desc: "focused then blurred textarea",
+      factory: () => {
+        var t = document.body.appendChild(document.createElement("textarea"));
+        t.focus();
+        t.blur();
+        return t;
+      },
+    },
+    {
+      desc: "focused then blurred input",
+      factory: () => {
+        var i = document.body.appendChild(document.createElement("input"));
+        i.focus();
+        i.blur()
+        return i;
+      },
+    },
+  ];
+
+for (var data of elemData) {
+  test(function() {
+    var el = data.factory();
+    this.add_cleanup(() => el.remove());
+    assert_equals(el.selectionStart, 0,
+                  `Cursor start should be at beginning of ${data.desc}`);
+    assert_equals(el.selectionEnd, 0,
+                  `Cursor end should be at beginning of ${data.desc}`);
+  }, `cursor location for initial value of ${data.desc}`);
+}
+
+for (var data of elemData) {
+  test(function() {
+    var el = data.factory();
+    this.add_cleanup(() => el.remove());
+    el.defaultValue = sometext;
+    // The "focused or has been focused" case behaves differently.
+    if (data.desc.includes("focused")) {
+      assert_equals(el.selectionStart, el.value.length,
+                    `Cursor start should be at end of ${data.desc}`);
+      assert_equals(el.selectionEnd, el.value.length,
+                    `Cursor end should be at end of ${data.desc}`);
+    } else {
+      assert_equals(el.selectionStart, 0,
+                    `Cursor start should be at beginning of ${data.desc}`);
+      assert_equals(el.selectionEnd, 0,
+                    `Cursor end should be at beginning of ${data.desc}`);
+    }
+  }, `cursor location after defaultValue set of ${data.desc}`);
+}
+
+for (var data of elemData) {
+  test(function() {
+    var el = data.factory();
+    this.add_cleanup(() => el.remove());
+    el.selectionStart = el.selectionStart;
+    el.defaultValue = sometext;
+    // The focused case behaves differently.
+    if (data.desc.includes("focused")) {
+      assert_equals(el.selectionStart, el.value.length,
+                    `Cursor start should be at end of ${data.desc}`);
+      assert_equals(el.selectionEnd, el.value.length,
+                    `Cursor end should be at end of ${data.desc}`);
+    } else {
+      assert_equals(el.selectionStart, 0,
+                    `Cursor start should be at beginning of ${data.desc}`);
+      assert_equals(el.selectionEnd, 0,
+                    `Cursor end should be at beginning of ${data.desc}`);
+    }
+  }, `cursor location after defaultValue set after no-op selectionStart set of ${data.desc}`);
+}
+
+for (var data of elemData) {
+  test(function() {
+    var el = data.factory();
+    this.add_cleanup(() => el.remove());
+    el.value = sometext;
+    assert_equals(el.selectionStart, sometext.length,
+                  `Cursor start should be at end of ${data.desc}`);
+    assert_equals(el.selectionEnd, sometext.length,
+                  `Cursor end should be at end of ${data.desc}`);
+  }, `cursor location after value set of ${data.desc}`);
+}
+
+for (var data of elemData) {
+  test(function() {
+    var el = data.factory();
+    this.add_cleanup(() => el.remove());
+    assert_true(sometext.length > 8,
+                "sometext too short, test won't work right");
+    el.defaultValue = sometext;
+    el.selectionStart = 1;
+    el.selectionEnd = 8;
+    assert_equals(el.selectionStart, 1, "We just set selectionStart!");
+    assert_equals(el.selectionEnd, 8, "We just set selectionEnd!");
+    assert_true(shorttext.length > 1,
+                "shorttext too short, test won't work right");
+    assert_true(shorttext.length < 8,
+                "shorttext too long, test won't work right");
+    el.defaultValue = shorttext;
+    // The "focused or has been focused" case behaves differently.
+    if (data.desc.includes("focused")) {
+      assert_equals(el.selectionStart, el.value.length,
+                    `Cursor start should be at end of ${data.desc}`);
+      assert_equals(el.selectionEnd, el.value.length,
+                    `Cursor end should be at end of ${data.desc}`);
+    } else {
+      assert_equals(el.selectionStart, 1,
+                    "Shouldn't have moved selection start");
+      assert_equals(el.selectionEnd, shorttext.length,
+                    "Should have adjusted selection end");
+    }
+  }, `selection location after defaultValue set to shorter than selectionEnd of ${data.desc}`);
+}
+
+for (var data of elemData) {
+  test(function() {
+    var el = data.factory();
+    this.add_cleanup(() => el.remove());
+    assert_true(sometext.length > 8,
+                "sometext too short, test won't work right");
+    el.defaultValue = sometext;
+    el.selectionStart = 5;
+    el.selectionEnd = 8;
+    assert_equals(el.selectionStart, 5, "We just set selectionStart!");
+    assert_equals(el.selectionEnd, 8, "We just set selectionEnd!");
+    assert_true(shorttext.length < 5,
+                "shorttext too long, test won't work right");
+    el.defaultValue = shorttext;
+    // The "focused or has been focused" case behaves differently.
+    if (data.desc.includes("focused")) {
+      assert_equals(el.selectionStart, el.value.length,
+                    `Cursor start should be at end of ${data.desc}`);
+      assert_equals(el.selectionEnd, el.value.length,
+                    `Cursor end should be at end of ${data.desc}`);
+    } else {
+      assert_equals(el.selectionStart, shorttext.length,
+                    "Should have adjusted selection start");
+      assert_equals(el.selectionEnd, shorttext.length,
+                    "Should have adjusted selection end");
+    }
+  }, `selection location after defaultValue set to shorter than selectionStart of ${data.desc}`);
+}
+
+</script>