changeset 10850:bc506190c9c3

8193207: [TESTBUG] Unit test case to check user agent string Reviewed-by: kcr, arajkumar
author mbilla
date Mon, 26 Feb 2018 12:49:58 +0530
parents 861a79b403da
children e321eebba79c
files modules/javafx.web/src/test/java/test/javafx/scene/web/MiscellaneousTest.java
diffstat 1 files changed, 31 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/modules/javafx.web/src/test/java/test/javafx/scene/web/MiscellaneousTest.java	Fri Feb 23 14:37:25 2018 -0800
+++ b/modules/javafx.web/src/test/java/test/javafx/scene/web/MiscellaneousTest.java	Mon Feb 26 12:49:58 2018 +0530
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,8 +25,11 @@
 
 package test.javafx.scene.web;
 
+import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.FileReader;
+import java.io.IOException;
 import static java.lang.String.format;
 import java.net.HttpURLConnection;
 import java.util.ArrayList;
@@ -423,4 +426,31 @@
             throw new AssertionError(e);
         }
     }
+
+    /**
+     * @test
+     * @bug 8193207
+     * Check UserAgentString for javafx runtime version and webkit version
+     */
+    @Test public void testUserAgentString() {
+        submit(() -> {
+            final String userAgentString = getEngine().getUserAgent();
+            final String fxVersion = System.getProperty("javafx.runtime.version");
+            final String numericStr = fxVersion.split("[^0-9]")[0];
+            final String fxVersionString = "JavaFX/" + numericStr;
+            assertTrue("UserAgentString does not contain " + fxVersionString, userAgentString.contains(fxVersionString));
+
+            File webkitLicense = new File("src/main/legal/webkit.md");
+            assertTrue("File does not exist: " + webkitLicense, webkitLicense.exists());
+
+            try (final BufferedReader licenseText = new BufferedReader(new FileReader(webkitLicense))) {
+                final String firstLine = licenseText.readLine().trim();
+                final String webkitVersion = firstLine.substring(firstLine.lastIndexOf(" ") + 2);
+                assertTrue("webkitVersion should not be empty", webkitVersion.length() > 0);
+                assertTrue("UserAgentString does not contain: " + webkitVersion, userAgentString.contains(webkitVersion));
+            } catch (IOException ex){
+                throw new AssertionError(ex);
+            }
+        });
+    }
 }