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

Side by Side Diff: chrome/browser/managed_mode/managed_user_service_unittest.cc

Issue 63423003: Set ENABLE_MANAGED_USERS #ifdef on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 7 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 (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/prefs/scoped_user_pref_update.h" 7 #include "base/prefs/scoped_user_pref_update.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/chrome_notification_types.h" 9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/extensions/extension_service_unittest.h" 10 #include "chrome/browser/extensions/extension_service_unittest.h"
11 #include "chrome/browser/extensions/unpacked_installer.h" 11 #include "chrome/browser/extensions/unpacked_installer.h"
12 #include "chrome/browser/managed_mode/custodian_profile_downloader_service.h" 12 #include "chrome/browser/managed_mode/custodian_profile_downloader_service.h"
13 #include "chrome/browser/managed_mode/custodian_profile_downloader_service_facto ry.h" 13 #include "chrome/browser/managed_mode/custodian_profile_downloader_service_facto ry.h"
14 #include "chrome/browser/managed_mode/managed_user_service.h" 14 #include "chrome/browser/managed_mode/managed_user_service.h"
15 #include "chrome/browser/managed_mode/managed_user_service_factory.h" 15 #include "chrome/browser/managed_mode/managed_user_service_factory.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/signin/fake_profile_oauth2_token_service.h"
18 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
17 #include "chrome/browser/ui/browser_list.h" 19 #include "chrome/browser/ui/browser_list.h"
18 #include "chrome/common/chrome_paths.h" 20 #include "chrome/common/chrome_paths.h"
19 #include "chrome/common/extensions/extension.h" 21 #include "chrome/common/extensions/extension.h"
20 #include "chrome/common/extensions/features/feature_channel.h" 22 #include "chrome/common/extensions/features/feature_channel.h"
21 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
22 #include "chrome/test/base/testing_profile.h" 24 #include "chrome/test/base/testing_profile.h"
23 #include "content/public/test/test_browser_thread_bundle.h" 25 #include "content/public/test/test_browser_thread_bundle.h"
24 #include "content/public/test/test_utils.h" 26 #include "content/public/test/test_utils.h"
25 #include "extensions/common/extension_builder.h" 27 #include "extensions/common/extension_builder.h"
26 #include "extensions/common/manifest_constants.h" 28 #include "extensions/common/manifest_constants.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 void Reset() { 62 void Reset() {
61 message_loop_runner_ = new MessageLoopRunner; 63 message_loop_runner_ = new MessageLoopRunner;
62 } 64 }
63 65
64 ManagedModeURLFilter* url_filter_; 66 ManagedModeURLFilter* url_filter_;
65 scoped_refptr<MessageLoopRunner> message_loop_runner_; 67 scoped_refptr<MessageLoopRunner> message_loop_runner_;
66 }; 68 };
67 69
68 class ManagedUserServiceTest : public ::testing::Test { 70 class ManagedUserServiceTest : public ::testing::Test {
69 public: 71 public:
70 ManagedUserServiceTest() { 72 ManagedUserServiceTest() {}
71 managed_user_service_ = ManagedUserServiceFactory::GetForProfile(&profile_); 73
74 virtual void SetUp() OVERRIDE {
75 TestingProfile::Builder builder;
76 builder.AddTestingFactory(ProfileOAuth2TokenServiceFactory::GetInstance(),
77 FakeProfileOAuth2TokenService::Build);
78 profile_ = builder.Build();
79 managed_user_service_ =
80 ManagedUserServiceFactory::GetForProfile(profile_.get());
81 }
82
83 virtual void TearDown() OVERRIDE {
84 profile_.reset();
72 } 85 }
73 86
74 virtual ~ManagedUserServiceTest() {} 87 virtual ~ManagedUserServiceTest() {}
75 88
76 protected: 89 protected:
77 content::TestBrowserThreadBundle thread_bundle_; 90 content::TestBrowserThreadBundle thread_bundle_;
78 TestingProfile profile_; 91 scoped_ptr<TestingProfile> profile_;
79 ManagedUserService* managed_user_service_; 92 ManagedUserService* managed_user_service_;
80 }; 93 };
81 94
82 } // namespace 95 } // namespace
83 96
84 TEST_F(ManagedUserServiceTest, GetManualExceptionsForHost) { 97 TEST_F(ManagedUserServiceTest, GetManualExceptionsForHost) {
85 GURL kExampleFooURL("http://www.example.com/foo"); 98 GURL kExampleFooURL("http://www.example.com/foo");
86 GURL kExampleBarURL("http://www.example.com/bar"); 99 GURL kExampleBarURL("http://www.example.com/bar");
87 GURL kExampleFooNoWWWURL("http://example.com/foo"); 100 GURL kExampleFooNoWWWURL("http://example.com/foo");
88 GURL kBlurpURL("http://blurp.net/bla"); 101 GURL kBlurpURL("http://blurp.net/bla");
89 GURL kMooseURL("http://moose.org/baz"); 102 GURL kMooseURL("http://moose.org/baz");
90 { 103 {
91 DictionaryPrefUpdate update(profile_.GetPrefs(), 104 DictionaryPrefUpdate update(profile_->GetPrefs(),
92 prefs::kManagedModeManualURLs); 105 prefs::kManagedModeManualURLs);
93 base::DictionaryValue* dict = update.Get(); 106 base::DictionaryValue* dict = update.Get();
94 dict->SetBooleanWithoutPathExpansion(kExampleFooURL.spec(), true); 107 dict->SetBooleanWithoutPathExpansion(kExampleFooURL.spec(), true);
95 dict->SetBooleanWithoutPathExpansion(kExampleBarURL.spec(), false); 108 dict->SetBooleanWithoutPathExpansion(kExampleBarURL.spec(), false);
96 dict->SetBooleanWithoutPathExpansion(kExampleFooNoWWWURL.spec(), true); 109 dict->SetBooleanWithoutPathExpansion(kExampleFooNoWWWURL.spec(), true);
97 dict->SetBooleanWithoutPathExpansion(kBlurpURL.spec(), true); 110 dict->SetBooleanWithoutPathExpansion(kBlurpURL.spec(), true);
98 } 111 }
99 112
100 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW, 113 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW,
101 managed_user_service_->GetManualBehaviorForURL(kExampleFooURL)); 114 managed_user_service_->GetManualBehaviorForURL(kExampleFooURL));
102 EXPECT_EQ(ManagedUserService::MANUAL_BLOCK, 115 EXPECT_EQ(ManagedUserService::MANUAL_BLOCK,
103 managed_user_service_->GetManualBehaviorForURL(kExampleBarURL)); 116 managed_user_service_->GetManualBehaviorForURL(kExampleBarURL));
104 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW, 117 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW,
105 managed_user_service_->GetManualBehaviorForURL( 118 managed_user_service_->GetManualBehaviorForURL(
106 kExampleFooNoWWWURL)); 119 kExampleFooNoWWWURL));
107 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW, 120 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW,
108 managed_user_service_->GetManualBehaviorForURL(kBlurpURL)); 121 managed_user_service_->GetManualBehaviorForURL(kBlurpURL));
109 EXPECT_EQ(ManagedUserService::MANUAL_NONE, 122 EXPECT_EQ(ManagedUserService::MANUAL_NONE,
110 managed_user_service_->GetManualBehaviorForURL(kMooseURL)); 123 managed_user_service_->GetManualBehaviorForURL(kMooseURL));
111 std::vector<GURL> exceptions; 124 std::vector<GURL> exceptions;
112 managed_user_service_->GetManualExceptionsForHost("www.example.com", 125 managed_user_service_->GetManualExceptionsForHost("www.example.com",
113 &exceptions); 126 &exceptions);
114 ASSERT_EQ(2u, exceptions.size()); 127 ASSERT_EQ(2u, exceptions.size());
115 EXPECT_EQ(kExampleBarURL, exceptions[0]); 128 EXPECT_EQ(kExampleBarURL, exceptions[0]);
116 EXPECT_EQ(kExampleFooURL, exceptions[1]); 129 EXPECT_EQ(kExampleFooURL, exceptions[1]);
117 130
118 { 131 {
119 DictionaryPrefUpdate update(profile_.GetPrefs(), 132 DictionaryPrefUpdate update(profile_->GetPrefs(),
120 prefs::kManagedModeManualURLs); 133 prefs::kManagedModeManualURLs);
121 base::DictionaryValue* dict = update.Get(); 134 base::DictionaryValue* dict = update.Get();
122 for (std::vector<GURL>::iterator it = exceptions.begin(); 135 for (std::vector<GURL>::iterator it = exceptions.begin();
123 it != exceptions.end(); ++it) { 136 it != exceptions.end(); ++it) {
124 dict->RemoveWithoutPathExpansion(it->spec(), NULL); 137 dict->RemoveWithoutPathExpansion(it->spec(), NULL);
125 } 138 }
126 } 139 }
127 140
128 EXPECT_EQ(ManagedUserService::MANUAL_NONE, 141 EXPECT_EQ(ManagedUserService::MANUAL_NONE,
129 managed_user_service_->GetManualBehaviorForURL(kExampleFooURL)); 142 managed_user_service_->GetManualBehaviorForURL(kExampleFooURL));
130 EXPECT_EQ(ManagedUserService::MANUAL_NONE, 143 EXPECT_EQ(ManagedUserService::MANUAL_NONE,
131 managed_user_service_->GetManualBehaviorForURL(kExampleBarURL)); 144 managed_user_service_->GetManualBehaviorForURL(kExampleBarURL));
132 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW, 145 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW,
133 managed_user_service_->GetManualBehaviorForURL( 146 managed_user_service_->GetManualBehaviorForURL(
134 kExampleFooNoWWWURL)); 147 kExampleFooNoWWWURL));
135 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW, 148 EXPECT_EQ(ManagedUserService::MANUAL_ALLOW,
136 managed_user_service_->GetManualBehaviorForURL(kBlurpURL)); 149 managed_user_service_->GetManualBehaviorForURL(kBlurpURL));
137 EXPECT_EQ(ManagedUserService::MANUAL_NONE, 150 EXPECT_EQ(ManagedUserService::MANUAL_NONE,
138 managed_user_service_->GetManualBehaviorForURL(kMooseURL)); 151 managed_user_service_->GetManualBehaviorForURL(kMooseURL));
139 } 152 }
140 153
141 // Ensure that the CustodianProfileDownloaderService shuts down cleanly. If no 154 // Ensure that the CustodianProfileDownloaderService shuts down cleanly. If no
142 // DCHECK is hit when the service is destroyed, this test passed. 155 // DCHECK is hit when the service is destroyed, this test passed.
143 TEST_F(ManagedUserServiceTest, ShutDownCustodianProfileDownloader) { 156 TEST_F(ManagedUserServiceTest, ShutDownCustodianProfileDownloader) {
144 CustodianProfileDownloaderService* downloader_service = 157 CustodianProfileDownloaderService* downloader_service =
145 CustodianProfileDownloaderServiceFactory::GetForProfile( 158 CustodianProfileDownloaderServiceFactory::GetForProfile(profile_.get());
146 &profile_);
147 159
148 // Emulate being logged in, then start to download a profile so a 160 // Emulate being logged in, then start to download a profile so a
149 // ProfileDownloader gets created. 161 // ProfileDownloader gets created.
150 profile_.GetPrefs()->SetString(prefs::kGoogleServicesUsername, "Logged In"); 162 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, "Logged In");
151 downloader_service->DownloadProfile(base::Bind(&OnProfileDownloadedFail)); 163 downloader_service->DownloadProfile(base::Bind(&OnProfileDownloadedFail));
152 } 164 }
153 165
166 #if !defined(OS_ANDROID)
154 class ManagedUserServiceExtensionTestBase : public ExtensionServiceTestBase { 167 class ManagedUserServiceExtensionTestBase : public ExtensionServiceTestBase {
155 public: 168 public:
156 explicit ManagedUserServiceExtensionTestBase(bool is_managed) 169 explicit ManagedUserServiceExtensionTestBase(bool is_managed)
157 : is_managed_(is_managed), 170 : is_managed_(is_managed),
158 channel_(chrome::VersionInfo::CHANNEL_DEV) {} 171 channel_(chrome::VersionInfo::CHANNEL_DEV) {}
159 virtual ~ManagedUserServiceExtensionTestBase() {} 172 virtual ~ManagedUserServiceExtensionTestBase() {}
160 173
161 virtual void SetUp() OVERRIDE { 174 virtual void SetUp() OVERRIDE {
162 ExtensionServiceTestBase::SetUp(); 175 ExtensionServiceTestBase::SetUp();
163 ExtensionServiceTestBase::ExtensionServiceInitParams params = 176 ExtensionServiceTestBase::ExtensionServiceInitParams params =
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 sites.clear(); 389 sites.clear();
377 site_lists[0]->GetSites(&sites); 390 site_lists[0]->GetSites(&sites);
378 ASSERT_EQ(1u, sites.size()); 391 ASSERT_EQ(1u, sites.size());
379 EXPECT_EQ(ASCIIToUTF16("Moose"), sites[0].name); 392 EXPECT_EQ(ASCIIToUTF16("Moose"), sites[0].name);
380 393
381 EXPECT_EQ(ManagedModeURLFilter::WARN, 394 EXPECT_EQ(ManagedModeURLFilter::WARN,
382 url_filter->GetFilteringBehaviorForURL(example_url)); 395 url_filter->GetFilteringBehaviorForURL(example_url));
383 EXPECT_EQ(ManagedModeURLFilter::ALLOW, 396 EXPECT_EQ(ManagedModeURLFilter::ALLOW,
384 url_filter->GetFilteringBehaviorForURL(moose_url)); 397 url_filter->GetFilteringBehaviorForURL(moose_url));
385 } 398 }
399 #endif // !defined(OS_ANDROID)
OLDNEW
« no previous file with comments | « chrome/browser/managed_mode/managed_user_service.cc ('k') | chrome/browser/signin/fake_profile_oauth2_token_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698