Source code
Revision control
Copy as Markdown
Other Tools
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
#include "gtest/gtest.h"
#include "mozilla/StorageOriginAttributes.h"
namespace mozilla::dom::quota::test {
TEST(DOM_Quota_StorageOriginAttributes, Constructor_Default)
{
{
StorageOriginAttributes originAttributes;
ASSERT_FALSE(originAttributes.InIsolatedMozBrowser());
ASSERT_EQ(originAttributes.UserContextId(), 0u);
}
}
TEST(DOM_Quota_StorageOriginAttributes, Constructor_InIsolatedMozbrowser)
{
{
StorageOriginAttributes originAttributes(/* aInIsolatedMozBrowser */ false);
ASSERT_FALSE(originAttributes.InIsolatedMozBrowser());
ASSERT_EQ(originAttributes.UserContextId(), 0u);
}
{
StorageOriginAttributes originAttributes(/* aInIsolatedMozBrowser */ true);
ASSERT_TRUE(originAttributes.InIsolatedMozBrowser());
ASSERT_EQ(originAttributes.UserContextId(), 0u);
}
}
TEST(DOM_Quota_StorageOriginAttributes, PopulateFromOrigin_NoOriginAttributes)
{
{
StorageOriginAttributes originAttributes;
nsCString originNoSuffix;
originNoSuffix);
ASSERT_TRUE(ok);
ASSERT_FALSE(originAttributes.InIsolatedMozBrowser());
}
}
TEST(DOM_Quota_StorageOriginAttributes,
PopulateFromOrigin_InvalidOriginAttribute)
{
{
StorageOriginAttributes originAttributes;
nsCString originNoSuffix;
bool ok = originAttributes.PopulateFromOrigin(
ASSERT_FALSE(ok);
ASSERT_FALSE(originAttributes.InIsolatedMozBrowser());
}
}
TEST(DOM_Quota_StorageOriginAttributes,
PopulateFromOrigin_InIsolatedMozBrowser_Valid)
{
{
StorageOriginAttributes originAttributes;
nsCString originNoSuffix;
bool ok = originAttributes.PopulateFromOrigin(
ASSERT_TRUE(ok);
ASSERT_TRUE(originAttributes.InIsolatedMozBrowser());
}
}
TEST(DOM_Quota_StorageOriginAttributes,
PopulateFromOrigin_InIsolatedMozBrowser_Invalid)
{
{
StorageOriginAttributes originAttributes;
nsCString originNoSuffix;
bool ok = originAttributes.PopulateFromOrigin(
ASSERT_FALSE(ok);
ASSERT_FALSE(originAttributes.InIsolatedMozBrowser());
}
{
StorageOriginAttributes originAttributes;
nsCString originNoSuffix;
bool ok = originAttributes.PopulateFromOrigin(
ASSERT_FALSE(ok);
ASSERT_FALSE(originAttributes.InIsolatedMozBrowser());
}
{
StorageOriginAttributes originAttributes;
nsCString originNoSuffix;
bool ok = originAttributes.PopulateFromOrigin(
ASSERT_FALSE(ok);
ASSERT_FALSE(originAttributes.InIsolatedMozBrowser());
}
}
TEST(DOM_Quota_StorageOriginAttributes, PopulateFromOrigin_UserContextId_Valid)
{
{
StorageOriginAttributes originAttributes;
nsCString originNoSuffix;
bool ok = originAttributes.PopulateFromOrigin(
ASSERT_TRUE(ok);
ASSERT_EQ(originAttributes.UserContextId(), 1u);
}
{
StorageOriginAttributes originAttributes;
nsCString originNoSuffix;
bool ok = originAttributes.PopulateFromOrigin(
ASSERT_TRUE(ok);
ASSERT_EQ(originAttributes.UserContextId(), 42u);
}
}
TEST(DOM_Quota_StorageOriginAttributes,
PopulateFromOrigin_UserContextId_Invalid)
{
{
StorageOriginAttributes originAttributes;
nsCString originNoSuffix;
bool ok = originAttributes.PopulateFromOrigin(
ASSERT_FALSE(ok);
ASSERT_EQ(originAttributes.UserContextId(), 0u);
}
}
TEST(DOM_Quota_StorageOriginAttributes, PopulateFromOrigin_Mixed_Valid)
{
{
StorageOriginAttributes originAttributes;
nsCString originNoSuffix;
bool ok = originAttributes.PopulateFromOrigin(
originNoSuffix);
ASSERT_TRUE(ok);
ASSERT_TRUE(originAttributes.InIsolatedMozBrowser());
ASSERT_EQ(originAttributes.UserContextId(), 1u);
}
}
TEST(DOM_Quota_StorageOriginAttributes, PopulateFromOrigin_Mixed_Invalid)
{
{
StorageOriginAttributes originAttributes;
nsCString originNoSuffix;
bool ok = originAttributes.PopulateFromOrigin(
originNoSuffix);
ASSERT_FALSE(ok);
ASSERT_TRUE(originAttributes.InIsolatedMozBrowser());
ASSERT_EQ(originAttributes.UserContextId(), 1u);
}
}
TEST(DOM_Quota_StorageOriginAttributes, CreateSuffix_NoOriginAttributes)
{
{
StorageOriginAttributes originAttributes;
nsCString suffix;
originAttributes.CreateSuffix(suffix);
ASSERT_TRUE(suffix.IsEmpty());
}
}
TEST(DOM_Quota_StorageOriginAttributes, CreateSuffix_InIsolatedMozbrowser)
{
{
StorageOriginAttributes originAttributes;
originAttributes.SetInIsolatedMozBrowser(true);
nsCString suffix;
originAttributes.CreateSuffix(suffix);
ASSERT_TRUE(suffix.Equals("^inBrowser=1"_ns));
}
}
TEST(DOM_Quota_StorageOriginAttributes, CreateSuffix_UserContextId)
{
{
StorageOriginAttributes originAttributes;
originAttributes.SetUserContextId(42);
nsCString suffix;
originAttributes.CreateSuffix(suffix);
ASSERT_TRUE(suffix.Equals("^userContextId=42"_ns));
}
}
TEST(DOM_Quota_StorageOriginAttributes, CreateSuffix_Mixed)
{
{
StorageOriginAttributes originAttributes;
originAttributes.SetInIsolatedMozBrowser(true);
originAttributes.SetUserContextId(42);
nsCString suffix;
originAttributes.CreateSuffix(suffix);
ASSERT_TRUE(suffix.Equals("^inBrowser=1&userContextId=42"_ns));
}
}
} // namespace mozilla::dom::quota::test