tor-browser

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

TestClientDirectoryLockHandle.cpp (2700B)


      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 "QuotaManagerDependencyFixture.h"
      8 #include "mozilla/dom/quota/ClientDirectoryLockHandle.h"
      9 #include "mozilla/dom/quota/ConditionalCompilation.h"
     10 
     11 namespace mozilla::dom::quota::test {
     12 
     13 class DOM_Quota_ClientDirectoryLockHandle
     14    : public QuotaManagerDependencyFixture {
     15 public:
     16  static void SetUpTestCase() { ASSERT_NO_FATAL_FAILURE(InitializeFixture()); }
     17 
     18  static void TearDownTestCase() { ASSERT_NO_FATAL_FAILURE(ShutdownFixture()); }
     19 };
     20 
     21 TEST_F(DOM_Quota_ClientDirectoryLockHandle, DefaultConstruction) {
     22  PerformClientDirectoryLockTest(
     23      GetTestClientMetadata(), [](RefPtr<ClientDirectoryLock> aDirectoryLock) {
     24        ASSERT_TRUE(aDirectoryLock);
     25 
     26        ClientDirectoryLockHandle handle;
     27 
     28        EXPECT_FALSE(handle);
     29 
     30        DIAGNOSTICONLY(EXPECT_TRUE(handle.IsInert()));
     31 
     32        aDirectoryLock->Drop();
     33      });
     34 }
     35 
     36 TEST_F(DOM_Quota_ClientDirectoryLockHandle, ConstructionWithLock) {
     37  PerformClientDirectoryLockTest(
     38      GetTestClientMetadata(), [](RefPtr<ClientDirectoryLock> aDirectoryLock) {
     39        ASSERT_TRUE(aDirectoryLock);
     40 
     41        ClientDirectoryLockHandle handle(std::move(aDirectoryLock));
     42 
     43        EXPECT_TRUE(handle);
     44 
     45        DIAGNOSTICONLY(EXPECT_FALSE(handle.IsInert()));
     46      });
     47 }
     48 
     49 TEST_F(DOM_Quota_ClientDirectoryLockHandle, MoveConstruction) {
     50  PerformClientDirectoryLockTest(
     51      GetTestClientMetadata(), [](RefPtr<ClientDirectoryLock> aDirectoryLock) {
     52        ASSERT_TRUE(aDirectoryLock);
     53 
     54        ClientDirectoryLockHandle handle1(std::move(aDirectoryLock));
     55        ClientDirectoryLockHandle handle2(std::move(handle1));
     56 
     57        EXPECT_FALSE(handle1);
     58        EXPECT_TRUE(handle2);
     59 
     60        DIAGNOSTICONLY(EXPECT_TRUE(handle1.IsInert()));
     61        DIAGNOSTICONLY(EXPECT_FALSE(handle2.IsInert()));
     62      });
     63 }
     64 
     65 TEST_F(DOM_Quota_ClientDirectoryLockHandle, MoveAssignment) {
     66  PerformClientDirectoryLockTest(
     67      GetTestClientMetadata(), [](RefPtr<ClientDirectoryLock> aDirectoryLock) {
     68        ASSERT_TRUE(aDirectoryLock);
     69 
     70        ClientDirectoryLockHandle handle1(std::move(aDirectoryLock));
     71        ClientDirectoryLockHandle handle2;
     72        handle2 = std::move(handle1);
     73 
     74        EXPECT_FALSE(handle1);
     75        EXPECT_TRUE(handle2);
     76 
     77        DIAGNOSTICONLY(EXPECT_TRUE(handle1.IsInert()));
     78        DIAGNOSTICONLY(EXPECT_FALSE(handle2.IsInert()));
     79      });
     80 }
     81 
     82 }  // namespace mozilla::dom::quota::test