1

我正在使用 gwt-test-utils 为我的 gwt 项目编写测试用例。我需要在谷歌网络工具包中以编程方式调度鼠标滚轮事件。

com.google.gwt.user.client.Event;

我试过这段代码

Event event = EventBuilder.create(Event.ONMOUSEWHEEL).build();      
Browser.dispatchEvent(myUIComponent,event );

该事件已成功创建并被触发。

我添加了一个事件监听器来监听鼠标滚轮事件

myUIComponent.addMouseWheelHandler(new MouseWheelHandler() {
        public void onMouseWheel(MouseWheelEvent event) {

            if (event.isNorth()) {

            } else {

            }

        }
    });

但是当事件侦听器被执行时,我在执行时收到一条错误消息event.isNorth()

堆栈跟踪如下

java.lang.UnsupportedOperationException: Abstract method 'DOMImpl.eventGetMouseWheelVelocityY()' is not patched by com.googlecode.gwt.test.internal.AutomaticPatcher
at com.google.gwt.dom.client.DOMImpl.eventGetMouseWheelVelocityY(DOMImpl.java)
at com.google.gwt.dom.client.NativeEvent$.getMouseWheelVelocityY$(NativeEvent.java:175)
at com.google.gwt.event.dom.client.MouseWheelEvent.getDeltaY(MouseWheelEvent.java:73)
at com.google.gwt.event.dom.client.MouseWheelEvent.isNorth(MouseWheelEvent.java:84)
at com.rubirules.uibuilder.client.TimePicker$4.onMouseWheel(TimePicker.java:227)
at com.google.gwt.event.dom.client.MouseWheelEvent.dispatch(MouseWheelEvent.java:100)
at com.google.gwt.event.dom.client.MouseWheelEvent.dispatch(MouseWheelEvent.java:23)
at com.google.web.bindery.event.shared.EventBus.dispatchEvent(EventBus.java:40)
at com.google.web.bindery.event.shared.SimpleEventBus.doFire(SimpleEventBus.java:193)
at com.google.web.bindery.event.shared.SimpleEventBus.fireEvent(SimpleEventBus.java:88)
at com.google.gwt.event.shared.HandlerManager.fireEvent(HandlerManager.java:127)
at com.google.gwt.user.client.ui.Widget.fireEvent(Widget.java:129)
at com.google.gwt.event.dom.client.DomEvent.fireNativeEvent(DomEvent.java:116)
at com.google.gwt.user.client.ui.Widget.onBrowserEvent(Widget.java:177)
at com.google.gwt.user.client.ui.ValueBoxBase.onBrowserEvent(ValueBoxBase.java:252)
at com.googlecode.gwt.test.utils.events.Browser.dispatchEventWithBubble(Browser.java:969)
at com.googlecode.gwt.test.utils.events.Browser.dispatchEventInternal(Browser.java:921)
at com.googlecode.gwt.test.utils.events.Browser.dispatchEventsInternal(Browser.java:946)
at com.googlecode.gwt.test.utils.events.Browser.dispatchEvent(Browser.java:313)
at com.rubirules.uibuilder.client.TimePickerTest.testHoursScrollUp(TimePickerTest.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
at com.googlecode.gwt.test.internal.junit.GwtBlockJUnit4ClassRunner.run(GwtBlockJUnit4ClassRunner.java:27)
at com.googlecode.gwt.test.internal.junit.AbstractGwtRunner.run(AbstractGwtRunner.java:47)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

当从实际的鼠标滚轮事件触发事件时,这可以正常工作。我的活动创建有问题吗?建议手动创建事件的最佳方法。

4

2 回答 2

2

向上移动鼠标滚轮调度事件:

Event ev = EventBuilder.create(Event.ONMOUSEWHEEL).setMouseX(KeyCodes.KEY_DOWN).build();
MouseWheelVelocity evnt = new MouseWheelVelocity(ev);
于 2013-01-09T06:16:47.410 回答
0

您必须手动修补此方法,因为它似乎不包括在内。

有关详细信息,请参阅http://code.google.com/p/gwt-test-utils/issues/detail?id=156

您将需要创建一个 Patcher 对象来模拟您希望从 DOMImpl.eventGetMouseWheelVelocityY() 返回的值。这可能是有问题的,因为 DOMImpl 被延迟绑定到多个运行时目标,而且我对 gwt-test-utils 不够熟悉,无法告诉您是否可以修补它。

如果您无法修补 DOMImpl,请改为修补 MouseWheelEvent.isNorth()。

于 2013-01-04T14:36:03.463 回答