Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #include "js/StructuredClone.h"
7 #include "jsapi-tests/tests.h"
9 BEGIN_TEST(testStructuredClone_object)
10 {
11 JS::RootedObject g1(cx, createGlobal());
12 JS::RootedObject g2(cx, createGlobal());
13 CHECK(g1);
14 CHECK(g2);
16 JS::RootedValue v1(cx);
18 {
19 JSAutoCompartment ac(cx, g1);
20 JS::RootedValue prop(cx, JS::Int32Value(1337));
22 JS::RootedObject obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()));
23 v1 = JS::ObjectOrNullValue(obj);
24 CHECK(v1.isObject());
25 CHECK(JS_SetProperty(cx, obj, "prop", prop));
26 }
28 {
29 JSAutoCompartment ac(cx, g2);
30 JS::RootedValue v2(cx);
32 CHECK(JS_StructuredClone(cx, v1, &v2, nullptr, nullptr));
33 CHECK(v2.isObject());
34 JS::RootedObject obj(cx, &v2.toObject());
36 JS::RootedValue prop(cx);
37 CHECK(JS_GetProperty(cx, obj, "prop", &prop));
38 CHECK(prop.isInt32());
39 CHECK(&v1.toObject() != obj);
40 CHECK_EQUAL(prop.toInt32(), 1337);
41 }
43 return true;
44 }
45 END_TEST(testStructuredClone_object)
47 BEGIN_TEST(testStructuredClone_string)
48 {
49 JS::RootedObject g1(cx, createGlobal());
50 JS::RootedObject g2(cx, createGlobal());
51 CHECK(g1);
52 CHECK(g2);
54 JS::RootedValue v1(cx);
56 {
57 JSAutoCompartment ac(cx, g1);
58 JS::RootedValue prop(cx, JS::Int32Value(1337));
60 v1 = JS::StringValue(JS_NewStringCopyZ(cx, "Hello World!"));
61 CHECK(v1.isString());
62 CHECK(v1.toString());
63 }
65 {
66 JSAutoCompartment ac(cx, g2);
67 JS::RootedValue v2(cx);
69 CHECK(JS_StructuredClone(cx, v1, &v2, nullptr, nullptr));
70 CHECK(v2.isString());
71 CHECK(v2.toString());
73 JS::RootedValue expected(cx, JS::StringValue(
74 JS_NewStringCopyZ(cx, "Hello World!")));
75 CHECK_SAME(v2, expected);
76 }
78 return true;
79 }
80 END_TEST(testStructuredClone_string)