Index: third_party/WebKit/Source/core/html/HTMLIFrameElementTest.cpp |
diff --git a/third_party/WebKit/Source/core/html/HTMLIFrameElementTest.cpp b/third_party/WebKit/Source/core/html/HTMLIFrameElementTest.cpp |
index 5a5b3fb565cbd7453b2e5c9430b86743122075b5..f08d9bff1ded6e01ef7a89beb58acd0430c3b013 100644 |
--- a/third_party/WebKit/Source/core/html/HTMLIFrameElementTest.cpp |
+++ b/third_party/WebKit/Source/core/html/HTMLIFrameElementTest.cpp |
@@ -285,4 +285,125 @@ TEST_F(HTMLIFrameElementTest, SameOriginSandboxAttributeContainerPolicy) { |
EXPECT_EQ("http://example.net", container_policy[0].origins[0].ToString()); |
} |
+// Test the ConstructContainerPolicy method when no attributes are set on the |
+// iframe element. |
+TEST_F(HTMLIFrameElementTest, ConstructEmptyContainerPolicy) { |
+ Document* document = Document::Create(); |
+ KURL document_url = KURL(KURL(), "http://example.com"); |
+ document->SetURL(document_url); |
+ document->UpdateSecurityOrigin(SecurityOrigin::Create(document_url)); |
+ |
+ HTMLIFrameElement* frame_element = HTMLIFrameElement::Create(*document); |
+ |
+ WebParsedFeaturePolicy container_policy = |
+ frame_element->ConstructContainerPolicy(); |
+ EXPECT_EQ(0UL, container_policy.size()); |
+} |
+ |
+// Test the ConstructContainerPolicy method when the "allow" attribute is used |
+// to enable features in the frame. |
+TEST_F(HTMLIFrameElementTest, ConstructContainerPolicy) { |
+ Document* document = Document::Create(); |
+ KURL document_url = KURL(KURL(), "http://example.com"); |
+ document->SetURL(document_url); |
+ document->UpdateSecurityOrigin(SecurityOrigin::Create(document_url)); |
+ |
+ HTMLIFrameElement* frame_element = HTMLIFrameElement::Create(*document); |
+ frame_element->setAttribute(HTMLNames::allowAttr, "payment usb"); |
+ WebParsedFeaturePolicy container_policy = |
+ frame_element->ConstructContainerPolicy(); |
+ EXPECT_EQ(2UL, container_policy.size()); |
+ EXPECT_EQ(WebFeaturePolicyFeature::kPayment, container_policy[0].feature); |
+ EXPECT_FALSE(container_policy[0].matches_all_origins); |
+ EXPECT_EQ(1UL, container_policy[0].origins.size()); |
+ EXPECT_TRUE(GetOriginForFeaturePolicy(frame_element) |
+ ->IsSameSchemeHostPortAndSuborigin( |
+ container_policy[0].origins[0].Get())); |
+ EXPECT_EQ(WebFeaturePolicyFeature::kUsb, container_policy[1].feature); |
+ EXPECT_FALSE(container_policy[1].matches_all_origins); |
+ EXPECT_EQ(1UL, container_policy[1].origins.size()); |
+ EXPECT_TRUE(GetOriginForFeaturePolicy(frame_element) |
+ ->IsSameSchemeHostPortAndSuborigin( |
+ container_policy[1].origins[0].Get())); |
+} |
+ |
+// Test the ConstructContainerPolicy method when the "allowfullscreen" attribute |
+// is used to enable fullscreen in the frame. |
+TEST_F(HTMLIFrameElementTest, ConstructContainerPolicyWithAllowFullscreen) { |
+ Document* document = Document::Create(); |
+ KURL document_url = KURL(KURL(), "http://example.com"); |
+ document->SetURL(document_url); |
+ document->UpdateSecurityOrigin(SecurityOrigin::Create(document_url)); |
+ |
+ HTMLIFrameElement* frame_element = HTMLIFrameElement::Create(*document); |
+ frame_element->SetBooleanAttribute(HTMLNames::allowfullscreenAttr, true); |
+ |
+ WebParsedFeaturePolicy container_policy = |
+ frame_element->ConstructContainerPolicy(); |
+ EXPECT_EQ(1UL, container_policy.size()); |
+ EXPECT_EQ(WebFeaturePolicyFeature::kFullscreen, container_policy[0].feature); |
+ EXPECT_TRUE(container_policy[0].matches_all_origins); |
+} |
+ |
+// Test the ConstructContainerPolicy method when the "allowpaymentrequest" |
+// attribute is used to enable the paymentrequest API in the frame. |
+TEST_F(HTMLIFrameElementTest, ConstructContainerPolicyWithAllowPaymentRequest) { |
+ Document* document = Document::Create(); |
+ KURL document_url = KURL(KURL(), "http://example.com"); |
+ document->SetURL(document_url); |
+ document->UpdateSecurityOrigin(SecurityOrigin::Create(document_url)); |
+ |
+ HTMLIFrameElement* frame_element = HTMLIFrameElement::Create(*document); |
+ frame_element->setAttribute(HTMLNames::allowAttr, "usb"); |
+ frame_element->SetBooleanAttribute(HTMLNames::allowpaymentrequestAttr, true); |
+ |
+ WebParsedFeaturePolicy container_policy = |
+ frame_element->ConstructContainerPolicy(); |
+ EXPECT_EQ(2UL, container_policy.size()); |
+ EXPECT_EQ(WebFeaturePolicyFeature::kUsb, container_policy[0].feature); |
+ EXPECT_FALSE(container_policy[0].matches_all_origins); |
+ EXPECT_EQ(1UL, container_policy[0].origins.size()); |
+ EXPECT_TRUE(GetOriginForFeaturePolicy(frame_element) |
+ ->IsSameSchemeHostPortAndSuborigin( |
+ container_policy[0].origins[0].Get())); |
+ EXPECT_EQ(WebFeaturePolicyFeature::kPayment, container_policy[1].feature); |
+ EXPECT_TRUE(container_policy[1].matches_all_origins); |
+} |
+ |
+// Test the ConstructContainerPolicy method when both "allowfullscreen" and |
+// "allowpaymentrequest" attributes are set on the iframe element, and the |
+// "allow" attribute is also used to override the paymentrequest feature. In the |
+// resulting container policy, the payment and usb features should be enabled |
+// only for the frame's origin, (since the allow attribute overrides |
+// allowpaymentrequest,) while fullscreen should be enabled for all origins. |
+TEST_F(HTMLIFrameElementTest, ConstructContainerPolicyWithAllowAttributes) { |
+ Document* document = Document::Create(); |
+ KURL document_url = KURL(KURL(), "http://example.com"); |
+ document->SetURL(document_url); |
+ document->UpdateSecurityOrigin(SecurityOrigin::Create(document_url)); |
+ |
+ HTMLIFrameElement* frame_element = HTMLIFrameElement::Create(*document); |
+ frame_element->setAttribute(HTMLNames::allowAttr, "payment usb"); |
+ frame_element->SetBooleanAttribute(HTMLNames::allowfullscreenAttr, true); |
+ frame_element->SetBooleanAttribute(HTMLNames::allowpaymentrequestAttr, true); |
+ |
+ WebParsedFeaturePolicy container_policy = |
+ frame_element->ConstructContainerPolicy(); |
+ EXPECT_EQ(3UL, container_policy.size()); |
+ EXPECT_EQ(WebFeaturePolicyFeature::kPayment, container_policy[0].feature); |
+ EXPECT_FALSE(container_policy[0].matches_all_origins); |
+ EXPECT_EQ(1UL, container_policy[0].origins.size()); |
+ EXPECT_TRUE(GetOriginForFeaturePolicy(frame_element) |
+ ->IsSameSchemeHostPortAndSuborigin( |
+ container_policy[0].origins[0].Get())); |
+ EXPECT_EQ(WebFeaturePolicyFeature::kUsb, container_policy[1].feature); |
+ EXPECT_FALSE(container_policy[1].matches_all_origins); |
+ EXPECT_EQ(1UL, container_policy[1].origins.size()); |
+ EXPECT_TRUE(GetOriginForFeaturePolicy(frame_element) |
+ ->IsSameSchemeHostPortAndSuborigin( |
+ container_policy[1].origins[0].Get())); |
+ EXPECT_EQ(WebFeaturePolicyFeature::kFullscreen, container_policy[2].feature); |
+ EXPECT_TRUE(container_policy[2].matches_all_origins); |
+} |
+ |
} // namespace blink |