Page implements Serializable { public Registration addBrowserWindowResizeListener( BrowserWindowResizeListener resizeListener) { Objects.requireNonNull(resizeListener); if (resizeReceiver == null) { resizeReceiver = new ResizeEventReceiver(); ui.getElement().appendVirtualChild(resizeReceiver.getElement()); } if (resizeReceiver.windowResizeListenersSize == 0) { executeJs(LazyJsLoader.WINDOW_LISTENER_JS, resizeReceiver); } return resizeReceiver.addListener(resizeListener); } Page(UI ui); void setTitle(String title); void addStyleSheet(String url); void addStyleSheet(String url, LoadMode loadMode); void addJavaScript(String url); void addJavaScript(String url, LoadMode loadMode); void addJsModule(String url); void addDynamicImport(String expression); @Deprecated ExecutionCanceler executeJavaScript(String expression,
            Serializable... parameters); PendingJavaScriptResult executeJs(String expression,
            Serializable... parameters); History getHistory(); void reload(); Registration addBrowserWindowResizeListener(
            BrowserWindowResizeListener resizeListener); void open(String url); void open(String url, String windowName); void setLocation(String uri); void setLocation(URI uri); void retrieveExtendedClientDetails(
            ExtendedClientDetailsReceiver receiver);  }
@Test(expected = NullPointerException.class) public void addNullAsAListener_trows() { page.addBrowserWindowResizeListener(null); }
@Test public void addListener_executeInitJs() { page.addBrowserWindowResizeListener(listener); Assert.assertThat(page.expression, CoreMatchers.allOf(CoreMatchers.containsString("init"), CoreMatchers.containsString("resize"))); Assert.assertTrue(page.firstParam instanceof Component); }
@Test public void addTwoListeners_jsIsExecutedOnce() { page.addBrowserWindowResizeListener(listener); page.addBrowserWindowResizeListener(event -> { }); Assert.assertEquals(1, page.count); }
@Test public void addTwoListeners_unregisterOneListener_jsListenerIsNotRemoved() { page.addBrowserWindowResizeListener(listener); Registration registration = page .addBrowserWindowResizeListener(event -> { }); registration.remove(); Assert.assertEquals(1, page.count); registration.remove(); Assert.assertEquals(1, page.count); }
@Test public void addTwoListeners_unregisterTwoListeners_jsListenerIsRemoved() { Registration registration1 = page .addBrowserWindowResizeListener(listener); Registration registration2 = page .addBrowserWindowResizeListener(event -> { }); registration1.remove(); registration2.remove(); Assert.assertEquals(2, page.count); Assert.assertEquals("$0.resizeRemove()", page.expression); Assert.assertTrue(page.firstParam instanceof Component); }
@Test public void addListener_unregisterListener_addListener_jsListenerIsRemovedAndInitialized() { Registration registration = page .addBrowserWindowResizeListener(listener); registration.remove(); registration.remove(); Assert.assertEquals(2, page.count); Assert.assertEquals("$0.resizeRemove()", page.expression); page.addBrowserWindowResizeListener(listener); Assert.assertEquals(3, page.count); Assert.assertThat(page.expression, CoreMatchers.allOf(CoreMatchers.containsString("init"), CoreMatchers.containsString("resize"))); Assert.assertTrue(page.firstParam instanceof Component); }