public EventListener acquireLockOnDemand(final Element element) { Event.sinkEvents(element, lockDemandDetector.getLockDemandEventTypes()); EventListener lockDemandListener = new EventListener() { @Override public void onBrowserEvent(Event event) { if (isLockedByCurrentUser()) { return; } if (lockDemandDetector.isLockRequired(event)) { acquireLock(); } } }; Event.setEventListener(element, lockDemandListener); return lockDemandListener; }
@Test public void handleWindowReparenting() { lockManager.acquireLockOnDemand(); verify(lockDemandDetector, times(1)).getLockDemandEventTypes(); final ArgumentCaptor<AttachEvent.Handler> handlerCaptor = ArgumentCaptor.forClass(AttachEvent.Handler.class); verify(widget, times(1)).addAttachHandler(handlerCaptor.capture()); handlerCaptor.getValue().onAttachOrDetach(new AttachEvent(true) { }); verify(lockDemandDetector, times(2)).getLockDemandEventTypes(); }
@Test public void handleWindowReparenting() { lockManager.acquireLockOnDemand(); verify(lockDemandDetector, times(1)).getLockDemandEventTypes(); final ArgumentCaptor<AttachEvent.Handler> handlerCaptor = ArgumentCaptor.forClass(AttachEvent.Handler.class); verify(widget, times(1)).addAttachHandler(handlerCaptor.capture()); handlerCaptor.getValue().onAttachOrDetach(new AttachEvent(true) { }); verify(lockDemandDetector, times(2)).getLockDemandEventTypes(); }