Project

General

Profile

upload-direct.p

Sergey Ivanovskiy, 11/20/2026 11:30 AM

Download (7.34 KB)

 
1
/*------------------------------------------------------------------------------
2
  upload-direct.p            #12082: direct web upload (no Security Warning)
3

    
4
  Path:     WEB-FILE-UPLOAD REGISTER <button> IN FRAME f CHOOSE UPLOAD ... (FWD
5
            extension) sends the button to the web client as a direct-upload
6
            widget.  Clicking it (mouse down, or SPACE / ENTER) is caught by
7
            p2j.screen.processDirectUpload, which calls
8
            p2j.screen.chooseFiles(direct = true, ...): the browser's file
9
            chooser opens at once, WITHOUT the "Security Warning" dialog.
10
            chooseFiles still creates both p2j.ModalDialogs:
11
              selectUploadFilesDialog  "Security Warning" - created hidden,
12
                                       never shown; hide() and close() are
13
                                       still called on it
14
              actionResultsDialog      "Uploading...", then "Uploaded N
15
                                       file(s)." and closeAction 5 s later
16
            The result reaches 4GL as WEB-UPLOAD-COMPLETE on the button, with
17
            SESSION:WEB-UPLOAD-ERROR and SESSION:WEB-UPLOAD-FILES.
18
            The cases cover the common shapes of the statement.
19

    
20
  Run:      web GUI only, https://localhost:7443/gui?prog=upload_12082/upload-direct.p
21

    
22
  Cases:
23
    1 "Direct one"      REGISTER ... CHOOSE UPLOAD DIR TITLE
24
                        (button in a window)
25
    2 "Direct many"     ... UPLOAD MULTIPLE TITLE
26
    3 "Direct filter"   ... UPLOAD TITLE FILTERS
27
    4 "Open dialog"     opens a DIALOG-BOX whose button "Choose file" is
28
                        registered the same way, a file-selection dialog
29
                        box; OK / Cancel leave the dialog box
30
    5 "Toggle 2"        switches btnMany (case 2) SENSITIVE off / on: a state
31
                        change of one registered widget, with no new
32
                        registration; cases 1 and 3 must keep opening the
33
                        file chooser, and case 2 must open it again once on
34
  Steps:    Click a case button: the browser's file chooser must open with no
35
            "Security Warning".  Pick a file.  Wait for "Uploaded 1 file." and
36
            5 more seconds.  Click "Ping".  Run every case twice, and once
37
            closing the file chooser with Cancel.
38
  Expected: no "Security Warning" at any time; "Uploading..." is gone 5 s
39
            after the upload; the log shows WEB-UPLOAD-COMPLETE with the
40
            uploaded file and "Ping" is logged at once.
41
  Broken:   a dialog stays on screen, or "Security Warning" becomes visible
42
            during or after the upload, and the application stays blocked.
43

    
44
  Found (2026-11-20, 12082a AND trunk r16862 - not caused by 12082a):
45
            after case 4's dialog box has been open (even left with Cancel,
46
            no upload in it), the buttons of cases 1-3 lose their direct
47
            upload: the client's window 1 directUploads becomes null and a
48
            click opens no file chooser, it is a plain CHOOSE (logged as
49
            "case N CHOOSE reached 4GL").
50
            Steps: 1 Direct one (chooser opens, cancel it), 4 Open dialog,
51
            Cancel, 1 Direct one again - no file chooser.
52
            Cause: GuiWebDriver.getDirectUploadDefinitions() sent only the
53
            registered widgets whose state changed, while the JS client
54
            (resetDirectUploads + registerDirectUploads) takes every upload
55
            section as the complete list of all windows.  Case 5 hits the
56
            same cause without a dialog box.
57
------------------------------------------------------------------------------*/
58

    
59
DEFINE VARIABLE cDir  AS CHARACTER NO-UNDO.
60
DEFINE VARIABLE iSeq  AS INTEGER   NO-UNDO.
61
DEFINE VARIABLE cLog  AS CHARACTER NO-UNDO
62
   VIEW-AS EDITOR SCROLLBAR-VERTICAL SIZE 96 BY 12.
63

    
64
DEFINE BUTTON btnOne    LABEL "1 Direct one".
65
DEFINE BUTTON btnMany   LABEL "2 Direct many".
66
DEFINE BUTTON btnFilter LABEL "3 Direct filter".
67
DEFINE BUTTON btnDialog LABEL "4 Open dialog".
68
DEFINE BUTTON btnToggle LABEL "5 Toggle 2".
69
DEFINE BUTTON btnPing   LABEL "Ping".
70
DEFINE BUTTON btnQuit   LABEL "Quit".
71

    
72
DEFINE BUTTON btnDlgFile LABEL "Choose file".
73
DEFINE BUTTON btnDlgOk   LABEL "OK"     AUTO-GO.
74
DEFINE BUTTON btnDlgCanc LABEL "Cancel" AUTO-ENDKEY.
75

    
76
DEFINE FRAME fMain
77
   btnOne btnMany btnFilter btnDialog btnPing btnQuit SKIP(0.5)
78
   btnToggle SKIP(0.5)
79
   cLog NO-LABEL
