OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <map> | 5 #include <map> |
6 #include <set> | 6 #include <set> |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
14 #include "base/prefs/scoped_user_pref_update.h" | 14 #include "base/prefs/scoped_user_pref_update.h" |
15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
17 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
18 #include "chrome/browser/component_updater/supervised_user_whitelist_installer.h
" | 18 #include "chrome/browser/component_updater/supervised_user_whitelist_installer.h
" |
19 #include "chrome/browser/supervised_user/supervised_user_site_list.h" | 19 #include "chrome/browser/supervised_user/supervised_user_site_list.h" |
20 #include "chrome/browser/supervised_user/supervised_user_whitelist_service.h" | 20 #include "chrome/browser/supervised_user/supervised_user_whitelist_service.h" |
21 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
23 #include "chrome/test/base/testing_profile.h" | 23 #include "chrome/test/base/testing_profile.h" |
| 24 #include "components/safe_json/testing_json_parser.h" |
24 #include "content/public/test/test_browser_thread_bundle.h" | 25 #include "content/public/test/test_browser_thread_bundle.h" |
25 #include "sync/api/sync_change.h" | 26 #include "sync/api/sync_change.h" |
26 #include "sync/api/sync_error_factory.h" | 27 #include "sync/api/sync_error_factory.h" |
27 #include "sync/protocol/sync.pb.h" | 28 #include "sync/protocol/sync.pb.h" |
28 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
29 | 30 |
30 namespace { | 31 namespace { |
31 | 32 |
32 const char kClientId[] = "client-id"; | 33 const char kClientId[] = "client-id"; |
33 | 34 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 class SupervisedUserWhitelistServiceTest : public testing::Test { | 84 class SupervisedUserWhitelistServiceTest : public testing::Test { |
84 public: | 85 public: |
85 SupervisedUserWhitelistServiceTest() | 86 SupervisedUserWhitelistServiceTest() |
86 : installer_(new MockSupervisedUserWhitelistInstaller), | 87 : installer_(new MockSupervisedUserWhitelistInstaller), |
87 service_(new SupervisedUserWhitelistService(profile_.GetPrefs(), | 88 service_(new SupervisedUserWhitelistService(profile_.GetPrefs(), |
88 installer_.get(), | 89 installer_.get(), |
89 kClientId)) { | 90 kClientId)) { |
90 service_->AddSiteListsChangedCallback( | 91 service_->AddSiteListsChangedCallback( |
91 base::Bind(&SupervisedUserWhitelistServiceTest::OnSiteListsChanged, | 92 base::Bind(&SupervisedUserWhitelistServiceTest::OnSiteListsChanged, |
92 base::Unretained(this))); | 93 base::Unretained(this))); |
93 SupervisedUserSiteList::SetLoadInProcessForTesting(true); | |
94 } | |
95 | |
96 ~SupervisedUserWhitelistServiceTest() override { | |
97 SupervisedUserSiteList::SetLoadInProcessForTesting(false); | |
98 } | 94 } |
99 | 95 |
100 protected: | 96 protected: |
101 void PrepareInitialStateAndPreferences() { | 97 void PrepareInitialStateAndPreferences() { |
102 // Create two whitelists. | 98 // Create two whitelists. |
103 DictionaryPrefUpdate update(profile_.GetPrefs(), | 99 DictionaryPrefUpdate update(profile_.GetPrefs(), |
104 prefs::kSupervisedUserWhitelists); | 100 prefs::kSupervisedUserWhitelists); |
105 base::DictionaryValue* dict = update.Get(); | 101 base::DictionaryValue* dict = update.Get(); |
106 | 102 |
107 scoped_ptr<base::DictionaryValue> whitelist_dict(new base::DictionaryValue); | 103 scoped_ptr<base::DictionaryValue> whitelist_dict(new base::DictionaryValue); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 void OnSiteListsChanged( | 145 void OnSiteListsChanged( |
150 const std::vector<scoped_refptr<SupervisedUserSiteList>>& site_lists) { | 146 const std::vector<scoped_refptr<SupervisedUserSiteList>>& site_lists) { |
151 site_lists_ = site_lists; | 147 site_lists_ = site_lists; |
152 if (!site_lists_changed_callback_.is_null()) | 148 if (!site_lists_changed_callback_.is_null()) |
153 site_lists_changed_callback_.Run(); | 149 site_lists_changed_callback_.Run(); |
154 } | 150 } |
155 | 151 |
156 content::TestBrowserThreadBundle thread_bundle_; | 152 content::TestBrowserThreadBundle thread_bundle_; |
157 TestingProfile profile_; | 153 TestingProfile profile_; |
158 | 154 |
| 155 safe_json::TestingJsonParser::ScopedFactoryOverride factory_override_; |
| 156 |
159 scoped_ptr<MockSupervisedUserWhitelistInstaller> installer_; | 157 scoped_ptr<MockSupervisedUserWhitelistInstaller> installer_; |
160 scoped_ptr<SupervisedUserWhitelistService> service_; | 158 scoped_ptr<SupervisedUserWhitelistService> service_; |
161 | 159 |
162 std::vector<scoped_refptr<SupervisedUserSiteList>> site_lists_; | 160 std::vector<scoped_refptr<SupervisedUserSiteList>> site_lists_; |
163 base::Closure site_lists_changed_callback_; | 161 base::Closure site_lists_changed_callback_; |
164 }; | 162 }; |
165 | 163 |
166 TEST_F(SupervisedUserWhitelistServiceTest, MergeEmpty) { | 164 TEST_F(SupervisedUserWhitelistServiceTest, MergeEmpty) { |
167 service_->Init(); | 165 service_->Init(); |
168 | 166 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 service_->GetAllSyncData(syncer::SUPERVISED_USER_WHITELISTS); | 267 service_->GetAllSyncData(syncer::SUPERVISED_USER_WHITELISTS); |
270 ASSERT_EQ(2u, sync_data.size()); | 268 ASSERT_EQ(2u, sync_data.size()); |
271 const sync_pb::ManagedUserWhitelistSpecifics* whitelist = | 269 const sync_pb::ManagedUserWhitelistSpecifics* whitelist = |
272 FindWhitelist(sync_data, "aaaa"); | 270 FindWhitelist(sync_data, "aaaa"); |
273 ASSERT_TRUE(whitelist); | 271 ASSERT_TRUE(whitelist); |
274 EXPECT_EQ("Whitelist A", whitelist->name()); | 272 EXPECT_EQ("Whitelist A", whitelist->name()); |
275 whitelist = FindWhitelist(sync_data, "bbbb"); | 273 whitelist = FindWhitelist(sync_data, "bbbb"); |
276 ASSERT_TRUE(whitelist); | 274 ASSERT_TRUE(whitelist); |
277 EXPECT_EQ("Whitelist B", whitelist->name()); | 275 EXPECT_EQ("Whitelist B", whitelist->name()); |
278 } | 276 } |
OLD | NEW |