Skip to content

Commit

Permalink
Bug 1669176 - Move out action initializing code from listener.js r=ma…
Browse files Browse the repository at this point in the history
…rionette-reviewers,whimboo

Differential Revision: https://phabricator.services.mozilla.com/D99389
  • Loading branch information
mjzffr committed Dec 11, 2020
1 parent 87b847b commit b0ea773
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
22 changes: 19 additions & 3 deletions testing/marionette/actors/MarionetteCommandsChild.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

"use strict";

const EXPORTED_SYMBOLS = ["MarionetteCommandsChild"];
const EXPORTED_SYMBOLS = ["MarionetteCommandsChild", "clearActionInputState"];

const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
Expand All @@ -28,6 +28,8 @@ XPCOMUtils.defineLazyModuleGetters(this, {

XPCOMUtils.defineLazyGetter(this, "logger", () => Log.get());

let inputStateIsDirty = false;

class MarionetteCommandsChild extends JSWindowActorChild {
constructor() {
super();
Expand Down Expand Up @@ -72,6 +74,7 @@ class MarionetteCommandsChild extends JSWindowActorChild {
event.DoubleClickTracker.resetClick,
true
);
clearActionInputState();
}

async receiveMessage(msg) {
Expand Down Expand Up @@ -448,6 +451,8 @@ class MarionetteCommandsChild extends JSWindowActorChild {
this.document.defaultView,
!capabilities["moz:useNonSpecCompliantPointerOrigin"]
);
inputStateIsDirty =
action.inputsToCancel.length || action.inputStateMap.size;
}

/**
Expand All @@ -462,8 +467,7 @@ class MarionetteCommandsChild extends JSWindowActorChild {
0,
this.document.defaultView
);
action.inputsToCancel.length = 0;
action.inputStateMap.clear();
clearActionInputState();

event.DoubleClickTracker.resetClick();
}
Expand Down Expand Up @@ -539,3 +543,15 @@ class MarionetteCommandsChild extends JSWindowActorChild {
return { browsingContextId: browsingContext.id };
}
}

/**
* Reset Action API input state
*/
function clearActionInputState() {
// Avoid loading the action module before it is needed by a command
if (inputStateIsDirty) {
action.inputStateMap.clear();
action.inputsToCancel.length = 0;
inputStateIsDirty = false;
}
}
3 changes: 3 additions & 0 deletions testing/marionette/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ XPCOMUtils.defineLazyModuleGetters(this, {
ChromeWebElement: "chrome://marionette/content/element.js",
clearElementIdCache:
"chrome://marionette/content/actors/MarionetteCommandsParent.jsm",
clearActionInputState:
"chrome://marionette/content/actors/MarionetteCommandsChild.jsm",
Context: "chrome://marionette/content/browser.js",
cookie: "chrome://marionette/content/cookie.js",
DebounceCallback: "chrome://marionette/content/sync.js",
Expand Down Expand Up @@ -3048,6 +3050,7 @@ GeckoDriver.prototype.deleteSession = function() {

if (MarionettePrefs.useActors) {
clearElementIdCache();
clearActionInputState();

unregisterCommandsActor();
}
Expand Down
8 changes: 0 additions & 8 deletions testing/marionette/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,6 @@ function deleteSession() {
curContainer.frame.focus();

legacyactions.touchIds = {};
if (action.inputStateMap !== undefined) {
action.inputStateMap.clear();
}
if (action.inputsToCancel !== undefined) {
action.inputsToCancel.length = 0;
}
}

/**
Expand Down Expand Up @@ -1071,8 +1065,6 @@ function registerSelf() {

sandboxes.clear();
legacyactions.mouseEventsOnly = false;
action.inputStateMap = new Map();
action.inputsToCancel = [];

let reply = sendSyncMessage("Marionette:Register", {
frameId: contentId,
Expand Down

0 comments on commit b0ea773

Please sign in to comment.