Skip to content
This repository has been archived by the owner on Dec 11, 2022. It is now read-only.

Commit

Permalink
Preference control misbehaves eclipse-archived#164 & Moving forward o…
Browse files Browse the repository at this point in the history
…n portability eclipse-archived#169

Signed-off-by: Andrew Bowley <[email protected]>

* Two new OS-specific packages org.eclipse.dartboard.os.linux/windows
* New PlatformUtil class hides portability solution
* New DartSdkChecker and SdkLocator classes support preferences access
to SDK installations
* SDKLocator (note different to SdkLocator) no longer needed, so removed
* Solved preference field editor issues with executing shell command in
validation eg. re-entry caused by SWT event handling
* Improvements DartPreferencePageTest including new WaitCondition for
transition from displaying error to clearing the error
  • Loading branch information
Kys3rK1ng committed Feb 6, 2020
1 parent 92fa69a commit 349918c
Show file tree
Hide file tree
Showing 20 changed files with 1,527 additions and 233 deletions.
4 changes: 2 additions & 2 deletions org.eclipse.dartboard.releng/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
<packaging>pom</packaging>

<properties>
<tycho.version>1.6.0-SNAPSHOT</tycho.version>
<tycho.version>1.6.0</tycho.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<eclipse-repo.url>http://download.eclipse.org/releases/2020-03</eclipse-repo.url>
<textmate-repo.url>http://download.eclipse.org/tm4e/snapshots/</textmate-repo.url>
<lspe-repo.url>http://download.eclipse.org/lsp4e/releases/latest/</lspe-repo.url>
<wwd-repo.url>http://download.eclipse.org/wildwebdeveloper/snapshots</wwd-repo.url>
<orbit-repo.url>https://download.eclipse.org/tools/orbit/downloads/drops/R20191126223242/repository</orbit-repo.url>
<tycho-extras.version>1.6.0-SNAPSHOT</tycho-extras.version>
<tycho-extras.version>1.6.0</tycho-extras.version>
</properties>

<repositories>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;

import org.eclipse.core.runtime.Platform;
import org.eclipse.dartboard.test.util.DefaultPreferences;
import org.eclipse.reddeer.common.wait.WaitUntil;
import org.eclipse.reddeer.core.reference.ReferencedComposite;
import org.eclipse.reddeer.jface.preference.PreferenceDialog;
import org.eclipse.reddeer.jface.preference.PreferencePage;
import org.eclipse.reddeer.junit.runner.RedDeerSuite;
import org.eclipse.reddeer.swt.impl.button.CheckBox;
import org.eclipse.reddeer.swt.impl.button.RadioButton;
import org.eclipse.reddeer.swt.impl.clabel.DefaultCLabel;
import org.eclipse.reddeer.swt.impl.text.DefaultText;
import org.eclipse.reddeer.swt.impl.text.LabeledText;
import org.eclipse.reddeer.workbench.ui.dialogs.WorkbenchPreferenceDialog;
Expand All @@ -35,16 +37,29 @@

