@@ -14,6 +14,9 @@ import (
14
14
"time"
15
15
)
16
16
17
+ // tNow is the synthetic current time used as now during testing.
18
+ var tNow = time .Date (2013 , 1 , 1 , 12 , 0 , 0 , 0 , time .UTC )
19
+
17
20
// testPSL implements PublicSuffixList with just two rules: "co.uk"
18
21
// and the default rule "*".
19
22
type testPSL struct {}
@@ -199,9 +202,9 @@ func TestDomainAndType(t *testing.T) {
199
202
}
200
203
}
201
204
202
- // expiresIn creates an expires attribute delta seconds from now .
205
+ // expiresIn creates an expires attribute delta seconds from tNow .
203
206
func expiresIn (delta int ) string {
204
- t := time . Now (). Round ( time . Second ) .Add (time .Duration (delta ) * time .Second )
207
+ t := tNow .Add (time .Duration (delta ) * time .Second )
205
208
return "expires=" + t .Format (time .RFC1123 )
206
209
}
207
210
@@ -216,9 +219,12 @@ func mustParseURL(s string) *url.URL {
216
219
217
220
// jarTest encapsulates the following actions on a jar:
218
221
// 1. Perform SetCookies with fromURL and the cookies from setCookies.
222
+ // (Done at time tNow + 0 ms.)
219
223
// 2. Check that the entries in the jar matches content.
224
+ // (Done at time tNow + 1001 ms.)
220
225
// 3. For each query in tests: Check that Cookies with toURL yields the
221
226
// cookies in want.
227
+ // (Query n done at tNow + (n+2)*1001 ms.)
222
228
type jarTest struct {
223
229
description string // The description of what this test is supposed to test
224
230
fromURL string // The full URL of the request from which Set-Cookie headers where received
@@ -235,6 +241,8 @@ type query struct {
235
241
236
242
// run runs the jarTest.
237
243
func (test jarTest ) run (t * testing.T , jar * Jar ) {
244
+ now := tNow
245
+
238
246
// Populate jar with cookies.
239
247
setCookies := make ([]* http.Cookie , len (test .setCookies ))
240
248
for i , cs := range test .setCookies {
@@ -244,11 +252,11 @@ func (test jarTest) run(t *testing.T, jar *Jar) {
244
252
}
245
253
setCookies [i ] = cookies [0 ]
246
254
}
247
- jar .SetCookies (mustParseURL (test .fromURL ), setCookies )
255
+ jar .setCookies (mustParseURL (test .fromURL ), setCookies , now )
256
+ now = now .Add (1001 * time .Millisecond )
248
257
249
258
// Serialize non-expired entries in the form "name1=val1 name2=val2".
250
259
var cs []string
251
- now := time .Now ().UTC ()
252
260
for _ , submap := range jar .entries {
253
261
for _ , cookie := range submap {
254
262
if ! cookie .Expires .After (now ) {
@@ -268,8 +276,9 @@ func (test jarTest) run(t *testing.T, jar *Jar) {
268
276
269
277
// Test different calls to Cookies.
270
278
for i , query := range test .queries {
279
+ now = now .Add (1001 * time .Millisecond )
271
280
var s []string
272
- for _ , c := range jar .Cookies (mustParseURL (query .toURL )) {
281
+ for _ , c := range jar .cookies (mustParseURL (query .toURL ), now ) {
273
282
s = append (s , c .Name + "=" + c .Value )
274
283
}
275
284
if got := strings .Join (s , " " ); got != query .want {
@@ -588,37 +597,33 @@ var updateAndDeleteTests = [...]jarTest{
588
597
}
589
598
590
599
func TestUpdateAndDelete (t * testing.T ) {
591
- t .Skip ("test is broken on windows/386" ) // issue 4823
592
600
jar := newTestJar ()
593
601
for _ , test := range updateAndDeleteTests {
594
602
test .run (t , jar )
595
603
}
596
604
}
597
605
598
606
func TestExpiration (t * testing.T ) {
599
- t .Skip ("test is broken on windows/386" ) // issue 4823
600
607
jar := newTestJar ()
601
608
jarTest {
602
- "Fill jar ." ,
609
+ "Expiration ." ,
603
610
"http://www.host.test" ,
604
611
[]string {
605
612
"a=1" ,
606
- "b=2; max-age=1" , // should expire in 1 second
607
- "c=3; " + expiresIn (1 ), // should expire in 1 second
608
- "d=4; max-age=100" ,
613
+ "b=2; max-age=3" ,
614
+ "c=3; " + expiresIn (3 ),
615
+ "d=4; max-age=5" ,
616
+ "e=5; " + expiresIn (5 ),
617
+ "f=6; max-age=100" ,
618
+ },
619
+ "a=1 b=2 c=3 d=4 e=5 f=6" , // executed at t0 + 1001 ms
620
+ []query {
621
+ {"http://www.host.test" , "a=1 b=2 c=3 d=4 e=5 f=6" }, // t0 + 2002 ms
622
+ {"http://www.host.test" , "a=1 d=4 e=5 f=6" }, // t0 + 3003 ms
623
+ {"http://www.host.test" , "a=1 d=4 e=5 f=6" }, // t0 + 4004 ms
624
+ {"http://www.host.test" , "a=1 f=6" }, // t0 + 5005 ms
625
+ {"http://www.host.test" , "a=1 f=6" }, // t0 + 6006 ms
609
626
},
610
- "a=1 b=2 c=3 d=4" ,
611
- []query {{"http://www.host.test" , "a=1 b=2 c=3 d=4" }},
612
- }.run (t , jar )
613
-
614
- time .Sleep (1500 * time .Millisecond )
615
-
616
- jarTest {
617
- "Check jar." ,
618
- "http://www.host.test" ,
619
- []string {},
620
- "a=1 d=4" ,
621
- []query {{"http://www.host.test" , "a=1 d=4" }},
622
627
}.run (t , jar )
623
628
}
624
629
@@ -885,7 +890,6 @@ var chromiumDomainTests = [...]jarTest{
885
890
}
886
891
887
892
func TestChromiumDomain (t * testing.T ) {
888
- t .Skip ("test is broken on windows/amd64" ) // issue 4823
889
893
jar := newTestJar ()
890
894
for _ , test := range chromiumDomainTests {
891
895
test .run (t , jar )
@@ -954,7 +958,6 @@ var chromiumDeletionTests = [...]jarTest{
954
958
}
955
959
956
960
func TestChromiumDeletion (t * testing.T ) {
957
- t .Skip ("test is broken on windows/386" ) // issue 4823
958
961
jar := newTestJar ()
959
962
for _ , test := range chromiumDeletionTests {
960
963
test .run (t , jar )
0 commit comments