]> source.dussan.org Git - vaadin-framework.git/commitdiff
Add autogenerated style name for UI based on its class name (#14670)
authorDenis Anisimov <denis@vaadin.com>
Sat, 20 Sep 2014 11:22:21 +0000 (14:22 +0300)
committerLeif Åstrand <leif@vaadin.com>
Mon, 22 Sep 2014 05:38:10 +0000 (05:38 +0000)
Change-Id: Ic2ff4c29f997c33ea952a94c17aa9e70a0339337

server/src/com/vaadin/server/BootstrapHandler.java
uitest/src/com/vaadin/tests/components/ui/UIAutoGeneratedStyleName.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/ui/UIAutoGeneratedStyleNameTest.java [new file with mode: 0644]

index 0605d6a2b8107db7bae55dccadec8dba79d7945e..f0666f63fc55623f568edda10fb5220e9efafaee 100644 (file)
@@ -350,7 +350,6 @@ public abstract class BootstrapHandler extends SynchronizedRequestHandler {
         /*- Add classnames;
          *      .v-app
          *      .v-app-loading
-         *      .v-app-<simpleName for app class>
          *- Additionally added from javascript:
          *      <themeName, remove non-alphanum>
          */
@@ -362,6 +361,8 @@ public abstract class BootstrapHandler extends SynchronizedRequestHandler {
         mainDiv.attr("id", context.getAppId());
         mainDiv.addClass("v-app");
         mainDiv.addClass(context.getThemeName());
+        mainDiv.addClass(context.getUIClass().getSimpleName()
+                .toLowerCase(Locale.ENGLISH));
         if (style != null && style.length() != 0) {
             mainDiv.attr("style", style);
         }
@@ -401,7 +402,7 @@ public abstract class BootstrapHandler extends SynchronizedRequestHandler {
         builder.append("//<![CDATA[\n");
         builder.append("if (!window.vaadin) alert("
                 + JsonUtil.quote("Failed to load the bootstrap javascript: "
-                + bootstrapLocation) + ");\n");
+                        + bootstrapLocation) + ");\n");
 
         appendMainScriptTagContents(context, builder);
 
@@ -501,7 +502,8 @@ public abstract class BootstrapHandler extends SynchronizedRequestHandler {
             if (systemMessages.getAuthenticationErrorURL() == null) {
                 authErrMsg.put("url", Json.createNull());
             } else {
-                authErrMsg.put("url", systemMessages.getAuthenticationErrorURL());
+                authErrMsg.put("url",
+                        systemMessages.getAuthenticationErrorURL());
             }
 
             appConfig.put("authErrMsg", authErrMsg);
diff --git a/uitest/src/com/vaadin/tests/components/ui/UIAutoGeneratedStyleName.java b/uitest/src/com/vaadin/tests/components/ui/UIAutoGeneratedStyleName.java
new file mode 100644 (file)
index 0000000..35dc4cd
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * 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.components.ui;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+
+/**
+ * Empty test ui to check auto-generated style name for UI.
+ * 
+ * @author Vaadin Ltd
+ */
+public class UIAutoGeneratedStyleName extends AbstractTestUI {
+
+    @Override
+    protected void setup(VaadinRequest request) {
+    }
+
+    @Override
+    protected String getTestDescription() {
+        return "Add UI specific autogenerated style name to ui div element"
+                + " and overlays container";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 14670;
+    }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/ui/UIAutoGeneratedStyleNameTest.java b/uitest/src/com/vaadin/tests/components/ui/UIAutoGeneratedStyleNameTest.java
new file mode 100644 (file)
index 0000000..48d4c40
--- /dev/null
@@ -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.components.ui;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Locale;
+
+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.phantomjs.PhantomJSDriver;
+import org.openqa.selenium.remote.DesiredCapabilities;
+
+import com.vaadin.testbench.TestBench;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+/**
+ * Test to check auto-generated style name for UI div and overlays div.
+ * 
+ * @author Vaadin Ltd
+ */
+public class UIAutoGeneratedStyleNameTest extends MultiBrowserTest {
+
+    @Test
+    public void testUiStyleName() {
+        openTestURL();
+
+        Assert.assertTrue(
+                "UI div element doesn't contain autogenerated style name",
+                containsStyle(getDriver().findElement(By.className("v-app")),
+                        UIAutoGeneratedStyleName.class.getSimpleName()
+                                .toLowerCase(Locale.ENGLISH)));
+
+        Assert.assertTrue(
+                "Overlays div element doesn't contain autogenerated style name",
+                containsStyle(
+                        getDriver().findElement(
+                                By.className("v-overlay-container")),
+                        UIAutoGeneratedStyleName.class.getSimpleName()
+                                .toLowerCase(Locale.ENGLISH)));
+    }
+
+    private boolean containsStyle(WebElement element, String style) {
+        return element.getAttribute("class").contains(style);
+    }
+
+    @Override
+    protected void setupDriver() throws Exception {
+        System.setProperty("phantomjs.binary.path",
+                "C:\\tmp\\phantom\\phantomjs.exe");
+        WebDriver dr = TestBench.createDriver(new PhantomJSDriver());
+        setDriver(dr);
+    }
+
+    @Override
+    protected String getScreenshotDirectory() {
+        return "C:\\tmp\\a";
+    }
+
+    @Override
+    protected void openTestURL() {
+        driver.get("http://localhost:8080/vaadin/run/UIAutoGeneratedStyleName");
+    }
+
+    @Override
+    public List<DesiredCapabilities> getBrowsersToTest() {
+        return Collections.singletonList(Browser.FIREFOX
+                .getDesiredCapabilities());
+    }
+
+}