TestPrincipalAttributes.cpp (1303B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 #include "gtest/gtest.h" 5 #include "mozilla/BasePrincipal.h" 6 #include "nsScriptSecurityManager.h" 7 8 using namespace mozilla; 9 10 class PrincipalAttributesParam { 11 public: 12 nsAutoCString spec; 13 bool expectIsIpAddress; 14 }; 15 16 class PrincipalAttributesTest 17 : public ::testing::TestWithParam<PrincipalAttributesParam> {}; 18 19 TEST_P(PrincipalAttributesTest, PrincipalAttributesTest) { 20 nsCOMPtr<nsIScriptSecurityManager> ssm = 21 nsScriptSecurityManager::GetScriptSecurityManager(); 22 23 nsAutoCString spec(GetParam().spec); 24 nsCOMPtr<nsIPrincipal> principal; 25 nsresult rv = 26 ssm->CreateContentPrincipalFromOrigin(spec, getter_AddRefs(principal)); 27 ASSERT_EQ(rv, NS_OK); 28 29 ASSERT_EQ(principal->GetIsIpAddress(), GetParam().expectIsIpAddress); 30 } 31 32 MOZ_RUNINIT static const PrincipalAttributesParam kAttributes[] = { 33 {nsAutoCString("https://mozilla.com"), false}, 34 {nsAutoCString("https://127.0.0.1"), true}, 35 {nsAutoCString("https://[::1]"), true}, 36 }; 37 38 INSTANTIATE_TEST_SUITE_P(TestPrincipalAttributes, PrincipalAttributesTest, 39 ::testing::ValuesIn(kAttributes));