tor-browser

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

TestPersistenceType.cpp (1496B)


      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/PersistenceType.h"
      9 #include "nsDirectoryServiceDefs.h"
     10 #include "nsDirectoryServiceUtils.h"
     11 #include "nsIFile.h"
     12 
     13 namespace mozilla::dom::quota {
     14 
     15 TEST(PersistenceType, FromFile)
     16 {
     17  nsCOMPtr<nsIFile> base;
     18  nsresult rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(base));
     19  EXPECT_EQ(rv, NS_OK);
     20 
     21  const auto testPersistenceType = [&base](const nsLiteralString& aString,
     22                                           const Maybe<PersistenceType> aType) {
     23    nsCOMPtr<nsIFile> file;
     24 
     25    nsresult rv = base->Clone(getter_AddRefs(file));
     26    EXPECT_EQ(rv, NS_OK);
     27 
     28    rv = file->Append(aString);
     29    EXPECT_EQ(rv, NS_OK);
     30 
     31    auto maybePersistenceType = PersistenceTypeFromFile(*file, fallible);
     32    EXPECT_EQ(maybePersistenceType, aType);
     33  };
     34 
     35  testPersistenceType(u"permanent"_ns, Some(PERSISTENCE_TYPE_PERSISTENT));
     36  testPersistenceType(u"temporary"_ns, Some(PERSISTENCE_TYPE_TEMPORARY));
     37  testPersistenceType(u"default"_ns, Some(PERSISTENCE_TYPE_DEFAULT));
     38  testPersistenceType(u"persistent"_ns, Nothing());
     39  testPersistenceType(u"foobar"_ns, Nothing());
     40 }
     41 
     42 }  // namespace mozilla::dom::quota