-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
363 lines (332 loc) · 11.2 KB
/
index.html
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>API sanity check</title>
<link rel="stylesheet" href="src/sanity.css" />
</head>
<body>
<!-- Changes to Node include additions to "process" -->
<h1>
<strong>NW.js</strong>
<script>
document.write(
process.versions.nw + "-" + process.versions["nw-flavor"],
);
</script>
</h1>
<h2>
<strong>Chromium</strong>
<script>
document.write(process.versions.chromium);
</script>
</h2>
<h2>
<strong>Node.js</strong>
<script>
document.write(process.version);
</script>
</h2>
<p>
<strong>Main Module</strong>
<script>
document.write(process.mainModule.filename);
</script>
</p>
<hr />
<h1>Manual testing</h1>
<h3>nw.App Actions:</h3>
<fieldset>
<legend>Closing the window</legend>
<button onclick="nw.App.closeAllWindows()">
nw.App.closeAllWindows();
</button>
<button onclick="nw.App.crashBrowser()">nw.App.crashBrowser();</button>
<button onclick="nw.App.crashRenderer()">nw.App.crashRenderer();</button>
<button onclick="nw.App.quit()">nw.App.quit();</button>
</fieldset>
<fieldset>
<legend>Global Shortcuts</legend>
<div class="mb-sm">
<button id="register-shortcut">
nw.App.registerGlobalHotKey('Ctrl+Shift+H');
</button>
<button id="unregister-shortcut">
nw.App.unregisterGlobalHotKey('Ctrl+Shift+H');
</button>
</div>
<p>
Try pressing <code>CTRL + SHIFT + H</code> on your desktop to see if it
focuses this window and shows an alert (or not) based on if you
registered or unregistered it.
</p>
</fieldset>
<h3>DOM Changes</h3>
<fieldset>
<legend>File inputs</legend>
<div class="halves">
<div>
<label>
File Select
<input id="file-select" type="file" />
</label>
</div>
<div>
<p>
Selected files should have a full file path, not relative, or with
"fake" in the path.
<strong id="selected-file"></strong>
</p>
</div>
<div>
<label>
Folder select
<input
id="folder-select"
type="file"
nwdirectory
nwdirectorydesc="Sanity Description"
nwworkingdir="C:\Users"
/>
</label>
</div>
<div>
<p>
Should show "Sanity Description" as window title and "C:\Users" as
the starting folder.
<strong id="selected-folder"></strong>
</p>
</div>
<div>
<label>
Save-As select
<input id="save-as-select" type="file" nwsaveas="sanity.txt" />
</label>
</div>
<div>
<p>
Should show "Save as" as window title with "sanity.txt" as file name
default.
<strong id="selected-save-as"></strong>
</p>
</div>
</div>
</fieldset>
<fieldset>
<legend>IFrames</legend>
<p class="mb-sm">These should all be green.</p>
<div class="halves">
<iframe src="src/iframe-node-accessible.html"></iframe>
<iframe src="src/iframe-node-blocked.html" nwdisable></iframe>
<iframe src="src/iframe-parent-accessed.html"></iframe>
<iframe src="src/iframe-parent-blocked.html" nwfaketop></iframe>
<iframe src="src/iframe-user-agent-real.html"></iframe>
<iframe
src="src/iframe-user-agent-mocked.html"
nwUserAgent="Custom User Agent"
></iframe>
</div>
</fieldset>
<fieldset>
<legend>Node Console</legend>
<ul>
<li>
Right-Click > Inspect Background Page
<ul>
<li>
Ensure the Node console shows a log, info, warning, and error.
</li>
</ul>
</li>
</ul>
</fieldset>
<fieldset>
<legend>Clipboard</legend>
<button id="clipboard-button">
Validate clipboard API (will clear your clipboard contents)
</button>
<p>
<strong id="clipboard-result"></strong>
</p>
</fieldset>
<footer></footer>
<script>
const win = nw.Window.get();
win.showDevTools();
const assert = require("assert").deepEqual;
const fs = require("fs");
const path = require("path");
/**
* nw.App
* https://nwjs.readthedocs.io/en/latest/References/App
*/
function nwApp() {
assert(nw.App.argv, []);
assert(nw.App.fullArgv, []);
assert(nw.App.filteredArgv, [
/^--url=/,
/^--remote-debugging-port=/,
/^--renderer-cmd-prefix=/,
/^--nwapp=/,
]);
assert(nw.App.startPath, process.cwd());
let appData;
if (process.platform === "win32") {
appData =
"C:\\Users\\" +
process.env.USERNAME +
"\\AppData\\Local\\nw-api-sanity-check\\User Data\\Default";
}
assert(nw.App.dataPath, appData);
let manifest = {
...require("./package.json"),
main: "file://index.html",
window: { position: "center" },
};
assert(nw.App.manifest, manifest);
nw.App.clearCache();
// NOTE: I have no idea what to pass into this function. Docs just say "manifest_url"?
nw.App.clearAppCache("");
// NOTE: So how I think this works is if you have not updated the component then it is false and
// '0.0.0.0'. But once you update it, it's `true` and '4.10.2391.0' on every load? I don't know.
// Will need to mock out somehting for that 4.10 version number, no doubt it'll change.
nw.App.updateComponent("WIDEVINE", function (success) {
assert(typeof success, "boolean");
nw.App.enableComponent("WIDEVINE", function (version) {
assert(version, "4.10.2391.0");
});
});
const proxy = nw.App.getProxyForURL("https://google.com");
assert(proxy === "DIRECT" || proxy === "PROXY direct:80", true);
assert(nw.App.setProxyConfig("DIRECT"), undefined);
assert(nw.App.getProxyForURL("https://google.com"), "PROXY direct:80");
// setCrashDumpDir was deprecated in 0.11.0
// nw.App.setCrashDumpDir('./folder');
nw.App.addOriginAccessWhitelistEntry(
"http://github.com/",
"chrome-extension",
location.host,
true,
);
nw.App.removeOriginAccessWhitelistEntry(
"http://github.com/",
"chrome-extension",
location.host,
true,
);
function testGlobalShortcuts() {
const shortcut = new nw.Shortcut({
key: "Ctrl+Shift+H",
active: function () {
nw.Window.get().focus();
alert(
"Global desktop keyboard shortcut: " + this.key + " active.",
);
},
failed: function (msg) {
console.log(msg);
},
});
const registerShortcutButton =
document.getElementById("register-shortcut");
const unregisterShortcutButton = document.getElementById(
"unregister-shortcut",
);
registerShortcutButton.addEventListener(
"click",
function registerShortcut() {
nw.App.registerGlobalHotKey(shortcut);
shortcut.on("active", function () {
console.log(
"Global desktop keyboard shortcut: " + this.key + " active.",
);
});
shortcut.on("failed", function (msg) {
console.log(msg);
});
},
);
unregisterShortcutButton.addEventListener("click", function () {
nw.App.unregisterGlobalHotKey(shortcut);
});
}
testGlobalShortcuts();
nw.App.on("open", function (evt) {
console.log("nw.App.open Event", evt);
});
nw.App.on("reopen", function (evt) {
console.log("nw.App.reopen Event", evt);
});
}
nwApp();
/**
* Changes to DOM
* https://nwjs.readthedocs.io/en/latest/References/Changes%20to%20DOM
*/
function domChanges() {
const fileInput = document.getElementById("file-select");
const fileOutput = document.getElementById("selected-file");
fileInput.addEventListener("change", function (evt) {
const selectedFile = evt.target.files[0].path;
fileOutput.innerText = selectedFile;
assert(path.isAbsolute(selectedFile), true);
assert(path.isAbsolute(fileInput.value), true);
});
const folderInput = document.getElementById("folder-select");
const folderOutput = document.getElementById("selected-folder");
folderInput.addEventListener("change", function (evt) {
const selectedFolder = evt.target.files[0].path;
folderOutput.innerText = selectedFolder;
assert(fs.lstatSync(selectedFolder).isFile(), false);
assert(fs.lstatSync(folderInput.value).isFile(), false);
});
const saveAsInput = document.getElementById("save-as-select");
const saveAsOutput = document.getElementById("selected-save-as");
saveAsInput.addEventListener("change", function (evt) {
const selectedFile = evt.target.files[0].path;
saveAsOutput.innerText = selectedFile;
assert(path.isAbsolute(selectedFile), true);
assert(path.isAbsolute(saveAsInput.value), true);
});
}
domChanges();
/**
* Changes to Node
* https://nwjs.readthedocs.io/en/latest/References/Changes%20to%20Node
*/
function nodeChanges() {
const nodeContext = require("./src/node-context.js");
nodeContext.consoleLogs();
}
nodeChanges();
/**
* Clipboard API
* https://nwjs.readthedocs.io/en/latest/References/Clipboard
*/
function clipboard() {
const button = document.getElementById("clipboard-button");
const output = document.getElementById("clipboard-result");
button.addEventListener("click", function () {
let result = "Successfully wrote, read, and cleared clipboard.";
const systemClipboard = nw.Clipboard.get();
systemClipboard.clear();
systemClipboard.set("Test", "text");
const types = systemClipboard.readAvailableTypes();
if (JSON.stringify(types) !== '["text"]') {
result = "Innacurate available types";
console.log({ availableTypes: types });
}
if (systemClipboard.get("text") !== "Test") {
result = "Failed to write or read from the clipboard";
}
systemClipboard.clear();
if (systemClipboard.get("text") !== "") {
result = "Failed to clear clipboard.";
}
output.innerText = result;
});
}
clipboard();
</script>
</body>
</html>