From c6efaba7316e74d8ef45020e942687a76b380a9f Mon Sep 17 00:00:00 2001 From: Maxime Meriouma-Caron Date: Fri, 8 Aug 2014 13:11:04 -0400 Subject: [PATCH 1/2] Fixed PopupPresenter setCloseHandler --- .../gwtplatform/mvp/client/PopupViewImpl.java | 7 ++- .../gwt/mvp/ClientModuleTestUtilGwt.java | 3 ++ .../client/gwt/mvp/GinjectorTestUtilGwt.java | 2 + .../gwt/mvp/MainPresenterTestUtilGwt.java | 31 ++++++++----- .../mvp/client/gwt/mvp/MvpGwtTestInSuite.java | 43 +++++++++++++++++++ .../gwt/mvp/PopupPresenterTestUtilGwt.java | 39 +++++++++++++++++ .../client/gwt/mvp/PopupViewTestUtilGwt.java | 42 ++++++++++++++++++ .../gwt/mvp/PopupViewTestUtilGwt.ui.xml | 5 +++ 8 files changed, 160 insertions(+), 12 deletions(-) create mode 100644 gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/PopupPresenterTestUtilGwt.java create mode 100644 gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/PopupViewTestUtilGwt.java create mode 100644 gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/PopupViewTestUtilGwt.ui.xml diff --git a/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/client/PopupViewImpl.java b/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/client/PopupViewImpl.java index 5a6fa420b4..912f8222c9 100644 --- a/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/client/PopupViewImpl.java +++ b/gwtp-core/gwtp-mvp-client/src/main/java/com/gwtplatform/mvp/client/PopupViewImpl.java @@ -161,11 +161,16 @@ protected void doCenter() { int top = (Window.getClientHeight() - popup.getOffsetHeight()) >> 1; if (!isShowing) { - popup.hide(); + hidePopup(asPopupPanel()); popup.setVisible(true); } popup.setPopupPosition(Math.max(Window.getScrollLeft() + left, 0), Math.max( Window.getScrollTop() + top, 0)); } + + private native void hidePopup(PopupPanel popupPanel) /*-{ + var resizeAnimation = popupPanel.@com.google.gwt.user.client.ui.PopupPanel::resizeAnimation; + resizeAnimation.@com.google.gwt.user.client.ui.PopupPanel.ResizeAnimation::setState(ZZ)(false, false); + }-*/; } diff --git a/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/ClientModuleTestUtilGwt.java b/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/ClientModuleTestUtilGwt.java index 07d4ccad06..f29ba3712f 100644 --- a/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/ClientModuleTestUtilGwt.java +++ b/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/ClientModuleTestUtilGwt.java @@ -46,6 +46,9 @@ protected void configure() { bindPresenter(AdminPresenterTestUtilGwt.class, AdminPresenterTestUtilGwt.MyView.class, AdminViewTestUtilGwt.class, AdminPresenterTestUtilGwt.MyProxy.class); + bindSingletonPresenterWidget(PopupPresenterTestUtilGwt.class, PopupPresenterTestUtilGwt.MyView.class, + PopupViewTestUtilGwt.class); + // For testing bind(InstantiationCounterTestUtilGwt.class).asEagerSingleton(); bindConstant().annotatedWith(Names.named("notice")).to("Hello"); diff --git a/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/GinjectorTestUtilGwt.java b/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/GinjectorTestUtilGwt.java index 4a12631eaa..dc9457b9cd 100644 --- a/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/GinjectorTestUtilGwt.java +++ b/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/GinjectorTestUtilGwt.java @@ -28,6 +28,8 @@ public interface GinjectorTestUtilGwt extends Ginjector { Provider getAdminPresenter(); + Provider getPopupPresenter(); + EventBus getEventBus(); PlaceManager getPlaceManager(); diff --git a/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/MainPresenterTestUtilGwt.java b/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/MainPresenterTestUtilGwt.java index bf3b3ee6ef..8eacc28330 100644 --- a/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/MainPresenterTestUtilGwt.java +++ b/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/MainPresenterTestUtilGwt.java @@ -17,8 +17,10 @@ package com.gwtplatform.mvp.client.gwt.mvp; import javax.inject.Inject; +import javax.inject.Provider; import com.google.web.bindery.event.shared.EventBus; +import com.gwtplatform.mvp.client.PopupViewCloseHandler; import com.gwtplatform.mvp.client.Presenter; import com.gwtplatform.mvp.client.View; import com.gwtplatform.mvp.client.annotations.NameToken; @@ -28,26 +30,33 @@ /** * A test presenter meant to be run in a GWTTestCase. */ -public class MainPresenterTestUtilGwt extends Presenter { +public class MainPresenterTestUtilGwt + extends Presenter { - /** - * Presenter's view. - */ - public interface MyView extends View { + interface MyView extends View { } - /** - * Presenter's proxy. - */ @ProxyStandard @NameToken("home") - public interface MyProxy extends ProxyPlace { + interface MyProxy extends ProxyPlace { } + private final Provider popupPresenterProvider; + @Inject - public MainPresenterTestUtilGwt(final EventBus eventBus, final MyView view, final MyProxy proxy) { + MainPresenterTestUtilGwt(EventBus eventBus, + MyView view, + MyProxy proxy, + Provider popupPresenterProvider) { super(eventBus, view, proxy, RevealType.Root); + + this.popupPresenterProvider = popupPresenterProvider; + } + + public void showPopup(PopupViewCloseHandler closeHandler) { + PopupPresenterTestUtilGwt popup = popupPresenterProvider.get(); + popup.setCloseHandler(closeHandler); + addToPopupSlot(popup); } } diff --git a/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/MvpGwtTestInSuite.java b/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/MvpGwtTestInSuite.java index 42c128129f..a345ea9373 100644 --- a/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/MvpGwtTestInSuite.java +++ b/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/MvpGwtTestInSuite.java @@ -19,8 +19,10 @@ import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler.ScheduledCommand; +import com.google.gwt.event.logical.shared.AttachEvent; import com.google.gwt.junit.client.GWTTestCase; import com.gwtplatform.mvp.client.DelayedBindRegistry; +import com.gwtplatform.mvp.client.PopupViewCloseHandler; import com.gwtplatform.mvp.shared.proxy.PlaceRequest; import com.gwtplatform.mvp.shared.proxy.PlaceRequest.Builder; @@ -43,6 +45,7 @@ protected void gwtSetUp() throws Exception { InstantiationCounterTestUtilGwt.resetCounter(); ginjector = GWT.create(GinjectorTestUtilGwt.class); DelayedBindRegistry.bind(ginjector); + presenter = ginjector.getMainPresenter().get(); } /** @@ -54,6 +57,42 @@ public void testShouldCreateOnlyOneGinjector() { assertEquals(1, InstantiationCounterTestUtilGwt.getCounter()); } + public void testPopupViewCloseHandlerCalledWhenClosed() { + delayTestFinish(1000); + runTest(new ScheduledCommand() { + @Override + public void execute() { + PopupPresenterTestUtilGwt popupPresenter = ginjector.getPopupPresenter().get(); + popupPresenter.asWidget().addAttachHandler(new AttachEvent.Handler() { + @Override + public void onAttachOrDetach(AttachEvent event) { + if (event.isAttached()) { + finishTest(); + } else { + fail(); + } + } + }); + + ginjector.getPlaceManager().revealDefaultPlace(); + + final PopupViewCloseHandler closeHandler = new PopupViewCloseHandler() { + @Override + public void onClose() { + fail(); + } + }; + + Scheduler.get().scheduleDeferred(new ScheduledCommand() { + @Override + public void execute() { + presenter.showPopup(closeHandler); + } + }); + } + }); + } + /** * Verify multiple name tokens. */ @@ -116,4 +155,8 @@ public void execute() { } }); } + + private void runTest(ScheduledCommand test) { + Scheduler.get().scheduleDeferred(test); + } } diff --git a/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/PopupPresenterTestUtilGwt.java b/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/PopupPresenterTestUtilGwt.java new file mode 100644 index 0000000000..6824a4f565 --- /dev/null +++ b/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/PopupPresenterTestUtilGwt.java @@ -0,0 +1,39 @@ +/** + * Copyright 2014 ArcBees Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.gwtplatform.mvp.client.gwt.mvp; + +import javax.inject.Inject; + +import com.google.web.bindery.event.shared.EventBus; +import com.gwtplatform.mvp.client.PopupView; +import com.gwtplatform.mvp.client.PopupViewCloseHandler; +import com.gwtplatform.mvp.client.PresenterWidget; + +public class PopupPresenterTestUtilGwt extends PresenterWidget { + public interface MyView extends PopupView { + } + + @Inject + PopupPresenterTestUtilGwt(EventBus eventBus, MyView view) { + super(eventBus, view); + } + + public void setCloseHandler(PopupViewCloseHandler closeHandler) { + getView().setCloseHandler(closeHandler); + } +} + diff --git a/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/PopupViewTestUtilGwt.java b/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/PopupViewTestUtilGwt.java new file mode 100644 index 0000000000..30428ac0df --- /dev/null +++ b/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/PopupViewTestUtilGwt.java @@ -0,0 +1,42 @@ +/** + * Copyright 2014 ArcBees Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.gwtplatform.mvp.client.gwt.mvp; + +import javax.inject.Inject; + +import com.google.gwt.uibinder.client.UiBinder; +import com.google.gwt.uibinder.client.UiField; +import com.google.gwt.user.client.ui.DialogBox; +import com.google.gwt.user.client.ui.Widget; +import com.google.web.bindery.event.shared.EventBus; +import com.gwtplatform.mvp.client.PopupViewImpl; + +public class PopupViewTestUtilGwt extends PopupViewImpl implements PopupPresenterTestUtilGwt.MyView { + + public interface Binder extends UiBinder { + } + + @UiField + DialogBox mainSlot; + + @Inject + PopupViewTestUtilGwt(EventBus eventBus, Binder uiBinder) { + super(eventBus); + + initWidget(uiBinder.createAndBindUi(this)); + } +} diff --git a/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/PopupViewTestUtilGwt.ui.xml b/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/PopupViewTestUtilGwt.ui.xml new file mode 100644 index 0000000000..5f3c4ff61e --- /dev/null +++ b/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/PopupViewTestUtilGwt.ui.xml @@ -0,0 +1,5 @@ + + + + From f55e43ad4be970b2865fe3846b8139fc9d93985c Mon Sep 17 00:00:00 2001 From: Maxime Meriouma-Caron Date: Fri, 8 Aug 2014 14:22:23 -0400 Subject: [PATCH 2/2] CR Fixes --- .../com/gwtplatform/mvp/client/gwt/mvp/MvpGwtTestInSuite.java | 2 +- .../mvp/client/gwt/mvp/PopupPresenterTestUtilGwt.java | 1 - .../gwtplatform/mvp/client/gwt/mvp/PopupViewTestUtilGwt.java | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/MvpGwtTestInSuite.java b/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/MvpGwtTestInSuite.java index a345ea9373..07793c5f75 100644 --- a/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/MvpGwtTestInSuite.java +++ b/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/MvpGwtTestInSuite.java @@ -57,7 +57,7 @@ public void testShouldCreateOnlyOneGinjector() { assertEquals(1, InstantiationCounterTestUtilGwt.getCounter()); } - public void testPopupViewCloseHandlerCalledWhenClosed() { + public void testPopupViewCloseHandlerNotCalledWhenShown() { delayTestFinish(1000); runTest(new ScheduledCommand() { @Override diff --git a/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/PopupPresenterTestUtilGwt.java b/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/PopupPresenterTestUtilGwt.java index 6824a4f565..8436aa613f 100644 --- a/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/PopupPresenterTestUtilGwt.java +++ b/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/PopupPresenterTestUtilGwt.java @@ -36,4 +36,3 @@ public void setCloseHandler(PopupViewCloseHandler closeHandler) { getView().setCloseHandler(closeHandler); } } - diff --git a/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/PopupViewTestUtilGwt.java b/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/PopupViewTestUtilGwt.java index 30428ac0df..2c8e703217 100644 --- a/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/PopupViewTestUtilGwt.java +++ b/gwtp-core/gwtp-mvp-client/src/test/java/com/gwtplatform/mvp/client/gwt/mvp/PopupViewTestUtilGwt.java @@ -26,7 +26,6 @@ import com.gwtplatform.mvp.client.PopupViewImpl; public class PopupViewTestUtilGwt extends PopupViewImpl implements PopupPresenterTestUtilGwt.MyView { - public interface Binder extends UiBinder { }