Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(965)

Unified Diff: third_party/WebKit/Source/core/html/HTMLIFrameElementAllowTest.cpp

Issue 2680083002: Initial Implementation of Iframe Attribute for Feature Policy (Part 1) (Closed)
Patch Set: Codereview: nit Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/html/HTMLIFrameElementAllowTest.cpp
diff --git a/third_party/WebKit/Source/core/html/HTMLIFrameElementAllowTest.cpp b/third_party/WebKit/Source/core/html/HTMLIFrameElementAllowTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..42966c97a980ae08560b17caf067d85ebd7916f8
--- /dev/null
+++ b/third_party/WebKit/Source/core/html/HTMLIFrameElementAllowTest.cpp
@@ -0,0 +1,64 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "core/html/HTMLIFrameElementAllow.h"
+
+#include "core/dom/Document.h"
+#include "core/html/HTMLIFrameElement.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using testing::UnorderedElementsAre;
+
+namespace blink {
+
+TEST(HTMLIFrameElementAllowTest, ParseAllowedFeatureNamesValid) {
+ Document* document = Document::create();
+ HTMLIFrameElement* iframe = HTMLIFrameElement::create(*document);
+ HTMLIFrameElementAllow* allow = HTMLIFrameElementAllow::create(iframe);
+ String errorMessage;
+ Vector<WebFeaturePolicyFeature> result;
+
+ allow->setValue("");
+ result = allow->parseAllowedFeatureNames(errorMessage);
+ EXPECT_TRUE(result.isEmpty());
+
+ allow->setValue("fullscreen");
+ result = allow->parseAllowedFeatureNames(errorMessage);
+ EXPECT_THAT(result,
+ UnorderedElementsAre(WebFeaturePolicyFeature::Fullscreen));
+
+ allow->setValue("fullscreen payment vibrate");
+ result = allow->parseAllowedFeatureNames(errorMessage);
+ EXPECT_THAT(result, UnorderedElementsAre(WebFeaturePolicyFeature::Fullscreen,
+ WebFeaturePolicyFeature::Payment,
+ WebFeaturePolicyFeature::Vibrate));
+}
+
+TEST(HTMLIFrameElementAllowTest, ParseAllowedFeatureNamesInvalid) {
+ Document* document = Document::create();
+ HTMLIFrameElement* iframe = HTMLIFrameElement::create(*document);
+ HTMLIFrameElementAllow* allow = HTMLIFrameElementAllow::create(iframe);
+ String errorMessage;
+ Vector<WebFeaturePolicyFeature> result;
+
+ allow->setValue("invalid");
+ result = allow->parseAllowedFeatureNames(errorMessage);
+ EXPECT_TRUE(result.isEmpty());
+ EXPECT_EQ("'invalid' is an invalid feature name.", errorMessage);
+
+ allow->setValue("fullscreen invalid1 invalid2");
+ result = allow->parseAllowedFeatureNames(errorMessage);
+ EXPECT_THAT(result,
+ UnorderedElementsAre(WebFeaturePolicyFeature::Fullscreen));
+ EXPECT_EQ("'invalid1', 'invalid2' are invalid feature names.", errorMessage);
+
+ allow->setValue("fullscreen invalid vibrate fullscreen");
+ result = allow->parseAllowedFeatureNames(errorMessage);
+ EXPECT_EQ("'invalid' is an invalid feature name.", errorMessage);
+ EXPECT_THAT(result, UnorderedElementsAre(WebFeaturePolicyFeature::Fullscreen,
+ WebFeaturePolicyFeature::Vibrate));
+}
+
+} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698