tor-browser

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

TestPersistenceScope.cpp (5099B)


      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 file,
      5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "gtest/gtest.h"
      8 #include "mozilla/dom/quota/PersistenceScope.h"
      9 
     10 namespace mozilla::dom::quota {
     11 
     12 TEST(DOM_Quota_PersistenceScope, SanityChecks)
     13 {
     14  // Sanity checks.
     15 
     16  {
     17    const auto persistenceScope(
     18        PersistenceScope::CreateFromValue(PERSISTENCE_TYPE_PERSISTENT));
     19    ASSERT_TRUE(persistenceScope.IsValue());
     20    ASSERT_EQ(persistenceScope.GetValue(), PERSISTENCE_TYPE_PERSISTENT);
     21  }
     22 
     23  {
     24    const auto persistenceScope(PersistenceScope::CreateFromNull());
     25    ASSERT_TRUE(persistenceScope.IsNull());
     26  }
     27 }
     28 
     29 TEST(DOM_Quota_PersistenceScope, MatchesValue)
     30 {
     31  // Test each persistence scope type against particular persistence types.
     32 
     33  {
     34    const auto persistenceScope(
     35        PersistenceScope::CreateFromValue(PERSISTENCE_TYPE_PERSISTENT));
     36 
     37    ASSERT_TRUE(persistenceScope.Matches(
     38        PersistenceScope::CreateFromValue(PERSISTENCE_TYPE_PERSISTENT)));
     39    ASSERT_FALSE(persistenceScope.Matches(
     40        PersistenceScope::CreateFromValue(PERSISTENCE_TYPE_TEMPORARY)));
     41    ASSERT_FALSE(persistenceScope.Matches(
     42        PersistenceScope::CreateFromValue(PERSISTENCE_TYPE_DEFAULT)));
     43    ASSERT_FALSE(persistenceScope.Matches(
     44        PersistenceScope::CreateFromValue(PERSISTENCE_TYPE_PRIVATE)));
     45  }
     46 
     47  {
     48    const auto persistenceScope(PersistenceScope::CreateFromSet(
     49        PERSISTENCE_TYPE_TEMPORARY, PERSISTENCE_TYPE_DEFAULT));
     50 
     51    ASSERT_FALSE(persistenceScope.Matches(
     52        PersistenceScope::CreateFromValue(PERSISTENCE_TYPE_PERSISTENT)));
     53    ASSERT_TRUE(persistenceScope.Matches(
     54        PersistenceScope::CreateFromValue(PERSISTENCE_TYPE_TEMPORARY)));
     55    ASSERT_TRUE(persistenceScope.Matches(
     56        PersistenceScope::CreateFromValue(PERSISTENCE_TYPE_DEFAULT)));
     57    ASSERT_FALSE(persistenceScope.Matches(
     58        PersistenceScope::CreateFromValue(PERSISTENCE_TYPE_PRIVATE)));
     59  }
     60 
     61  {
     62    const auto persistenceScope(PersistenceScope::CreateFromNull());
     63 
     64    ASSERT_TRUE(persistenceScope.Matches(
     65        PersistenceScope::CreateFromValue(PERSISTENCE_TYPE_PERSISTENT)));
     66    ASSERT_TRUE(persistenceScope.Matches(
     67        PersistenceScope::CreateFromValue(PERSISTENCE_TYPE_TEMPORARY)));
     68    ASSERT_TRUE(persistenceScope.Matches(
     69        PersistenceScope::CreateFromValue(PERSISTENCE_TYPE_DEFAULT)));
     70    ASSERT_TRUE(persistenceScope.Matches(
     71        PersistenceScope::CreateFromValue(PERSISTENCE_TYPE_PRIVATE)));
     72  }
     73 }
     74 
     75 TEST(DOM_Quota_PersistenceScope, MatchesSet)
     76 {
     77  // Test each persistence scope type against particular persistence types.
     78 
     79  {
     80    const auto persistenceScope(
     81        PersistenceScope::CreateFromValue(PERSISTENCE_TYPE_PERSISTENT));
     82 
     83    ASSERT_TRUE(persistenceScope.Matches(
     84        PersistenceScope::CreateFromSet(PERSISTENCE_TYPE_PERSISTENT)));
     85    ASSERT_TRUE(persistenceScope.Matches(PersistenceScope::CreateFromSet(
     86        PERSISTENCE_TYPE_PERSISTENT, PERSISTENCE_TYPE_TEMPORARY)));
     87    ASSERT_TRUE(persistenceScope.Matches(PersistenceScope::CreateFromSet(
     88        PERSISTENCE_TYPE_PERSISTENT, PERSISTENCE_TYPE_TEMPORARY,
     89        PERSISTENCE_TYPE_DEFAULT)));
     90    ASSERT_TRUE(persistenceScope.Matches(PersistenceScope::CreateFromSet(
     91        PERSISTENCE_TYPE_PERSISTENT, PERSISTENCE_TYPE_TEMPORARY,
     92        PERSISTENCE_TYPE_DEFAULT, PERSISTENCE_TYPE_PRIVATE)));
     93  }
     94 
     95  {
     96    const auto persistenceScope(PersistenceScope::CreateFromSet(
     97        PERSISTENCE_TYPE_TEMPORARY, PERSISTENCE_TYPE_DEFAULT));
     98 
     99    ASSERT_FALSE(persistenceScope.Matches(
    100        PersistenceScope::CreateFromSet(PERSISTENCE_TYPE_PERSISTENT)));
    101    ASSERT_TRUE(persistenceScope.Matches(PersistenceScope::CreateFromSet(
    102        PERSISTENCE_TYPE_PERSISTENT, PERSISTENCE_TYPE_TEMPORARY)));
    103    ASSERT_TRUE(persistenceScope.Matches(PersistenceScope::CreateFromSet(
    104        PERSISTENCE_TYPE_PERSISTENT, PERSISTENCE_TYPE_TEMPORARY,
    105        PERSISTENCE_TYPE_DEFAULT)));
    106    ASSERT_TRUE(persistenceScope.Matches(PersistenceScope::CreateFromSet(
    107        PERSISTENCE_TYPE_PERSISTENT, PERSISTENCE_TYPE_TEMPORARY,
    108        PERSISTENCE_TYPE_DEFAULT, PERSISTENCE_TYPE_PRIVATE)));
    109  }
    110 
    111  {
    112    const auto persistenceScope(PersistenceScope::CreateFromNull());
    113 
    114    ASSERT_TRUE(persistenceScope.Matches(
    115        PersistenceScope::CreateFromSet(PERSISTENCE_TYPE_PERSISTENT)));
    116    ASSERT_TRUE(persistenceScope.Matches(PersistenceScope::CreateFromSet(
    117        PERSISTENCE_TYPE_PERSISTENT, PERSISTENCE_TYPE_TEMPORARY)));
    118    ASSERT_TRUE(persistenceScope.Matches(PersistenceScope::CreateFromSet(
    119        PERSISTENCE_TYPE_PERSISTENT, PERSISTENCE_TYPE_TEMPORARY,
    120        PERSISTENCE_TYPE_DEFAULT)));
    121    ASSERT_TRUE(persistenceScope.Matches(PersistenceScope::CreateFromSet(
    122        PERSISTENCE_TYPE_PERSISTENT, PERSISTENCE_TYPE_TEMPORARY,
    123        PERSISTENCE_TYPE_DEFAULT, PERSISTENCE_TYPE_PRIVATE)));
    124  }
    125 }
    126 
    127 }  //  namespace mozilla::dom::quota