@RunWith(RedDeerSuite.class)
public class DartPreferencePageTest {
/** Dart SDK location is operating system specific. Here catering for Linuz and Windows */
private static String DART_SDK_LOC;

static private final String DIALOG_TITLE = "Dart and Flutter";
/**
* Dart SDK location is operating system specific. Here catering for Linux and
* Windows
*/
private PreferenceDialog preferenceDialog;
private DartPreferencePage preferencePage;

@Before
public void setup() {
DART_SDK_LOC = Platform.getOS().equals(Platform.OS_WIN32) ? "C:\\Program Files\\Dart\\dart-sdk" : "/usr/lib/dart";
boolean firstTime = preferenceDialog == null;
if (firstTime) {// First time - clear settings from previous test session
DefaultPreferences.resetPreferences();
}

preferenceDialog = new WorkbenchPreferenceDialog();
if (firstTime) {
// Make sure preferences dialog is closed before test commences
if (preferenceDialog.isOpen()) {
preferenceDialog.cancel();
}
}
preferencePage = new DartPreferencePage(preferenceDialog);
preferenceDialog.open();
preferenceDialog.select(preferencePage);
Expand All @@ -56,40 +71,61 @@ public void tearDown() {
if (preferenceDialog.isOpen()) {
preferenceDialog.cancel();
}
}

public void doAllTests() throws Exception {
dartPreferencePage__DefaultPreferences__CorrectDefaultsAreDisplayed();
dartPreferencePage__InvalidToValidSDKLocation_PageIsNotValidThenOk();
}

@Test
public void dartPreferencePage__DefaultPreferences__CorrectDefaultsAreDisplayed() throws Exception {
assumeTrue(PreferenceTestConstants.DEFAULT_FLUTTER_LOCATION != null);
assertEquals(PreferenceTestConstants.DEFAULT_FLUTTER_LOCATION, preferencePage.getFlutterSDKLocation());
assertTrue("Auto pub synchronization not selected", preferencePage.isAutoPubSynchronization());
assertFalse("Use offline pub is selected", preferencePage.isUseOfflinePub());
preferencePage.setPluginMode("Dart");

assertEquals(DART_SDK_LOC, preferencePage.getSDKLocation());
assertEquals(PreferenceTestConstants.DEFAULT_DART_LOCATION, preferencePage.getDartSDKLocation());
}

@Test
public void dartPreferencePage__InvalidSDKLocation__PageIsNotValid() throws Exception {
public void dartPreferencePage__InvalidToValidSDKLocation_PageIsNotValidThenOk() throws Exception {
preferencePage.setPluginMode("Dart");
preferencePage.setSDKLocation("some-random-test-location/path-segment");
String result = preferencePage.getDartSDKLocation();
assertTrue(PreferenceTestConstants.DEFAULT_DART_LOCATION.equals(result));
// Change away from default so it can be changed back
preferencePage.setSDKLocation(PreferenceTestConstants.INVALID_SDK_LOCATION);
assertTrue(preferencePage.isShowingSDKInvalidError());
// Always leave an open preference page set to a valid value or a modal dialog pops up
// warning the page has an invalid value. RedDeer is unable to close the modal
// dialog because it is native.
preferencePage.setSDKLocation(PreferenceTestConstants.DEFAULT_DART_LOCATION);
new WaitUntil(new WaitForValidState(preferencePage, DIALOG_TITLE));
result = preferencePage.getDartSDKLocation();
assertTrue(PreferenceTestConstants.DEFAULT_DART_LOCATION.equals(result));
}

public class DartPreferencePage extends PreferencePage {

public class DartPreferencePage extends PreferencePage implements ValidPreferenceState {

public DartPreferencePage(ReferencedComposite referencedComposite) {
super(referencedComposite, "Dart and Flutter");
super(referencedComposite, DIALOG_TITLE);
}

public DartPreferencePage setSDKLocation(String text) {
new LabeledText("Dart SDK Location:").setText(text);
return this;
}

public String getSDKLocation() {
public String getDartSDKLocation() {
return new LabeledText("Dart SDK Location:").getText();
}

public String getFlutterSDKLocation() {
return new LabeledText("Flutter SDK Location:").getText();
}

public DartPreferencePage setAutoPubSynchronization(boolean value) {
new CheckBox("Automatic Pub dependency synchronization").toggle(value);
return this;
Expand Down Expand Up @@ -125,6 +161,15 @@ public boolean isShowingSDKInvalidError() {
return false;
}
}

@Override
public boolean isValid() {
try {
new DefaultCLabel(DIALOG_TITLE);
return true;
} catch (Exception e) {
return false;
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*******************************************************************************
* Copyright (c) 2020 vogella GmbH and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Jonas Hungershausen - initial API and implementation
*******************************************************************************/
package org.eclipse.dartboard.test.preference;

import java.nio.file.Path;
import java.util.Optional;
import java.util.concurrent.ExecutionException;

import org.eclipse.dartboard.util.PlatformUtil;

public class PreferenceTestConstants {

private static String OS = System.getProperty("os.name").toLowerCase();

public static final String DEFAULT_DART_LOCATION;
public static final String INVALID_SDK_LOCATION = "some-random-test-location/path-segment";

public static final String DEFAULT_FLUTTER_LOCATION;

static {
boolean isWindows = OS.indexOf("win") >= 0;
DEFAULT_DART_LOCATION = isWindows ? "C:\\Program Files\\Dart\\dart-sdk" : "/usr/lib/dart";
Optional<Path> flutterSdkLocation = null;
try {
flutterSdkLocation = PlatformUtil.getInstance().getLocation("flutter");
} catch (ExecutionException e) {
}
boolean isFlutterAvailable = (flutterSdkLocation != null) && flutterSdkLocation.isPresent();
DEFAULT_FLUTTER_LOCATION = isFlutterAvailable ? flutterSdkLocation.get().toString() : null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*******************************************************************************
* Copyright (c) 2020 vogella GmbH and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Andrew Bowley
*******************************************************************************/
package org.eclipse.dartboard.test.preference;

/**
* Interface for preference dialog which can flag when it is displaying it's
* valid state
*
* @author Andrew Bowley
*
*/
public interface ValidPreferenceState {

boolean isValid();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.eclipse.dartboard.test.preference;

import org.eclipse.reddeer.common.condition.WaitCondition;

/**
* RedDeer WaitCondition implementation for wait for preference dialog to
* display it's valid state. This normally means the dialog header displays a
* title rather than an error message.
*
* @author Andrew Bowley
*
*/
public class WaitForValidState implements WaitCondition {

private final String title;
private final ValidPreferenceState preferencePage;
private boolean isValid;

/**
* Construct WaitForValidState object
*
* @param preferencePage Preference page implementing ValidPreferenceState
* interface
* @param title Title displayed in dialog header
*/
public WaitForValidState(ValidPreferenceState preferencePage, String title) {
this.preferencePage = preferencePage;
this.title = title;
}

@Override
public boolean test() {
isValid = preferencePage.isValid();
return isValid;
}

@SuppressWarnings("unchecked")
@Override
public Boolean getResult() {
return isValid;
}

@Override
public String description() {
return title + " preference dialog transition to valid state";
}

@Override
public String errorMessageWhile() {
return "Waiting for " + description();
}

@Override
public String errorMessageUntil() {
return "Until " + description();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*******************************************************************************
* Copyright (c) 2020 vogella GmbH and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Andrew Bowley
*******************************************************************************/
package org.eclipse.dartboard.os.linux;

import java.io.File;
import java.util.List;

import org.eclipse.dartboard.util.DartSdkChecker;
import org.eclipse.swt.widgets.Shell;

import com.google.common.collect.Lists;

/**
* Checks if a given Linux location contains a Dart SDK
*
* @author Andrew Bowley
*
*/
@SuppressWarnings("nls")
public class PlatformDartSdkChecker extends DartSdkChecker {

/**
* Construct LinuxDartSdkChecker object
*
* @param shell Parent shell of owner or null if none
* @param isFlutter Flag set true if Dart SDK is inside Flutter
*/
public PlatformDartSdkChecker(Shell shell, boolean isFlutter) {
super(shell, !isFlutter ? "bin"
: "bin" + File.separator + "cache" + File.separator + "dart-sdk" + File.separator + "bin");
}

@Override
public String[] getDartVersionCommands(String executablePath) {
return new String[] { "/bin/bash", "-c", executablePath + " --version" };
}

@Override
public List<String> getBlacklist() {
return Lists.newArrayList("/bin/dart", "/usr/bin/dart");
}

@Override
public String getDartExecutable() {
return "dart"; //$NON-NLS-1$
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*******************************************************************************
* Copyright (c) 2020 vogella GmbH and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Andrew Bowley
*******************************************************************************/
package org.eclipse.dartboard.os.linux;

import org.eclipse.dartboard.util.DartSdkChecker;
import org.eclipse.dartboard.util.IPlatformFactory;
import org.eclipse.dartboard.util.SdkLocator;
import org.eclipse.swt.widgets.Shell;

public class PlatformFactory implements IPlatformFactory {

private final PlatformSdkLocator sdkLocator;

public PlatformFactory() {
sdkLocator = new PlatformSdkLocator();
}

@Override
public DartSdkChecker getDartSdkChecker(Shell shell, boolean isFlutter) {

/**
* Returns a Dart SDK checker
*
* @param shell Parent shell of owner or null if none
* @param isFlutter Flag set true if Dart SDK is inside Flutter
* @return DartSdkChecker object
*/
return new PlatformDartSdkChecker(shell, isFlutter);

}

/**
* Returns support for locating SDK artifacts
*
* @return SdkLocator
*/
@Override
public SdkLocator getSdkLocator() {
return sdkLocator;
}
}
Loading

0 comments on commit 349918c

Please sign in to comment.