tor-browser

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

TestClientStorageScope.cpp (3743B)


      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/ClientStorageScope.h"
      9 
     10 namespace mozilla::dom::quota {
     11 
     12 TEST(DOM_Quota_ClientStorageScope, SanityChecks)
     13 {
     14  // Sanity checks.
     15 
     16  {
     17    const auto clientStorageScope(
     18        ClientStorageScope::CreateFromClient(Client::IDB));
     19    ASSERT_TRUE(clientStorageScope.IsClient());
     20    ASSERT_EQ(clientStorageScope.GetClientType(), Client::IDB);
     21  }
     22 
     23  {
     24    const auto clientStorageScope(ClientStorageScope::CreateFromMetadata());
     25    ASSERT_TRUE(clientStorageScope.IsMetadata());
     26  }
     27 
     28  {
     29    const auto clientStorageScope(ClientStorageScope::CreateFromNull());
     30    ASSERT_TRUE(clientStorageScope.IsNull());
     31  }
     32 }
     33 
     34 TEST(DOM_Quota_ClientStorageScope, MatchesClient)
     35 {
     36  // Test each client storage scope type against particular client types.
     37 
     38  {
     39    const auto clientStorageScope(
     40        ClientStorageScope::CreateFromClient(Client::IDB));
     41 
     42    ASSERT_TRUE(clientStorageScope.Matches(
     43        ClientStorageScope::CreateFromClient(Client::IDB)));
     44    ASSERT_FALSE(clientStorageScope.Matches(
     45        ClientStorageScope::CreateFromClient(Client::DOMCACHE)));
     46    ASSERT_FALSE(clientStorageScope.Matches(
     47        ClientStorageScope::CreateFromClient(Client::SDB)));
     48    ASSERT_FALSE(clientStorageScope.Matches(
     49        ClientStorageScope::CreateFromClient(Client::FILESYSTEM)));
     50    ASSERT_FALSE(clientStorageScope.Matches(
     51        ClientStorageScope::CreateFromClient(Client::LS)));
     52  }
     53 
     54  {
     55    const auto clientStorageScope(ClientStorageScope::CreateFromMetadata());
     56 
     57    ASSERT_FALSE(clientStorageScope.Matches(
     58        ClientStorageScope::CreateFromClient(Client::IDB)));
     59    ASSERT_FALSE(clientStorageScope.Matches(
     60        ClientStorageScope::CreateFromClient(Client::DOMCACHE)));
     61    ASSERT_FALSE(clientStorageScope.Matches(
     62        ClientStorageScope::CreateFromClient(Client::SDB)));
     63    ASSERT_FALSE(clientStorageScope.Matches(
     64        ClientStorageScope::CreateFromClient(Client::FILESYSTEM)));
     65    ASSERT_FALSE(clientStorageScope.Matches(
     66        ClientStorageScope::CreateFromClient(Client::LS)));
     67  }
     68 
     69  {
     70    const auto clientStorageScope(ClientStorageScope::CreateFromNull());
     71 
     72    ASSERT_TRUE(clientStorageScope.Matches(
     73        ClientStorageScope::CreateFromClient(Client::IDB)));
     74    ASSERT_TRUE(clientStorageScope.Matches(
     75        ClientStorageScope::CreateFromClient(Client::DOMCACHE)));
     76    ASSERT_TRUE(clientStorageScope.Matches(
     77        ClientStorageScope::CreateFromClient(Client::SDB)));
     78    ASSERT_TRUE(clientStorageScope.Matches(
     79        ClientStorageScope::CreateFromClient(Client::FILESYSTEM)));
     80    ASSERT_TRUE(clientStorageScope.Matches(
     81        ClientStorageScope::CreateFromClient(Client::LS)));
     82  }
     83 }
     84 
     85 TEST(DOM_Quota_ClientStorageScope, MatchesMetadata)
     86 {
     87  // Test each client storage scope type against particular client types.
     88 
     89  {
     90    const auto clientStorageScope(
     91        ClientStorageScope::CreateFromClient(Client::IDB));
     92 
     93    ASSERT_FALSE(
     94        clientStorageScope.Matches(ClientStorageScope::CreateFromMetadata()));
     95  }
     96 
     97  {
     98    const auto clientStorageScope(ClientStorageScope::CreateFromMetadata());
     99 
    100    ASSERT_TRUE(
    101        clientStorageScope.Matches(ClientStorageScope::CreateFromMetadata()));
    102  }
    103 
    104  {
    105    const auto clientStorageScope(ClientStorageScope::CreateFromNull());
    106 
    107    ASSERT_TRUE(
    108        clientStorageScope.Matches(ClientStorageScope::CreateFromMetadata()));
    109  }
    110 }
    111 
    112 }  //  namespace mozilla::dom::quota