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

Side by Side Diff: chrome/browser/chromeos/policy/device_local_account_browsertest.cc

Issue 1431593008: Remove deprecated extension notification from device_local_account_browsertest.cc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: no busy waiting Created 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <map> 5 #include <map>
6 #include <set> 6 #include <set>
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "ash/shell.h" 10 #include "ash/shell.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 #include "content/public/browser/notification_service.h" 114 #include "content/public/browser/notification_service.h"
115 #include "content/public/browser/notification_source.h" 115 #include "content/public/browser/notification_source.h"
116 #include "content/public/browser/web_contents.h" 116 #include "content/public/browser/web_contents.h"
117 #include "content/public/browser/web_ui.h" 117 #include "content/public/browser/web_ui.h"
118 #include "content/public/test/browser_test_utils.h" 118 #include "content/public/test/browser_test_utils.h"
119 #include "content/public/test/test_utils.h" 119 #include "content/public/test/test_utils.h"
120 #include "crypto/rsa_private_key.h" 120 #include "crypto/rsa_private_key.h"
121 #include "extensions/browser/app_window/app_window.h" 121 #include "extensions/browser/app_window/app_window.h"
122 #include "extensions/browser/app_window/app_window_registry.h" 122 #include "extensions/browser/app_window/app_window_registry.h"
123 #include "extensions/browser/app_window/native_app_window.h" 123 #include "extensions/browser/app_window/native_app_window.h"
124 #include "extensions/browser/extension_registry.h"
124 #include "extensions/browser/extension_system.h" 125 #include "extensions/browser/extension_system.h"
125 #include "extensions/browser/install/crx_install_error.h" 126 #include "extensions/browser/install/crx_install_error.h"
126 #include "extensions/browser/management_policy.h" 127 #include "extensions/browser/management_policy.h"
127 #include "extensions/browser/notification_types.h" 128 #include "extensions/browser/notification_types.h"
129 #include "extensions/browser/test_extension_registry_observer.h"
128 #include "extensions/common/constants.h" 130 #include "extensions/common/constants.h"
129 #include "extensions/common/extension.h" 131 #include "extensions/common/extension.h"
130 #include "net/base/url_util.h" 132 #include "net/base/url_util.h"
131 #include "net/http/http_status_code.h" 133 #include "net/http/http_status_code.h"
132 #include "net/test/embedded_test_server/embedded_test_server.h" 134 #include "net/test/embedded_test_server/embedded_test_server.h"
133 #include "net/test/embedded_test_server/http_request.h" 135 #include "net/test/embedded_test_server/http_request.h"
134 #include "net/test/embedded_test_server/http_response.h" 136 #include "net/test/embedded_test_server/http_response.h"
135 #include "net/url_request/test_url_fetcher_factory.h" 137 #include "net/url_request/test_url_fetcher_factory.h"
136 #include "net/url_request/url_fetcher_delegate.h" 138 #include "net/url_request/url_fetcher_delegate.h"
137 #include "net/url_request/url_request_status.h" 139 #include "net/url_request/url_request_status.h"
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 const base::DictionaryValue* pref = 368 const base::DictionaryValue* pref =
367 pref_change_registrar_.prefs()->GetDictionary(pref_.c_str()); 369 pref_change_registrar_.prefs()->GetDictionary(pref_.c_str());
368 ASSERT_TRUE(pref); 370 ASSERT_TRUE(pref);
369 std::string actual_value; 371 std::string actual_value;
370 if (pref->GetStringWithoutPathExpansion(key_, &actual_value) && 372 if (pref->GetStringWithoutPathExpansion(key_, &actual_value) &&
371 actual_value == expected_value_) { 373 actual_value == expected_value_) {
372 run_loop_.Quit(); 374 run_loop_.Quit();
373 } 375 }
374 } 376 }
375 377
376 bool DoesInstallSuccessReferToId(const std::string& id,
377 const content::NotificationSource& source,
378 const content::NotificationDetails& details) {
379 return content::Details<const extensions::InstalledExtensionInfo>(details)->
380 extension->id() == id;
381 }
382
383 bool DoesInstallFailureReferToId(const std::string& id, 378 bool DoesInstallFailureReferToId(const std::string& id,
384 const content::NotificationSource& source, 379 const content::NotificationSource& source,
385 const content::NotificationDetails& details) { 380 const content::NotificationDetails& details) {
386 return content::Details<const extensions::CrxInstallError>(details) 381 return content::Details<const extensions::CrxInstallError>(details)
387 ->message() 382 ->message()
388 .find(base::UTF8ToUTF16(id)) != base::string16::npos; 383 .find(base::UTF8ToUTF16(id)) != base::string16::npos;
389 } 384 }
390 385
391 scoped_ptr<net::FakeURLFetcher> RunCallbackAndReturnFakeURLFetcher( 386 scoped_ptr<net::FakeURLFetcher> RunCallbackAndReturnFakeURLFetcher(
392 scoped_refptr<base::SequencedTaskRunner> task_runner, 387 scoped_refptr<base::SequencedTaskRunner> task_runner,
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 content::WebContents* contents_; 799 content::WebContents* contents_;
805 800
806 private: 801 private:
807 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountTest); 802 DISALLOW_COPY_AND_ASSIGN(DeviceLocalAccountTest);
808 }; 803 };
809 804
810 static bool IsKnownUser(const AccountId& account_id) { 805 static bool IsKnownUser(const AccountId& account_id) {
811 return user_manager::UserManager::Get()->IsKnownUser(account_id); 806 return user_manager::UserManager::Get()->IsKnownUser(account_id);
812 } 807 }
813 808
809 // Helper that listen extension installation when new profile is created.
810 class ExtensionInstallObserver : public content::NotificationObserver,
811 public extensions::ExtensionRegistryObserver {
812 public:
813 ExtensionInstallObserver() : registry_(nullptr) {
814 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED,
815 content::NotificationService::AllSources());
816 }
817
818 ~ExtensionInstallObserver() override {
819 if (registry_ != nullptr)
820 registry_->RemoveObserver(this);
821 }
822
823 // Wait until an extension with |extension_id| is installed.
824 void Wait(const std::string& extension_id) {
825 waiting_extension_id_ = extension_id;
826 run_loop_.Run();
827 }
828
829 private:
830 // extensions::ExtensionRegistryObserver:
831 void OnExtensionWillBeInstalled(content::BrowserContext* browser_context,
832 const extensions::Extension* extension,
833 bool is_update,
834 bool from_ephemeral,
835 const std::string& old_name) override {
836 DCHECK_EQ(waiting_extension_id_, extension->id());
837
838 run_loop_.Quit();
839 }
840
841 // content::NotificationObserver:
842 void Observe(int type,
843 const content::NotificationSource& source,
844 const content::NotificationDetails& details) override {
845 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_CREATED, type);
cschuet (SLOW) 2015/11/17 15:02:48 You should probably check whether the app has alre
limasdf 2015/11/17 17:00:57 Done.
846
847 Profile* profile = content::Source<Profile>(source).ptr();
848 registry_ = extensions::ExtensionRegistry::Get(profile);
849
850 // Start listening for extension installation.
851 registry_->AddObserver(this);
852 }
853
854 extensions::ExtensionRegistry* registry_;
855 base::RunLoop run_loop_;
856 content::NotificationRegistrar registrar_;
857 std::string waiting_extension_id_;
858
859 DISALLOW_COPY_AND_ASSIGN(ExtensionInstallObserver);
860 };
861
814 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, LoginScreen) { 862 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, LoginScreen) {
815 AddPublicSessionToDevicePolicy(kAccountId1); 863 AddPublicSessionToDevicePolicy(kAccountId1);
816 AddPublicSessionToDevicePolicy(kAccountId2); 864 AddPublicSessionToDevicePolicy(kAccountId2);
817 865
818 content::WindowedNotificationObserver(chrome::NOTIFICATION_USER_LIST_CHANGED, 866 content::WindowedNotificationObserver(chrome::NOTIFICATION_USER_LIST_CHANGED,
819 base::Bind(&IsKnownUser, account_id_1_)) 867 base::Bind(&IsKnownUser, account_id_1_))
820 .Wait(); 868 .Wait();
821 EXPECT_TRUE(IsKnownUser(account_id_2_)); 869 EXPECT_TRUE(IsKnownUser(account_id_2_));
822 870
823 CheckPublicSessionPresent(account_id_1_); 871 CheckPublicSessionPresent(account_id_1_);
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 "%s;%s", 1087 "%s;%s",
1040 kGoodExtensionID, 1088 kGoodExtensionID,
1041 embedded_test_server()->GetURL(kRelativeUpdateURL).spec().c_str())); 1089 embedded_test_server()->GetURL(kRelativeUpdateURL).spec().c_str()));
1042 1090
1043 UploadAndInstallDeviceLocalAccountPolicy(); 1091 UploadAndInstallDeviceLocalAccountPolicy();
1044 AddPublicSessionToDevicePolicy(kAccountId1); 1092 AddPublicSessionToDevicePolicy(kAccountId1);
1045 1093
1046 WaitForPolicy(); 1094 WaitForPolicy();
1047 1095
1048 // Start listening for app/extension installation results. 1096 // Start listening for app/extension installation results.
1049 content::WindowedNotificationObserver hosted_app_observer( 1097 ExtensionInstallObserver install_observer;
1050 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
1051 base::Bind(DoesInstallSuccessReferToId, kHostedAppID));
1052 content::WindowedNotificationObserver extension_observer( 1098 content::WindowedNotificationObserver extension_observer(
1053 extensions::NOTIFICATION_EXTENSION_INSTALL_ERROR, 1099 extensions::NOTIFICATION_EXTENSION_INSTALL_ERROR,
1054 base::Bind(DoesInstallFailureReferToId, kGoodExtensionID)); 1100 base::Bind(DoesInstallFailureReferToId, kGoodExtensionID));
1055
1056 ASSERT_NO_FATAL_FAILURE(StartLogin(std::string(), std::string())); 1101 ASSERT_NO_FATAL_FAILURE(StartLogin(std::string(), std::string()));
1057 1102
1058 // Wait for the hosted app installation to succeed and the extension 1103 // Wait for the hosted app installation to succeed and the extension
1059 // installation to fail (because hosted apps are whitelisted for use in 1104 // installation to fail (because hosted apps are whitelisted for use in
1060 // device-local accounts and extensions are not). 1105 // device-local accounts and extensions are not).
1061 hosted_app_observer.Wait(); 1106 install_observer.Wait(kHostedAppID);
1062 extension_observer.Wait(); 1107 extension_observer.Wait();
1063 1108
1064 // Verify that the hosted app was installed. 1109 // Verify that the hosted app was installed.
1065 Profile* profile = GetProfileForTest(); 1110 Profile* profile = GetProfileForTest();
1066 ASSERT_TRUE(profile); 1111 ASSERT_TRUE(profile);
1067 ExtensionService* extension_service = 1112 ExtensionService* extension_service =
1068 extensions::ExtensionSystem::Get(profile)->extension_service(); 1113 extensions::ExtensionSystem::Get(profile)->extension_service();
1069 EXPECT_TRUE(extension_service->GetExtensionById(kHostedAppID, true)); 1114 EXPECT_TRUE(extension_service->GetExtensionById(kHostedAppID, true));
1070 1115
1071 // Verify that the extension was not installed. 1116 // Verify that the extension was not installed.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 "%s;%s", 1165 "%s;%s",
1121 kGoodExtensionID, 1166 kGoodExtensionID,
1122 embedded_test_server()->GetURL(kRelativeUpdateURL).spec().c_str())); 1167 embedded_test_server()->GetURL(kRelativeUpdateURL).spec().c_str()));
1123 1168
1124 UploadAndInstallDeviceLocalAccountPolicy(); 1169 UploadAndInstallDeviceLocalAccountPolicy();
1125 AddPublicSessionToDevicePolicy(kAccountId1); 1170 AddPublicSessionToDevicePolicy(kAccountId1);
1126 1171
1127 WaitForPolicy(); 1172 WaitForPolicy();
1128 1173
1129 // Start listening for app/extension installation results. 1174 // Start listening for app/extension installation results.
1130 content::WindowedNotificationObserver hosted_app_observer( 1175 ExtensionInstallObserver install_observer;
1131 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
1132 base::Bind(DoesInstallSuccessReferToId, kHostedAppID));
1133 content::WindowedNotificationObserver extension_observer( 1176 content::WindowedNotificationObserver extension_observer(
1134 extensions::NOTIFICATION_EXTENSION_INSTALL_ERROR, 1177 extensions::NOTIFICATION_EXTENSION_INSTALL_ERROR,
1135 base::Bind(DoesInstallFailureReferToId, kGoodExtensionID)); 1178 base::Bind(DoesInstallFailureReferToId, kGoodExtensionID));
1136 1179
1137 ASSERT_NO_FATAL_FAILURE(StartLogin(std::string(), std::string())); 1180 ASSERT_NO_FATAL_FAILURE(StartLogin(std::string(), std::string()));
1138 1181
1139 // Wait for the hosted app installation to succeed and the extension 1182 // Wait for the hosted app installation to succeed and the extension
1140 // installation to fail. 1183 // installation to fail.
1141 hosted_app_observer.Wait(); 1184 install_observer.Wait(kHostedAppID);
1142 extension_observer.Wait(); 1185 extension_observer.Wait();
1143 1186
1144 // Verify that the hosted app was installed. 1187 // Verify that the hosted app was installed.
1145 Profile* profile = GetProfileForTest(); 1188 Profile* profile = GetProfileForTest();
1146 ASSERT_TRUE(profile); 1189 ASSERT_TRUE(profile);
1147 ExtensionService* extension_service = 1190 ExtensionService* extension_service =
1148 extensions::ExtensionSystem::Get(profile)->extension_service(); 1191 extensions::ExtensionSystem::Get(profile)->extension_service();
1149 EXPECT_TRUE(extension_service->GetExtensionById(kHostedAppID, true)); 1192 EXPECT_TRUE(extension_service->GetExtensionById(kHostedAppID, true));
1150 1193
1151 // Verify that the extension was not installed. 1194 // Verify that the extension was not installed.
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1251 "%s;%s", 1294 "%s;%s",
1252 kGoodExtensionID, 1295 kGoodExtensionID,
1253 embedded_test_server()->GetURL(kRelativeUpdateURL).spec().c_str())); 1296 embedded_test_server()->GetURL(kRelativeUpdateURL).spec().c_str()));
1254 1297
1255 UploadAndInstallDeviceLocalAccountPolicy(); 1298 UploadAndInstallDeviceLocalAccountPolicy();
1256 AddPublicSessionToDevicePolicy(kAccountId1); 1299 AddPublicSessionToDevicePolicy(kAccountId1);
1257 1300
1258 WaitForPolicy(); 1301 WaitForPolicy();
1259 1302
1260 // Start listening for app/extension installation results. 1303 // Start listening for app/extension installation results.
1261 content::WindowedNotificationObserver hosted_app_observer( 1304 ExtensionInstallObserver install_observer;
1262 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
1263 base::Bind(DoesInstallSuccessReferToId, kHostedAppID));
1264 content::WindowedNotificationObserver extension_observer( 1305 content::WindowedNotificationObserver extension_observer(
1265 extensions::NOTIFICATION_EXTENSION_INSTALL_ERROR, 1306 extensions::NOTIFICATION_EXTENSION_INSTALL_ERROR,
1266 base::Bind(DoesInstallFailureReferToId, kGoodExtensionID)); 1307 base::Bind(DoesInstallFailureReferToId, kGoodExtensionID));
1267 1308
1268 ASSERT_NO_FATAL_FAILURE(StartLogin(std::string(), std::string())); 1309 ASSERT_NO_FATAL_FAILURE(StartLogin(std::string(), std::string()));
1269 1310
1270 // Wait for the hosted app installation to succeed and the extension 1311 // Wait for the hosted app installation to succeed and the extension
1271 // installation to fail (because hosted apps are whitelisted for use in 1312 // installation to fail (because hosted apps are whitelisted for use in
1272 // device-local accounts and extensions are not). 1313 // device-local accounts and extensions are not).
1273 hosted_app_observer.Wait(); 1314 install_observer.Wait(kHostedAppID);
1274 extension_observer.Wait(); 1315 extension_observer.Wait();
1275 1316
1276 // Verify that the extension was kept in the local cache. 1317 // Verify that the extension was kept in the local cache.
1277 EXPECT_TRUE(cache_impl.GetExtension(kGoodExtensionID, hash, NULL, NULL)); 1318 EXPECT_TRUE(cache_impl.GetExtension(kGoodExtensionID, hash, NULL, NULL));
1278 1319
1279 // Verify that the extension file was kept in the local cache. 1320 // Verify that the extension file was kept in the local cache.
1280 EXPECT_TRUE(PathExists(local_file)); 1321 EXPECT_TRUE(PathExists(local_file));
1281 } 1322 }
1282 1323
1283 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, ExternalData) { 1324 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, ExternalData) {
(...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after
2192 " }" 2233 " }"
2193 "}")); 2234 "}"));
2194 2235
2195 // Install and refresh the device policy now. This will also fetch the initial 2236 // Install and refresh the device policy now. This will also fetch the initial
2196 // user policy for the device-local account now. 2237 // user policy for the device-local account now.
2197 UploadAndInstallDeviceLocalAccountPolicy(); 2238 UploadAndInstallDeviceLocalAccountPolicy();
2198 AddPublicSessionToDevicePolicy(kAccountId1); 2239 AddPublicSessionToDevicePolicy(kAccountId1);
2199 WaitForPolicy(); 2240 WaitForPolicy();
2200 2241
2201 // Observe the app installation after login. 2242 // Observe the app installation after login.
2202 content::WindowedNotificationObserver extension_observer( 2243 ExtensionInstallObserver install_observer;
2203 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
2204 base::Bind(DoesInstallSuccessReferToId, kShowManagedStorageID));
2205 ASSERT_NO_FATAL_FAILURE(StartLogin(std::string(), std::string())); 2244 ASSERT_NO_FATAL_FAILURE(StartLogin(std::string(), std::string()));
2206 WaitForSessionStart(); 2245 WaitForSessionStart();
2207 extension_observer.Wait(); 2246 install_observer.Wait(kShowManagedStorageID);
2208 2247
2209 // Verify that the app was installed. 2248 // Verify that the app was installed.
2210 Profile* profile = GetProfileForTest(); 2249 Profile* profile = GetProfileForTest();
2211 ASSERT_TRUE(profile); 2250 ASSERT_TRUE(profile);
2212 ExtensionService* extension_service = 2251 ExtensionService* extension_service =
2213 extensions::ExtensionSystem::Get(profile)->extension_service(); 2252 extensions::ExtensionSystem::Get(profile)->extension_service();
2214 EXPECT_TRUE(extension_service->GetExtensionById(kShowManagedStorageID, true)); 2253 EXPECT_TRUE(extension_service->GetExtensionById(kShowManagedStorageID, true));
2215 2254
2216 // Wait for the app policy if it hasn't been fetched yet. 2255 // Wait for the app policy if it hasn't been fetched yet.
2217 ProfilePolicyConnector* connector = 2256 ProfilePolicyConnector* connector =
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
2385 ASSERT_TRUE(content::ExecuteScript(contents_, 2424 ASSERT_TRUE(content::ExecuteScript(contents_,
2386 "$('tos-accept-button').click();")); 2425 "$('tos-accept-button').click();"));
2387 2426
2388 WaitForSessionStart(); 2427 WaitForSessionStart();
2389 } 2428 }
2390 2429
2391 INSTANTIATE_TEST_CASE_P(TermsOfServiceDownloadTestInstance, 2430 INSTANTIATE_TEST_CASE_P(TermsOfServiceDownloadTestInstance,
2392 TermsOfServiceDownloadTest, testing::Bool()); 2431 TermsOfServiceDownloadTest, testing::Bool());
2393 2432
2394 } // namespace policy 2433 } // namespace policy
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698