80
   WITH SIDE-LABELS THREE-D SIZE 100 BY 17 TITLE "#12082 direct upload".
81

    
82
DEFINE FRAME D-Dialog
83
   btnDlgFile SKIP(1)
84
   btnDlgOk btnDlgCanc
85
   WITH VIEW-AS DIALOG-BOX THREE-D SIDE-LABELS TITLE "12082 dialog-box upload".
86

    
87
PROCEDURE log-step:
88
   DEFINE INPUT PARAMETER pText AS CHARACTER NO-UNDO.
89

    
90
   iSeq = iSeq + 1.
91
   cLog:INSERT-STRING(STRING(iSeq, "999") + " " + STRING(TIME, "HH:MM:SS") + " "
92
                      + pText + CHR(10)) IN FRAME fMain.
93
END PROCEDURE.
94

    
95
PROCEDURE log-upload:
96
   DEFINE INPUT PARAMETER pCase AS CHARACTER NO-UNDO.
97

    
98
   RUN log-step (pCase + " WEB-UPLOAD-COMPLETE, error " + STRING(SESSION:WEB-UPLOAD-ERROR)
99
                 + " [" + (IF SESSION:WEB-UPLOAD-FILES = ? THEN "?" ELSE SESSION:WEB-UPLOAD-FILES)
100
                 + "] - wait 5 s, no dialog may stay, then click Ping").
101
END PROCEDURE.
102

    
103
/* case 1: a button in a window, with UPLOAD DIR */
104
ON CHOOSE OF btnOne IN FRAME fMain
105
DO:
106
   RUN log-step ("case 1 CHOOSE reached 4GL (the direct upload consumes the click)").
107
END.
108
ON WEB-UPLOAD-COMPLETE OF btnOne IN FRAME fMain
109
DO:
110
   RUN log-upload ("case 1").
111
END.
112

    
113
/* case 2: MULTIPLE */
114
ON CHOOSE OF btnMany IN FRAME fMain
115
DO:
116
   RUN log-step ("case 2 CHOOSE reached 4GL (the direct upload consumes the click)").
117
END.
118
ON WEB-UPLOAD-COMPLETE OF btnMany IN FRAME fMain
119
DO:
120
   RUN log-upload ("case 2").
121
END.
122

    
123
/* case 3: FILTERS */
124
ON CHOOSE OF btnFilter IN FRAME fMain
125
DO:
126
   RUN log-step ("case 3 CHOOSE reached 4GL (the direct upload consumes the click)").
127
END.
128
ON WEB-UPLOAD-COMPLETE OF btnFilter IN FRAME fMain
129
DO:
130
   RUN log-upload ("case 3").
131
END.
132

    
133
/* case 4: the registered button is in a DIALOG-BOX */
134
ON WEB-UPLOAD-COMPLETE OF btnDlgFile IN FRAME D-Dialog
135
DO:
136
   RUN log-upload ("case 4").
137
END.
138

    
139
ON CHOOSE OF btnDialog IN FRAME fMain
140
DO:
141
   RUN log-step ("case 4: dialog box open - click Choose file, then OK").
142

    
143
   WEB-FILE-UPLOAD REGISTER btnDlgFile IN FRAME D-Dialog CHOOSE
144
      UPLOAD
145
      TITLE "12082 dialog-box file".
146

    
147
   ENABLE ALL WITH FRAME D-Dialog.
148
   DO ON ENDKEY UNDO, LEAVE:
149
      WAIT-FOR GO OF FRAME D-Dialog.
150
   END.
151
   HIDE FRAME D-Dialog.
152

    
153
   RUN log-step ("case 4: dialog box closed - click Ping").
154
END.
155

    
156
/* case 5: a state change of one registered widget, no new registration */
157
ON CHOOSE OF btnToggle IN FRAME fMain
158
DO:
159
   btnMany:SENSITIVE = NOT btnMany:SENSITIVE.
160
   RUN log-step ("case 5: btnMany SENSITIVE " + STRING(btnMany:SENSITIVE)
161
                 + " - 1 Direct one and 3 Direct filter must still open the chooser").
162
END.
163

    
164
ON CHOOSE OF btnPing IN FRAME fMain
165
DO:
166
   RUN log-step ("Ping - the application takes input").
167
END.
168

    
169
cDir = SESSION:TEMP-DIRECTORY.
170

    
171
WEB-FILE-UPLOAD REGISTER btnOne IN FRAME fMain CHOOSE
172
   UPLOAD DIR cDir
173
   TITLE "12082 direct one".
174

    
175
WEB-FILE-UPLOAD REGISTER btnMany IN FRAME fMain CHOOSE
176
   UPLOAD
177
   MULTIPLE
178
   TITLE "12082 direct many".
179

    
180
WEB-FILE-UPLOAD REGISTER btnFilter IN FRAME fMain CHOOSE
181
   UPLOAD
182
   TITLE "12082 direct filter"
183
   FILTERS "Text file" "*.txt".
184

    
185
ENABLE ALL WITH FRAME fMain.
186
RUN log-step ("upload dir " + cDir + " - click a case button").
187

    
188
WAIT-FOR CHOOSE OF btnQuit IN FRAME fMain.