forked from eclipse-archived/reddeer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Internal Browser preferences requirement, fixes eclipse-arc…
…hived#2157 Signed-off-by: Ondrej Dockal <[email protected]>
- Loading branch information
Showing
5 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...requirements/src/org/eclipse/reddeer/requirements/browser/InternalBrowserRequirement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/******************************************************************************* | ||
* 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()) { | ||
Preferences.setDefault(BROWSER_PLUGIN, BROWSER_KEY); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
...est/src/org/eclipse/reddeer/requirements/test/browser/InternalBrowserRequirementTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
/******************************************************************************* | ||
* 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.test.browser; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.lang.annotation.Annotation; | ||
|
||
import org.eclipse.reddeer.direct.preferences.Preferences; | ||
import org.eclipse.reddeer.eclipse.ui.browser.WebBrowserPreferencePage; | ||
import org.eclipse.reddeer.junit.runner.RedDeerSuite; | ||
import org.eclipse.reddeer.requirements.browser.InternalBrowserRequirement; | ||
import org.eclipse.reddeer.requirements.browser.InternalBrowserRequirement.UseInternalBrowser; | ||
import org.eclipse.reddeer.workbench.ui.dialogs.WorkbenchPreferenceDialog; | ||
import org.junit.After; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* | ||
* @author odockal | ||
* | ||
*/ | ||
@RunWith(RedDeerSuite.class) | ||
public class InternalBrowserRequirementTest { | ||
|
||
private static InternalBrowserRequirement internalRequirement; | ||
private static InternalBrowserRequirement externalRequirement; | ||
private static String BROWSER_PLUGIN = "org.eclipse.ui.browser"; | ||
private static String BROWSER_KEY = "browser-choice"; | ||
|
||
@BeforeClass | ||
public static void setup() { | ||
internalRequirement = new InternalBrowserRequirement(); | ||
internalRequirement.setDeclaration(new UseInternalBrowser() { | ||
|
||
@Override | ||
public Class<? extends Annotation> annotationType() { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean cleanup() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public String browserChoice() { | ||
return "0"; | ||
} | ||
}); | ||
|
||
externalRequirement = new InternalBrowserRequirement(); | ||
externalRequirement.setDeclaration(new UseInternalBrowser() { | ||
|
||
@Override | ||
public Class<? extends Annotation> annotationType() { | ||
// TODO Auto-generated method stub | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean cleanup() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public String browserChoice() { | ||
return "1"; | ||
} | ||
}); | ||
} | ||
|
||
@After | ||
public void cleanup() { | ||
Preferences.setDefault(BROWSER_PLUGIN, BROWSER_KEY); | ||
} | ||
|
||
@Test | ||
public void testInternalBrowser() { | ||
// default setup is to use external browser | ||
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=577081 | ||
// should be overridden by use of @UseInternalBrowser requirement | ||
internalRequirement.fulfill(); | ||
assertEquals(true, internalBrowserUsed()); | ||
} | ||
|
||
@Test | ||
public void testClenaupAction() { | ||
internalRequirement.fulfill(); | ||
assertEquals("0", Preferences.get(BROWSER_PLUGIN, BROWSER_KEY)); | ||
internalRequirement.cleanUp(); // clean up is turned on | ||
assertEquals("1", Preferences.get(BROWSER_PLUGIN, BROWSER_KEY)); | ||
internalRequirement.fulfill(); | ||
assertEquals("0", Preferences.get(BROWSER_PLUGIN, BROWSER_KEY)); | ||
externalRequirement.cleanUp(); // clean up is turned off | ||
assertEquals("0", Preferences.get(BROWSER_PLUGIN, BROWSER_KEY)); | ||
} | ||
|
||
@Test | ||
public void testExternalBrowserRequirement() { | ||
internalRequirement.fulfill(); | ||
assertEquals(true, internalBrowserUsed()); | ||
externalRequirement.fulfill(); | ||
assertEquals(false, internalBrowserUsed()); | ||
} | ||
|
||
private boolean internalBrowserUsed() { | ||
WorkbenchPreferenceDialog dialog = new WorkbenchPreferenceDialog(); | ||
dialog.open(); | ||
WebBrowserPreferencePage page = new WebBrowserPreferencePage(dialog); | ||
|
||
dialog.select(page); | ||
boolean internalBrowserUsed = page.getInternalBrowserCheckBox().isSelected(); | ||
|
||
dialog.cancel(); | ||
return internalBrowserUsed; | ||
} | ||
} |