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.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | #include "mozilla/TimeStamp.h" |
michael@0 | 7 | |
michael@0 | 8 | #include "TestHarness.h" |
michael@0 | 9 | |
michael@0 | 10 | #include "prinrval.h" |
michael@0 | 11 | #include "prthread.h" |
michael@0 | 12 | |
michael@0 | 13 | using mozilla::TimeStamp; |
michael@0 | 14 | using mozilla::TimeDuration; |
michael@0 | 15 | |
michael@0 | 16 | static void Assert(bool aCond, const char* aMsg) |
michael@0 | 17 | { |
michael@0 | 18 | if (aCond) { |
michael@0 | 19 | passed(aMsg); |
michael@0 | 20 | } else { |
michael@0 | 21 | fail("%s", aMsg); |
michael@0 | 22 | } |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | int main(int argc, char** argv) |
michael@0 | 26 | { |
michael@0 | 27 | ScopedXPCOM xpcom("nsTimeStamp"); |
michael@0 | 28 | if (xpcom.failed()) |
michael@0 | 29 | return 1; |
michael@0 | 30 | |
michael@0 | 31 | TimeDuration td; |
michael@0 | 32 | Assert(td.ToSeconds() == 0.0, "TimeDuration default value 0"); |
michael@0 | 33 | Assert(TimeDuration::FromSeconds(5).ToSeconds() == 5.0, |
michael@0 | 34 | "TimeDuration FromSeconds/ToSeconds round-trip"); |
michael@0 | 35 | Assert(TimeDuration::FromMilliseconds(5000).ToSeconds() == 5.0, |
michael@0 | 36 | "TimeDuration FromMilliseconds/ToSeconds round-trip"); |
michael@0 | 37 | Assert(TimeDuration::FromSeconds(1) < TimeDuration::FromSeconds(2), |
michael@0 | 38 | "TimeDuration < operator works"); |
michael@0 | 39 | Assert(!(TimeDuration::FromSeconds(1) < TimeDuration::FromSeconds(1)), |
michael@0 | 40 | "TimeDuration < operator works"); |
michael@0 | 41 | Assert(TimeDuration::FromSeconds(2) > TimeDuration::FromSeconds(1), |
michael@0 | 42 | "TimeDuration > operator works"); |
michael@0 | 43 | Assert(!(TimeDuration::FromSeconds(1) > TimeDuration::FromSeconds(1)), |
michael@0 | 44 | "TimeDuration > operator works"); |
michael@0 | 45 | Assert(TimeDuration::FromSeconds(1) <= TimeDuration::FromSeconds(2), |
michael@0 | 46 | "TimeDuration <= operator works"); |
michael@0 | 47 | Assert(TimeDuration::FromSeconds(1) <= TimeDuration::FromSeconds(1), |
michael@0 | 48 | "TimeDuration <= operator works"); |
michael@0 | 49 | Assert(!(TimeDuration::FromSeconds(2) <= TimeDuration::FromSeconds(1)), |
michael@0 | 50 | "TimeDuration <= operator works"); |
michael@0 | 51 | Assert(TimeDuration::FromSeconds(2) >= TimeDuration::FromSeconds(1), |
michael@0 | 52 | "TimeDuration >= operator works"); |
michael@0 | 53 | Assert(TimeDuration::FromSeconds(1) >= TimeDuration::FromSeconds(1), |
michael@0 | 54 | "TimeDuration >= operator works"); |
michael@0 | 55 | Assert(!(TimeDuration::FromSeconds(1) >= TimeDuration::FromSeconds(2)), |
michael@0 | 56 | "TimeDuration >= operator works"); |
michael@0 | 57 | |
michael@0 | 58 | TimeStamp ts; |
michael@0 | 59 | Assert(ts.IsNull(), "Default TimeStamp value null"); |
michael@0 | 60 | |
michael@0 | 61 | ts = TimeStamp::Now(); |
michael@0 | 62 | Assert(!ts.IsNull(), "TimeStamp time value non-null"); |
michael@0 | 63 | Assert((ts - ts).ToSeconds() == 0.0, "TimeStamp zero-length duration"); |
michael@0 | 64 | |
michael@0 | 65 | PR_Sleep(PR_SecondsToInterval(2)); |
michael@0 | 66 | |
michael@0 | 67 | TimeStamp ts2(TimeStamp::Now()); |
michael@0 | 68 | Assert(ts2 > ts, "TimeStamp > comparison"); |
michael@0 | 69 | Assert(!(ts > ts), "TimeStamp > comparison"); |
michael@0 | 70 | Assert(ts < ts2, "TimeStamp < comparison"); |
michael@0 | 71 | Assert(!(ts < ts), "TimeStamp < comparison"); |
michael@0 | 72 | Assert(ts <= ts2, "TimeStamp <= comparison"); |
michael@0 | 73 | Assert(ts <= ts, "TimeStamp <= comparison"); |
michael@0 | 74 | Assert(!(ts2 <= ts), "TimeStamp <= comparison"); |
michael@0 | 75 | Assert(ts2 >= ts, "TimeStamp >= comparison"); |
michael@0 | 76 | Assert(ts2 >= ts, "TimeStamp >= comparison"); |
michael@0 | 77 | Assert(!(ts >= ts2), "TimeStamp >= comparison"); |
michael@0 | 78 | |
michael@0 | 79 | // We can't be sure exactly how long PR_Sleep slept for. It should have |
michael@0 | 80 | // slept for at least one second. We might have slept a lot longer due |
michael@0 | 81 | // to process scheduling, but hopefully not more than 10 seconds. |
michael@0 | 82 | td = ts2 - ts; |
michael@0 | 83 | Assert(td.ToSeconds() > 1.0, "TimeStamp difference lower bound"); |
michael@0 | 84 | Assert(td.ToSeconds() < 20.0, "TimeStamp difference upper bound"); |
michael@0 | 85 | td = ts - ts2; |
michael@0 | 86 | Assert(td.ToSeconds() < -1.0, "TimeStamp negative difference lower bound"); |
michael@0 | 87 | Assert(td.ToSeconds() > -20.0, "TimeStamp negative difference upper bound"); |
michael@0 | 88 | |
michael@0 | 89 | double resolution = TimeDuration::Resolution().ToSecondsSigDigits(); |
michael@0 | 90 | printf(" (platform timer resolution is ~%g s)\n", resolution); |
michael@0 | 91 | Assert(0.000000001 < resolution, "Time resolution is sane"); |
michael@0 | 92 | // Don't upper-bound sanity check ... although NSPR reports 1ms |
michael@0 | 93 | // resolution, it might be lying, so we shouldn't compare with it |
michael@0 | 94 | |
michael@0 | 95 | return gFailCount > 0; |
michael@0 | 96 | } |