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

Side by Side Diff: third_party/WebKit/Source/platform/feature_policy/FeaturePolicyTest.cpp

Issue 2505663002: Add unit tests for testing Feature Policy features in frames, and for testing isFeatureEnabledForOr… (Closed)
Patch Set: Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "platform/feature_policy/FeaturePolicy.h" 5 #include "platform/feature_policy/FeaturePolicy.h"
6 6
7 #include "platform/RuntimeEnabledFeatures.h" 7 #include "platform/RuntimeEnabledFeatures.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 // Origin strings used for tests 10 // Origin strings used for tests
(...skipping 657 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 // | +-------------------------------------------+ | 668 // | +-------------------------------------------+ |
669 // | |(2) Origin B | | 669 // | |(2) Origin B | |
670 // | |Policy: {"default-self": ["*"], | | 670 // | |Policy: {"default-self": ["*"], | |
671 // | | "default-on": ["*"]} | | 671 // | | "default-on": ["*"]} | |
672 // | | +-------------+ | | 672 // | | +-------------+ | |
673 // | | |(3)Origin C | | | 673 // | | |(3)Origin C | | |
674 // | | |No Policy | | | 674 // | | |No Policy | | |
675 // | | +-------------+ | | 675 // | | +-------------+ | |
676 // | +-------------------------------------------+ | 676 // | +-------------------------------------------+ |
677 // +-----------------------------------------------+ 677 // +-----------------------------------------------+
678 // Vibrate feature should be enabled in all frames; Docwrite feature 678 // Default-self feature should be enabled in all frames; Default-on feature
679 // should be enabled in frame 1, and disabled in frames 2 and 3. 679 // should be enabled in frame 1, and disabled in frames 2 and 3.
680 Vector<String> messages; 680 Vector<String> messages;
681 std::unique_ptr<FeaturePolicy> policy1 = 681 std::unique_ptr<FeaturePolicy> policy1 =
682 createFromParentPolicy(nullptr, m_originA); 682 createFromParentPolicy(nullptr, m_originA);
683 policy1->setHeaderPolicy("{\"default-self\": [\"self\", \"" ORIGIN_B 683 policy1->setHeaderPolicy("{\"default-self\": [\"self\", \"" ORIGIN_B
684 "\"], \"default-on\": [\"self\"]}", 684 "\"], \"default-on\": [\"self\"]}",
685 messages); 685 messages);
686 EXPECT_EQ(0UL, messages.size()); 686 EXPECT_EQ(0UL, messages.size());
687 std::unique_ptr<FeaturePolicy> policy2 = 687 std::unique_ptr<FeaturePolicy> policy2 =
688 createFromParentPolicy(policy1.get(), m_originB); 688 createFromParentPolicy(policy1.get(), m_originB);
689 policy2->setHeaderPolicy( 689 policy2->setHeaderPolicy(
690 "{\"default-self\": [\"*\"], \"default-on\": [\"*\"]}", messages); 690 "{\"default-self\": [\"*\"], \"default-on\": [\"*\"]}", messages);
691 EXPECT_EQ(0UL, messages.size()); 691 EXPECT_EQ(0UL, messages.size());
692 std::unique_ptr<FeaturePolicy> policy3 = 692 std::unique_ptr<FeaturePolicy> policy3 =
693 createFromParentPolicy(policy2.get(), m_originC); 693 createFromParentPolicy(policy2.get(), m_originC);
694 EXPECT_TRUE(policy1->isFeatureEnabled(kDefaultSelfFeature)); 694 EXPECT_TRUE(policy1->isFeatureEnabled(kDefaultSelfFeature));
695 EXPECT_TRUE(policy1->isFeatureEnabled(kDefaultOnFeature)); 695 EXPECT_TRUE(policy1->isFeatureEnabled(kDefaultOnFeature));
696 EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultSelfFeature)); 696 EXPECT_TRUE(policy2->isFeatureEnabled(kDefaultSelfFeature));
697 EXPECT_FALSE(policy2->isFeatureEnabled(kDefaultOnFeature)); 697 EXPECT_FALSE(policy2->isFeatureEnabled(kDefaultOnFeature));
698 EXPECT_TRUE(policy3->isFeatureEnabled(kDefaultSelfFeature)); 698 EXPECT_TRUE(policy3->isFeatureEnabled(kDefaultSelfFeature));
699 EXPECT_FALSE(policy3->isFeatureEnabled(kDefaultOnFeature)); 699 EXPECT_FALSE(policy3->isFeatureEnabled(kDefaultOnFeature));
700 } 700 }
701 701
702 TEST_F(FeaturePolicyTest, TestFeatureEnabledForOrigin) {
raymes 2016/11/16 02:55:39 Hmm - is this not covered by other tests?
iclelland 2016/11/16 04:41:04 Only implicitly; feature policy inheritance would
raymes 2016/11/16 23:10:14 Ah ok that makes sense!
703 // +-----------------------------------------------+
704 // |(1) Origin A |
705 // |Policy: {"default-off": ["self", "Origin B"]} |
706 // +-----------------------------------------------+
707 // Features should be enabled by the policy in frame 1 for origins A and B,
708 // and disabled for origin c.
raymes 2016/11/16 02:55:39 nit: C
raymes 2016/11/16 23:10:14 nit: C
iclelland 2016/11/17 04:13:32 Done.
709 Vector<String> messages;
710 std::unique_ptr<FeaturePolicy> policy1 =
711 createFromParentPolicy(nullptr, m_originA);
712 policy1->setHeaderPolicy("{\"default-off\": [\"self\", \"" ORIGIN_B "\"]}",
713 messages);
714 EXPECT_EQ(0UL, messages.size());
715 EXPECT_TRUE(
716 policy1->isFeatureEnabledForOrigin(kDefaultOffFeature, *m_originA));
717 EXPECT_TRUE(
718 policy1->isFeatureEnabledForOrigin(kDefaultOffFeature, *m_originB));
719 EXPECT_FALSE(
720 policy1->isFeatureEnabledForOrigin(kDefaultOffFeature, *m_originC));
721 }
722
702 } // namespace blink 723 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698