diff --git a/plugins/org.eclipse.reddeer.requirements/META-INF/MANIFEST.MF b/plugins/org.eclipse.reddeer.requirements/META-INF/MANIFEST.MF index e838fa4c3a..551ef86f31 100644 --- a/plugins/org.eclipse.reddeer.requirements/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.reddeer.requirements/META-INF/MANIFEST.MF @@ -21,6 +21,7 @@ Bundle-RequiredExecutionEnvironment: JavaSE-11 Bundle-ActivationPolicy: lazy Bundle-Vendor: Eclipse.org - RedDeer Export-Package: org.eclipse.reddeer.requirements.autobuilding, + org.eclipse.reddeer.requirements.browser, org.eclipse.reddeer.requirements.cleanerrorlog, org.eclipse.reddeer.requirements.cleanworkspace, org.eclipse.reddeer.requirements.closeeditors, diff --git a/plugins/org.eclipse.reddeer.requirements/plugin.xml b/plugins/org.eclipse.reddeer.requirements/plugin.xml index 7bd457082d..038f0c1ef9 100644 --- a/plugins/org.eclipse.reddeer.requirements/plugin.xml +++ b/plugins/org.eclipse.reddeer.requirements/plugin.xml @@ -15,6 +15,7 @@ + diff --git a/plugins/org.eclipse.reddeer.requirements/src/org/eclipse/reddeer/requirements/browser/InternalBrowserRequirement.java b/plugins/org.eclipse.reddeer.requirements/src/org/eclipse/reddeer/requirements/browser/InternalBrowserRequirement.java new file mode 100644 index 0000000000..acb173938a --- /dev/null +++ b/plugins/org.eclipse.reddeer.requirements/src/org/eclipse/reddeer/requirements/browser/InternalBrowserRequirement.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2022 Red Hat, Inc. + * Distributed under license by Red Hat, Inc. All rights reserved. + * This program is made available under the terms of the + * Eclipse Public License v2.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: Red Hat, Inc. + ******************************************************************************/ + +package org.eclipse.reddeer.requirements.browser; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.eclipse.reddeer.direct.preferences.Preferences; +import org.eclipse.reddeer.junit.requirement.AbstractRequirement; +import org.eclipse.reddeer.requirements.browser.InternalBrowserRequirement.UseInternalBrowser; + +/** + * RedDeer Requirement that allows to setup an Internal Browser option as default + * in Preferences: General -> Web Browser. + * + * @author Ondrej Dockal + * + */ +public class InternalBrowserRequirement extends AbstractRequirement{ + + private static String BROWSER_PLUGIN = "org.eclipse.ui.browser"; + private static String BROWSER_KEY = "browser-choice"; + + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.TYPE) + public @interface UseInternalBrowser { + + /** + * String param dedicated to Internal Browser, change to "1" of necessary + * @return 0 option to denote Internal browser, 1 for external + */ + String browserChoice() default "0"; + + boolean cleanup() default false; + } + + @Override + public void fulfill() { + Preferences.set(BROWSER_PLUGIN, BROWSER_KEY, annotation.browserChoice()); + } + + @Override + public void cleanUp() { + if (annotation.cleanup()) { + String choice = annotation.browserChoice().equals("0") ? "0" : "1"; + Preferences.set(BROWSER_PLUGIN, BROWSER_KEY, choice); + } + } + +} diff --git a/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/ui/browser/BrowserEditorTest.java b/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/ui/browser/BrowserEditorTest.java index 9978779e06..1fedf8094f 100644 --- a/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/ui/browser/BrowserEditorTest.java +++ b/tests/org.eclipse.reddeer.eclipse.test/src/org/eclipse/reddeer/eclipse/test/ui/browser/BrowserEditorTest.java @@ -15,22 +15,31 @@ import java.net.MalformedURLException; import java.net.URL; +import java.util.Arrays; +import java.util.List; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.browser.IWorkbenchBrowserSupport; import org.eclipse.reddeer.common.util.Display; +import org.eclipse.reddeer.direct.preferences.Preferences; import org.eclipse.reddeer.eclipse.exception.EclipseLayerException; import org.eclipse.reddeer.eclipse.ui.browser.BrowserEditor; import org.eclipse.reddeer.junit.runner.RedDeerSuite; import org.eclipse.reddeer.workbench.impl.editor.DefaultEditor; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @RunWith(RedDeerSuite.class) public class BrowserEditorTest { + @BeforeClass + public static void setupInternalBrowser() { + Preferences.set("org.eclipse.ui.browser", "browser-choice", "0"); + } + @Before public void openBrowser() { Display.syncExec(new Runnable() { diff --git a/tests/org.eclipse.reddeer.requirements.test/src/org/eclipse/reddeer/requirements/test/browser/InternalBrowserRequirementTest.java b/tests/org.eclipse.reddeer.requirements.test/src/org/eclipse/reddeer/requirements/test/browser/InternalBrowserRequirementTest.java new file mode 100644 index 0000000000..273dc19bcc --- /dev/null +++ b/tests/org.eclipse.reddeer.requirements.test/src/org/eclipse/reddeer/requirements/test/browser/InternalBrowserRequirementTest.java @@ -0,0 +1,27 @@ +package org.eclipse.reddeer.requirements.test.browser; + +import org.eclipse.reddeer.junit.requirement.inject.InjectRequirement; +import org.eclipse.reddeer.junit.runner.RedDeerSuite; +import org.eclipse.reddeer.requirements.browser.InternalBrowserRequirement; +import org.eclipse.reddeer.requirements.browser.InternalBrowserRequirement.UseInternalBrowser; +import org.junit.Test; +import org.junit.runner.RunWith; + +@UseInternalBrowser +@RunWith(RedDeerSuite.class) +public class InternalBrowserRequirementTest { + + @InjectRequirement + InternalBrowserRequirement requirement; + + + @Test + public void testInternalBrowser() { + + } + + @Test + public void testClenaupAction() { + + } +}