From 9fc3cb00ce142aabd5f0d2b17e83cfce8b8f910d Mon Sep 17 00:00:00 2001 From: Morris Tseng Date: Thu, 28 May 2015 01:39:00 -0400 Subject: [PATCH] Bug 1155493 - Part 4 - Add test for mozbrowsercaretstatechanged. r=kanru --- .../mochitest/browserElementTestHelpers.js | 4 ++ .../mochitest/browserElement_CopyPaste.js | 46 ++++++++++++++----- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/dom/browser-element/mochitest/browserElementTestHelpers.js b/dom/browser-element/mochitest/browserElementTestHelpers.js index 007b0300ccc..f557517de47 100644 --- a/dom/browser-element/mochitest/browserElementTestHelpers.js +++ b/dom/browser-element/mochitest/browserElementTestHelpers.js @@ -65,6 +65,10 @@ const browserElementTestHelpers = { this._setPref('selectioncaret.enabled', value); }, + setAccessibleCaretEnabledPref: function(value) { + this._setPref('layout.accessiblecaret.enabled', value); + }, + getOOPByDefaultPref: function() { return this._getBoolPref("dom.ipc.browser_frames.oop_by_default"); }, diff --git a/dom/browser-element/mochitest/browserElement_CopyPaste.js b/dom/browser-element/mochitest/browserElement_CopyPaste.js index 762b792507c..dd3012f688f 100644 --- a/dom/browser-element/mochitest/browserElement_CopyPaste.js +++ b/dom/browser-element/mochitest/browserElement_CopyPaste.js @@ -6,8 +6,10 @@ SimpleTest.waitForExplicitFinish(); SimpleTest.requestFlakyTimeout("untriaged"); +SimpleTest.requestLongerTimeout(2); // slow on android browserElementTestHelpers.setEnabledPref(true); -browserElementTestHelpers.setSelectionChangeEnabledPref(true); +browserElementTestHelpers.setSelectionChangeEnabledPref(false); +browserElementTestHelpers.setAccessibleCaretEnabledPref(true); browserElementTestHelpers.addPermission(); const { Services } = SpecialPowers.Cu.import('resource://gre/modules/Services.jsm'); @@ -21,6 +23,7 @@ var defaultData; var pasteData; var focusScript; var createEmbededFrame = false; +var testSelectionChange = false; function copyToClipboard(str) { gTextarea.value = str; @@ -89,6 +92,14 @@ function doCommand(cmd) { 'copypaste-docommand', cmd); } +function rerunTest() { + // clean up and run test again. + document.body.removeChild(iframeOuter); + document.body.removeChild(gTextarea); + state = 0; + runTest(); +} + function dispatchTest(e) { iframeInner.addEventListener("mozbrowserloadend", function onloadend2(e) { iframeInner.removeEventListener("mozbrowserloadend", onloadend2); @@ -160,15 +171,23 @@ function dispatchTest(e) { break; default: if (createEmbededFrame || browserElementTestHelpers.getOOPByDefaultPref()) { - SimpleTest.finish(); + if (testSelectionChange) { + SimpleTest.finish(); + return; + } else { + testSelectionChange = true; + createEmbededFrame = false; + SpecialPowers.pushPrefEnv( + {'set': + [['selectioncaret.enabled', true], + ['layout.accessiblecaret.enabled', false]]}, + function() { + rerunTest(); + }); + } } else { createEmbededFrame = true; - - // clean up and run test again. - document.body.removeChild(iframeOuter); - document.body.removeChild(gTextarea); - state = 0; - runTest(); + rerunTest(); } break; } @@ -183,14 +202,17 @@ function isChildProcess() { function testSelectAll(e) { // Skip mozbrowser test if we're at child process. if (!isChildProcess()) { - iframeOuter.addEventListener("mozbrowserselectionstatechanged", function selectchangeforselectall(e) { - if (e.detail.states.indexOf('selectall') == 0) { - iframeOuter.removeEventListener("mozbrowserselectionstatechanged", selectchangeforselectall, true); + let eventName = testSelectionChange ? "mozbrowserselectionstatechanged" : "mozbrowsercaretstatechanged"; + iframeOuter.addEventListener(eventName, function selectchangeforselectall(e) { + if (!e.detail.states || e.detail.states.indexOf('selectall') == 0) { + iframeOuter.removeEventListener(eventName, 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); + if (testSelectionChange) { + ok(e.detail.states, "event.detail.state " + e.detail.states); + } SimpleTest.executeSoon(function() { testCopy1(e); }); } }, true);