tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Basics.cpp (2382B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "gtest/gtest.h"
      8 #include "mozilla/Preferences.h"
      9 
     10 using namespace mozilla;
     11 
     12 TEST(PrefsBasics, Errors)
     13 {
     14  Preferences::SetBool("foo.bool", true, PrefValueKind::Default);
     15  Preferences::SetBool("foo.bool", false, PrefValueKind::User);
     16  ASSERT_EQ(Preferences::GetBool("foo.bool", false, PrefValueKind::Default),
     17            true);
     18  ASSERT_EQ(Preferences::GetBool("foo.bool", true, PrefValueKind::User), false);
     19 
     20  Preferences::SetInt("foo.int", -66, PrefValueKind::Default);
     21  Preferences::SetInt("foo.int", -77, PrefValueKind::User);
     22  ASSERT_EQ(Preferences::GetInt("foo.int", 1, PrefValueKind::Default), -66);
     23  ASSERT_EQ(Preferences::GetInt("foo.int", 1, PrefValueKind::User), -77);
     24 
     25  Preferences::SetUint("foo.uint", 88, PrefValueKind::Default);
     26  Preferences::SetUint("foo.uint", 99, PrefValueKind::User);
     27  ASSERT_EQ(Preferences::GetUint("foo.uint", 1, PrefValueKind::Default), 88U);
     28  ASSERT_EQ(Preferences::GetUint("foo.uint", 1, PrefValueKind::User), 99U);
     29 
     30  Preferences::SetFloat("foo.float", 3.33f, PrefValueKind::Default);
     31  Preferences::SetFloat("foo.float", 4.44f, PrefValueKind::User);
     32  ASSERT_FLOAT_EQ(
     33      Preferences::GetFloat("foo.float", 1.0f, PrefValueKind::Default), 3.33f);
     34  ASSERT_FLOAT_EQ(Preferences::GetFloat("foo.float", 1.0f, PrefValueKind::User),
     35                  4.44f);
     36 }
     37 
     38 TEST(PrefsBasics, Serialize)
     39 {
     40  // Ensure that at least this one preference exists
     41  Preferences::SetBool("foo.bool", true, PrefValueKind::Default);
     42  ASSERT_EQ(Preferences::GetBool("foo.bool", false, PrefValueKind::Default),
     43            true);
     44 
     45  nsCString str;
     46  Preferences::SerializePreferences(str, true);
     47  fprintf(stderr, "%s\n", str.Data());
     48  // Assert that some prefs were not sanitized
     49  ASSERT_NE(nullptr, strstr(str.Data(), "B--:"));
     50  ASSERT_NE(nullptr, strstr(str.Data(), "I--:"));
     51  ASSERT_NE(nullptr, strstr(str.Data(), "S--:"));
     52  // Assert that something was sanitized
     53  ASSERT_NE(
     54      nullptr,
     55      strstr(
     56          str.Data(),
     57          "I-S:56/datareporting.policy.dataSubmissionPolicyAcceptedVersion"));
     58 }