Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(823)

Side by Side Diff: testing/resources/javascript/globals.in

Issue 943783002: Add test for PDF's JS "global". (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | testing/resources/javascript/globals_expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 {{header}}
2 {{object 1 0}} <<
3 /Type /Catalog
4 /Pages 2 0 R
5 /OpenAction 10 0 R
6 >>
7 endobj
8 {{object 2 0}} <<
9 /Type /Pages
10 /Count 1
11 /Kids [
12 3 0 R
13 ]
14 >>
15 endobj
16 % Page number 0.
17 {{object 3 0}} <<
18 /Type /Page
19 /Parent 2 0 R
20 /Resources <<
21 /Font <</F1 15 0 R>>
22 >>
23 /Contents [21 0 R]
24 /MediaBox [0 0 612 792]
25 >>
26 % OpenAction action
27 {{object 10 0}} <<
28 /Type /Action
29 /S /JavaScript
30 /JS 11 0 R
31 >>
32 endobj
33 % JS program to exexute
34 {{object 11 0}} <<
35 >>
36 stream
37 // The "global" object stores data in a C-like manner, and
38 // can theoretically persist them between sessions (though
39 // pdfium deliberately excludes that functionality).
40
41 var some_object = { "colors": [ "red", "green", "blue"] };
42
43 var props_to_test = [
44 // Cover both bool values.
45 { "name": "true_var", "value": true },
46 { "name": "false_var", "value": false },
47
48 // Include both zero and a number with some fractional digits.
49 { "name": "zero_var", "value": 0 },
50 { "name": "number_var", "value": -3.918 },
51
52 // TODO(tsepez): unicode doesn't seem to survive.
53 { "name": "string_var", "value": "This is a string" },
54
55 // Try a complex object.
56 { "name": "object_var", "value": some_object },
57
58 // Test null and undefined.
59 { "name": "null_var", "value": null },
60 { "name": "undefined_var", "value": undefined }
61 ];
62
63 function setup_global() {
64 for (var i = 0; i < props_to_test.length; ++i) {
65 var prop = props_to_test[i];
66 global[prop.name] = prop.value;
67 }
68 }
69
70 function delete_global() {
71 for (var i = 0; i < props_to_test.length; ++i) {
72 var prop = props_to_test[i];
73 delete global[prop.name];
74 }
75 }
76
77 function persist_global(should_persist) {
78 for (var i = 0; i < props_to_test.length; ++i) {
79 var prop = props_to_test[i];
80 global.setPersistent(prop.name, should_persist);
81 }
82 }
83
84 function dump_global(msg) {
85 app.alert("************ " + msg + " ************");
86 app.alert("Enumerable Globals:");
87 for (var name in global) {
88 app.alert(" " + name + " = " + global[name] +
89 ", own property = " + global.hasOwnProperty(name));
90 }
91 app.alert("Expected Globals:");
92 for (var i = 0; i < props_to_test.length; ++i) {
93 var prop = props_to_test[i];
94 var actual = global[prop.name];
95 app.alert(" " + prop.name + " = " + actual);
96 if (actual != null && typeof actual == "object") {
97 app.alert(" " + actual.colors[0]);
98 app.alert(" " + actual.colors[1]);
99 app.alert(" " + actual.colors[2]);
100 }
101 }
102 }
103
104 dump_global("Initial State");
105
106 // Check that they all exist.
107 setup_global();
108 dump_global("After Setup");
109
110 // Test deletion.
111 delete_global();
112 dump_global("After Deletion");
113
114 // setPersistent() should be a no-op for pdfium.
115 setup_global();
116 persist_global(false);
117 dump_global("After Setup and Persist false");
118
119 // Test setting deleted variables as persistent.
120 delete_global();
121 persist_global(true);
122 dump_global("After Delete and Persist");
123
124 // Exit with variables marked as persistent to test whatever path
125 // may exist to persist them (should be igonored on pdfium).
126 setup_global();
127 persist_global(true);
128 dump_global("After Setup and Persist true");
129
130 endstream
131 endobj
132 {{xref}}
133 trailer <<
134 /Root 1 0 R
135 >>
136 {{startxref}}
137 %%EOF
OLDNEW
« no previous file with comments | « no previous file | testing/resources/javascript/globals_expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698