Skip to content

Commit

Permalink
Implement Internal Browser preferences requirement, fixes eclipse-arc…
Browse files Browse the repository at this point in the history
…hived#2157

Signed-off-by: Ondrej Dockal <[email protected]>
  • Loading branch information
odockal committed Jan 25, 2022
1 parent 4fc24cc commit 3b071ac
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions plugins/org.eclipse.reddeer.requirements/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<plugin>
<extension point="org.eclipse.reddeer.junit.requirement">
<requirement class="org.eclipse.reddeer.requirements.autobuilding.AutoBuildingRequirement"/>
<requirement class="org.eclipse.reddeer.requirements.browser.InternalBrowserRequirement"/>
<requirement class="org.eclipse.reddeer.requirements.cleanworkspace.CleanWorkspaceRequirement"/>
<requirement class="org.eclipse.reddeer.requirements.closeeditors.CloseAllEditorsRequirement"/>
<requirement class="org.eclipse.reddeer.requirements.db.DatabaseRequirement"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<UseInternalBrowser>{

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);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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() {

}
}

0 comments on commit 3b071ac

Please sign in to comment.