Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Extend Browser API to check for custom text location" #1533

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
*******************************************************************************/
package org.eclipse.swt.browser;

import java.net.*;
import java.util.*;

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;

Expand Down Expand Up @@ -1190,21 +1187,6 @@ public boolean setUrl (String url, String postData, String[] headers) {
return webBrowser.setUrl (url, postData, headers);
}

/**
* Checks if the location supplied is the location for setting custom text in the browser.
* This means, when passing the browser URL to this method after a custom text has been set
* via {@link #setText(String)} will yield true as long as no further navigation
* to some other location is performed.
*
* @param location the URL to be checked, must not be null
*
* @since 3.128
*/
public boolean isLocationForCustomText(String location) {
checkWidget();
return URI.create(Objects.requireNonNull(location)).equals(webBrowser.getUriForCustomText());
}

/**
* Stop any loading and rendering activity.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*******************************************************************************/
package org.eclipse.swt.browser;

import java.net.*;
import java.util.*;
import java.util.List;

Expand All @@ -37,7 +36,6 @@ abstract class WebBrowser {

static final String ERROR_ID = "org.eclipse.swt.browser.error"; // $NON-NLS-1$
static final String EXECUTE_ID = "SWTExecuteTemporaryFunction"; // $NON-NLS-1$
private static final URI URI_FOR_CUSTOM_TEXT_PAGE = URI.create("about:blank");

static List<String[]> NativePendingCookies = new ArrayList<> ();
static String CookieName, CookieValue, CookieUrl;
Expand Down Expand Up @@ -726,10 +724,6 @@ public void setBrowser (Browser browser) {
this.browser = browser;
}

URI getUriForCustomText() {
return URI_FOR_CUSTOM_TEXT_PAGE;
}

public abstract boolean setText (String html, boolean trusted);

public abstract boolean setUrl (String url, String postData, String[] headers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ void disposeExampleWidgets () {
/* store the state of the Browser if applicable */
if (browser != null) {
String url = browser.getUrl();
if (url.length() > 0 && !browser.isLocationForCustomText(url)) { //$NON-NLS-1$
if (url.length() > 0 && !url.equals("about:blank")) { //$NON-NLS-1$
lastUrl = url;
} else {
String text = browser.getText();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,75 +518,6 @@ public void changing(LocationEvent event) {
for (int i = 0; i < 100; i++) browser.removeLocationListener(listener);
}

@Test
public void test_isLocationForCustomText_setUrlAfterDisposedThrowsSwtException() {
Browser testBrowser = createBrowser(shell, SWT.NONE);
testBrowser.dispose();
assertThrows(SWTException.class, () -> testBrowser.isLocationForCustomText("about:blank"));
}

@Test
public void test_isLocationForCustomText_isSetUrlNotCustomTextUrlAfterSetText() {
String url = getValidUrl();
AtomicBoolean locationChanged = new AtomicBoolean(false);
browser.addLocationListener(changedAdapter(event -> {
locationChanged.set(true);
}));

browser.setText("Custom text");
assertTrue("Time Out: The Browser didn't navigate to the URL", waitForPassCondition(locationChanged::get));
locationChanged.set(false);
browser.setUrl(url);
assertTrue("Time Out: The Browser didn't navigate to the URL", waitForPassCondition(locationChanged::get));
assertFalse("The navigated URL is falsly indicated to be the custom text URL", browser.isLocationForCustomText(browser.getUrl()));
}

@Test
public void test_isLocationForCustomText_isFirstSetTextURLStillCustomTextUrlAfterSetUrl() {
AtomicBoolean locationChanged = new AtomicBoolean(false);
browser.addLocationListener(changedAdapter(event -> locationChanged.set(true)));
String url = getValidUrl();
browser.setText("Custom text");
assertTrue(waitForPassCondition(locationChanged::get));
String firstUrl = browser.getUrl();
locationChanged.set(false);
browser.setUrl(url);
assertTrue("Time Out: The Browser didn't navigate to the URL", waitForPassCondition(locationChanged::get));
assertTrue(browser.isLocationForCustomText(firstUrl));
assertFalse(browser.isLocationForCustomText(browser.getUrl()));
}

private String getValidUrl() {
String pluginPath = System.getProperty("PLUGIN_PATH");
testLogAppend("PLUGIN_PATH: " + pluginPath);
// When test is run via Ant, URL needs to be acquired differently. In that case the PLUGIN_PATH property is set and used.
if (pluginPath != null) {
return pluginPath + "/data/testWebsiteWithTitle.html";
} else {
// used when ran from Eclipse gui.
return Test_org_eclipse_swt_browser_Browser.class.getClassLoader().getResource("testWebsiteWithTitle.html").toString();
}
}

@Test
public void test_isLocationForCustomText_isSetUrlNotCustomTextUrl() {
AtomicBoolean locationChanged = new AtomicBoolean(false);
browser.addLocationListener(changedAdapter(event -> locationChanged.set(true)));
String url = getValidUrl();
browser.setUrl(url);
waitForPassCondition(locationChanged::get);
assertFalse("Url is wrongly considered Custom Text Url", browser.isLocationForCustomText(browser.getUrl()));
}

@Test
public void test_isLocationForCustomText() {
AtomicBoolean locationChanged = new AtomicBoolean(false);
browser.addLocationListener(changedAdapter(e -> locationChanged.set(true)));
browser.setText("Hello world");
assertTrue("Timeout: LocationListener.changing() event was never fired", waitForPassCondition(locationChanged::get));
assertTrue("Custom Text URI was not loaded on setText", browser.isLocationForCustomText(browser.getUrl()));
}

@Test
public void test_LocationListener_changing() {
AtomicBoolean changingFired = new AtomicBoolean(false);
Expand Down Expand Up @@ -762,9 +693,20 @@ public void test_LocationListener_LocationListener_ordered_changing () {
String url = getValidUrl();
browser.setUrl(url);
waitForPassCondition(() -> locations.size() == 2);
assertTrue("Change of locations do not fire in order.", browser.isLocationForCustomText(locations.get(0)) && locations.get(1).contains("testWebsiteWithTitle.html"));
assertTrue("Change of locations do not fire in order.", locations.get(0).equals("about:blank") && locations.get(1).contains("testWebsiteWithTitle.html"));
}

private String getValidUrl() {
String pluginPath = System.getProperty("PLUGIN_PATH");
testLogAppend("PLUGIN_PATH: " + pluginPath);
// When test is run via Ant, URL needs to be acquired differently. In that case the PLUGIN_PATH property is set and used.
if (pluginPath != null) {
return pluginPath + "/data/testWebsiteWithTitle.html";
} else {
// used when ran from Eclipse gui.
return Test_org_eclipse_swt_browser_Browser.class.getClassLoader().getResource("testWebsiteWithTitle.html").toString();
}
}

@Test
/** Ensue that only one changed and one completed event are fired for url changes */
Expand Down
Loading