From bea9e75fb9739657d77095c00929340985bfb089 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Thu, 5 Apr 2018 15:07:07 +0200 Subject: [PATCH] =?UTF-8?q?UI=20DSL=20and=20LaF=20tests=20=E2=80=94=20run?= =?UTF-8?q?=20on=20TC,=20part=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- .../intellij.platform.tests.iml | 1 + .../testData/ui/laf/Darcula/components.yml | 71 ++------- .../ui/laf/Darcula/mac/components.svg | 6 +- .../ui/laf/IntelliJ/mac/components.svg | 76 +++++----- .../ui/laf/IntelliJ/mac/components.yml | 71 ++------- .../mac/align fields in the nested grid.svg | 6 +- .../ui/layout/Darcula/mac/align fields.svg | 4 +- .../testData/ui/layout/Darcula/mac/cell.svg | 6 +- .../Darcula/mac/note row in the dialog.svg | 4 +- .../ui/layout/Darcula/mac/visual paddings.svg | 34 ++--- .../mac/align fields in the nested grid.svg | 6 +- .../ui/layout/IntelliJ/mac/align fields.svg | 4 +- .../testData/ui/layout/IntelliJ/mac/cell.svg | 6 +- .../IntelliJ/mac/note row in the dialog.svg | 4 +- .../layout/IntelliJ/mac/visual paddings.svg | 135 +++++++++--------- .../layout/IntelliJ/mac/visual paddings.yml | 42 +++--- .../testSrc/com/intellij/ui/SvgRenderer.kt | 62 ++++++++ .../testSrc/com/intellij/ui/laf/LafTest.kt | 2 +- .../com/intellij/ui/layout/UiDslTest.kt | 2 +- .../testSrc/com/intellij/ui/uiTestUtil.kt | 113 ++++----------- 21 files changed, 275 insertions(+), 383 deletions(-) create mode 100644 platform/platform-tests/testSrc/com/intellij/ui/SvgRenderer.kt diff --git a/.gitignore b/.gitignore index 1b9df87d1898..6a20fa05a217 100644 --- a/.gitignore +++ b/.gitignore @@ -12,5 +12,4 @@ build/dependencies/build .idea/libraries/Gradle__*.xml .idea/gradle_extensions.xml edu/dependencies/build -edu/dependencies/.gradle -platform/platform-tests/testData/ui/image-snapshots/ \ No newline at end of file +edu/dependencies/.gradle \ No newline at end of file diff --git a/platform/platform-tests/intellij.platform.tests.iml b/platform/platform-tests/intellij.platform.tests.iml index 88a8e46943a9..6b9f619850c6 100644 --- a/platform/platform-tests/intellij.platform.tests.iml +++ b/platform/platform-tests/intellij.platform.tests.iml @@ -39,5 +39,6 @@ + \ No newline at end of file diff --git a/platform/platform-tests/testData/ui/laf/Darcula/components.yml b/platform/platform-tests/testData/ui/laf/Darcula/components.yml index 6e2b7e6e87ff..e3040c935ec3 100644 --- a/platform/platform-tests/testData/ui/laf/Darcula/components.yml +++ b/platform/platform-tests/testData/ui/laf/Darcula/components.yml @@ -1,64 +1,9 @@ bounds: -- - height: 32 - location: {x: 8, y: 10} - size: {height: 32, width: 464} - width: 464 - x: 8 - y: 10 -- - height: 30 - location: {x: 8, y: 52} - size: {height: 30, width: 464} - width: 464 - x: 8 - y: 52 -- - height: 30 - location: {x: 8, y: 92} - size: {height: 30, width: 464} - width: 464 - x: 8 - y: 92 -- - height: 30 - location: {x: 8, y: 132} - size: {height: 30, width: 464} - width: 464 - x: 8 - y: 132 -- - height: 30 - location: {x: 8, y: 172} - size: {height: 30, width: 464} - width: 464 - x: 8 - y: 172 -- - height: 22 - location: {x: 8, y: 212} - size: {height: 22, width: 464} - width: 464 - x: 8 - y: 212 -- - height: 23 - location: {x: 8, y: 244} - size: {height: 23, width: 464} - width: 464 - x: 8 - y: 244 -- - height: 30 - location: {x: 8, y: 277} - size: {height: 30, width: 464} - width: 464 - x: 8 - y: 277 -- - height: 30 - location: {x: 8, y: 317} - size: {height: 30, width: 464} - width: 464 - x: 8 - y: 317 + 'JTextField #0': [8, 10, 464, 32] + 'JPasswordField #1': [8, 52, 464, 30] + 'JComboBox #2': [8, 92, 464, 30] + 'JComboBox #3': [8, 132, 464, 30] + label: [8, 244, 464, 23] + enabled: [8, 212, 464, 22] + 'JBIntSpinner #7': [8, 277, 464, 30] + 'TextFieldWithHistoryWithBrowseButton #8': [8, 317, 464, 30] diff --git a/platform/platform-tests/testData/ui/laf/Darcula/mac/components.svg b/platform/platform-tests/testData/ui/laf/Darcula/mac/components.svg index 3faf46ed92b3..590240604217 100644 --- a/platform/platform-tests/testData/ui/laf/Darcula/mac/components.svg +++ b/platform/platform-tests/testData/ui/laf/Darcula/mac/components.svg @@ -1,4 +1,4 @@ - + @@ -56,13 +56,13 @@ - + label - + enabled diff --git a/platform/platform-tests/testData/ui/laf/IntelliJ/mac/components.svg b/platform/platform-tests/testData/ui/laf/IntelliJ/mac/components.svg index ebebee7abb09..6eb73615ca78 100644 --- a/platform/platform-tests/testData/ui/laf/IntelliJ/mac/components.svg +++ b/platform/platform-tests/testData/ui/laf/IntelliJ/mac/components.svg @@ -1,4 +1,4 @@ - + @@ -8,19 +8,19 @@ - + - - - + + + - + - + @@ -39,49 +39,49 @@ - + - - + + - - - - - + + + + + - - + + - - - - - label + + + + + label - - - enabled + + + enabled - - + + - - - - label + + + + label - - - + + + - + one - - + + @@ -97,7 +97,7 @@ - + diff --git a/platform/platform-tests/testData/ui/laf/IntelliJ/mac/components.yml b/platform/platform-tests/testData/ui/laf/IntelliJ/mac/components.yml index 01c6346b3709..8cb9455e714c 100644 --- a/platform/platform-tests/testData/ui/laf/IntelliJ/mac/components.yml +++ b/platform/platform-tests/testData/ui/laf/IntelliJ/mac/components.yml @@ -1,64 +1,9 @@ bounds: -- - height: 26 - location: {x: 8, y: 10} - size: {height: 26, width: 464} - width: 464 - x: 8 - y: 10 -- - height: 30 - location: {x: 8, y: 46} - size: {height: 30, width: 464} - width: 464 - x: 8 - y: 46 -- - height: 26 - location: {x: 8, y: 86} - size: {height: 26, width: 464} - width: 464 - x: 8 - y: 86 -- - height: 26 - location: {x: 8, y: 122} - size: {height: 26, width: 464} - width: 464 - x: 8 - y: 122 -- - height: 27 - location: {x: 8, y: 158} - size: {height: 27, width: 464} - width: 464 - x: 8 - y: 158 -- - height: 26 - location: {x: 8, y: 195} - size: {height: 26, width: 464} - width: 464 - x: 8 - y: 195 -- - height: 26 - location: {x: 8, y: 231} - size: {height: 26, width: 464} - width: 464 - x: 8 - y: 231 -- - height: 27 - location: {x: 8, y: 267} - size: {height: 27, width: 464} - width: 464 - x: 8 - y: 267 -- - height: 26 - location: {x: 8, y: 304} - size: {height: 26, width: 464} - width: 464 - x: 8 - y: 304 + 'JTextField #0': [8, 10, 464, 26] + 'JPasswordField #1': [8, 46, 464, 30] + 'JComboBox #2': [8, 86, 464, 27] + 'JComboBox #3': [8, 123, 464, 27] + label: [8, 233, 464, 26] + enabled: [8, 197, 464, 26] + 'JBIntSpinner #7': [8, 269, 464, 27] + 'TextFieldWithHistoryWithBrowseButton #8': [8, 306, 464, 27] diff --git a/platform/platform-tests/testData/ui/layout/Darcula/mac/align fields in the nested grid.svg b/platform/platform-tests/testData/ui/layout/Darcula/mac/align fields in the nested grid.svg index 393ad5ca62d2..25202dfb1d1f 100644 --- a/platform/platform-tests/testData/ui/layout/Darcula/mac/align fields in the nested grid.svg +++ b/platform/platform-tests/testData/ui/layout/Darcula/mac/align fields in the nested grid.svg @@ -1,4 +1,4 @@ - + @@ -56,7 +56,7 @@ Master Password: - + @@ -73,7 +73,7 @@ - + In KeePass diff --git a/platform/platform-tests/testData/ui/layout/Darcula/mac/align fields.svg b/platform/platform-tests/testData/ui/layout/Darcula/mac/align fields.svg index 0f097806438d..c26b39e1d1ac 100644 --- a/platform/platform-tests/testData/ui/layout/Darcula/mac/align fields.svg +++ b/platform/platform-tests/testData/ui/layout/Darcula/mac/align fields.svg @@ -1,4 +1,4 @@ - + @@ -46,7 +46,7 @@ - + Android module name: diff --git a/platform/platform-tests/testData/ui/layout/Darcula/mac/cell.svg b/platform/platform-tests/testData/ui/layout/Darcula/mac/cell.svg index 1995dde655b4..d28ca1105c3d 100644 --- a/platform/platform-tests/testData/ui/layout/Darcula/mac/cell.svg +++ b/platform/platform-tests/testData/ui/layout/Darcula/mac/cell.svg @@ -1,4 +1,8 @@ - + + diff --git a/platform/platform-tests/testData/ui/layout/Darcula/mac/note row in the dialog.svg b/platform/platform-tests/testData/ui/layout/Darcula/mac/note row in the dialog.svg index 36625d223a47..bfa57a44fd2f 100644 --- a/platform/platform-tests/testData/ui/layout/Darcula/mac/note row in the dialog.svg +++ b/platform/platform-tests/testData/ui/layout/Darcula/mac/note row in the dialog.svg @@ -1,4 +1,4 @@ - + @@ -37,7 +37,7 @@ - + &Remember diff --git a/platform/platform-tests/testData/ui/layout/Darcula/mac/visual paddings.svg b/platform/platform-tests/testData/ui/layout/Darcula/mac/visual paddings.svg index 6e9a2fbb5c64..ced9478c1ea5 100644 --- a/platform/platform-tests/testData/ui/layout/Darcula/mac/visual paddings.svg +++ b/platform/platform-tests/testData/ui/layout/Darcula/mac/visual paddings.svg @@ -1,4 +1,4 @@ - + @@ -138,13 +138,13 @@ - + rb - + c @@ -181,12 +181,12 @@ - ● - ● - ● - ● - ● - ● + • + • + • + • + • + • @@ -227,7 +227,7 @@ - + label @@ -236,7 +236,7 @@ - + enabled @@ -295,12 +295,12 @@ - ● - ● - ● - ● - ● - ● + • + • + • + • + • + • diff --git a/platform/platform-tests/testData/ui/layout/IntelliJ/mac/align fields in the nested grid.svg b/platform/platform-tests/testData/ui/layout/IntelliJ/mac/align fields in the nested grid.svg index a55180a03bac..30ff194a16c6 100644 --- a/platform/platform-tests/testData/ui/layout/IntelliJ/mac/align fields in the nested grid.svg +++ b/platform/platform-tests/testData/ui/layout/IntelliJ/mac/align fields in the nested grid.svg @@ -1,4 +1,4 @@ - + @@ -51,7 +51,7 @@ Master Password: - + @@ -68,7 +68,7 @@ - + In KeePass diff --git a/platform/platform-tests/testData/ui/layout/IntelliJ/mac/align fields.svg b/platform/platform-tests/testData/ui/layout/IntelliJ/mac/align fields.svg index e82840bbce2e..9aa8b8915434 100644 --- a/platform/platform-tests/testData/ui/layout/IntelliJ/mac/align fields.svg +++ b/platform/platform-tests/testData/ui/layout/IntelliJ/mac/align fields.svg @@ -1,4 +1,4 @@ - + @@ -44,7 +44,7 @@ Android module name: - + Android module name: diff --git a/platform/platform-tests/testData/ui/layout/IntelliJ/mac/cell.svg b/platform/platform-tests/testData/ui/layout/IntelliJ/mac/cell.svg index 3c3916568db4..6c7c02537fd4 100644 --- a/platform/platform-tests/testData/ui/layout/IntelliJ/mac/cell.svg +++ b/platform/platform-tests/testData/ui/layout/IntelliJ/mac/cell.svg @@ -1,4 +1,8 @@ - + + diff --git a/platform/platform-tests/testData/ui/layout/IntelliJ/mac/note row in the dialog.svg b/platform/platform-tests/testData/ui/layout/IntelliJ/mac/note row in the dialog.svg index d004faf5a4ee..d2dd8ca5625b 100644 --- a/platform/platform-tests/testData/ui/layout/IntelliJ/mac/note row in the dialog.svg +++ b/platform/platform-tests/testData/ui/layout/IntelliJ/mac/note row in the dialog.svg @@ -1,4 +1,4 @@ - + @@ -32,7 +32,7 @@ . - + &Remember diff --git a/platform/platform-tests/testData/ui/layout/IntelliJ/mac/visual paddings.svg b/platform/platform-tests/testData/ui/layout/IntelliJ/mac/visual paddings.svg index 5c64abc21789..ff9d52f3e66e 100644 --- a/platform/platform-tests/testData/ui/layout/IntelliJ/mac/visual paddings.svg +++ b/platform/platform-tests/testData/ui/layout/IntelliJ/mac/visual paddings.svg @@ -1,4 +1,4 @@ - + @@ -12,7 +12,7 @@ - + @@ -54,7 +54,7 @@ - + @@ -63,7 +63,7 @@ - + @@ -81,107 +81,104 @@ - - - - + - + - + - + - + - + - + - + - + - + - + - + Scroll pane: - + - + rb - - + + c - + - + b - + c1 - + - + - ● - ● - ● - ● - ● - ● + • + • + • + • + • + • - + - + - + - + t - + - + All: - + Text with browse: @@ -190,7 +187,7 @@ - + @@ -201,78 +198,78 @@ - + label RadioButton: - + enabled CheckBox: - + - - - label + + + label - Button: + Button: - - + + - Combobox Editable: + Combobox Editable: - - one + + one - - + + - Combobox: + Combobox: - ● - ● - ● - ● - ● - ● + • + • + • + • + • + • - Password: + Password: - + - + - text + text - + - Text field: + Text field: diff --git a/platform/platform-tests/testData/ui/layout/IntelliJ/mac/visual paddings.yml b/platform/platform-tests/testData/ui/layout/IntelliJ/mac/visual paddings.yml index 43bd8d23fd03..dd245eeacc7f 100644 --- a/platform/platform-tests/testData/ui/layout/IntelliJ/mac/visual paddings.yml +++ b/platform/platform-tests/testData/ui/layout/IntelliJ/mac/visual paddings.yml @@ -176,17 +176,17 @@ cellBounds: - [130, 186, 519, 21] - [0, 217, 124, 21] - [130, 217, 519, 21] -- [0, 248, 124, 20] -- [130, 248, 519, 20] -- [0, 278, 124, 21] -- [130, 278, 511, 21] -- [130, 278, 511, 21] -- [130, 278, 511, 21] -- [130, 278, 511, 21] -- [130, 278, 511, 21] -- [130, 278, 511, 21] -- [0, 309, 124, 21] -- [130, 309, 519, 21] +- [0, 248, 124, 21] +- [130, 248, 519, 21] +- [0, 279, 124, 21] +- [130, 279, 511, 21] +- [130, 279, 511, 21] +- [130, 279, 511, 21] +- [130, 279, 511, 21] +- [130, 279, 511, 21] +- [130, 279, 511, 21] +- [0, 310, 124, 21] +- [130, 310, 519, 21] componentBounds: 'Text field:': [0, 2, 61, 16] 'JTextField #1': [127, -3, 525, 27] @@ -204,13 +204,13 @@ componentBounds: 'Spinner:': [0, 219, 51, 16] 'JBIntSpinner #15': [127, 214, 76, 27] 'Text with browse:': [0, 250, 110, 16] - 'TextFieldWithHistoryWithBrowseButton #17': [127, 245, 525, 26] - 'All:': [0, 280, 19, 16] - 'JTextField #19': [127, 275, 37, 27] - 'JPasswordField #20': [166, 275, 256, 27] - 'JComboBox #21': [424, 275, 60, 27] - b: [485, 275, 78, 27] - c: [564, 275, 33, 26] - rb: [602, 275, 39, 26] - 'Scroll pane:': [0, 310, 72, 16] - 'JBScrollPane #26': [130, 309, 519, 21] + 'TextFieldWithHistoryWithBrowseButton #17': [127, 245, 525, 27] + 'All:': [0, 281, 19, 16] + 'JTextField #19': [127, 276, 37, 27] + 'JPasswordField #20': [166, 276, 256, 27] + 'JComboBox #21': [424, 276, 60, 27] + b: [485, 276, 78, 27] + c: [564, 276, 33, 26] + rb: [602, 276, 39, 26] + 'Scroll pane:': [0, 311, 72, 16] + 'JBScrollPane #26': [130, 310, 519, 21] diff --git a/platform/platform-tests/testSrc/com/intellij/ui/SvgRenderer.kt b/platform/platform-tests/testSrc/com/intellij/ui/SvgRenderer.kt new file mode 100644 index 000000000000..3c3b3708ce2e --- /dev/null +++ b/platform/platform-tests/testSrc/com/intellij/ui/SvgRenderer.kt @@ -0,0 +1,62 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.ui + +import org.apache.batik.dom.GenericDOMImplementation +import org.apache.batik.svggen.SVGGeneratorContext +import org.apache.batik.svggen.SVGGraphics2D +import org.apache.batik.svggen.SVGSyntax +import org.apache.xmlgraphics.java2d.GraphicsConfigurationWithTransparency +import java.awt.Component +import java.io.StringWriter +import javax.xml.transform.OutputKeys +import javax.xml.transform.TransformerFactory +import javax.xml.transform.dom.DOMSource +import javax.xml.transform.stream.StreamResult + +// jFreeSvg produces not so compact and readable SVG as batik +internal class SvgRenderer { + private val xmlTransformer = TransformerFactory.newInstance().newTransformer() + + // todo check on Retina - does it works or not (is Retina disabled or not) + private val deviceConfiguration = GraphicsConfigurationWithTransparency() + + private val xmlFactory = GenericDOMImplementation.getDOMImplementation().createDocument("http://www.w3.org/2000/svg", "svg", null) + private val context = SVGGeneratorContext.createDefault(xmlFactory) + + init { + xmlTransformer.setOutputProperty(OutputKeys.METHOD, "xml") + xmlTransformer.setOutputProperty(OutputKeys.INDENT, "yes") + xmlTransformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2") + xmlTransformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8") + } + + // CSS (style) not used - attributes more readable and shorter + // separate styles (in the defs) also not suitable, so, we keep it simple as is + private fun svgGraphicsToString(svgGenerator: SVGGraphics2D, component: Component): String { + val writer = StringWriter() + writer.use { + val root = svgGenerator.root + + root.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", SVGSyntax.SVG_NAMESPACE_URI) + root.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xlink", "http://www.w3.org/1999/xlink") + + val bounds = component.bounds + root.setAttributeNS(null, "viewBox", "${bounds.x} ${bounds.y} ${bounds.width} ${bounds.height}") + + xmlTransformer.transform(DOMSource(root), StreamResult(writer)) + } + return writer + .toString() + // Remember + // no idea why transformer/batik doesn't escape it correctly + .replace(">", ">&") + } + + fun render(component: Component): String { + val svgGenerator = object : SVGGraphics2D(context, false) { + override fun getDeviceConfiguration() = this@SvgRenderer.deviceConfiguration + } + component.paint(svgGenerator) + return svgGraphicsToString(svgGenerator, component) + } +} \ No newline at end of file diff --git a/platform/platform-tests/testSrc/com/intellij/ui/laf/LafTest.kt b/platform/platform-tests/testSrc/com/intellij/ui/laf/LafTest.kt index d2607752298d..ff27d671e303 100644 --- a/platform/platform-tests/testSrc/com/intellij/ui/laf/LafTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/ui/laf/LafTest.kt @@ -32,7 +32,7 @@ class LafTest { companion object { @JvmStatic @Parameterized.Parameters(name = "{0}") - fun lafNames() = listOf("IntelliJ", "Darcula") + fun lafNames() = listOf("Darcula", "IntelliJ") } @Suppress("MemberVisibilityCanBePrivate") diff --git a/platform/platform-tests/testSrc/com/intellij/ui/layout/UiDslTest.kt b/platform/platform-tests/testSrc/com/intellij/ui/layout/UiDslTest.kt index 3fbb03ecc0d6..458fd1144a28 100644 --- a/platform/platform-tests/testSrc/com/intellij/ui/layout/UiDslTest.kt +++ b/platform/platform-tests/testSrc/com/intellij/ui/layout/UiDslTest.kt @@ -28,7 +28,7 @@ class UiDslTest { companion object { @JvmStatic @Parameterized.Parameters(name = "{0}") - fun lafNames() = listOf("IntelliJ", "Darcula") + fun lafNames() = listOf("Darcula", "IntelliJ") } @Suppress("MemberVisibilityCanBePrivate") diff --git a/platform/platform-tests/testSrc/com/intellij/ui/uiTestUtil.kt b/platform/platform-tests/testSrc/com/intellij/ui/uiTestUtil.kt index d510f9018612..f7b30f3c94e9 100644 --- a/platform/platform-tests/testSrc/com/intellij/ui/uiTestUtil.kt +++ b/platform/platform-tests/testSrc/com/intellij/ui/uiTestUtil.kt @@ -5,38 +5,47 @@ import com.intellij.ide.ui.laf.IntelliJLaf import com.intellij.ide.ui.laf.darcula.DarculaLaf import com.intellij.openapi.application.invokeAndWaitIfNeed import com.intellij.openapi.util.SystemInfo -import com.intellij.openapi.util.SystemInfoRt import com.intellij.openapi.util.text.StringUtil import com.intellij.testFramework.assertions.Assertions.assertThat import com.intellij.ui.layout.* import com.intellij.util.io.exists import com.intellij.util.io.sanitizeFileName import com.intellij.util.io.write -import com.intellij.util.ui.JBDimension import com.intellij.util.ui.JBUI import com.intellij.util.ui.UIUtil import io.netty.util.internal.SystemPropertyUtil import net.miginfocom.swing.MigLayout -import org.apache.batik.dom.GenericDOMImplementation -import org.apache.batik.svggen.SVGGraphics2D -import org.junit.rules.ExternalResource import org.junit.rules.TestName import org.yaml.snakeyaml.DumperOptions import org.yaml.snakeyaml.Yaml -import java.awt.* +import java.awt.Component +import java.awt.Container import java.io.File -import java.io.StringWriter import java.nio.file.Path -import javax.swing.* +import javax.swing.AbstractButton +import javax.swing.JLabel +import javax.swing.JPanel +import javax.swing.UIManager import javax.swing.plaf.metal.MetalLookAndFeel -import javax.xml.transform.OutputKeys -import javax.xml.transform.TransformerFactory -import javax.xml.transform.dom.DOMSource -import javax.xml.transform.stream.StreamResult -import kotlin.properties.Delegates private val isUpdateSnapshotsGlobal by lazy { SystemPropertyUtil.getBoolean("test.update.snapshots", false) } +//class RestoreLafRule : ExternalResource() { +// var oldLafName: String? = null +// +// override fun before() { +// oldLafName = UIManager.getLookAndFeel().name +// } +// +// override fun after() { +// val oldLafName = oldLafName +// if (oldLafName != null && oldLafName != UIManager.getLookAndFeel().name) { +// assertThat(oldLafName).isEqualTo("IntelliJ") +// UIManager.setLookAndFeel(IntelliJLaf()) +// } +// } +//} + fun changeLafIfNeed(lafName: String) { if (UIManager.getLookAndFeel().name == lafName) { return @@ -55,57 +64,6 @@ fun changeLafIfNeed(lafName: String) { } } -class FrameRule : ExternalResource() { - var frame: JFrame by Delegates.notNull() - private set - - private var wasFrameCreated = false - - override fun after() { - if (wasFrameCreated) { - invokeAndWaitIfNeed { - frame.isVisible = false - frame.dispose() - } - } - } - - // must be called in EDT - fun show(component: Component, minSize: Dimension? = JBDimension(480, 320)) { - frame = createTestFrame(minSize) - wasFrameCreated = true - - frame.contentPane.add(component, BorderLayout.CENTER) - - frame.pack() - frame.isVisible = true - - // clear focus from first input field - frame.requestFocusInWindow() - } -} - -private fun createTestFrame(minSize: Dimension?): JFrame { - val frame = JFrame() - frame.isUndecorated = true - if (minSize != null) { - frame.minimumSize = minSize - } - - val screenDevices = GraphicsEnvironment.getLocalGraphicsEnvironment().screenDevices - if (SystemInfoRt.isMac && screenDevices != null && screenDevices.size > 1) { - // use non-Retina - for (screenDevice in screenDevices) { - if (!UIUtil.isRetina(screenDevice)) { - frame.setLocation(screenDevice.defaultConfiguration.bounds.x, frame.y) - break - } - } - } - - return frame -} - fun getSnapshotRelativePath(lafName: String, isForImage: Boolean): String { val platformName = when { SystemInfo.isWindows -> "win" @@ -134,8 +92,7 @@ fun validateBounds(component: Container, snapshotDir: Path, snapshotName: String dumperOptions.lineBreak = DumperOptions.LineBreak.UNIX val yaml = Yaml(dumperOptions) actualSerializedLayout = yaml - .dump(linkedMapOf("bounds" to component.components.map { it.bounds })) - .replace(" !!java.awt.Rectangle", "") + .dump(linkedMapOf("bounds" to dumpComponentBounds(component))) } compareSnapshot(snapshotDir.resolve("$snapshotName.yml"), actualSerializedLayout, isUpdateSnapshots) @@ -162,30 +119,8 @@ private fun compareSnapshot(snapshotFile: Path, newData: String, isUpdateSnapsho } } -private fun svgGraphicsToString(svgGenerator: SVGGraphics2D): String { - val transformer = TransformerFactory.newInstance().newTransformer() - transformer.setOutputProperty(OutputKeys.METHOD, "xml") - transformer.setOutputProperty(OutputKeys.INDENT, "yes") - transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes") - transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2") - transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8") - - val writer = StringWriter() - writer.use { - transformer.transform(DOMSource(svgGenerator.root), StreamResult(writer)) - } - return writer - .toString() - // Remember - // no idea why transformer/batik doesn't escape it correctly - .replace(">", ">&") -} - fun validateUsingImage(component: Component, snapshotDir: Path, snapshotName: String, isUpdateSnapshots: Boolean = isUpdateSnapshotsGlobal) { - // jFreeSvg produces not so compact and readable SVG as batik - val svgGenerator = SVGGraphics2D(GenericDOMImplementation.getDOMImplementation().createDocument("http://www.w3.org/2000/svg", "svg", null)) - component.paint(svgGenerator) - compareSnapshot(snapshotDir.resolve("$snapshotName.svg"), svgGraphicsToString(svgGenerator), isUpdateSnapshots) + compareSnapshot(snapshotDir.resolve("$snapshotName.svg"), SvgRenderer().render(component), isUpdateSnapshots) } val TestName.snapshotFileName: String