Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 326172 - SWTBot fails to load the internal browser in headless mode
Summary: SWTBot fails to load the internal browser in headless mode
Status: RESOLVED INVALID
Alias: None
Product: SWTBot
Classification: Technology
Component: SWTBot (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 blocker (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-24 12:18 EDT by Gabriel Petrovay CLA
Modified: 2011-01-17 14:01 EST (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gabriel Petrovay CLA 2010-09-24 12:18:26 EDT
Hi,

There must be a bug somewhere in there on Windows 7 at least. This happens only when running SWTBot in headless mode. I also ran it "as Administrator" to make sure there are no permission problems. But the behaviour is the same.

I have one test containing the lines:

public void test_InternalBrowser() throws Exception {
  SWTWorkbenchBot bot = AllTests.bot;
  final StringBuffer sb = new StringBuffer();
  PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() {
    public void run() {
      sb.append("canUseInternalWebBrowser: " + WebBrowserUtil.canUseInternalWebBrowser() + "\n");
    }
  });
  try {
    Class.forName("org.eclipse.swt.browser.Browser");
    sb.append("class \"org.eclipse.swt.browser.Browser\" found.\n");
  } catch (ClassNotFoundException e) {
    sb.append("class \"org.eclipse.swt.browser.Browser\" not found.\n");
  }
  assertTrue(sb.toString(), false);
}


The output is:
canUseInternalWebBrowser: false
class "org.eclipse.swt.browser.Browser" found


The problem is that WebBrowserUtil.canUseInternalWebBrowser() tries to construct a Browser object. The call goes down to org.eclipse.swt.browser.WebSite.createTempStorage() method inherited from org.eclipse.swt.ole.win32.OleClientSite:

protected IStorage createTempStorage() {
  int /*long*/[] tempStorage = new int /*long*/[1];
  int grfMode = COM.STGM_READWRITE | COM.STGM_SHARE_EXCLUSIVE | COM.STGM_DELETEONRELEASE;
  int result = COM.StgCreateDocfile(null, grfMode, 0, tempStorage);
  if (result != COM.S_OK) OLE.error(OLE.ERROR_CANNOT_CREATE_FILE, result);
    return new IStorage(tempStorage[0]);
}


After the call to the native method COM.StgCreateDocfile(...) result has the value -2147286788. This translates to 0x800300FC which is STG_E_INVALIDNAME
http://msdn.microsoft.com/en-us/library/aa380323(VS.85).aspx

1. Why is the name not valid if NULL is also a valid input value as the page above describes?
2. Eclipse calls this function many times and it always succeeds called in the same way (providing NULL as the first parameter). When SWTBot is hosted in Eclipse, the environments are already set up by the eclipse host. In headless mode, when SWTBot starts eclipse, something is missing.

So I assume there is a problem in how SWTBot launches Eclipse when started headlessly
Comment 1 Ketan Padegaonkar CLA 2010-09-24 12:40:15 EDT
Anyone on the SWT team have any thoughts ? It appears like an SWT bug, but I'm unable to reproduce this locally on linux and mac. SWTBot is not doing anything that is specific about any platform.

There's some more context on the forum here: http://www.eclipse.org/forums/index.php?t=msg&th=175593&start=0&S=f81450a23963083a9e57b7a1bd2298f5
Comment 2 Gabriel Petrovay CLA 2010-09-24 15:09:39 EDT
(In reply to comment #1)
> Anyone on the SWT team have any thoughts ? It appears like an SWT bug, but I'm
> unable to reproduce this locally on linux and mac. SWTBot is not doing anything
> that is specific about any platform.
> 
> There's some more context on the forum here:
> http://www.eclipse.org/forums/index.php?t=msg&th=175593&start=0&S=f81450a23963083a9e57b7a1bd2298f5

I am thinking more about something that does not get loaded/initialized properly by the org.eclipse.swtbot.eclipse.junit4.headless.swtbottestapplication.

For the SWT guys, there is the Bug 326174 that you can discuss on. Once we see exactly where the problem lies, I will mark one of the two as invalid or duplicate of the other.
Comment 3 Gabriel Petrovay CLA 2010-09-24 18:36:07 EDT
For a comparison, if this helps: the arguments passed to the two UITestApplication's are:

to the  failing application (headless):
org.eclipse.swtbot.eclipse.junit4.headless.UITestApplication
args:
[-testApplication, org.eclipse.ui.ide.workbench, formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,D:\STTF\nightly_downloads\Sausalito Tools/result.xml, formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter, -testPluginName, my.test.plugin, -className, org.eclipse.wst.xquery.set.ui.tests.AllTests]


to the successful application (from Eclipse):
org.eclipse.swtbot.eclipse.core.UITestApplication
args:
[-version, 3, -port, 9310, -testLoaderClass, org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader, -loaderpluginname, org.eclipse.jdt.junit4.runtime, -classNames, org.eclipse.wst.xquery.set.ui.tests.AllTests, -testpluginname, my.test.plugin]
Comment 4 Gabriel Petrovay CLA 2010-09-25 06:08:09 EDT
Adding Ketan from SWTBot to the discussion.
Comment 5 Gabriel Petrovay CLA 2010-09-26 09:12:45 EDT
I have attached a zip to the bug 326174 with a sample plug-in (independent of SWTBot) and the steps to reproduce.

We still have to see if this is a bug in SWT or a configuration problem in both SWTBot and my sample plug-in.
Comment 6 Libor Zoubek CLA 2010-11-10 06:44:41 EST
Hi, 

I' facing a little bit similar problems with SWTBotBrowser. I've updated bot to 2.0.1 few days ago, and I am getting NoClassDefFound (org/eclipse/swt/browser/Browser) whenever I try to access it. This is reproducible always on linux

I looked into org.eclipse.swtbot.swt.finder manifest and found out, that there is missing 'Import package: org.eclipse.swt.browser'.
Comment 7 Grant Gayed CLA 2010-11-10 09:33:08 EST
This would be a different issue, the problem described in this report was recently resolved in bug 326174.
Comment 8 Ketan Padegaonkar CLA 2010-12-26 02:04:55 EST
Gabriel,

Is this still an issue? I can see that bug 326174 was marked as NOT_ECLIPSE. Are you able to run the tests after setting the TMP environment variable?
Comment 9 Ketan Padegaonkar CLA 2011-01-17 14:01:15 EST
Marking as INVALID since this was a case of an environment variable not set correctly.

Please reopen if this is still an issue.