Files
sousa-gecko/caps/tests/gtest/TestPrincipalHash.cpp
T
Emilio Cobos Álvarez c33f976fda Bug 2054311 - Sort headers in caps/. r=tschuster
Autogenerated with:

    cp dom/.clang-format caps/ && mach format caps/**.{cpp,h}

No manual changes required.

Differential Revision: https://phabricator.services.mozilla.com/D311689
2026-07-13 11:08:21 +00:00

29 lines
975 B
C++

/* 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, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "gtest/gtest.h"
#include "mozilla/gtest/MozAssertions.h"
#include "nsIPrincipal.h"
#include "nsNetUtil.h"
#include "nsScriptSecurityManager.h"
TEST(PrincipalHash, DocumentDomain)
{
nsCOMPtr<nsIScriptSecurityManager> ssm =
nsScriptSecurityManager::GetScriptSecurityManager();
nsCOMPtr<nsIPrincipal> principal;
nsresult rv = ssm->CreateContentPrincipalFromOrigin(
"https://sub.mozilla.org"_ns, getter_AddRefs(principal));
EXPECT_NS_SUCCEEDED(rv);
const auto hash = principal->GetHashValue();
nsCOMPtr<nsIURI> domain;
rv = NS_NewURI(getter_AddRefs(domain), "https://mozilla.org"_ns);
EXPECT_NS_SUCCEEDED(rv);
principal->SetDomain(domain);
ASSERT_EQ(principal->GetHashValue(), hash)
<< "Principal hash shouldn't change";
}