| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "base/path_service.h" | 5 #include "base/path_service.h" |
| 6 #include "base/prefs/pref_service.h" | 6 #include "base/prefs/pref_service.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/extensions/extension_service_unittest.h" | 8 #include "chrome/browser/extensions/extension_service_unittest.h" |
| 9 #include "chrome/browser/extensions/unpacked_installer.h" | 9 #include "chrome/browser/extensions/unpacked_installer.h" |
| 10 #include "chrome/browser/managed_mode/managed_user_service.h" | 10 #include "chrome/browser/managed_mode/managed_user_service.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 message_loop_runner_ = new MessageLoopRunner; | 51 message_loop_runner_ = new MessageLoopRunner; |
| 52 } | 52 } |
| 53 | 53 |
| 54 ManagedModeURLFilter* url_filter_; | 54 ManagedModeURLFilter* url_filter_; |
| 55 scoped_refptr<MessageLoopRunner> message_loop_runner_; | 55 scoped_refptr<MessageLoopRunner> message_loop_runner_; |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 class ManagedUserServiceTest : public ::testing::Test { | 58 class ManagedUserServiceTest : public ::testing::Test { |
| 59 public: | 59 public: |
| 60 ManagedUserServiceTest() : ui_thread_(content::BrowserThread::UI, | 60 ManagedUserServiceTest() : ui_thread_(content::BrowserThread::UI, |
| 61 &message_loop_), | 61 &message_loop_) { |
| 62 managed_user_service_(&profile_) {} | 62 managed_user_service_ = ManagedUserServiceFactory::GetForProfile(&profile_); |
| 63 } |
| 64 |
| 63 virtual ~ManagedUserServiceTest() {} | 65 virtual ~ManagedUserServiceTest() {} |
| 64 | 66 |
| 65 protected: | 67 protected: |
| 66 base::MessageLoop message_loop_; | 68 base::MessageLoop message_loop_; |
| 67 content::TestBrowserThread ui_thread_; | 69 content::TestBrowserThread ui_thread_; |
| 68 TestingProfile profile_; | 70 TestingProfile profile_; |
| 69 ManagedUserService managed_user_service_; | 71 ManagedUserService* managed_user_service_; |
| 70 }; | 72 }; |
| 71 | 73 |
| 72 } // namespace | 74 } // namespace |
| 73 | 75 |
| 74 TEST_F(ManagedUserServiceTest, ExtensionManagementPolicyProviderUnmanaged) { | 76 TEST_F(ManagedUserServiceTest, ExtensionManagementPolicyProviderUnmanaged) { |
| 75 EXPECT_FALSE(managed_user_service_.ProfileIsManaged()); | 77 EXPECT_FALSE(managed_user_service_->ProfileIsManaged()); |
| 76 | 78 |
| 77 string16 error_1; | 79 string16 error_1; |
| 78 EXPECT_TRUE(managed_user_service_.UserMayLoad(NULL, &error_1)); | 80 EXPECT_TRUE(managed_user_service_->UserMayLoad(NULL, &error_1)); |
| 79 EXPECT_EQ(string16(), error_1); | 81 EXPECT_EQ(string16(), error_1); |
| 80 | 82 |
| 81 string16 error_2; | 83 string16 error_2; |
| 82 EXPECT_TRUE(managed_user_service_.UserMayModifySettings(NULL, &error_2)); | 84 EXPECT_TRUE(managed_user_service_->UserMayModifySettings(NULL, &error_2)); |
| 83 EXPECT_EQ(string16(), error_2); | 85 EXPECT_EQ(string16(), error_2); |
| 84 } | 86 } |
| 85 | 87 |
| 86 TEST_F(ManagedUserServiceTest, ExtensionManagementPolicyProviderManaged) { | 88 TEST_F(ManagedUserServiceTest, ExtensionManagementPolicyProviderManaged) { |
| 87 ManagedModeURLFilterObserver observer( | 89 ManagedModeURLFilterObserver observer( |
| 88 managed_user_service_.GetURLFilterForUIThread()); | 90 managed_user_service_->GetURLFilterForUIThread()); |
| 89 managed_user_service_.InitForTesting(); | 91 managed_user_service_->InitForTesting(); |
| 90 EXPECT_TRUE(managed_user_service_.ProfileIsManaged()); | 92 EXPECT_TRUE(managed_user_service_->ProfileIsManaged()); |
| 91 | 93 |
| 92 string16 error_1; | 94 string16 error_1; |
| 93 EXPECT_FALSE(managed_user_service_.UserMayLoad(NULL, &error_1)); | 95 EXPECT_FALSE(managed_user_service_->UserMayLoad(NULL, &error_1)); |
| 94 EXPECT_FALSE(error_1.empty()); | 96 EXPECT_FALSE(error_1.empty()); |
| 95 | 97 |
| 96 string16 error_2; | 98 string16 error_2; |
| 97 EXPECT_FALSE(managed_user_service_.UserMayModifySettings(NULL, &error_2)); | 99 EXPECT_FALSE(managed_user_service_->UserMayModifySettings(NULL, &error_2)); |
| 98 EXPECT_FALSE(error_2.empty()); | 100 EXPECT_FALSE(error_2.empty()); |
| 99 | 101 |
| 100 #ifndef NDEBUG | 102 #ifndef NDEBUG |
| 101 EXPECT_FALSE(managed_user_service_.GetDebugPolicyProviderName().empty()); | 103 EXPECT_FALSE(managed_user_service_->GetDebugPolicyProviderName().empty()); |
| 102 #endif | 104 #endif |
| 103 // Wait for the initial update to finish (otherwise we'll get leaks). | 105 // Wait for the initial update to finish (otherwise we'll get leaks). |
| 104 observer.Wait(); | 106 observer.Wait(); |
| 105 } | 107 } |
| 106 | 108 |
| 107 TEST_F(ManagedUserServiceTest, GetManualExceptionsForHost) { | 109 TEST_F(ManagedUserServiceTest, GetManualExceptionsForHost) { |
| 108 GURL kExampleFooURL("http://www.example.com/foo"); | 110 GURL kExampleFooURL("http://www.example.com/foo"); |
| 109 GURL kExampleBarURL("http://www.example.com/bar"); | 111 GURL kExampleBarURL("http://www.example.com/bar"); |
| 110 GURL kExampleFooNoWWWURL("http://example.com/foo"); | 112 GURL kExampleFooNoWWWURL("http://example.com/foo"); |
| 111 GURL kBlurpURL("http://blurp.net/bla"); | 113 GURL kBlurpURL("http://blurp.net/bla"); |
| 112 GURL kMooseURL("http://moose.org/baz"); | 114 GURL kMooseURL("http://moose.org/baz"); |
| 113 { | 115 { |
| 114 DictionaryPrefUpdate update(profile_.GetPrefs(), | 116 DictionaryPrefUpdate update(profile_.GetPrefs(), |
| 115 prefs::kManagedModeManualURLs); | 117 prefs::kManagedModeManualURLs); |
| 116 base::DictionaryValue* dict = update.Get(); | 118 base::DictionaryValue* dict = update.Get(); |
| 117 dict->SetBooleanWithoutPathExpansion(kExampleFooURL.spec(), true); | 119 dict->SetBooleanWithoutPathExpansion(kExampleFooURL.spec(), true); |
| 118 dict->SetBooleanWithoutPathExpansion(kExampleBarURL.spec(), false); | 120 dict->SetBooleanWithoutPathExpansion(kExampleBarURL.spec(), false); |
| 119 dict->SetBooleanWithoutPathExpansion(kExampleFooNoWWWURL.spec(), true); | 121 dict->SetBooleanWithoutPathExpansion(kExampleFooNoWWWURL.spec(), true); |
| 120 dict->SetBooleanWithoutPathExpansion(kBlurpURL.spec(), true); | 122 dict->SetBooleanWithoutPathExpansion(kBlurpURL.spec(), true); |
| 121 } | 123 } |
| 122 | 124 |
| 123 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW, | 125 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW, |
| 124 managed_user_service_.GetManualBehaviorForURL(kExampleFooURL)); | 126 managed_user_service_->GetManualBehaviorForURL(kExampleFooURL)); |
| 125 EXPECT_EQ(ManagedUserService::MANUAL_BLOCK, | 127 EXPECT_EQ(ManagedUserService::MANUAL_BLOCK, |
| 126 managed_user_service_.GetManualBehaviorForURL(kExampleBarURL)); | 128 managed_user_service_->GetManualBehaviorForURL(kExampleBarURL)); |
| 127 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW, | 129 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW, |
| 128 managed_user_service_.GetManualBehaviorForURL(kExampleFooNoWWWURL)); | 130 managed_user_service_->GetManualBehaviorForURL( |
| 131 kExampleFooNoWWWURL)); |
| 129 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW, | 132 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW, |
| 130 managed_user_service_.GetManualBehaviorForURL(kBlurpURL)); | 133 managed_user_service_->GetManualBehaviorForURL(kBlurpURL)); |
| 131 EXPECT_EQ(ManagedUserService::MANUAL_NONE, | 134 EXPECT_EQ(ManagedUserService::MANUAL_NONE, |
| 132 managed_user_service_.GetManualBehaviorForURL(kMooseURL)); | 135 managed_user_service_->GetManualBehaviorForURL(kMooseURL)); |
| 133 std::vector<GURL> exceptions; | 136 std::vector<GURL> exceptions; |
| 134 managed_user_service_.GetManualExceptionsForHost("www.example.com", | 137 managed_user_service_->GetManualExceptionsForHost("www.example.com", |
| 135 &exceptions); | 138 &exceptions); |
| 136 ASSERT_EQ(2u, exceptions.size()); | 139 ASSERT_EQ(2u, exceptions.size()); |
| 137 EXPECT_EQ(kExampleBarURL, exceptions[0]); | 140 EXPECT_EQ(kExampleBarURL, exceptions[0]); |
| 138 EXPECT_EQ(kExampleFooURL, exceptions[1]); | 141 EXPECT_EQ(kExampleFooURL, exceptions[1]); |
| 139 | 142 |
| 140 { | 143 { |
| 141 DictionaryPrefUpdate update(profile_.GetPrefs(), | 144 DictionaryPrefUpdate update(profile_.GetPrefs(), |
| 142 prefs::kManagedModeManualURLs); | 145 prefs::kManagedModeManualURLs); |
| 143 base::DictionaryValue* dict = update.Get(); | 146 base::DictionaryValue* dict = update.Get(); |
| 144 for (std::vector<GURL>::iterator it = exceptions.begin(); | 147 for (std::vector<GURL>::iterator it = exceptions.begin(); |
| 145 it != exceptions.end(); ++it) { | 148 it != exceptions.end(); ++it) { |
| 146 dict->RemoveWithoutPathExpansion(it->spec(), NULL); | 149 dict->RemoveWithoutPathExpansion(it->spec(), NULL); |
| 147 } | 150 } |
| 148 } | 151 } |
| 149 | 152 |
| 150 EXPECT_EQ(ManagedUserService::MANUAL_NONE, | 153 EXPECT_EQ(ManagedUserService::MANUAL_NONE, |
| 151 managed_user_service_.GetManualBehaviorForURL(kExampleFooURL)); | 154 managed_user_service_->GetManualBehaviorForURL(kExampleFooURL)); |
| 152 EXPECT_EQ(ManagedUserService::MANUAL_NONE, | 155 EXPECT_EQ(ManagedUserService::MANUAL_NONE, |
| 153 managed_user_service_.GetManualBehaviorForURL(kExampleBarURL)); | 156 managed_user_service_->GetManualBehaviorForURL(kExampleBarURL)); |
| 154 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW, | 157 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW, |
| 155 managed_user_service_.GetManualBehaviorForURL(kExampleFooNoWWWURL)); | 158 managed_user_service_->GetManualBehaviorForURL( |
| 159 kExampleFooNoWWWURL)); |
| 156 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW, | 160 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW, |
| 157 managed_user_service_.GetManualBehaviorForURL(kBlurpURL)); | 161 managed_user_service_->GetManualBehaviorForURL(kBlurpURL)); |
| 158 EXPECT_EQ(ManagedUserService::MANUAL_NONE, | 162 EXPECT_EQ(ManagedUserService::MANUAL_NONE, |
| 159 managed_user_service_.GetManualBehaviorForURL(kMooseURL)); | 163 managed_user_service_->GetManualBehaviorForURL(kMooseURL)); |
| 160 } | 164 } |
| 161 | 165 |
| 162 class ManagedUserServiceExtensionTest : public ExtensionServiceTestBase { | 166 class ManagedUserServiceExtensionTest : public ExtensionServiceTestBase { |
| 163 public: | 167 public: |
| 164 ManagedUserServiceExtensionTest() {} | 168 ManagedUserServiceExtensionTest() {} |
| 165 virtual ~ManagedUserServiceExtensionTest() {} | 169 virtual ~ManagedUserServiceExtensionTest() {} |
| 166 | 170 |
| 167 virtual void SetUp() OVERRIDE { | 171 virtual void SetUp() OVERRIDE { |
| 168 ExtensionServiceTestBase::SetUp(); | 172 ExtensionServiceTestBase::SetUp(); |
| 169 InitializeEmptyExtensionService(); | 173 InitializeEmptyExtensionService(); |
| 170 } | 174 } |
| 171 | 175 |
| 172 virtual void TearDown() OVERRIDE { | 176 virtual void TearDown() OVERRIDE { |
| 173 ExtensionServiceTestBase::TearDown(); | 177 ExtensionServiceTestBase::TearDown(); |
| 174 } | 178 } |
| 175 | 179 |
| 176 protected: | 180 protected: |
| 177 ScopedVector<ManagedModeSiteList> GetActiveSiteLists( | 181 ScopedVector<ManagedModeSiteList> GetActiveSiteLists( |
| 178 ManagedUserService* managed_user_service) { | 182 ManagedUserService* managed_user_service) { |
| 179 return managed_user_service->GetActiveSiteLists(); | 183 return managed_user_service->GetActiveSiteLists(); |
| 180 } | 184 } |
| 181 }; | 185 }; |
| 182 | 186 |
| 183 TEST_F(ManagedUserServiceExtensionTest, NoContentPacks) { | 187 TEST_F(ManagedUserServiceExtensionTest, NoContentPacks) { |
| 184 ManagedUserService managed_user_service(profile_.get()); | 188 ManagedUserService* managed_user_service = |
| 185 managed_user_service.Init(); | 189 ManagedUserServiceFactory::GetForProfile(profile_.get()); |
| 190 managed_user_service->Init(); |
| 186 ManagedModeURLFilter* url_filter = | 191 ManagedModeURLFilter* url_filter = |
| 187 managed_user_service.GetURLFilterForUIThread(); | 192 managed_user_service->GetURLFilterForUIThread(); |
| 188 | 193 |
| 189 GURL url("http://youtube.com"); | 194 GURL url("http://youtube.com"); |
| 190 ScopedVector<ManagedModeSiteList> site_lists = | 195 ScopedVector<ManagedModeSiteList> site_lists = |
| 191 GetActiveSiteLists(&managed_user_service); | 196 GetActiveSiteLists(managed_user_service); |
| 192 ASSERT_EQ(0u, site_lists.size()); | 197 ASSERT_EQ(0u, site_lists.size()); |
| 193 EXPECT_EQ(ManagedModeURLFilter::ALLOW, | 198 EXPECT_EQ(ManagedModeURLFilter::ALLOW, |
| 194 url_filter->GetFilteringBehaviorForURL(url)); | 199 url_filter->GetFilteringBehaviorForURL(url)); |
| 195 } | 200 } |
| 196 | 201 |
| 197 #if !defined(OS_CHROMEOS) | 202 #if !defined(OS_CHROMEOS) |
| 198 TEST_F(ManagedUserServiceExtensionTest, InstallContentPacks) { | 203 TEST_F(ManagedUserServiceExtensionTest, InstallContentPacks) { |
| 199 ManagedUserService* managed_user_service = | 204 ManagedUserService* managed_user_service = |
| 200 ManagedUserServiceFactory::GetForProfile(profile_.get()); | 205 ManagedUserServiceFactory::GetForProfile(profile_.get()); |
| 201 managed_user_service->InitForTesting(); | 206 managed_user_service->InitForTesting(); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 | 308 |
| 304 EXPECT_EQ(ManagedModeURLFilter::WARN, | 309 EXPECT_EQ(ManagedModeURLFilter::WARN, |
| 305 url_filter->GetFilteringBehaviorForURL(example_url)); | 310 url_filter->GetFilteringBehaviorForURL(example_url)); |
| 306 #if defined(ENABLE_CONFIGURATION_POLICY) | 311 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 307 EXPECT_EQ(ManagedModeURLFilter::ALLOW, | 312 EXPECT_EQ(ManagedModeURLFilter::ALLOW, |
| 308 url_filter->GetFilteringBehaviorForURL(moose_url)); | 313 url_filter->GetFilteringBehaviorForURL(moose_url)); |
| 309 #endif | 314 #endif |
| 310 } | 315 } |
| 311 | 316 |
| 312 #endif // OS_CHROMEOS | 317 #endif // OS_CHROMEOS |
| OLD | NEW |