-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
index.html
129 lines (120 loc) · 3.77 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
<!DOCTYPE html>
<html>
<head>
<title>TEST CASE FOR COOKIES API</title>
</head>
<body>
<h1>Hello World!</h1>
We are using node.js
<script>
var gui = require('nw.gui');
var win = gui.Window.get( window.open('http://115.com'));
var results = new Array();
var changed = false;
// action 1: retrieve(get), retrieveAll(getAll) set
// action 2: set
// action 3: set and onChanged
var action = gui.App.argv[0];
//retrieveAll(".115.com")
function retrieveAll(domain) {
win.cookies.getAll({ 'domain': domain}, function(cookies) {
console.log(cookies);
if (cookies != null && cookies != undefined)
results.push(true);
else
results.push(false);
// for (var i = 0; i < cookies.length; i++) {
// console.log("name: " + cookies[i].name + "\n" + "path: " + cookies[i].path + "\n" + "domain: " + cookies[i].domain + "\n" + "session: " + cookies[i].session.toString() + "\n" + "value: " + cookies[i].value + " " + "\n");
// }
})
}
//remove("http://www.115.com","115_lang")
function remove(url, name) {
win.cookies.remove({ 'url': url, 'name': name });
}
//set('.115.com',"http://www.115.com","115_lang","en")
function set(domain, url, name, value) {
win.cookies.set({ 'domain': domain, 'url': url, 'name': name, 'value': value, 'expirationDate': 9999999999});
}
//retrieve("http://www.115.com","115_lang")
function retrieve(url, name){
win.cookies.get({"url":url, "name": name},function (cookie){
console.log(cookie);
if (cookie != null && cookie != undefined) {
results.push(true);
} else {
results.push(false);
}
});
}
win.cookies.onChanged.addListener(function() {
changed = true;
});
if (action == '1') {
win.window.onload = function() {
retrieve("http://www.115.com","115_lang");//get true
retrieveAll(".115.com");//getAll true
results.push(changed);
win.close();
// true, true
setTimeout(function() {
var client = require('../../nw_test_app').createClient({
argv: gui.App.argv,
data: results
});
}, 1000);
}
} else if (action == '2') {
win.close();
set('.115.com',"http://www.115.com","115_lang","en");//set true
win = gui.Window.get(window.open('http://115.com'));
win.window.onload = function() {
if (win.window.document.title != "115 Cloud drive-Your files in the cloud-Easy&Safe")
results.push(false);
else
results.push(true);
results.push(changed);
win.close();
setTimeout(function() {
var client = require('../../nw_test_app').createClient({
argv: gui.App.argv,
data: results
});
}, 2000)
}
} else if (action == '3') {
win.close();
set('.115.com',"http://www.115.com","115_lang","zh");//set true
win = gui.Window.get(window.open('http://115.com'));
win.window.onload = function() {
if (win.window.document.title == "115 Cloud drive-Your files in the cloud-Easy&Safe")
results.push(false);
else
results.push(true);
setTimeout(function() {
win.close();
results.push(changed);
}, 1000);
// true
setTimeout(function() {
var client = require('../../nw_test_app').createClient({
argv: gui.App.argv,
data: results
});
}, 3000);
}
} else if (action == '4') {
remove("http://www.115.com","115_lang");
results.push(changed);
retrieve("http://www.115.com","115_lang");//get false
//false, true
setTimeout(function() {
var client = require('../../nw_test_app').createClient({
argv: gui.App.argv,
data: results
});
}, 1000);
}
</script>
</body>
</html>