Skip to content

Commit

Permalink
IDEA-283718 com.intellij.ui.jcef.JCEFHtmlPanel ctor causes disposal e…
Browse files Browse the repository at this point in the history
…rror

GitOrigin-RevId: 3fc4401d6fc5876f00654145db89f739d50fd1c9
  • Loading branch information
forantar authored and intellij-monorepo-bot committed Dec 1, 2021
1 parent 521658a commit 66b51c1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ public JCEFHtmlPanel(JBCefClient client, String url) {
public JCEFHtmlPanel(boolean isOffScreenRendering, @Nullable JBCefClient client, @Nullable String url) {
super(JBCefBrowser.createBuilder().setOffScreenRendering(isOffScreenRendering).setClient(client).setUrl(url));
myUrl = getCefBrowser().getURL();
if (client != null && client != ourCefClient) {
Disposer.register(this, client);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2000-2021 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.jcef;

import com.intellij.openapi.util.Disposer;
import com.intellij.testFramework.ApplicationRule;
import com.intellij.testFramework.NonHeadlessRule;
import com.intellij.ui.scale.TestScaleHelper;
import junit.framework.TestCase;
import org.jetbrains.annotations.Nullable;
import org.junit.*;
import org.junit.rules.TestRule;

/**
* Tests https://youtrack.jetbrains.com/issue/IDEA-283718
* 1) JCEFHtmlPanel should not additionally chain the new browser instance for disposal.
* 2) JCEFHtmlPanel should be auto-disposed after its client.
*
* @author tav
*/
public class IDEA283718Test {
@Rule public TestRule nonHeadless = new NonHeadlessRule();
@ClassRule public static final ApplicationRule appRule = new ApplicationRule();

@Before
public void before() {
TestScaleHelper.assumeStandalone();
}

@Test
public void test() {
//
// Try external JBCefClient.
//
doTest(JBCefApp.getInstance().createClient());

//
// Try default JBCefClient.
//
doTest(null);
}

private static void doTest(@Nullable JBCefClient client) {
JBCefBrowserBase browser = null;
try {
browser = new JCEFHtmlPanel(client, "about:blank");
} catch (RuntimeException ex) {
TestCase.fail("Exception occurred: " + ex.getMessage());
ex.printStackTrace();
}
if (client == null) client = browser.getJBCefClient();
TestCase.assertFalse(browser.isDisposed());
Disposer.dispose(client);
TestCase.assertTrue(browser.isDisposed());
}
}

0 comments on commit 66b51c1

Please sign in to comment.