Skip to content

Commit

Permalink
JBR-4875 update test to use new JBR API window custom decorations
Browse files Browse the repository at this point in the history
  • Loading branch information
sshelomentsev authored and jbrbot committed Nov 8, 2024
1 parent 373482f commit df92d71
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 16 deletions.
46 changes: 46 additions & 0 deletions test/jdk/jb/build-jbr-api.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh
#
# Copyright 2000-2021 JetBrains s.r.o.
#
# 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.
#

# COMPILEJAVA and TESTJAVA are always in UNIX format, other paths are Win-style on Windows

PATHTOOL=echo
PATHTOOL_WIN=echo
case "`uname -a | tr '[:upper:]' '[:lower:]'`" in
cygwin* )
PATHTOOL="cygpath -au" ; PATHTOOL_WIN="cygpath -aw" ;;
*microsoft* )
PATHTOOL="wslpath -au" ; PATHTOOL_WIN="wslpath -aw" ;;
esac
PWD=`pwd`
PWD=`$PATHTOOL_WIN "$PWD"`
TESTSRC_UNIX=`$PATHTOOL "$TESTSRC"`
TESTCLASSES_UNIX=`$PATHTOOL "$TESTCLASSES"`

SRC="$TESTROOT/../../src"
# Generate sources
"$COMPILEJAVA/bin/java$EXE_SUFFIX" "$SRC/jetbrains.api/tools/Gensrc.java" "$SRC" "$PWD/jbr-api" "TEST" || exit $?
# Validate version
"$COMPILEJAVA/bin/java$EXE_SUFFIX" "$SRC/jetbrains.api/tools/CheckVersion.java" "$SRC/jetbrains.api" "$PWD/jbr-api/gensrc" "true" || exit $?
# Compile API
if [ "$PATHTOOL" != "echo" ]; then
where.exe /r "jbr-api\\gensrc" *.java > compile.list
else
find jbr-api/gensrc -name *.java > compile.list
fi
"$COMPILEJAVA/bin/javac$EXE_SUFFIX" $TESTJAVACOPTS -d "$TESTCLASSES" @compile.list || exit $?
rm "$TESTCLASSES_UNIX/module-info.class"
exit 0
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import com.jetbrains.JBR;
import com.jetbrains.WindowDecorations;

import javax.swing.*;
import javax.swing.plaf.basic.BasicComboPopup;
import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

/**
/*
* @test
* @key headful
* @summary JBR-4875 The test drag&drops a frame which contains an instance of JComboBox and checks that ComboBoxPopup
* does not become detached from its' control. The test performs checking for both cases when
* <code>apple.awt.transparentTitleBar</code> is not set and it is set to <code>true</code>.
* It is expected that <code>x</code>-coordinates for <code>JFrame</code>, <code>JComboBox</code> and ComboBoxPopup
* have the same values after dragging&dropping <code>JFrame</code>.
* @run shell ${test.root}/jb/build-jbr-api.sh
* @run main/timeout=600 ComboBoxTransparentTittleBarTest
*/
public final class ComboBoxTransparentTittleBarTest {
Expand All @@ -24,6 +31,8 @@ public final class ComboBoxTransparentTittleBarTest {
private static final StringBuilder errMessages= new StringBuilder();
private static int errCount = 0;

private static final float TITLE_BAR_HEIGHT = 54f;

public static void main(final String[] args) throws Exception {
robot = new Robot();
robot.setAutoDelay(100);
Expand All @@ -42,17 +51,17 @@ public static void main(final String[] args) throws Exception {
throw new RuntimeException(String.valueOf(errMessages));
}

private static void test() throws Exception {
Point framePoint = getLocationOnScreen(frame);
Point comboBoxPoint = getLocationOnScreen(comboBox);
private static void test() {
getLocationOnScreen(frame);
getLocationOnScreen(comboBox);

BasicComboPopup popup = (BasicComboPopup) comboBox.getUI().getAccessibleChild(comboBox, 0);
popup.show();
Point popupPoint = getLocationOnScreen(popup);
getLocationOnScreen(popup);
popup.hide();

int x_init = framePoint.x + frame.getWidth() / 2;
int y_init = framePoint.y + 5;
int x_init = frame.getLocationOnScreen().x + frame.getWidth() / 2;;
int y_init = frame.getLocationOnScreen().y + 5;
System.out.print("Drag " + frame.getName() + " from: (" + x_init + ", " + y_init + ")");
robot.mouseMove(x_init, y_init);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
Expand All @@ -68,17 +77,17 @@ private static void test() throws Exception {
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.waitForIdle();

framePoint = getLocationOnScreen(frame);
comboBoxPoint = getLocationOnScreen(comboBox);
Point frameLocation = getLocationOnScreen(frame);
Point comboBoxLocation = getLocationOnScreen(comboBox);

int errCount_before = errCount;
if (popup.isVisible()) {
System.out.println("ComboPopup is visible");
popupPoint = getLocationOnScreen(popup);
if (framePoint.x - comboBoxPoint.x !=0)
appendErrMsg("***ComboBox location was not changed. Expected point: (" + framePoint.x + ", " + comboBoxPoint.y + ")");
if (framePoint.x - popupPoint.x !=0)
appendErrMsg("***ComboPopup location was not changed. Expected point: (" + framePoint.x + ", " + popupPoint.y + ")");
Point popupLocation = popup.getLocationOnScreen();
if (frameLocation.x - comboBoxLocation.x != 0)
appendErrMsg("***ComboBox location was not changed. Expected point: (" + frameLocation.x + ", " + comboBoxLocation.y + ")");
if (frameLocation.x - popupLocation.x != 0)
appendErrMsg("***ComboPopup location was not changed. Expected point: (" + frameLocation.x + ", " + popupLocation.y + ")");
}
if (errCount_before < errCount)
System.out.println("***FAILED***");
Expand Down Expand Up @@ -120,8 +129,20 @@ private static void setup(boolean doTitleBarTransparent) {
System.out.println("------------------------------------");
System.out.println("The case transparentTitleBar = " + doTitleBarTransparent);
if (doTitleBarTransparent) {
frame.getRootPane().putClientProperty("apple.awt.transparentTitleBar", true);
frame.getRootPane().putClientProperty("apple.awt.windowTransparentTitleBarHeight", 54f);
WindowDecorations.CustomTitleBar titleBar = JBR.getWindowDecorations().createCustomTitleBar();
titleBar.setHeight(TITLE_BAR_HEIGHT);
JBR.getWindowDecorations().setCustomTitleBar(frame, titleBar);

MouseListener mouseListener = new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
titleBar.forceHitTest(false);
}
};
for (int i = 0; i < comboBox.getComponents().length; i++) {
comboBox.getComponent(i).addMouseListener(mouseListener);
}

}
}
}

0 comments on commit df92d71

Please sign in to comment.