Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeo Ufimtsev2017-07-04 15:30:21 +0000
committerLeo Ufimtsev2017-07-04 15:41:42 +0000
commit1a34eb77413b2fbc007bc59fabb14e23b8a08b61 (patch)
tree243405b76b9a7eed5e2a12a0b8435bfced3adb16 /tests/org.eclipse.swt.tests
parent02b9a351f7ff73087a18829f3564e535491adedf (diff)
downloadeclipse.platform.swt-1a34eb77413b2fbc007bc59fabb14e23b8a08b61.tar.gz
eclipse.platform.swt-1a34eb77413b2fbc007bc59fabb14e23b8a08b61.tar.xz
eclipse.platform.swt-1a34eb77413b2fbc007bc59fabb14e23b8a08b61.zip
Bug 514719 – [Browser][Webkit2] port Browser.getText() to webkit2
On Windows, getText returns the processed HTML (after page load). Adjusting tests accordingly. Tests: jUNits for Browser Tests [x] Linux webkit1 & webkit2 [x] Win32 [x] Cocoa Change-Id: I207189439a92eddad7f8133f39ee4b1acae77c66 Signed-off-by: Leo Ufimtsev <lufimtse@redhat.com>
Diffstat (limited to 'tests/org.eclipse.swt.tests')
-rw-r--r--tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_browser_Browser.java48
1 files changed, 35 insertions, 13 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 37e5601937..1057f7842e 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
@@ -849,37 +849,59 @@ public void test_setUrl() {
// TODO - it would be good to verify that the page actually loaded. ex download the webpage etc..
}
+/** Text without html tags */
@Test
public void test_getText() {
- getText_helper("helloWorld");
+ if (SwtTestUtil.isWindows) {
+ // Window's Browser implementation returns the processed HTML rather than the original one.
+ // The processed webpage has html tags added to it.
+ getText_helper("helloWorld", "<html><head></head><body>helloWorld</body></html>");
+ } else {
+ // Linux Webkit1, Webkit2
+ // Cocoa
+ getText_helper("helloWorld", "helloWorld");
+ }
}
@Test
public void test_getText_html() {
- getText_helper("<html><head></head><body>hello<b>World</b></body></html>");
+ String testString = "<html><head></head><body>hello<b>World</b></body></html>";
+ getText_helper(testString, testString);
}
/** Ensure we get webpage before javascript processed it.
* E.g js would add 'style' tag to body after processing. */
@Test
public void test_getText_script() {
- getText_helper("<html><head></head><body>hello World<script>document.body.style.backgroundColor = \"red\";</script></body></html>");
+ String testString = "<html><head></head><body>hello World<script>document.body.style.backgroundColor = \"red\";</script></body></html>";
+ if (SwtTestUtil.isWindows) {
+ // Window's Browser implementation returns the processed HTML rather than the original one.
+ // The processed page injects "style" property into the body from the script.
+ getText_helper(testString, "<html><head></head><body style=\"background-color: red;\">hello World<script>document.body.style.backgroundColor = \"red\";</script></body></html>");
+ } else {
+ // Linux Webkit1, Webkit2
+ // Cocoa
+ getText_helper(testString, testString);
+ }
+
}
/** Ensure that 'DOCTYPE' is not stripped out of original string */
@Test
public void test_getText_doctype() {
- getText_helper("<!DOCTYPE html><html><head></head><body>hello World</body></html>");
-}
-
-/** Ensure custom DOCTYPE is not stripped out of original string */
-@Test
-public void test_getText_doctype_custom() {
- getText_helper("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" "
- + "\"http://www.w3.org/TR/html4/strict.dtd\"><html><head></head><body>hello World</body></html>");
+ String testString = "<!DOCTYPE html><html><head></head><body>hello World</body></html>";
+ if (SwtTestUtil.isWindows) {
+ // Window's Browser implementation returns the processed HTML rather than the original one.
+ // The processed page strips out DOCTYPE.
+ getText_helper(testString, "<html><head></head><body>hello World</body></html>");
+ } else {
+ // Linux Webkit1, Webkit2
+ // Cocoa
+ getText_helper(testString,testString);
+ }
}
-private void getText_helper(String testString) {
+private void getText_helper(String testString, String expectedOutput) {
AtomicReference<String> returnString= new AtomicReference<>("");
AtomicBoolean finished = new AtomicBoolean(false);
browser.setText(testString);
@@ -894,7 +916,7 @@ private void getText_helper(String testString) {
});
shell.open();
waitForPassCondition(() -> finished.get());
- boolean passed = returnString.get().equals(testString);
+ boolean passed = returnString.get().equals(expectedOutput);
String error_msg = finished.get() ?
"Test did not return correct string.\n"
+ "Expected:"+testString+"\n"

Back to the top