Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 511874 - [win32] Test_getChildren fails on windows
Summary: [win32] Test_getChildren fails on windows
Status: CLOSED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.7   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: 4.7 M6   Edit
Assignee: Leo Ufimtsev CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-02-07 17:59 EST by Leo Ufimtsev CLA
Modified: 2017-03-10 14:34 EST (History)
5 users (show)

See Also:


Attachments
snippet_to_reproduce_issue (873 bytes, text/plain)
2017-02-07 18:01 EST, Leo Ufimtsev CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Leo Ufimtsev CLA 2017-02-07 17:59:06 EST
I recently added a test in Test_*_Browser:
test_execute_and_closeListener().
(in Bug 509615 - [Webkit2] Test_BrowserSuite fails/hangs with tests.)

This test executes javascript: "window.close()" and waits for CloseWindowListener to trigger.

On Linux/Win32 this works. But on OSX it seems that the browser is closed but the listener is not triggered.

As a result, the test fails on OS X.

Could someone with SWT/OS X knowledge investigate why this functionality fails on OS X?
Comment 1 Leo Ufimtsev CLA 2017-02-07 17:59:28 EST
Details:

-  Look at the code of test_execute_and_closeListener
-  Trace is:
> expected:<true> but was:<false>
> java.lang.AssertionError: expected:<true> but was:<false>
> at org.eclipse.swt.tests.junit.Test_org_eclipse_swt_widgets_Widget.tearDown(Test_org_eclipse_swt_widgets_Widget.java:55)
> at org.eclipse.test.EclipseTestRunner.run(EclipseTestRunner.java:749)
> ...

- This means that in Test_*_Widget, the assertion assertEquals(disposedIntentionally) is triggered. I.e Browser was closed but in the test the condition that sets disposedIntentionally=true was not met. Thus this test fails.

Original build log:
http://download.eclipse.org/eclipse/downloads/drops4/I20170206-2000/testresults/html/org.eclipse.swt.tests_ep47I-unit-win32_win32.win32.x86_8.0.html
(these will be deleted in ~15 days or so).
Comment 2 Leo Ufimtsev CLA 2017-02-07 18:01:19 EST
Created attachment 266717 [details]
snippet_to_reproduce_issue

Attaching snippet. On Linux this prints "PASSED : Close listener was triggerd". I expect this not to print on OS X. Instead the browser will close without launching this handler.

