From c4c17a18dcb013588518c1542fd8d3966b08cd40 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Thu, 6 Mar 2014 20:09:06 +0200 Subject: Do not ever set title to null (#13430) * If title is null, leave it as-is (assume somebody else is setting it) * If title is non-null, set it as before Change-Id: I72699efa089df64b58448ceef59ba31995f330bf --- .../src/com/vaadin/client/ui/ui/UIConnector.java | 6 ++- server/src/com/vaadin/server/Page.java | 5 ++- shared/src/com/vaadin/shared/ui/ui/PageState.java | 2 +- .../vaadin/tests/components/page/PageTitle.java | 44 ++++++++++++++++++++++ .../tests/components/page/PageTitleTest.java | 36 ++++++++++++++++++ 5 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/page/PageTitle.java create mode 100644 uitest/src/com/vaadin/tests/components/page/PageTitleTest.java diff --git a/client/src/com/vaadin/client/ui/ui/UIConnector.java b/client/src/com/vaadin/client/ui/ui/UIConnector.java index 17a23baad5..47a5b5f807 100644 --- a/client/src/com/vaadin/client/ui/ui/UIConnector.java +++ b/client/src/com/vaadin/client/ui/ui/UIConnector.java @@ -680,8 +680,10 @@ public class UIConnector extends AbstractSingleComponentContainerConnector } if (stateChangeEvent.hasPropertyChanged("pageState.title")) { - com.google.gwt.user.client.Window - .setTitle(getState().pageState.title); + String title = getState().pageState.title; + if (title != null) { + com.google.gwt.user.client.Window.setTitle(title); + } } if (stateChangeEvent.hasPropertyChanged("pushConfiguration")) { diff --git a/server/src/com/vaadin/server/Page.java b/server/src/com/vaadin/server/Page.java index 5c8b1aeb42..19b84381d5 100644 --- a/server/src/com/vaadin/server/Page.java +++ b/server/src/com/vaadin/server/Page.java @@ -1133,9 +1133,12 @@ public class Page implements Serializable { /** * Sets the page title. The page title is displayed by the browser e.g. as * the title of the browser window or as the title of the tab. + *

+ * If the title is set to null, it will not left as-is. Set to empty string + * to clear the title. * * @param title - * the new page title to set + * the page title to set */ public void setTitle(String title) { getState(true).title = title; diff --git a/shared/src/com/vaadin/shared/ui/ui/PageState.java b/shared/src/com/vaadin/shared/ui/ui/PageState.java index ded73d16d5..4d2768787f 100644 --- a/shared/src/com/vaadin/shared/ui/ui/PageState.java +++ b/shared/src/com/vaadin/shared/ui/ui/PageState.java @@ -32,7 +32,7 @@ public class PageState implements Serializable { public boolean hasResizeListeners = false; /** - * Non-null if the title is set. + * Non-null if the title is set. Null means Vaadin does not touch the title. */ public String title = null; } \ No newline at end of file diff --git a/uitest/src/com/vaadin/tests/components/page/PageTitle.java b/uitest/src/com/vaadin/tests/components/page/PageTitle.java new file mode 100644 index 0000000000..38dcd4673c --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/page/PageTitle.java @@ -0,0 +1,44 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * 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.vaadin.tests.components.page; + +import com.vaadin.annotations.Title; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; + +@Title("bar") +public class PageTitle extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + String title = request.getParameter("title"); + if (title != null) { + getPage().setTitle(title); + } + + } + + @Override + protected String getTestDescription() { + return "Sets the title according to a given ?title parameter. By default the ApplicationServletRunner will set the title to the fully qualified class name"; + } + + @Override + protected Integer getTicketNumber() { + return 13430; + } + +} diff --git a/uitest/src/com/vaadin/tests/components/page/PageTitleTest.java b/uitest/src/com/vaadin/tests/components/page/PageTitleTest.java new file mode 100644 index 0000000000..039f52be73 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/page/PageTitleTest.java @@ -0,0 +1,36 @@ +/* + * Copyright 2000-2013 Vaadin Ltd. + * + * 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.vaadin.tests.components.page; + +import org.junit.Assert; +import org.junit.Test; + +import com.vaadin.tests.tb3.MultiBrowserTest; + +public class PageTitleTest extends MultiBrowserTest { + + @Test + public void nullTitle() { + driver.get(getTestUrl()); + Assert.assertEquals(PageTitle.class.getName(), driver.getTitle()); + } + + @Test + public void fooTitle() { + driver.get(getTestUrl() + "?title=foo"); + Assert.assertEquals("foo", driver.getTitle()); + } +} -- cgit v1.2.3