!******************************************************************************!
! Test WEBVNCSERVER;WEBVNC command
!
! Arguments: None
!
! Bug:     NXM-3831 NeXtMidas needs to support applications being accessible via a client's web browser
! Since:   NeXtMidas 4.1.3
! @author: Jeanette McCall
!******************************************************************************!
startmacro
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE  ! for normal interactive test(s)
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE  ! for defects or more obscure test case(s)

  if interAct then

    invoke nmroot nxm.sys.lib.Shell.getNmRoot()

    set instructions &
      "1) See required software notes below if this is your first time.\n&
       2) Click WEBVNC button\n&
       3) Navigate to 'http://localhost:8080' in your web browser\n    &
          a) Click 'Connect'\n    &
          b) DEMOENHANCED should be displayed in your browser\n&
          c) Click 'Disconnect'\n&
       4) Expect to have to do a Ctrl-C once in your terminal after \n   &
          you exit this test to stop the NOVNC session\n&
       5) Click 'X' in the top right corner to exit this test\n\n\n\n&
       +---------------------------------------------------------------+\n&
       |          FIRST TIME SOFTWARE INSTALLATION NOTES               |\n&
       | This primitive requires the following commands to be          |\n&
       | available on the host:                                        |\n&
       |    1. vncserver                                               |\n&
       |    2. websockify (this is provided by python-websockify)      |\n&
       | This primitive also requires the WRITE AUX (defaults to AUX.1)|\n&
       | exist and have the appropriate permissions. If you get an     |\n&
       | error mentioning that HPAGE could not open webvnc_1.tbl or    |\n&
       | webvnc_2.tbl, run WEBVNC with /DEBUG to see where it is       |\n&
       | trying to write the table. Example error:                     |\n&
       |   ERROR:                                                      |\n&
       |   HPAGE: Error processing request URI=/rest/session/new?:     |\n&
       |   Could not open webvnc_1.tbl: ...                            |\n&
       +---------------------------------------------------------------+"

    pipe on
      panel/msgid=MAIN/setup/controls=gc
      gcontrol text  idtext "Instructions" instructions 24 30 /title
      gcontrol button webvnc "WEBVNC Session" "Start" "Start"

    pipe off

  endif
endmacro

!******************************************************************************!
! Main process message for this macro. Should be right after the ENDMACRO.
procedure processMessage m:msg
  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: User indicated tests" msg.data eqss "PASS"
    pipe stop
  elseif msg.name eqs "WEBVNC" then
  res nmroot
    WEBVNC  VNCSECURITYTYPES="none" XSTARTUP="^{nmroot}/nxm/webvnc/test/xstartup" 
  else
    say "Unhandled message name: ^msg.name from fid: ^msg.fid data: ^msg.data"
  endif
return

!******************************************************************************!
! If an unexpected exception is caught, mark test as failed
!******************************************************************************!
procedure processException m:emsg
  assert/text="^reg.main.name: Caught unexpected exception ^{emsg.data}" "FALSE" isTrue
  if "Trace" SUBS ENV.DEBUG invoke ,, emsg.data.printStackTrace()
return
