!
! Test of HTTPSERV (defaults to listening on any available port )
! that requires user interaction.
!
! Bug     : 2261     HTTPSERV: should return "Not Found" HTML in addition to 404 error code
! Bug     : NXM-3835 HTTPSERV behavior does not match intended or documented behavior
! Author  : Neon Ngo
!
startmacro L:port[0]
  switch INTERACTIVE interAct GET DEF=TRUE  SDEF=TRUE
  switch BASELINE    baseline GET DEF=FALSE SDEF=TRUE

  if interAct isTRUE then
    pipe on
      panel/msgid=MAIN/setup/controls=gc
      httpserv/ID=hs1/bg port
      invoke ,, reg.hs1.nullHomePage()
      set urlForNotFound1  "http://localhost:^{reg.hs1.port}/Files/bogusUrlTestForNotFound.abc"
      set urlForNotFound2  "http://localhost:^{reg.hs1.port}/anotherNotFoundTest.xyz"
      set urlForDefaultDir "http://localhost:^{reg.hs1.port}"

      gcontrol label mainLabel "Main"
      gcontrol menu main "Exit with Status = " "PASS,FAIL" /tleft
      set gc.main.itemColors {PASS=GREEN,FAIL=RED}
      gcontrol text idtext "Instructions" "Open the following two URLs in your web browser:\n&
          1. ^{urlForNotFound1} and\n2. ^{urlForNotFound2} and it should display a &
          'Not Found' message for both\n\nThen, open the third URL in your web browser:\n&
          3. ^{urlForDefaultDir} and it should display the NeXtMidas help index." 40 10 /title

      gcontrol button browser "Display in local browser (Only in Java6+)" "URL #1,URL #2,URL #3"
    pipe off
  endif

endmacro

!******************************************************************************!
procedure processMessage m:msg
  if msg.name eqs "MAIN" then
    assert/text="^reg.main.name: user indicated" msg.data eqs "PASS"
    pipe stop
  elseif msg.name eqs "BROWSER" then
    if msg.data eqs "URL #1" then
      new java.net.URL(^urlForNotFound1) url
    elseif msg.data eqs "URL #2" then
      new java.net.URL(^urlForNotFound2) url
    elseif msg.data eqs "URL #3" then
      new java.net.URL(^urlForDefaultDir) url
    endif
    ! java6+ only feature to display URL in local web browser
    invoke ,, nxm.sys.libg.MJBrowser.browse(url)
  endif
return
