diff options
author | Leo Ufimtsev | 2017-05-26 18:40:38 +0000 |
---|---|---|
committer | Leo Ufimtsev | 2017-07-20 15:34:32 +0000 |
commit | 902a410605c4c3ebba72480b3628d720948a5e18 (patch) | |
tree | 2d62d809da4679fbda925dd1d945a881b28e7647 | |
parent | 511aa0454b2843c23c65b83a67b3012babdde383 (diff) | |
download | eclipse.platform.swt-902a410605c4c3ebba72480b3628d720948a5e18.tar.gz eclipse.platform.swt-902a410605c4c3ebba72480b3628d720948a5e18.tar.xz eclipse.platform.swt-902a410605c4c3ebba72480b3628d720948a5e18.zip |
Bug 517264: browser_tests (part 2)
Replacing Browser2 with newer tests.
test1->test_LocationListener_ProgressListener_noExtraEvents (new)
test2->test_LocationListener_ProgressListener_cancledLoad (from Part 1)
Change-Id: Iacfba4e12fcb23c072dc193b873e32d07a0a5869
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=517264
Signed-off-by: Leo Ufimtsev <lufimtse@redhat.com>
3 files changed, 35 insertions, 244 deletions
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java index 53b1c0c5aa..6f29b5e846 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java @@ -375,6 +375,41 @@ public void test_LocationListener_ProgressListener_cancledLoad () { @Test +/** Ensue that only one changed and one completed event are fired for url changes */ +public void test_LocationListener_ProgressListener_noExtraEvents() { + AtomicInteger changedCount = new AtomicInteger(0); + AtomicInteger completedCount = new AtomicInteger(0); + + browser.addLocationListener(new LocationAdapter() { + @Override + public void changed(LocationEvent event) { + changedCount.incrementAndGet(); + } + }); + + browser.addProgressListener(new ProgressAdapter() { + @Override + public void completed(ProgressEvent event) { + completedCount.incrementAndGet(); + } + }); + + shell.open(); + browser.setText("Hello world"); + + // We have to wait to check that no extra events are fired. + // On Gtk, Quad Core, pcie this takes 80 ms. ~1000ms for stability. + waitForMilliseconds(600); + boolean passed = changedCount.get() == 1 && completedCount.get() == 1; + + String errorMsg = "\nIncorrect event sequences. Events missing or too many fired:" + + "\nExpected one of each, but received:" + + "\nChanged count: " + changedCount.get() + + "\nCompleted count: " + completedCount.get(); + assertTrue(errorMsg, passed); +} + +@Test public void test_OpenWindowListener_closeShell() { Display display = Display.getCurrent(); Shell shell = new Shell(display); diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/browser/Browser2_location_and_progress_advanced.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/browser/Browser2_location_and_progress_advanced.java deleted file mode 100644 index 5560652d86..0000000000 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/browser/Browser2_location_and_progress_advanced.java +++ /dev/null @@ -1,238 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2016 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.tests.junit.browser; - -import org.eclipse.swt.SWT; -import org.eclipse.swt.browser.Browser; -import org.eclipse.swt.browser.LocationEvent; -import org.eclipse.swt.browser.LocationListener; -import org.eclipse.swt.browser.ProgressEvent; -import org.eclipse.swt.browser.ProgressListener; -import org.eclipse.swt.layout.FillLayout; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.Shell; - -/** - * Tests a range of listeners: - * - Location change (different URL) - * - progress load listener - * But goes into more depth than browser2. - * - */ -public class Browser2_location_and_progress_advanced { - public static boolean verbose = false; - public static boolean passed = false; - public static boolean locationChanging = false; - public static boolean locationChanged = false; - public static boolean progressCompleted = false; - - public static boolean test1(String html) { - if (verbose) System.out.println("setText - args: "+html+" Expected Event Sequence: Location.changing > Location.changed > Progress.completed"); - passed = false; - locationChanging = locationChanged = progressCompleted = false; - - final Display display = new Display(); - final Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - Browser browser = new Browser(shell, SWT.NONE); - browser.addLocationListener(new LocationListener() { - @Override - public void changing(LocationEvent event) { - if (verbose) System.out.println("changing "+event.location); - /* certain browsers do send multiple changing events. Safari does this. */ - passed = !locationChanged && !progressCompleted; - locationChanging = true; - if (!passed) shell.close(); - } - @Override - public void changed(LocationEvent event) { - if (verbose) System.out.println("changed "+event.location); - passed = locationChanging && !locationChanged && !progressCompleted; - locationChanged = true; - if (!passed) shell.close(); - } - }); - browser.addProgressListener(new ProgressListener() { - @Override - public void changed(ProgressEvent event) { - } - @Override - public void completed(ProgressEvent event) { - if (verbose) System.out.println("completed"); - passed = locationChanging && locationChanged && !progressCompleted; - progressCompleted = true; - if (!passed) shell.close(); - if (passed) { - /* wait a little bit more before declaring it a success, - * in case bogus events follow this one. - */ - new Thread() { - @Override - public void run() { - if (verbose) System.out.println("timer start"); - try { sleep(2000); } catch (Exception e) {} - if (!display.isDisposed()) - display.asyncExec(() -> { - if (verbose) System.out.println("timer asyncexec shell.close"); - if (!shell.isDisposed()) shell.close(); - }); - if (verbose) System.out.println("timer over"); - } - }.start(); - } - } - }); - - shell.open(); - browser.setText(html); - - boolean timeout = runLoopTimer(display, shell, 600); - if (timeout) passed = false; - display.dispose(); - return passed; - } - - public static boolean test2(String html) { - if (verbose) System.out.println("setText URL Loading Filtering - args: "+html+" Expected Event Sequence: Location.changing cancel true > no Location.changed, no Progress.completed"); - locationChanging = locationChanged = progressCompleted = false; - passed = false; - final Display display = new Display(); - final Shell shell = new Shell(display); - shell.setLayout(new FillLayout()); - final Browser browser = new Browser(shell, SWT.NONE); - browser.addLocationListener(new LocationListener() { - @Override - public void changing(LocationEvent event) { - if (verbose) System.out.println("changing "+event.location); - /* - * Feature on Internet Explorer. When pending requests are stopped, IE - * emits a Location.changing with res://C:\WINDOWS\System32\shdoclc.dll/navcancl.htm. - * Pending requests are stopped before going to the blank page to set HTML in memory - * with setText. - * The test considers it is OK to get multiple Location.changing events at the condition - * that no locationChanged and progressCompleted are reported. - */ - passed = !locationChanged && !progressCompleted; - locationChanging = true; - if (!passed) { - shell.close(); - return; - } - event.doit = false; - new Thread() { - @Override - public void run() { - if (verbose) System.out.println("timer start"); - try { sleep(2000); } catch (Exception e) {} - if (!display.isDisposed()) - display.asyncExec(() -> { - if (verbose) System.out.println("timer asyncexec shell.close"); - if (!shell.isDisposed()) shell.close(); - }); - if (verbose) System.out.println("timer over"); - } - }.start(); - } - @Override - public void changed(LocationEvent event) { - /* - * Feature on Internet Explorer. If there is no current location, IE still fires a DocumentComplete - * following the BeforeNavigate2 cancel event. This DocumentComplete event contains an empty URL - * since the URL in BeforeNavigate2 was correctly cancelled. - * The test considers it is OK to send a Location.changed and a Progress.completed events after - * a Location.changing cancel true - at the condition that the current location is empty, - * otherwise it is considered that the location was not successfully cancelled. - */ - passed = event.location.length() == 0; - if (verbose) System.out.println("changed "+event.location+" "+passed); - /* ignore LocationChanged that are empty */ - locationChanged = !passed; - } - }); - browser.addProgressListener(new ProgressListener() { - @Override - public void changed(ProgressEvent event) { - } - @Override - public void completed(ProgressEvent event) { - /* - * Feature on Internet Explorer. If there is no current location, IE still fires a DocumentComplete - * following the BeforeNavigate2 cancel event. This DocumentComplete event contains an empty URL - * since the URL in BeforeNavigate2 was correctly cancelled. - * The test considers it is OK to send a Location.changed and a Progress.completed events after - * a Location.changing cancel true - at the condition that the current location is empty, - * otherwise it is considered that the location was not successfully cancelled. - */ - String location = browser.getUrl(); - passed = location.length() == 0; - if (verbose) System.out.println("completed "+passed); - progressCompleted = true; - } - }); - shell.open(); - browser.setText(html); - boolean timeout = runLoopTimer(display, shell, 600); - if (timeout) passed = false; - display.dispose(); - return passed; - } - - static boolean runLoopTimer(final Display display, final Shell shell, final int seconds) { - final boolean[] timeout = {false}; - new Thread() { - @Override - public void run() { - try { - for (int i = 0; i < seconds; i++) { - Thread.sleep(1000); - if (display.isDisposed() || shell.isDisposed()) return; - } - } - catch (Exception e) {} - timeout[0] = true; - /* wake up the event loop */ - if (!display.isDisposed()) { - display.asyncExec(() -> { - if (!shell.isDisposed()) shell.redraw(); - }); - } - } - }.start(); - while (!timeout[0] && !shell.isDisposed()) if (!display.readAndDispatch()) display.sleep(); - return timeout[0]; - } - - public static boolean test() { - int fail = 0; - String[] html = {file1}; - for (int i = 0; i < html.length; i++) { - boolean result = test1(html[i]); - if (verbose) System.out.print(result ? "." : "E"); - if (!result) fail++; - } - for (int i = 0; i < html.length; i++) { - boolean result = test2(html[i]); - if (verbose) System.out.print(result ? "." : "E"); - if (!result) fail++; - } - return fail == 0; - } - - public static void main(String[] argv) { - System.out.println("\r\nTests Finished. SUCCESS: "+test()); - } - - public static String file1 = "<HTML><HEAD>"+ - "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=iso-8859-1\">"+ - "<TITLE>Test with 2 frames</TITLE>"+ - "</HEAD><BODY>some simple test case here</BODY></HTML>"; - -} diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/browser/Test_BrowserSuite.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/browser/Test_BrowserSuite.java index ecdf99eef8..c2e9fe1a5e 100644 --- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/browser/Test_BrowserSuite.java +++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/browser/Test_BrowserSuite.java @@ -34,12 +34,6 @@ String skipMsg() { } -@Test -public void testBrowser2() { - manualSetUp(); - assertTrue(Browser2_location_and_progress_advanced.test()); - manualTearDown(); -} @Test public void testBrowser3() { |