summaryrefslogtreecommitdiff
path: root/testing/resources/javascript/document_methods.in
blob: cd43e32070da369ee1df910e56274f3f05a9218c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
{{header}}
{{object 1 0}} <<
  /Type /Catalog
  /Pages 2 0 R
  /OpenAction 10 0 R
>>
endobj
{{object 2 0}} <<
  /Type /Pages
  /Count 4
  /Kids [
    3 0 R
    4 0 R
    5 0 R
    6 0 R
  ]
>>
endobj
% Page number 0.
{{object 3 0}} <<
  /Type /Page
  /Parent 2 0 R
  /Resources <<
    /Font <</F1 15 0 R>>
  >>
  /MediaBox [0 0 612 792]
  /Contents 8 0 R
>>
% Page number 1.
{{object 4 0}} <<
  /Type /Page
  /Parent 2 0 R
  /Resources <<
    /Font <</F1 15 0 R>>
  >>
  /MediaBox [0 0 612 792]
>>
% Page number 2.
{{object 5 0}} <<
  /Type /Page
  /Parent 2 0 R
  /Resources <<
    /Font <</F1 15 0 R>>
  >>
  /MediaBox [0 0 612 792]
>>
% Page number 3.
{{object 6 0}} <<
  /Type /Page
  /Parent 2 0 R
  /Resources <<
    /Font <</F1 15 0 R>>
  >>
  /MediaBox [0 0 612 792]
>>
% Contents of the page.
{{object 8 0}} <<
>>
stream
BT
20 50 Td
/F1 12 Tf
(Hello, world!) Tj
0 50 Td
endstream
endobj
% Info
{{object 9 0}} <<
  /Author (Joe Random Author)
  /Creator (Joe Random Creator)
>>
endobj
% OpenAction action
{{object 10 0}} <<
  /Type /Action
  /S /JavaScript
  /JS 11 0 R
>>
endobj
% JS program to exexute
{{object 11 0}} <<
>>
stream
function expect(str, expected) {
  try {
    var result = eval(str);
    if (result == expected) {
      app.alert('PASS: ' + str + ' = ' + result);
    } else {
      app.alert('FAIL: ' + str + ' = ' + result + ', expected = ' + expected);
    }
  } catch (e) {
    app.alert('ERROR: ' + e.toString());
  }
}

function expectError(str) {
  try {
    var result = eval(str);
    app.alert('FAIL: ' + str + ' = ' + result + ', expected to throw error');
  } catch (e) {
    app.alert('PASS: ' + str + ' threw error ' + e.toString());
  }
}

// "Unsupported" methods are present in the document object, but not
// implemented. They always return |undefined| regardless of arguments.
function testUnsupported(str) {
  expect('typeof ' + str, 'function');
  expect(str + '()', undefined);
  expect(str + '(1, 2, "clams", [1, 2, 3])', undefined);
}

function testAddIcon() {
   // Method is present.
   expect('typeof this.addIcon', 'function');

   // Method takes exactly two arguments.
   expectError('this.addIcon()');
   expectError('this.addIcon(1)');
   expectError('this.addIcon(1, 2, 3)');

   // Second argument must actually be an icon.
   expectError('this.addIcon("myicon", 3)');
   expectError('this.addIcon("myicon", undefined)');

   // TODO(tsepez): test success cases.
}

function testCalculateNow() {
   // Method is present.
   expect('typeof this.calculateNow', 'function');

   // TODO(tsepez): test with no permissions.
   // TODO(tsepez): test success cases.
}

function testDeletePages() {
   // Method is present.
   expect('typeof this.deletePages', 'function');

   // TODO(tsepez): test with no permissions.
   // TODO(tsepez): test success cases.
}

function testGetField() {
   // Method is present.
   expect('typeof this.getField', 'function');

   // Method needs at least one argument.
   expectError('this.getField()');

   // TODO(tsepez): test success cases.
}

function testGetIcon() {
   // Method is present.
   expect('typeof this.getIcon', 'function');

   // Method needs exactly one argument.
   expectError('this.getIcon()');
   expectError('this.getIcon(1, 2)');

  // TODO(tsepez): test success cases.
}

function testGetNthFieldName() {
  // Method is present.
  expect('typeof this.getNthFieldName', 'function');

  // Method needs at least one argument.
  expectError('this.getNthFieldName()');

  // Argument can not be negative.
  expectError('this.getNthFieldName(-1)');

  // TODO(tsepez): test success cases.
}

