Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / phantomjs / lib / phantom / examples / detectsniff.js
1 // Detect if a web page sniffs the user agent or not.
2
3 var page = require('webpage').create(),
4     system = require('system'),
5     sniffed,
6     address;
7
8 page.onInitialized = function () {
9     page.evaluate(function () {
10
11         (function () {
12             var userAgent = window.navigator.userAgent,
13                 platform = window.navigator.platform;
14
15             window.navigator = {
16                 appCodeName: 'Mozilla',
17                 appName: 'Netscape',
18                 cookieEnabled: false,
19                 sniffed: false
20             };
21
22             window.navigator.__defineGetter__('userAgent', function () {
23                 window.navigator.sniffed = true;
24                 return userAgent;
25             });
26
27             window.navigator.__defineGetter__('platform', function () {
28                 window.navigator.sniffed = true;
29                 return platform;
30             });
31         })();
32     });
33 };
34
35 if (system.args.length === 1) {
36     console.log('Usage: detectsniff.js <some URL>');
37     phantom.exit(1);
38 } else {
39     address = system.args[1];
40     console.log('Checking ' + address + '...');
41     page.open(address, function (status) {
42         if (status !== 'success') {
43             console.log('FAIL to load the address');
44             phantom.exit();
45         } else {
46             window.setTimeout(function () {
47                 sniffed = page.evaluate(function () {
48                     return navigator.sniffed;
49                 });
50                 if (sniffed) {
51                     console.log('The page tried to sniff the user agent.');
52                 } else {
53                     console.log('The page did not try to sniff the user agent.');
54                 }
55                 phantom.exit();
56             }, 1500);
57         }
58     });
59 }