From 6ce22d8ad5c9e81cc2e34a70779413fb2c7040d6 Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Tue, 30 Dec 2014 12:18:24 +0200 Subject: Update favicon when changing themes (#15481) Change-Id: I3622d211ac5e668f7dce999605118f8f16ffae90 --- .../vaadin/tests/themes/ThemeChangeFavicon.java | 44 +++++++++++ .../tests/themes/ThemeChangeFaviconTest.java | 87 ++++++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/themes/ThemeChangeFavicon.java create mode 100644 uitest/src/com/vaadin/tests/themes/ThemeChangeFaviconTest.java (limited to 'uitest/src') diff --git a/uitest/src/com/vaadin/tests/themes/ThemeChangeFavicon.java b/uitest/src/com/vaadin/tests/themes/ThemeChangeFavicon.java new file mode 100644 index 0000000000..8995583975 --- /dev/null +++ b/uitest/src/com/vaadin/tests/themes/ThemeChangeFavicon.java @@ -0,0 +1,44 @@ +/* + * Copyright 2000-2014 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.themes; + +import java.util.Arrays; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; + +public class ThemeChangeFavicon extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + for (final String theme : Arrays.asList("valo", "reindeer")) { + addComponent(new Button(theme, new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + setTheme(theme); + } + })); + } + } + + @Override + public String getDescription() { + return "UI for testing that the favicon changes when changing themes"; + } + +} diff --git a/uitest/src/com/vaadin/tests/themes/ThemeChangeFaviconTest.java b/uitest/src/com/vaadin/tests/themes/ThemeChangeFaviconTest.java new file mode 100644 index 0000000000..e4788f93f5 --- /dev/null +++ b/uitest/src/com/vaadin/tests/themes/ThemeChangeFaviconTest.java @@ -0,0 +1,87 @@ +/* + * Copyright 2000-2014 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.themes; + +import java.util.Collections; +import java.util.List; + +import org.junit.Assert; +import org.junit.Test; +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.support.ui.ExpectedCondition; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.parallel.Browser; +import com.vaadin.tests.tb3.SingleBrowserTest; + +public class ThemeChangeFaviconTest extends SingleBrowserTest { + + @Override + public List getBrowsersToTest() { + // Seems like stylesheet onload is not fired on PhantomJS + // https://github.com/ariya/phantomjs/issues/12332 + return Collections.singletonList(Browser.FIREFOX + .getDesiredCapabilities()); + } + + @Test + public void changeFavicon() throws InterruptedException { + setDebug(true); + openTestURL(); + assertFavicon("reindeer"); + + changeTheme("valo"); + assertFavicon("valo"); + + changeTheme("reindeer"); + assertFavicon("reindeer"); + } + + private void changeTheme(final String theme) { + $(ButtonElement.class).caption(theme).first().click(); + + final WebElement rootDiv = findElement(By + .xpath("//div[contains(@class,'v-app')]")); + waitUntil(new ExpectedCondition() { + + @Override + public Boolean apply(WebDriver input) { + String rootClass = rootDiv.getAttribute("class").trim(); + + return rootClass.contains(theme); + } + }, 30); + } + + private void assertFavicon(String theme) { + String faviconUrl = "/VAADIN/themes/" + theme + "/favicon.ico"; + + List elements = findElements(By + .cssSelector("link[rel~=\"icon\"]")); + + Assert.assertEquals(2, elements.size()); + + for (WebElement element : elements) { + Assert.assertTrue(element.getAttribute("href") + + " does not end with " + faviconUrl, + element.getAttribute("href").endsWith(faviconUrl)); + } + } + +} -- cgit v1.2.3