No dual_mode on Win10+ shortcuts.
[chromium-blink-merge.git] / chrome / browser / content_settings / content_settings_supervised_provider_unittest.cc
blob62d2aff62a5ab89bd2d55f6bf742ef94af0d5da6
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/content_settings/content_settings_supervised_provider.h"
7 #include <string>
9 #include "base/memory/scoped_ptr.h"
10 #include "base/prefs/testing_pref_store.h"
11 #include "chrome/browser/content_settings/content_settings_mock_observer.h"
12 #include "chrome/browser/supervised_user/supervised_user_constants.h"
13 #include "chrome/browser/supervised_user/supervised_user_settings_service.h"
14 #include "components/content_settings/core/browser/content_settings_rule.h"
15 #include "components/content_settings/core/browser/content_settings_utils.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 using ::testing::_;
20 namespace content_settings {
22 class SupervisedUserProviderTest : public ::testing::Test {
23 public:
24 void SetUp() override;
25 void TearDown() override;
27 protected:
28 SupervisedUserSettingsService service_;
29 scoped_refptr<TestingPrefStore> pref_store_;
30 scoped_ptr<SupervisedProvider> provider_;
31 content_settings::MockObserver mock_observer_;
34 void SupervisedUserProviderTest::SetUp() {
35 pref_store_ = new TestingPrefStore();
36 pref_store_->NotifyInitializationCompleted();
37 service_.Init(pref_store_);
38 service_.SetActive(true);
39 provider_.reset(new SupervisedProvider(&service_));
40 provider_->AddObserver(&mock_observer_);
43 void SupervisedUserProviderTest::TearDown() {
44 provider_->RemoveObserver(&mock_observer_);
45 provider_->ShutdownOnUIThread();
46 service_.Shutdown();
49 TEST_F(SupervisedUserProviderTest, GeolocationTest) {
50 scoped_ptr<RuleIterator> rule_iterator(provider_->GetRuleIterator(
51 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(), false));
52 EXPECT_FALSE(rule_iterator->HasNext());
53 rule_iterator.reset();
55 // Disable the default geolocation setting.
56 EXPECT_CALL(mock_observer_, OnContentSettingChanged(
57 _, _, CONTENT_SETTINGS_TYPE_GEOLOCATION, ""));
58 service_.SetLocalSetting(
59 supervised_users::kGeolocationDisabled,
60 scoped_ptr<base::Value>(new base::FundamentalValue(true)));
62 rule_iterator.reset(provider_->GetRuleIterator(
63 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(), false));
64 ASSERT_TRUE(rule_iterator->HasNext());
65 Rule rule = rule_iterator->Next();
66 EXPECT_FALSE(rule_iterator->HasNext());
68 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.primary_pattern);
69 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.secondary_pattern);
70 EXPECT_EQ(CONTENT_SETTING_BLOCK, ValueToContentSetting(rule.value.get()));
71 rule_iterator.reset();
73 // Re-enable the default geolocation setting.
74 EXPECT_CALL(mock_observer_, OnContentSettingChanged(
75 _, _, CONTENT_SETTINGS_TYPE_GEOLOCATION, ""));
76 service_.SetLocalSetting(
77 supervised_users::kGeolocationDisabled,
78 scoped_ptr<base::Value>(new base::FundamentalValue(false)));
80 rule_iterator.reset(provider_->GetRuleIterator(
81 CONTENT_SETTINGS_TYPE_GEOLOCATION, std::string(), false));
82 EXPECT_FALSE(rule_iterator->HasNext());
85 TEST_F(SupervisedUserProviderTest, CameraMicTest) {
86 scoped_ptr<RuleIterator> rule_iterator(provider_->GetRuleIterator(
87 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, std::string(), false));
88 EXPECT_FALSE(rule_iterator->HasNext());
89 rule_iterator.reset();
90 rule_iterator.reset(provider_->GetRuleIterator(
91 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, std::string(), false));
92 EXPECT_FALSE(rule_iterator->HasNext());
93 rule_iterator.reset();
95 // Disable the default camera and microphone setting.
96 EXPECT_CALL(mock_observer_,
97 OnContentSettingChanged(
98 _, _, CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, ""));
99 EXPECT_CALL(
100 mock_observer_,
101 OnContentSettingChanged(_, _, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, ""));
102 service_.SetLocalSetting(
103 supervised_users::kCameraMicDisabled,
104 scoped_ptr<base::Value>(new base::FundamentalValue(true)));
106 rule_iterator.reset(provider_->GetRuleIterator(
107 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, std::string(), false));
108 ASSERT_TRUE(rule_iterator->HasNext());
109 Rule rule = rule_iterator->Next();
110 EXPECT_FALSE(rule_iterator->HasNext());
112 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.primary_pattern);
113 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.secondary_pattern);
114 EXPECT_EQ(CONTENT_SETTING_BLOCK, ValueToContentSetting(rule.value.get()));
115 rule_iterator.reset();
117 rule_iterator.reset(provider_->GetRuleIterator(
118 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, std::string(), false));
119 ASSERT_TRUE(rule_iterator->HasNext());
120 rule = rule_iterator->Next();
121 EXPECT_FALSE(rule_iterator->HasNext());
123 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.primary_pattern);
124 EXPECT_EQ(ContentSettingsPattern::Wildcard(), rule.secondary_pattern);
125 EXPECT_EQ(CONTENT_SETTING_BLOCK, ValueToContentSetting(rule.value.get()));
126 rule_iterator.reset();
128 // Re-enable the default camera and microphone setting.
129 EXPECT_CALL(mock_observer_,
130 OnContentSettingChanged(
131 _, _, CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, ""));
132 EXPECT_CALL(
133 mock_observer_,
134 OnContentSettingChanged(_, _, CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, ""));
135 service_.SetLocalSetting(
136 supervised_users::kCameraMicDisabled,
137 scoped_ptr<base::Value>(new base::FundamentalValue(false)));
139 rule_iterator.reset(provider_->GetRuleIterator(
140 CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA, std::string(), false));
141 EXPECT_FALSE(rule_iterator->HasNext());
142 rule_iterator.reset();
143 rule_iterator.reset(provider_->GetRuleIterator(
144 CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC, std::string(), false));
145 EXPECT_FALSE(rule_iterator->HasNext());
148 } // namespace content_settings