function testGetPageNthWord() {
  // Method is present.
  expect('typeof this.getPageNthWord', 'function');

  // Method accepts any number of parameters.
  expect('this.getPageNthWord(0, 0, true, "clams", [1, 2])', 'Hello,');

  // Arguments can't be negative or out of range.
  expectError('this.getPageNthWord(-1, 0, true)');
  expectError('this.getPageNthWord(6, 0, true)');

  // TODO(tsepez): test with no permissions.
  // TODO(tsepez): test success cases.
}

function testGetPageNthWordQuads() {
   // Method is present.
   expect('typeof this.getPageNthWordQuads', 'function');

  // TODO(tsepez): test with no permissions.
  // TODO(tsepez): test success cases.
}

function testGetPageNumWords() {
   // Method is present.
   expect('typeof this.getPageNumWords', 'function');

  // Method accepts any number of parameters.
  expect('this.getPageNumWords(0, "clams", [1, 2])', 2);

  // Arguments can't be negative or out of range.
  expectError('this.getPageNumWords(-1)');
  expectError('this.getPageNumWords(6)');

  // TODO(tsepez): test with no permissions.
  // TODO(tsepez): test success cases.
}

function testGetPrintParams() {
   // Method is present.
   expect('typeof this.getPrintParams', 'function');

  // TODO(tsepez): test success cases.
}

function testMailDoc() {
   // Method is present.
   expect('typeof this.mailDoc', 'function');

  // TODO(tsepez): test with no permissions.
  // TODO(tsepez): test success cases.
}

function testMailForm() {
   // Method is present.
   expect('typeof this.mailForm', 'function');

  // TODO(tsepez): test with no permissions.
  // TODO(tsepez): test success cases.
}

function testPrint() {
   // Method is present.
   expect('typeof this.print', 'function');

  // TODO(tsepez): test success cases.
}

function testRemoveField() {
  // Method is present.
  expect('typeof this.removeField', 'function');

  // Method requires at least one argument.
  expectError('this.removeField()');

  // TODO(tsepez): test with no permissions.
  // TODO(tsepez): test success cases.
}

function testRemoveIcon() {
   // Method is present.
   expect('typeof this.removeIcon', 'function');

  // Method requires at least one argument.
  expectError('this.removeIcon()');

  // TODO(tsepez): test success cases.
}

function testResetForm() {
   // Method is present.
   expect('typeof this.resetForm', 'function');

  // TODO(tsepez): test with no permissions.
  // TODO(tsepez): test success cases.
}

function testSubmitForm() {
   // Method is present.
   expect('typeof this.submitForm', 'function');

  // Method requires at least one argument.
  expectError('this.submitForm()');

  // TODO(tsepez): test success cases.
}

try {
  app.alert('*** Testing Unsupported Methods ***');
  testUnsupported('this.addAnnot');
  testUnsupported('this.addField');
  testUnsupported('this.addLink');
  testUnsupported('this.closeDoc');
  testUnsupported('this.createDataObject');
  testUnsupported('this.exportAsFDF');
  testUnsupported('this.exportAsText');
  testUnsupported('this.exportAsXFDF');
  testUnsupported('this.extractPages');
  testUnsupported('this.getAnnot');
  testUnsupported('this.getAnnot3D');
  testUnsupported('this.getAnnots');
  testUnsupported('this.getLinks');
  testUnsupported('this.getOCGs');
  testUnsupported('this.getPageBox');
  testUnsupported('this.getURL');
  testUnsupported('this.importAnFDF');
  testUnsupported('this.importAnXFDF');
  testUnsupported('this.importTextData');
  testUnsupported('this.insertPages');
  testUnsupported('this.replacePages');
  testUnsupported('this.saveAs');

  app.alert('*** Testing Supported Methods ***');
  testAddIcon();
  testCalculateNow();
  testDeletePages();
  testGetField();
  testGetIcon();
  testGetNthFieldName();
  testGetPageNthWord();
  testGetPageNthWordQuads();
  testGetPageNumWords();
  testGetPrintParams();
  testMailDoc();
  testMailForm();
  testPrint();
  testRemoveField();
  testRemoveIcon();
  testResetForm();
  testSubmitForm();
} catch (e) {
  app.alert('FATAL: ' + e.toString());
}
endstream
endobj
{{xref}}
trailer <<
  /Root 1 0 R
  /Info 9 0 R
>>
{{startxref}}
%%EOF