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

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: check if already installed 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 explicit ExtensionInstallObserver(const std::string& extension_id)
814 : registry_(nullptr),
815 waiting_extension_id_(extension_id),
816 observed_(false) {
817 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CREATED,
818 content::NotificationService::AllSources());
819 }
820
821 ~ExtensionInstallObserver() override {
822 if (registry_ != nullptr)
823 registry_->RemoveObserver(this);
824 }
825
826 // Wait until an extension with |extension_id| is installed.
827 void Wait() {
828 if (!observed_)
829 run_loop_.Run();
830 }
831
832 private:
833 // extensions::ExtensionRegistryObserver:
834 void OnExtensionWillBeInstalled(content::BrowserContext* browser_context,
835 const extensions::Extension* extension,
836 bool is_update,
837 bool from_ephemeral,
838 const std::string& old_name) override {
839 if (waiting_extension_id_ == extension->id()) {
840 observed_ = true;
841 run_loop_.Quit();
842 }
843 }
844
845 // content::NotificationObserver:
846 void Observe(int type,
847 const content::NotificationSource& source,
848 const content::NotificationDetails& details) override {
849 DCHECK_EQ(chrome::NOTIFICATION_PROFILE_CREATED, type);
850
851 Profile* profile = content::Source<Profile>(source).ptr();
852 registry_ = extensions::ExtensionRegistry::Get(profile);
853
854 // Check if extension is already installed with newly created profile.
855 if (registry_->GetInstalledExtension(waiting_extension_id_)) {
856 observed_ = true;
857 run_loop_.Quit();
858 return;
859 }
860
861 // Start listening for extension installation.
862 registry_->AddObserver(this);
863 }
864
865 extensions::ExtensionRegistry* registry_;
866 base::RunLoop run_loop_;
867 content::NotificationRegistrar registrar_;
868 std::string waiting_extension_id_;
869 bool observed_;
870
871 DISALLOW_COPY_AND_ASSIGN(ExtensionInstallObserver);
872 };
873
814 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, LoginScreen) { 874 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, LoginScreen) {
815 AddPublicSessionToDevicePolicy(kAccountId1); 875 AddPublicSessionToDevicePolicy(kAccountId1);
816 AddPublicSessionToDevicePolicy(kAccountId2); 876 AddPublicSessionToDevicePolicy(kAccountId2);
817 877
818 content::WindowedNotificationObserver(chrome::NOTIFICATION_USER_LIST_CHANGED, 878 content::WindowedNotificationObserver(chrome::NOTIFICATION_USER_LIST_CHANGED,
819 base::Bind(&IsKnownUser, account_id_1_)) 879 base::Bind(&IsKnownUser, account_id_1_))
820 .Wait(); 880 .Wait();
821 EXPECT_TRUE(IsKnownUser(account_id_2_)); 881 EXPECT_TRUE(IsKnownUser(account_id_2_));
822 882
823 CheckPublicSessionPresent(account_id_1_); 883 CheckPublicSessionPresent(account_id_1_);
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 "%s;%s", 1099 "%s;%s",
1040 kGoodExtensionID, 1100 kGoodExtensionID,
1041 embedded_test_server()->GetURL(kRelativeUpdateURL).spec().c_str())); 1101 embedded_test_server()->GetURL(kRelativeUpdateURL).spec().c_str()));
1042 1102
1043 UploadAndInstallDeviceLocalAccountPolicy(); 1103 UploadAndInstallDeviceLocalAccountPolicy();
1044 AddPublicSessionToDevicePolicy(kAccountId1); 1104 AddPublicSessionToDevicePolicy(kAccountId1);
1045 1105
1046 WaitForPolicy(); 1106 WaitForPolicy();
1047 1107
1048 // Start listening for app/extension installation results. 1108 // Start listening for app/extension installation results.
1049 content::WindowedNotificationObserver hosted_app_observer( 1109 ExtensionInstallObserver install_observer(kHostedAppID);
1050 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
1051 base::Bind(DoesInstallSuccessReferToId, kHostedAppID));
1052 content::WindowedNotificationObserver extension_observer( 1110 content::WindowedNotificationObserver extension_observer(
1053 extensions::NOTIFICATION_EXTENSION_INSTALL_ERROR, 1111 extensions::NOTIFICATION_EXTENSION_INSTALL_ERROR,
1054 base::Bind(DoesInstallFailureReferToId, kGoodExtensionID)); 1112 base::Bind(DoesInstallFailureReferToId, kGoodExtensionID));
1055
1056 ASSERT_NO_FATAL_FAILURE(StartLogin(std::string(), std::string())); 1113 ASSERT_NO_FATAL_FAILURE(StartLogin(std::string(), std::string()));
1057 1114
1058 // Wait for the hosted app installation to succeed and the extension 1115 // Wait for the hosted app installation to succeed and the extension
1059 // installation to fail (because hosted apps are whitelisted for use in 1116 // installation to fail (because hosted apps are whitelisted for use in
1060 // device-local accounts and extensions are not). 1117 // device-local accounts and extensions are not).
1061 hosted_app_observer.Wait(); 1118 install_observer.Wait();
1062 extension_observer.Wait(); 1119 extension_observer.Wait();
1063 1120
1064 // Verify that the hosted app was installed. 1121 // Verify that the hosted app was installed.
1065 Profile* profile = GetProfileForTest(); 1122 Profile* profile = GetProfileForTest();
1066 ASSERT_TRUE(profile); 1123 ASSERT_TRUE(profile);
1067 ExtensionService* extension_service = 1124 ExtensionService* extension_service =
1068 extensions::ExtensionSystem::Get(profile)->extension_service(); 1125 extensions::ExtensionSystem::Get(profile)->extension_service();
1069 EXPECT_TRUE(extension_service->GetExtensionById(kHostedAppID, true)); 1126 EXPECT_TRUE(extension_service->GetExtensionById(kHostedAppID, true));
1070 1127
1071 // Verify that the extension was not installed. 1128 // Verify that the extension was not installed.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 "%s;%s", 1177 "%s;%s",
1121 kGoodExtensionID, 1178 kGoodExtensionID,
1122 embedded_test_server()->GetURL(kRelativeUpdateURL).spec().c_str())); 1179 embedded_test_server()->GetURL(kRelativeUpdateURL).spec().c_str()));
1123 1180
1124 UploadAndInstallDeviceLocalAccountPolicy(); 1181 UploadAndInstallDeviceLocalAccountPolicy();
1125 AddPublicSessionToDevicePolicy(kAccountId1); 1182 AddPublicSessionToDevicePolicy(kAccountId1);
1126 1183
1127 WaitForPolicy(); 1184 WaitForPolicy();
1128 1185
1129 // Start listening for app/extension installation results. 1186 // Start listening for app/extension installation results.
1130 content::WindowedNotificationObserver hosted_app_observer( 1187 ExtensionInstallObserver install_observer(kHostedAppID);
1131 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
1132 base::Bind(DoesInstallSuccessReferToId, kHostedAppID));
1133 content::WindowedNotificationObserver extension_observer( 1188 content::WindowedNotificationObserver extension_observer(
1134 extensions::NOTIFICATION_EXTENSION_INSTALL_ERROR, 1189 extensions::NOTIFICATION_EXTENSION_INSTALL_ERROR,
1135 base::Bind(DoesInstallFailureReferToId, kGoodExtensionID)); 1190 base::Bind(DoesInstallFailureReferToId, kGoodExtensionID));
1136 1191
1137 ASSERT_NO_FATAL_FAILURE(StartLogin(std::string(), std::string())); 1192 ASSERT_NO_FATAL_FAILURE(StartLogin(std::string(), std::string()));
1138 1193
1139 // Wait for the hosted app installation to succeed and the extension 1194 // Wait for the hosted app installation to succeed and the extension
1140 // installation to fail. 1195 // installation to fail.
1141 hosted_app_observer.Wait(); 1196 install_observer.Wait();
1142 extension_observer.Wait(); 1197 extension_observer.Wait();
1143 1198
1144 // Verify that the hosted app was installed. 1199 // Verify that the hosted app was installed.
1145 Profile* profile = GetProfileForTest(); 1200 Profile* profile = GetProfileForTest();
1146 ASSERT_TRUE(profile); 1201 ASSERT_TRUE(profile);
1147 ExtensionService* extension_service = 1202 ExtensionService* extension_service =
1148 extensions::ExtensionSystem::Get(profile)->extension_service(); 1203 extensions::ExtensionSystem::Get(profile)->extension_service();
1149 EXPECT_TRUE(extension_service->GetExtensionById(kHostedAppID, true)); 1204 EXPECT_TRUE(extension_service->GetExtensionById(kHostedAppID, true));
1150 1205
1151 // Verify that the extension was not installed. 1206 // Verify that the extension was not installed.
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1251 "%s;%s", 1306 "%s;%s",
1252 kGoodExtensionID, 1307 kGoodExtensionID,
1253 embedded_test_server()->GetURL(kRelativeUpdateURL).spec().c_str())); 1308 embedded_test_server()->GetURL(kRelativeUpdateURL).spec().c_str()));
1254 1309
1255 UploadAndInstallDeviceLocalAccountPolicy(); 1310 UploadAndInstallDeviceLocalAccountPolicy();
1256 AddPublicSessionToDevicePolicy(kAccountId1); 1311 AddPublicSessionToDevicePolicy(kAccountId1);
1257 1312
1258 WaitForPolicy(); 1313 WaitForPolicy();
1259 1314
1260 // Start listening for app/extension installation results. 1315 // Start listening for app/extension installation results.
1261 content::WindowedNotificationObserver hosted_app_observer( 1316 ExtensionInstallObserver install_observer(kHostedAppID);
1262 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
1263 base::Bind(DoesInstallSuccessReferToId, kHostedAppID));
1264 content::WindowedNotificationObserver extension_observer( 1317 content::WindowedNotificationObserver extension_observer(
1265 extensions::NOTIFICATION_EXTENSION_INSTALL_ERROR, 1318 extensions::NOTIFICATION_EXTENSION_INSTALL_ERROR,
1266 base::Bind(DoesInstallFailureReferToId, kGoodExtensionID)); 1319 base::Bind(DoesInstallFailureReferToId, kGoodExtensionID));
1267 1320
1268 ASSERT_NO_FATAL_FAILURE(StartLogin(std::string(), std::string())); 1321 ASSERT_NO_FATAL_FAILURE(StartLogin(std::string(), std::string()));
1269 1322
1270 // Wait for the hosted app installation to succeed and the extension 1323 // Wait for the hosted app installation to succeed and the extension
1271 // installation to fail (because hosted apps are whitelisted for use in 1324 // installation to fail (because hosted apps are whitelisted for use in
1272 // device-local accounts and extensions are not). 1325 // device-local accounts and extensions are not).
1273 hosted_app_observer.Wait(); 1326 install_observer.Wait();
1274 extension_observer.Wait(); 1327 extension_observer.Wait();
1275 1328
1276 // Verify that the extension was kept in the local cache. 1329 // Verify that the extension was kept in the local cache.
1277 EXPECT_TRUE(cache_impl.GetExtension(kGoodExtensionID, hash, NULL, NULL)); 1330 EXPECT_TRUE(cache_impl.GetExtension(kGoodExtensionID, hash, NULL, NULL));
1278 1331
1279 // Verify that the extension file was kept in the local cache. 1332 // Verify that the extension file was kept in the local cache.
1280 EXPECT_TRUE(PathExists(local_file)); 1333 EXPECT_TRUE(PathExists(local_file));
1281 } 1334 }
1282 1335
1283 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, ExternalData) { 1336 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, ExternalData) {
(...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after
2192 " }" 2245 " }"
2193 "}")); 2246 "}"));
2194 2247
2195 // Install and refresh the device policy now. This will also fetch the initial 2248 // Install and refresh the device policy now. This will also fetch the initial
2196 // user policy for the device-local account now. 2249 // user policy for the device-local account now.
2197 UploadAndInstallDeviceLocalAccountPolicy(); 2250 UploadAndInstallDeviceLocalAccountPolicy();
2198 AddPublicSessionToDevicePolicy(kAccountId1); 2251 AddPublicSessionToDevicePolicy(kAccountId1);
2199 WaitForPolicy(); 2252 WaitForPolicy();
2200 2253
2201 // Observe the app installation after login. 2254 // Observe the app installation after login.
2202 content::WindowedNotificationObserver extension_observer( 2255 ExtensionInstallObserver install_observer(kShowManagedStorageID);
2203 extensions::NOTIFICATION_EXTENSION_WILL_BE_INSTALLED_DEPRECATED,
2204 base::Bind(DoesInstallSuccessReferToId, kShowManagedStorageID));
2205 ASSERT_NO_FATAL_FAILURE(StartLogin(std::string(), std::string())); 2256 ASSERT_NO_FATAL_FAILURE(StartLogin(std::string(), std::string()));
2206 WaitForSessionStart(); 2257 WaitForSessionStart();
2207 extension_observer.Wait(); 2258 install_observer.Wait();
2208 2259
2209 // Verify that the app was installed. 2260 // Verify that the app was installed.
2210 Profile* profile = GetProfileForTest(); 2261 Profile* profile = GetProfileForTest();
2211 ASSERT_TRUE(profile); 2262 ASSERT_TRUE(profile);
2212 ExtensionService* extension_service = 2263 ExtensionService* extension_service =
2213 extensions::ExtensionSystem::Get(profile)->extension_service(); 2264 extensions::ExtensionSystem::Get(profile)->extension_service();
2214 EXPECT_TRUE(extension_service->GetExtensionById(kShowManagedStorageID, true)); 2265 EXPECT_TRUE(extension_service->GetExtensionById(kShowManagedStorageID, true));
2215 2266
2216 // Wait for the app policy if it hasn't been fetched yet. 2267 // Wait for the app policy if it hasn't been fetched yet.
2217 ProfilePolicyConnector* connector = 2268 ProfilePolicyConnector* connector =
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
2385 ASSERT_TRUE(content::ExecuteScript(contents_, 2436 ASSERT_TRUE(content::ExecuteScript(contents_,
2386 "$('tos-accept-button').click();")); 2437 "$('tos-accept-button').click();"));
2387 2438
2388 WaitForSessionStart(); 2439 WaitForSessionStart();
2389 } 2440 }
2390 2441
2391 INSTANTIATE_TEST_CASE_P(TermsOfServiceDownloadTestInstance, 2442 INSTANTIATE_TEST_CASE_P(TermsOfServiceDownloadTestInstance,
2392 TermsOfServiceDownloadTest, testing::Bool()); 2443 TermsOfServiceDownloadTest, testing::Bool());
2393 2444
2394 } // namespace policy 2445 } // 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