Bug 1285082 - Check map coordinates with small tolerance to prevent tolerance caused by scaling on Android. r=smaug a=testonly
authorStone Shih <sshih@mozilla.com>
Mon, 08 Aug 2016 16:43:33 +0800
changeset 348066 8c26f35e08a3ab42d442895a87ff6dd7614d0b70
parent 348065 c6f75c8af7d08a91477404ac967de6f35a0ba928
child 348067 7d3d4f307002cc8475800df191196b94999ffd0a
push id6389
push userraliiev@mozilla.com
push dateMon, 19 Sep 2016 13:38:22 +0000
treeherdermozilla-beta@01d67bfe6c81 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, testonly
bugs1285082
milestone50.0a2
Bug 1285082 - Check map coordinates with small tolerance to prevent tolerance caused by scaling on Android. r=smaug a=testonly
dom/html/test/test_bug1260704.html
--- a/dom/html/test/test_bug1260704.html
+++ b/dom/html/test/test_bug1260704.html
@@ -19,39 +19,43 @@ function runTests() {
     "bug1260704_iframe.html?noDefault=true&isMap=false",
     "bug1260704_iframe.html?noDefault=false&isMap=true",
     "bug1260704_iframe.html?noDefault=false&isMap=false"
   ];
 
   let runningTest = false;
   let iframe = document.getElementById("testFrame");
   let iframeWin = iframe.contentWindow;
-  let emptySearch = "";
-  let searchWithCoordinates;
+  let rect;
+  let x;
+  let y;
 
   window.addEventListener("message", event => {
     if (event.data == "started") {
       ok(!runningTest, "Start to test " + testIdx);
       runningTest = true;
-
-      let rect = iframeWin.document.getElementById("testImage").getBoundingClientRect();
-      let x = rect.left + rect.width / 2;
-      let y = rect.top + rect.height / 2;
-      searchWithCoordinates = "?" + rect.width / 2 + "," + rect.height / 2;
-      synthesizeMouseAtPoint(x, y, { type: 'mousedown' }, iframeWin);
-      synthesizeMouseAtPoint(x, y, { type: 'mouseup' }, iframeWin);
+      rect = iframeWin.document.getElementById("testImage").getBoundingClientRect();
+      x = rect.width / 2;
+      y = rect.height / 2;
+      synthesizeMouseAtPoint(rect.left + x, rect.top + y, { type: 'mousedown' }, iframeWin);
+      synthesizeMouseAtPoint(rect.left + x, rect.top + y, { type: 'mouseup' }, iframeWin);
     }
     else if (runningTest && event.data == "empty_frame_loaded") {
       ok(testUrls[testIdx].includes("noDefault=false"), "Page unload");
       let search = iframeWin.location.search;
-        
-      //url trigger by image with ismap attribute should contains coordinates
-      let expectSearch = testUrls[testIdx].includes("isMap=true") ?
-                         searchWithCoordinates : emptySearch;
-      ok(search == expectSearch, "expect:" + expectSearch + " got:" + search);
+      if (testUrls[testIdx].includes("isMap=true")) {
+        // url trigger by image with ismap attribute should contains coordinates
+        // try to parse coordinates and check them with small tolerance
+        let coorStr = search.split("?");
+        let coordinates = coorStr[1].split(",");
+        ok(Math.abs(coordinates[0] - x) <= 1, "expect X=" + x + " got " + coordinates[0]);
+        ok(Math.abs(coordinates[1] - y) <= 1, "expect Y=" + y + " got " + coordinates[1]);
+      } else {
+        ok(search == "", "expect empty search string got:" + search);
+      }
       nextTest();
     }
     else if (runningTest && event.data == "finished") {
       ok(testUrls[testIdx].includes("noDefault=true"), "Page should not leave");
       nextTest();
     }
   }, false);