Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/CookieHandler/NullUriCookieTest.java
41149 views
1
/*
2
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 6953455 7045655
27
* @summary CookieStore.add() cannot handle null URI parameter
28
* and An empty InMemoryCookieStore should not return true for removeAll
29
*/
30
31
import java.net.CookieManager;
32
import java.net.CookieStore;
33
import java.net.HttpCookie;
34
import java.net.URI;
35
import java.net.URISyntaxException;
36
import java.util.List;
37
38
public class NullUriCookieTest {
39
static boolean fail = false;
40
41
public static void main(String[] args) throws Exception {
42
checkCookieNullUri();
43
}
44
45
static void checkCookieNullUri() throws Exception {
46
//get a cookie store implementation and add a cookie to the store with null URI
47
CookieStore cookieStore = (new CookieManager()).getCookieStore();
48
//Check if removeAll() retrurns false on an empty CookieStore
49
if (cookieStore.removeAll()) {
50
fail = true;
51
}
52
checkFail("removeAll on empty store should return false");
53
HttpCookie cookie = new HttpCookie("MY_COOKIE", "MY_COOKIE_VALUE");
54
cookie.setDomain("foo.com");
55
cookieStore.add(null, cookie);
56
57
//Retrieve added cookie
58
URI uri = new URI("http://foo.com");
59
List<HttpCookie> addedCookieList = cookieStore.get(uri);
60
61
//Verify CookieStore behaves well
62
if (addedCookieList.size() != 1) {
63
fail = true;
64
}
65
checkFail("Abnormal size of cookie jar");
66
67
for (HttpCookie chip : addedCookieList) {
68
if (!chip.equals(cookie)) {
69
fail = true;
70
}
71
}
72
checkFail("Cookie not retrieved from Cookie Jar");
73
boolean ret = cookieStore.remove(null,cookie);
74
if (!ret) {
75
fail = true;
76
}
77
checkFail("Abnormal removal behaviour from Cookie Jar");
78
}
79
80
static void checkFail(String exp) {
81
if (fail) {
82
throw new RuntimeException(exp);
83
}
84
}
85
}
86
87
88