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
|
/*
* Bug 1267910 - The regression test case for session cookies.
*/
"use strict";
const TEST_HOST = "www.example.com";
const COOKIE =
{
name: "test1",
value: "yes1",
path: "/browser/browser/components/sessionstore/test/"
};
const SESSION_DATA = `
{
"version": ["sessionrestore", 1],
"windows": [{
"tabs": [{
"entries": [],
"lastAccessed": 1463893009797,
"hidden": false,
"attributes": {},
"image": null
}, {
"entries": [{
"url": "http://www.example.com/browser/browser/components/sessionstore/test/browser_1267910_page.html",
\"charset": "UTF-8",
"ID": 0,
"docshellID": 2,
"originalURI": "http://www.example.com/browser/browser/components/sessionstore/test/browser_1267910_page.html",
\"docIdentifier": 0,
"persist": true
}],
"lastAccessed": 1463893009321,
"hidden": false,
"attributes": {},
"userContextId": 0,
"index": 1,
"image": "http://www.example.com/favicon.ico"
}],
"selected": 1,
"_closedTabs": [],
"busy": false,
"width": 1024,
"height": 768,
"screenX": 4,
"screenY": 23,
"sizemode": "normal",
"cookies": [{
"host": "www.example.com",
"value": "yes1",
"path": "/browser/browser/components/sessionstore/test/",
"name": "test1"
}]
}],
"selectedWindow": 1,
"_closedWindows": [],
"session": {
"lastUpdate": 1463893009801,
"startTime": 1463893007134,
"recentCrashes": 0
},
"global": {}
}`;
const SESSION_DATA_OA = `
{
"version": ["sessionrestore", 1],
"windows": [{
"tabs": [{
"entries": [],
"lastAccessed": 1463893009797,
"hidden": false,
"attributes": {},
"image": null
}, {
"entries": [{
"url": "http://www.example.com/browser/browser/components/sessionstore/test/browser_1267910_page.html",
\"charset": "UTF-8",
"ID": 0,
"docshellID": 2,
"originalURI": "http://www.example.com/browser/browser/components/sessionstore/test/browser_1267910_page.html",
\"docIdentifier": 0,
"persist": true
}],
"lastAccessed": 1463893009321,
"hidden": false,
"attributes": {},
"userContextId": 0,
"index": 1,
"image": "http://www.example.com/favicon.ico"
}],
"selected": 1,
"_closedTabs": [],
"busy": false,
"width": 1024,
"height": 768,
"screenX": 4,
"screenY": 23,
"sizemode": "normal",
"cookies": [{
"host": "www.example.com",
"value": "yes1",
"path": "/browser/browser/components/sessionstore/test/",
"name": "test1",
"originAttributes": {
"addonId": "",
"appId": 0,
"inIsolatedMozBrowser": false,
"userContextId": 0
}
}]
}],
"selectedWindow": 1,
"_closedWindows": [],
"session": {
"lastUpdate": 1463893009801,
"startTime": 1463893007134,
"recentCrashes": 0
},
"global": {}
}`;
add_task(function* run_test() {
// Wait until initialization is complete.
yield SessionStore.promiseInitialized;
// Clear cookies.
Services.cookies.removeAll();
// Open a new window.
let win = yield promiseNewWindowLoaded();
// Restore window with session cookies that have no originAttributes.
ss.setWindowState(win, SESSION_DATA, true);
let enumerator = Services.cookies.getCookiesFromHost(TEST_HOST, {});
let cookie;
let cookieCount = 0;
while (enumerator.hasMoreElements()) {
cookie = enumerator.getNext().QueryInterface(Ci.nsICookie);
cookieCount++;
}
// Check that the cookie is restored successfully.
is(cookieCount, 1, "expected one cookie");
is(cookie.name, COOKIE.name, "cookie name successfully restored");
is(cookie.value, COOKIE.value, "cookie value successfully restored");
is(cookie.path, COOKIE.path, "cookie path successfully restored");
// Clear cookies.
Services.cookies.removeAll();
// Restore window with session cookies that have originAttributes within.
ss.setWindowState(win, SESSION_DATA_OA, true);
enumerator = Services.cookies.getCookiesFromHost(TEST_HOST, {});
cookieCount = 0;
while (enumerator.hasMoreElements()) {
cookie = enumerator.getNext().QueryInterface(Ci.nsICookie);
cookieCount++;
}
// Check that the cookie is restored successfully.
is(cookieCount, 1, "expected one cookie");
is(cookie.name, COOKIE.name, "cookie name successfully restored");
is(cookie.value, COOKIE.value, "cookie value successfully restored");
is(cookie.path, COOKIE.path, "cookie path successfully restored");
// Close our window.
yield BrowserTestUtils.closeWindow(win);
});
|