Commit 418313cf authored by treib's avatar treib Committed by Commit bot

SupervisedUserService cleanup: remove some dead code.

Also update some tests accordingly.

BUG=

Review URL: https://codereview.chromium.org/664313004

Cr-Commit-Position: refs/heads/master@{#300650}
parent ffd71248
......@@ -228,6 +228,9 @@ IN_PROC_BROWSER_TEST_F(SupervisedUserBlockModeTest,
HistoryVisitRecorded) {
GURL allowed_url("http://www.example.com/files/simple.html");
scoped_refptr<SupervisedUserURLFilter> filter =
supervised_user_service_->GetURLFilterForUIThread();
// Set the host as allowed.
scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue);
dict->SetBooleanWithoutPathExpansion(allowed_url.host(), true);
......@@ -236,9 +239,10 @@ IN_PROC_BROWSER_TEST_F(SupervisedUserBlockModeTest,
browser()->profile());
supervised_user_settings_service->SetLocalSettingForTesting(
supervised_users::kContentPackManualBehaviorHosts, dict.Pass());
EXPECT_EQ(
SupervisedUserService::MANUAL_ALLOW,
supervised_user_service_->GetManualBehaviorForHost(allowed_url.host()));
EXPECT_EQ(SupervisedUserURLFilter::ALLOW,
filter->GetFilteringBehaviorForURL(allowed_url));
EXPECT_EQ(SupervisedUserURLFilter::ALLOW,
filter->GetFilteringBehaviorForURL(allowed_url.GetWithEmptyPath()));
ui_test_utils::NavigateToURL(browser(), allowed_url);
......@@ -258,13 +262,10 @@ IN_PROC_BROWSER_TEST_F(SupervisedUserBlockModeTest,
// Check that we went back to the first URL and that the manual behaviors
// have not changed.
EXPECT_EQ(allowed_url.spec(), tab->GetURL().spec());
EXPECT_EQ(SupervisedUserService::MANUAL_ALLOW,
supervised_user_service_->GetManualBehaviorForHost(
"www.example.com"));
EXPECT_EQ(
SupervisedUserService::MANUAL_NONE,
supervised_user_service_->GetManualBehaviorForHost(
"www.new-example.com"));
EXPECT_EQ(SupervisedUserURLFilter::ALLOW,
filter->GetFilteringBehaviorForURL(allowed_url.GetWithEmptyPath()));
EXPECT_EQ(SupervisedUserURLFilter::BLOCK,
filter->GetFilteringBehaviorForURL(blocked_url.GetWithEmptyPath()));
// Query the history entry.
HistoryService* history_service = HistoryServiceFactory::GetForProfile(
......@@ -302,9 +303,11 @@ IN_PROC_BROWSER_TEST_F(SupervisedUserBlockModeTest, Unblock) {
browser()->profile());
supervised_user_settings_service->SetLocalSettingForTesting(
supervised_users::kContentPackManualBehaviorHosts, dict.Pass());
EXPECT_EQ(
SupervisedUserService::MANUAL_ALLOW,
supervised_user_service_->GetManualBehaviorForHost(test_url.host()));
scoped_refptr<SupervisedUserURLFilter> filter =
supervised_user_service_->GetURLFilterForUIThread();
EXPECT_EQ(SupervisedUserURLFilter::ALLOW,
filter->GetFilteringBehaviorForURL(test_url.GetWithEmptyPath()));
observer.Wait();
EXPECT_EQ(test_url, web_contents->GetURL());
......
......@@ -662,43 +662,6 @@ void SupervisedUserService::AddAccessRequest(const GURL& url,
0);
}
SupervisedUserService::ManualBehavior
SupervisedUserService::GetManualBehaviorForHost(
const std::string& hostname) {
const base::DictionaryValue* dict =
profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualHosts);
bool allow = false;
if (!dict->GetBooleanWithoutPathExpansion(hostname, &allow))
return MANUAL_NONE;
return allow ? MANUAL_ALLOW : MANUAL_BLOCK;
}
SupervisedUserService::ManualBehavior
SupervisedUserService::GetManualBehaviorForURL(
const GURL& url) {
const base::DictionaryValue* dict =
profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualURLs);
GURL normalized_url = SupervisedUserURLFilter::Normalize(url);
bool allow = false;
if (!dict->GetBooleanWithoutPathExpansion(normalized_url.spec(), &allow))
return MANUAL_NONE;
return allow ? MANUAL_ALLOW : MANUAL_BLOCK;
}
void SupervisedUserService::GetManualExceptionsForHost(
const std::string& host,
std::vector<GURL>* urls) {
const base::DictionaryValue* dict =
profile_->GetPrefs()->GetDictionary(prefs::kSupervisedUserManualURLs);
for (base::DictionaryValue::Iterator it(*dict); !it.IsAtEnd(); it.Advance()) {
GURL url(it.key());
if (url.host() == host)
urls->push_back(url);
}
}
void SupervisedUserService::InitSync(const std::string& refresh_token) {
StartSetupSync();
......
......@@ -71,12 +71,6 @@ class SupervisedUserService : public KeyedService,
typedef base::Callback<void(const GoogleServiceAuthError&)> AuthErrorCallback;
typedef base::Callback<void(bool)> SuccessCallback;
enum ManualBehavior {
MANUAL_NONE = 0,
MANUAL_ALLOW,
MANUAL_BLOCK
};
class Delegate {
public:
virtual ~Delegate() {}
......@@ -131,20 +125,6 @@ class SupervisedUserService : public KeyedService,
// empty.
std::string GetCustodianName() const;
// These methods allow querying and modifying the manual filtering behavior.
// The manual behavior is set by the user and overrides all other settings
// (whitelists or the default behavior).
// Returns the manual behavior for the given host.
ManualBehavior GetManualBehaviorForHost(const std::string& hostname);
// Returns the manual behavior for the given URL.
ManualBehavior GetManualBehaviorForURL(const GURL& url);
// Returns all URLS on the given host that have exceptions.
void GetManualExceptionsForHost(const std::string& host,
std::vector<GURL>* urls);
// Initializes this object. This method does nothing if the profile is not
// supervised.
void Init();
......
......@@ -127,61 +127,6 @@ class SupervisedUserServiceTest : public ::testing::Test {
} // namespace
TEST_F(SupervisedUserServiceTest, GetManualExceptionsForHost) {
GURL kExampleFooURL("http://www.example.com/foo");
GURL kExampleBarURL("http://www.example.com/bar");
GURL kExampleFooNoWWWURL("http://example.com/foo");
GURL kBlurpURL("http://blurp.net/bla");
GURL kMooseURL("http://moose.org/baz");
{
DictionaryPrefUpdate update(profile_->GetPrefs(),
prefs::kSupervisedUserManualURLs);
base::DictionaryValue* dict = update.Get();
dict->SetBooleanWithoutPathExpansion(kExampleFooURL.spec(), true);
dict->SetBooleanWithoutPathExpansion(kExampleBarURL.spec(), false);
dict->SetBooleanWithoutPathExpansion(kExampleFooNoWWWURL.spec(), true);
dict->SetBooleanWithoutPathExpansion(kBlurpURL.spec(), true);
}
EXPECT_EQ(SupervisedUserService::MANUAL_ALLOW,
supervised_user_service_->GetManualBehaviorForURL(kExampleFooURL));
EXPECT_EQ(SupervisedUserService::MANUAL_BLOCK,
supervised_user_service_->GetManualBehaviorForURL(kExampleBarURL));
EXPECT_EQ(SupervisedUserService::MANUAL_ALLOW,
supervised_user_service_->GetManualBehaviorForURL(
kExampleFooNoWWWURL));
EXPECT_EQ(SupervisedUserService::MANUAL_ALLOW,
supervised_user_service_->GetManualBehaviorForURL(kBlurpURL));
EXPECT_EQ(SupervisedUserService::MANUAL_NONE,
supervised_user_service_->GetManualBehaviorForURL(kMooseURL));
std::vector<GURL> exceptions;
supervised_user_service_->GetManualExceptionsForHost("www.example.com",
&exceptions);
ASSERT_EQ(2u, exceptions.size());
EXPECT_EQ(kExampleBarURL, exceptions[0]);
EXPECT_EQ(kExampleFooURL, exceptions[1]);
{
DictionaryPrefUpdate update(profile_->GetPrefs(),
prefs::kSupervisedUserManualURLs);
base::DictionaryValue* dict = update.Get();
for (const GURL& url : exceptions)
dict->RemoveWithoutPathExpansion(url.spec(), NULL);
}
EXPECT_EQ(SupervisedUserService::MANUAL_NONE,
supervised_user_service_->GetManualBehaviorForURL(kExampleFooURL));
EXPECT_EQ(SupervisedUserService::MANUAL_NONE,
supervised_user_service_->GetManualBehaviorForURL(kExampleBarURL));
EXPECT_EQ(SupervisedUserService::MANUAL_ALLOW,
supervised_user_service_->GetManualBehaviorForURL(
kExampleFooNoWWWURL));
EXPECT_EQ(SupervisedUserService::MANUAL_ALLOW,
supervised_user_service_->GetManualBehaviorForURL(kBlurpURL));
EXPECT_EQ(SupervisedUserService::MANUAL_NONE,
supervised_user_service_->GetManualBehaviorForURL(kMooseURL));
}
TEST_F(SupervisedUserServiceTest, ChangesIncludedSessionOnChangedSettings) {
supervised_user_service_->Init();
EXPECT_TRUE(supervised_user_service_->IncludesSyncSessionsType());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment