Skip to content

Commit

Permalink
jetbrains.jdk: add a NixOS test
Browse files Browse the repository at this point in the history
The test attempts to verify that JCEF works by building a simple browser
application and checking that it can display the `chrome://system` page.
  • Loading branch information
liff committed Sep 24, 2024
1 parent 32f0bfd commit fd31c05
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 0 deletions.
1 change: 1 addition & 0 deletions nixos/tests/all-tests.nix
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ in {
jellyfin = handleTest ./jellyfin.nix {};
jenkins = handleTest ./jenkins.nix {};
jenkins-cli = handleTest ./jenkins-cli.nix {};
jetbrains-jdk = runTest ./jetbrains-jdk;
jibri = handleTest ./jibri.nix {};
jirafeau = handleTest ./jirafeau.nix {};
jitsi-meet = handleTest ./jitsi-meet.nix {};
Expand Down
34 changes: 34 additions & 0 deletions nixos/tests/jetbrains-jdk/BrowserTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import com.jetbrains.cef.JCefAppConfig;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import javax.swing.JFrame;
import org.cef.CefApp;
import org.cef.CefSettings;
import org.cef.browser.CefRendering;

public class BrowserTest {
private static void fail(String message) {
throw new RuntimeException(message);
}

public static void main(String[] args) throws InterruptedException {
var started = CefApp.startup(args);
var config = JCefAppConfig.getInstance();

var settings = config.getCefSettings();
var app = CefApp.getInstance(settings);
var latch = new CountDownLatch(1);
app.onInitialization(s -> latch.countDown());
latch.await(30, TimeUnit.SECONDS);
if (latch.getCount() > 0) {
fail("CEF initialization timed out");
}

var client = app.createClient();
var browser = client.createBrowser("chrome://system", CefRendering.DEFAULT, false);
var frame = new JFrame("browser test");
frame.add(browser.getUIComponent());
frame.setSize(640, 480);
frame.setVisible(true);
}
}
25 changes: 25 additions & 0 deletions nixos/tests/jetbrains-jdk/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Tests if opening a JCEF window with chrome://about by building
# and running a simple Java application using JBR.
{ lib, ... }:
{
name = "jetbrains-jdk-jcef";

meta.maintainers = with lib.maintainers; [ liff ];

enableOCR = true;

nodes.machine =
{ lib, pkgs, ... }:
let
jbr-browser-test = pkgs.callPackage ./jbr-browser-test.nix { };
in
{
services.cage.program = lib.getExe jbr-browser-test;
imports = [ ../common/wayland-cage.nix ];
};

testScript = ''
machine.wait_for_unit('graphical.target')
machine.wait_for_text('CHROME VERSION', timeout=90)
'';
}
30 changes: 30 additions & 0 deletions nixos/tests/jetbrains-jdk/jbr-browser-test.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
stdenv,
lib,
makeWrapper,
jetbrains,
}:

stdenv.mkDerivation {
name = "jbr-browser-test";

src = ./BrowserTest.java;
dontUnpack = true;

nativeBuildInputs = [ makeWrapper ];
buildInputs = [ jetbrains.jdk ];

buildPhase = ''
cp $src BrowserTest.java
javac BrowserTest.java
'';

installPhase = ''
mkdir --parents $out/{lib,bin}
cp *.class $out/lib/
makeWrapper ${lib.getBin jetbrains.jdk}/bin/java $out/bin/jbr-browser-test \
--append-flags "-cp $out/lib BrowserTest"
'';

meta.mainProgram = "jbr-browser-test";
}
10 changes: 10 additions & 0 deletions pkgs/development/compilers/jetbrains-jdk/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{ lib
, stdenv
, fetchFromGitHub
, testers
, nixosTests
, jetbrains
, jdk
, git
Expand Down Expand Up @@ -152,5 +154,13 @@ jdk.overrideAttrs (oldAttrs: rec {

passthru = oldAttrs.passthru // {
home = "${jetbrains.jdk}/lib/openjdk";
tests = {
version = testers.testVersion {
package = jetbrains.jdk;
command = "java --version";
version = javaVersion;
};
jcef = nixosTests.jetbrains-jdk;
};
};
})

0 comments on commit fd31c05

Please sign in to comment.