Bug 1111433 - Add mochitest to verify SelectionStateChanged with blur state. r=ehsan
authorpchang <pchang@mozilla.com>
Wed, 07 Jan 2015 23:34:00 -0500
changeset 222763 40f4f285ea0c16f522387edb5aa292a0b3955fc7
parent 222762 0257f42048f3c790b101a9715563b376aea4a683
child 222764 384695747028cf0f20cd305c76d0c74d7fca93e0
push id28073
push userkwierso@gmail.com
push dateFri, 09 Jan 2015 01:08:23 +0000
treeherdermozilla-central@b3f84cf78dc2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1111433
milestone37.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 1111433 - Add mochitest to verify SelectionStateChanged with blur state. r=ehsan
dom/browser-element/mochitest/browserElement_CopyPaste.js
dom/browser-element/mochitest/browserElement_SelectionStateBlur.js
dom/browser-element/mochitest/mochitest-oop.ini
dom/browser-element/mochitest/mochitest.ini
dom/browser-element/mochitest/test_browserElement_inproc_SelectionStateBlur.html
dom/browser-element/mochitest/test_browserElement_oop_SelectionStateBlur.html
--- a/dom/browser-element/mochitest/browserElement_CopyPaste.js
+++ b/dom/browser-element/mochitest/browserElement_CopyPaste.js
@@ -176,22 +176,25 @@ function isChildProcess() {
                          .getService(SpecialPowers.Ci.nsIXULRuntime)
                          .processType != SpecialPowers.Ci.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
 }
 
 function testSelectAll(e) {
   // Skip mozbrowser test if we're at child process.
   if (!isChildProcess()) {
     iframeOuter.addEventListener("mozbrowserselectionstatechanged", function selectchangeforselectall(e) {
-      iframeOuter.removeEventListener("mozbrowserselectionstatechanged", selectchangeforselectall, true);
-      ok(true, "got mozbrowserselectionstatechanged event." + stateMeaning);
-      ok(e.detail, "event.detail is not null." + stateMeaning);
-      ok(e.detail.width != 0, "event.detail.width is not zero" + stateMeaning);
-      ok(e.detail.height != 0, "event.detail.height is not zero" + stateMeaning);
-      SimpleTest.executeSoon(function() { testCopy1(e); });
+      if (e.detail.states.indexOf('selectall') == 0) {
+        iframeOuter.removeEventListener("mozbrowserselectionstatechanged", selectchangeforselectall, true);
+        ok(true, "got mozbrowserselectionstatechanged event." + stateMeaning);
+        ok(e.detail, "event.detail is not null." + stateMeaning);
+        ok(e.detail.width != 0, "event.detail.width is not zero" + stateMeaning);
+        ok(e.detail.height != 0, "event.detail.height is not zero" + stateMeaning);
+        ok(e.detail.states, "event.detail.state " + e.detail.states);
+        SimpleTest.executeSoon(function() { testCopy1(e); });
+      }
     }, true);
   }
 
   mm.addMessageListener('content-focus', function messageforfocus(msg) {
     mm.removeMessageListener('content-focus', messageforfocus);
     // test selectall command, after calling this the selectionstatechanged event should be fired.
     doCommand('selectall');
     if (isChildProcess()) {
new file mode 100644
--- /dev/null
+++ b/dom/browser-element/mochitest/browserElement_SelectionStateBlur.js
@@ -0,0 +1,57 @@
+/* Any copyright is dedicated to the public domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// Bug 1111433: Send out the SelectionStateChanged event with Blur state
+
+"use strict";
+
+SimpleTest.waitForExplicitFinish();
+browserElementTestHelpers.setEnabledPref(true);
+browserElementTestHelpers.setSelectionChangeEnabledPref(true);
+browserElementTestHelpers.addPermission();
+
+var mm;
+var iframe;
+
+var changefocus = function () {
+  var elt = content.document.getElementById("text");
+  if (elt) {
+    elt.focus();
+    elt.select();
+    elt.blur();
+  }
+}
+
+function runTest() {
+  iframe = document.createElement('iframe');
+  iframe.setAttribute('mozbrowser', 'true');
+  document.body.appendChild(iframe);
+
+  mm = SpecialPowers.getBrowserFrameMessageManager(iframe);
+
+  iframe.src = "data:text/html,<html><body>" +
+               "<textarea id='text'> Bug 1111433 </textarea>"+
+               "</body></html>";
+
+  var loadtime = 0;
+  iframe.addEventListener("mozbrowserloadend", function onloadend(e) {
+    loadtime++;
+    if (loadtime === 2) {
+      iframe.removeEventListener("mozbrowserloadend", onloadend);
+      SimpleTest.executeSoon(function() { testBlur(e); });
+    }
+  });
+}
+
+function testBlur(e) {
+  iframe.addEventListener("mozbrowserselectionstatechanged", function selectionstatechanged(e) {
+    iframe.removeEventListener("mozbrowserselectionstatechanged", selectionstatechanged, true);
+    ok(e.detail.states.indexOf('blur') == 0, "received state  " + e.detail.states);
+    SimpleTest.finish();
+  }, true);
+
+  iframe.focus();
+  mm.loadFrameScript('data:,(' + changefocus.toString() + ')();', false);
+}
+
+addEventListener('testready', runTest);
--- a/dom/browser-element/mochitest/mochitest-oop.ini
+++ b/dom/browser-element/mochitest/mochitest-oop.ini
@@ -65,16 +65,18 @@ skip-if = (toolkit == 'gonk' && !debug)
 [test_browserElement_oop_PromptConfirm.html]
 [test_browserElement_oop_PurgeHistory.html]
 [test_browserElement_oop_Reload.html]
 [test_browserElement_oop_ReloadPostRequest.html]
 [test_browserElement_oop_RemoveBrowserElement.html]
 [test_browserElement_oop_ScrollEvent.html]
 [test_browserElement_oop_SecurityChange.html]
 skip-if = toolkit == 'android' || (toolkit == 'gonk' && !debug) #TIMED_OUT, bug 766586
+[test_browserElement_oop_SelectionStateBlur.html]
+skip-if = (toolkit == 'gonk') # Disabled on b2g due to bug 1097419
 [test_browserElement_oop_SendEvent.html]
 [test_browserElement_oop_SetInputMethodActive.html]
 skip-if = (os == "android")
 [test_browserElement_oop_SetVisible.html]
 [test_browserElement_oop_SetVisibleFrames.html]
 [test_browserElement_oop_SetVisibleFrames2.html]
 [test_browserElement_oop_Stop.html]
 [test_browserElement_oop_TargetBlank.html]
--- a/dom/browser-element/mochitest/mochitest.ini
+++ b/dom/browser-element/mochitest/mochitest.ini
@@ -48,16 +48,17 @@ support-files =
   browserElement_PromptConfirm.js
   browserElement_PurgeHistory.js
   browserElement_Reload.js
   browserElement_ReloadPostRequest.js
   browserElement_RemoveBrowserElement.js
   browserElement_ScrollEvent.js
   browserElement_SecurityChange.js
   browserElement_SendEvent.js
+  browserElement_SelectionStateBlur.js
   browserElement_SetInputMethodActive.js
   browserElement_SetVisible.js
   browserElement_SetVisibleFrames.js
   browserElement_SetVisibleFrames2.js
   browserElement_Stop.js
   browserElement_TargetBlank.js
   browserElement_TargetTop.js
   browserElement_Titlechange.js
@@ -179,16 +180,18 @@ skip-if = (toolkit == 'gonk' && !debug)
 [test_browserElement_inproc_PromptCheck.html]
 [test_browserElement_inproc_PromptConfirm.html]
 [test_browserElement_inproc_PurgeHistory.html]
 [test_browserElement_inproc_ReloadPostRequest.html]
 [test_browserElement_inproc_RemoveBrowserElement.html]
 [test_browserElement_inproc_ScrollEvent.html]
 [test_browserElement_inproc_SecurityChange.html]
 skip-if = toolkit == 'android' || (toolkit == 'gonk' && !debug) # android(TIMED_OUT, bug 766586) androidx86(TIMED_OUT, bug 766586)
+[test_browserElement_inproc_SelectionStateBlur.html]
+skip-if = (toolkit == 'gonk') # Disabled on b2g due to bug 1097419
 [test_browserElement_inproc_SendEvent.html]
 # The setInputMethodActive() tests will timed out on Android
 [test_browserElement_inproc_SetInputMethodActive.html]
 skip-if = (os == "android")
 [test_browserElement_inproc_SetVisible.html]
 [test_browserElement_inproc_SetVisibleFrames.html]
 [test_browserElement_inproc_SetVisibleFrames2.html]
 [test_browserElement_inproc_Stop.html]
new file mode 100644
--- /dev/null
+++ b/dom/browser-element/mochitest/test_browserElement_inproc_SelectionStateBlur.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1111433
+-->
+<head>
+  <title>Test for Bug 1111433</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="browserElementTestHelpers.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1111433">Mozilla Bug 1111433</a>
+
+<script type="application/javascript;version=1.7" src="browserElement_SelectionStateBlur.js">
+</script>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/browser-element/mochitest/test_browserElement_oop_SelectionStateBlur.html
@@ -0,0 +1,18 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1111433
+-->
+<head>
+  <title>Test for Bug 1111433</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="browserElementTestHelpers.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1111433">Mozilla Bug 1111433</a>
+
+<script type="application/javascript;version=1.7" src="browserElement_SelectionStateBlur.js">
+</script>
+</body>
+</html>