diff options
author | Artur Signell <artur@vaadin.com> | 2014-03-06 20:09:06 +0200 |
---|---|---|
committer | Vaadin Code Review <review@vaadin.com> | 2014-03-11 19:47:43 +0000 |
commit | c4c17a18dcb013588518c1542fd8d3966b08cd40 (patch) | |
tree | 6ccafe06ec8d0bb9000f7a708e376592b6ef7091 | |
parent | 729b79a737fd2b3ed1c49ec66b3c823393bab017 (diff) | |
download | vaadin-framework-c4c17a18dcb013588518c1542fd8d3966b08cd40.tar.gz vaadin-framework-c4c17a18dcb013588518c1542fd8d3966b08cd40.zip |
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
5 files changed, 89 insertions, 4 deletions
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. + * <p> + * 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()); + } +} |