(Let me know if it does thou).
Comment 3 Eclipse Genie CLA 2017-02-07 18:15:07 EST
New Gerrit change created: https://git.eclipse.org/r/90598
Comment 5 Leo Ufimtsev CLA 2017-02-08 12:25:25 EST
(In reply to Eclipse Genie from comment #3)
> New Gerrit change created: https://git.eclipse.org/r/90598

Above was not a fix, just a note in the test linking to this bug.
Comment 6 Markus Keller CLA 2017-02-08 12:31:38 EST
I haven't seen this test fail on the Mac, but it does fail on Windows, also when run locally.

The test in master doesn't make much sense, since it executes the window.close() Javascript *before* the SWT call to shell.open();.

Bug 497962 made it again harder to track code history, but AFAICS, the implementation in IE.java:997 looks OK.

But your hack in Test_org_eclipse_swt_browser_Browser.setUp():126 seems to be responsible for the platform difference that ultimately makes widget.isDisposed()  in #tearDown() run on an unexpected widget:

	 * See: Bug 499387
	 */
	if (! SwtTestUtil.isWindows) {
		setWidget(browser);
	}
Comment 7 Eclipse Genie CLA 2017-02-09 12:34:35 EST
New Gerrit change created: https://git.eclipse.org/r/90759
Comment 8 Leo Ufimtsev CLA 2017-02-09 12:44:12 EST
(In reply to Eclipse Genie from comment #7)
> New Gerrit change created: https://git.eclipse.org/r/90759

Hello Markus, 

Thank you for taking the time to investigate.

(In reply to Markus Keller from comment #6)
> I haven't seen this test fail on the Mac, but it does fail on Windows, also
> when run locally.

Strange, according to eclipse build logs it passed on Windows. But recent build logs also show it to pass on OSX. Maybe it fails sporadically on those platforms.


> The test in master doesn't make much sense, since it executes the
> window.close() Javascript *before* the SWT call to shell.open();.

That's a good point.
(On Linux it triggers the listener even when the shell is not open, but I see where you're coming from).
I've moved the browser.execute("window.close()") into a progress completion listener. 
I've submitted a preview patch:
https://git.eclipse.org/r/90759
Is it possible for you to check it out and see if this makes the test pass?
If so, I'll submit a proper patch.


> Bug 497962 made it again harder to track code history, but AFAICS, the
> implementation in IE.java:997 looks OK.

If test still fails, can you do me a favour and run the attached snippet_to_reproduce and let me know if it prints anything to the console? This should help me understand how windows does it's thing.

> But your hack in Test_org_eclipse_swt_browser_Browser.setUp():126 

This method is used in many test setups. See: Test_*_(CCombo|Canvas|Combo|Coolbar|Group|Spinner|Tree etc..)
It just behaves differently on windows than on OSX/Linux. Does the test or snippet behave differently without it?
I don't think that's the cause thou, because in test_execute_and_close, if the close listener gets triggered, then disposedIntentionally is set to true and setWidget(browser) should not make a difference?

Thank you for your time.
Comment 9 Leo Ufimtsev CLA 2017-02-15 16:45:32 EST
I should setup a win32/cocoa test box to investigate why the test fails sporadically on those platforms.
Comment 10 Eclipse Genie CLA 2017-02-16 14:24:39 EST
New Gerrit change created: https://git.eclipse.org/r/91325
Comment 12 Leo Ufimtsev CLA 2017-02-16 14:26:52 EST
I temporarily dissabled the test on Win32/Cocoa. I'm going on vacation for 2 weeks, after I'll setup a win32/Cocoa box to investigate this further.
Comment 13 Markus Keller CLA 2017-02-21 10:57:21 EST
(In reply to Leo Ufimtsev from comment #8)
This is not a sporadic failure. test_execute_and_closeListener() never failed on macOS, but it consistently failed on Windows.

test_BrowserFunction_callback_with_multipleValues fails on macOS, but that's unrelated to this bug.

> > But your hack in Test_org_eclipse_swt_browser_Browser.setUp():126 
> 
> This method is used in many test setups. See:

The hack is that the Test*Browser#setUp() method no longer calls setWidget(browser) on Windows. The comment there already tells that the widget hierarchy is not the same on all platforms. You have to debug this on Windows.
Comment 14 Leo Ufimtsev CLA 2017-03-06 17:52:28 EST
(In reply to Markus Keller from comment #13)
> (In reply to Leo Ufimtsev from comment #8)
> This is not a sporadic failure. test_execute_and_closeListener() never
> failed on macOS, but it consistently failed on Windows.
> 
> test_BrowserFunction_callback_with_multipleValues fails on macOS, but that's
> unrelated to this bug.
> 
> > > But your hack in Test_org_eclipse_swt_browser_Browser.setUp():126 
> > 
> > This method is used in many test setups. See:
> 
> The hack is that the Test*Browser#setUp() method no longer calls
> setWidget(browser) on Windows. The comment there already tells that the
> widget hierarchy is not the same on all platforms. You have to debug this on
> Windows.

I've spent some time and setup a win32 box and got SWT development going (except rebuilding bindings). After debugging a bit, I see what you mean when you say the breakage is due to the 'hack' (setwidget). This is an error on my part, thanks for looking into this.

I'll look for a solution tomorrow.
Comment 15 Eclipse Genie CLA 2017-03-07 15:16:24 EST
New Gerrit change created: https://git.eclipse.org/r/92555
Comment 16 Leo Ufimtsev CLA 2017-03-07 15:32:33 EST
Test_*_Browser#test_execute_and_closeListener() was actually working if setWidget() is called in the constructor.

But calling setWidget() in the constructor would cause test_getChildren() to fail. The reason is that Browser on Win32 has 1 child (an OleFrame). See:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=499387#c22

The solution in this case is to remove the "if (!windows) {" condition in the constructor and instead override test_getChildren in Browser and treat it differently on Win32.

@Niraj / Markus. If you have time, could you take a quick peak at the provided patch and let me know if you have any concerns.
If not, I'll merge it later.
Comment 18 Leo Ufimtsev CLA 2017-03-08 17:30:07 EST
I pushed the patch to master. (If there is feedaback about the patch, feel free to post it here). 

There shouldn't be any SWT Browser jUnits that still fail now. I'll double check build logs tomorrow to verify.
Comment 19 Leo Ufimtsev CLA 2017-03-10 12:17:42 EST
No errors in build logs. All tests passed.