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

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

Issue 389313003: Fix races in DeviceLocalAccountTest.Extensions* (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 6 years, 5 months 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/chromeos/extensions/device_local_account_external_policy_loader.cc ('k') | 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 <string> 6 #include <string>
7 7
8 #include "apps/app_window_registry.h" 8 #include "apps/app_window_registry.h"
9 #include "apps/ui/native_app_window.h" 9 #include "apps/ui/native_app_window.h"
10 #include "ash/shell.h" 10 #include "ash/shell.h"
(...skipping 17 matching lines...) Expand all
28 #include "base/prefs/pref_service.h" 28 #include "base/prefs/pref_service.h"
29 #include "base/run_loop.h" 29 #include "base/run_loop.h"
30 #include "base/sequenced_task_runner.h" 30 #include "base/sequenced_task_runner.h"
31 #include "base/strings/string_number_conversions.h" 31 #include "base/strings/string_number_conversions.h"
32 #include "base/strings/string_util.h" 32 #include "base/strings/string_util.h"
33 #include "base/strings/stringprintf.h" 33 #include "base/strings/stringprintf.h"
34 #include "base/strings/utf_string_conversions.h" 34 #include "base/strings/utf_string_conversions.h"
35 #include "base/values.h" 35 #include "base/values.h"
36 #include "chrome/browser/browser_process.h" 36 #include "chrome/browser/browser_process.h"
37 #include "chrome/browser/chrome_notification_types.h" 37 #include "chrome/browser/chrome_notification_types.h"
38 #include "chrome/browser/chromeos/extensions/device_local_account_external_polic y_loader.h"
39 #include "chrome/browser/chromeos/extensions/external_cache.h"
38 #include "chrome/browser/chromeos/login/existing_user_controller.h" 40 #include "chrome/browser/chromeos/login/existing_user_controller.h"
39 #include "chrome/browser/chromeos/login/screens/wizard_screen.h" 41 #include "chrome/browser/chromeos/login/screens/wizard_screen.h"
40 #include "chrome/browser/chromeos/login/ui/login_display_host.h" 42 #include "chrome/browser/chromeos/login/ui/login_display_host.h"
41 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" 43 #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h"
42 #include "chrome/browser/chromeos/login/ui/webui_login_view.h" 44 #include "chrome/browser/chromeos/login/ui/webui_login_view.h"
43 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager.h" 45 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager.h"
44 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager_impl.h" 46 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager_impl.h"
45 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager_test_uti l.h" 47 #include "chrome/browser/chromeos/login/users/avatar/user_image_manager_test_uti l.h"
46 #include "chrome/browser/chromeos/login/users/user.h" 48 #include "chrome/browser/chromeos/login/users/user.h"
47 #include "chrome/browser/chromeos/login/users/user_manager.h" 49 #include "chrome/browser/chromeos/login/users/user_manager.h"
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 // Verify that the hosted app was installed. 745 // Verify that the hosted app was installed.
744 Profile* profile = GetProfileForTest(); 746 Profile* profile = GetProfileForTest();
745 ASSERT_TRUE(profile); 747 ASSERT_TRUE(profile);
746 ExtensionService* extension_service = 748 ExtensionService* extension_service =
747 extensions::ExtensionSystem::Get(profile)->extension_service(); 749 extensions::ExtensionSystem::Get(profile)->extension_service();
748 EXPECT_TRUE(extension_service->GetExtensionById(kHostedAppID, true)); 750 EXPECT_TRUE(extension_service->GetExtensionById(kHostedAppID, true));
749 751
750 // Verify that the extension was not installed. 752 // Verify that the extension was not installed.
751 EXPECT_FALSE(extension_service->GetExtensionById(kGoodExtensionID, true)); 753 EXPECT_FALSE(extension_service->GetExtensionById(kGoodExtensionID, true));
752 754
753 // Verify that the app was copied to the account's extension cache. 755 // Verify that the app was downloaded to the account's extension cache.
754 base::FilePath test_dir; 756 base::FilePath test_dir;
755 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir)); 757 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir));
756 EXPECT_TRUE(ContentsEqual( 758 EXPECT_TRUE(ContentsEqual(
757 GetCacheCRXFile(kAccountId1, kHostedAppID, kHostedAppVersion), 759 GetCacheCRXFile(kAccountId1, kHostedAppID, kHostedAppVersion),
758 test_dir.Append(kHostedAppCRXPath))); 760 test_dir.Append(kHostedAppCRXPath)));
759 761
760 // Verify that the extension was not copied to the account's extension cache. 762 // Verify that the extension was removed from the account's extension cache
761 EXPECT_FALSE(PathExists(GetCacheCRXFile( 763 // after the installation failure.
762 kAccountId1, kGoodExtensionID, kGoodExtensionVersion))); 764 DeviceLocalAccountPolicyBroker* broker =
765 g_browser_process->platform_part()->browser_policy_connector_chromeos()->
766 GetDeviceLocalAccountPolicyService()->GetBrokerForUser(user_id_1_);
767 ASSERT_TRUE(broker);
768 chromeos::ExternalCache* cache =
769 broker->extension_loader()->GetExternalCacheForTesting();
770 ASSERT_TRUE(cache);
771 EXPECT_FALSE(cache->GetExtension(kGoodExtensionID, NULL, NULL));
763 } 772 }
764 773
765 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, ExtensionsCached) { 774 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, ExtensionsCached) {
766 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); 775 ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady());
767 776
768 // Pre-populate the device local account's extension cache with a hosted app 777 // Pre-populate the device local account's extension cache with a hosted app
769 // and an extension. 778 // and an extension.
770 EXPECT_TRUE(base::CreateDirectory( 779 EXPECT_TRUE(base::CreateDirectory(
771 GetExtensionCacheDirectoryForAccountID(kAccountId1))); 780 GetExtensionCacheDirectoryForAccountID(kAccountId1)));
772 base::FilePath test_dir; 781 base::FilePath test_dir;
773 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir)); 782 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &test_dir));
774 const base::FilePath cached_hosted_app = 783 const base::FilePath cached_hosted_app =
775 GetCacheCRXFile(kAccountId1, kHostedAppID, kHostedAppVersion); 784 GetCacheCRXFile(kAccountId1, kHostedAppID, kHostedAppVersion);
776 EXPECT_TRUE(CopyFile(test_dir.Append(kHostedAppCRXPath), 785 EXPECT_TRUE(CopyFile(test_dir.Append(kHostedAppCRXPath),
777 cached_hosted_app)); 786 cached_hosted_app));
778 const base::FilePath cached_extension = 787 EXPECT_TRUE(CopyFile(
779 GetCacheCRXFile(kAccountId1, kGoodExtensionID, kGoodExtensionVersion); 788 test_dir.Append(kGoodExtensionCRXPath),
780 EXPECT_TRUE(CopyFile(test_dir.Append(kGoodExtensionCRXPath), 789 GetCacheCRXFile(kAccountId1, kGoodExtensionID, kGoodExtensionVersion)));
781 cached_extension));
782 790
783 // Specify policy to force-install the hosted app. 791 // Specify policy to force-install the hosted app.
784 em::StringList* forcelist = device_local_account_policy_.payload() 792 em::StringList* forcelist = device_local_account_policy_.payload()
785 .mutable_extensioninstallforcelist()->mutable_value(); 793 .mutable_extensioninstallforcelist()->mutable_value();
786 forcelist->add_entries(base::StringPrintf( 794 forcelist->add_entries(base::StringPrintf(
787 "%s;%s", 795 "%s;%s",
788 kHostedAppID, 796 kHostedAppID,
789 embedded_test_server()->GetURL(kRelativeUpdateURL).spec().c_str())); 797 embedded_test_server()->GetURL(kRelativeUpdateURL).spec().c_str()));
790 forcelist->add_entries(base::StringPrintf( 798 forcelist->add_entries(base::StringPrintf(
791 "%s;%s", 799 "%s;%s",
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 extensions::ExtensionSystem::Get(profile)->extension_service(); 849 extensions::ExtensionSystem::Get(profile)->extension_service();
842 EXPECT_TRUE(extension_service->GetExtensionById(kHostedAppID, true)); 850 EXPECT_TRUE(extension_service->GetExtensionById(kHostedAppID, true));
843 851
844 // Verify that the extension was not installed. 852 // Verify that the extension was not installed.
845 EXPECT_FALSE(extension_service->GetExtensionById(kGoodExtensionID, true)); 853 EXPECT_FALSE(extension_service->GetExtensionById(kGoodExtensionID, true));
846 854
847 // Verify that the app is still in the account's extension cache. 855 // Verify that the app is still in the account's extension cache.
848 EXPECT_TRUE(PathExists(cached_hosted_app)); 856 EXPECT_TRUE(PathExists(cached_hosted_app));
849 857
850 // Verify that the extension was removed from the account's extension cache. 858 // Verify that the extension was removed from the account's extension cache.
851 EXPECT_FALSE(PathExists(cached_extension)); 859 DeviceLocalAccountPolicyBroker* broker =
860 g_browser_process->platform_part()->browser_policy_connector_chromeos()->
861 GetDeviceLocalAccountPolicyService()->GetBrokerForUser(user_id_1_);
862 ASSERT_TRUE(broker);
863 chromeos::ExternalCache* cache =
864 broker->extension_loader()->GetExternalCacheForTesting();
865 ASSERT_TRUE(cache);
866 EXPECT_FALSE(cache->GetExtension(kGoodExtensionID, NULL, NULL));
852 } 867 }
853 868
854 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, ExternalData) { 869 IN_PROC_BROWSER_TEST_F(DeviceLocalAccountTest, ExternalData) {
855 // chromeos::UserManager requests an external data fetch whenever 870 // chromeos::UserManager requests an external data fetch whenever
856 // the key::kUserAvatarImage policy is set. Since this test wants to 871 // the key::kUserAvatarImage policy is set. Since this test wants to
857 // verify that the underlying policy subsystem will start a fetch 872 // verify that the underlying policy subsystem will start a fetch
858 // without this request as well, the chromeos::UserManager must be 873 // without this request as well, the chromeos::UserManager must be
859 // prevented from seeing the policy change. 874 // prevented from seeing the policy change.
860 reinterpret_cast<chromeos::UserManagerImpl*>(chromeos::UserManager::Get())-> 875 reinterpret_cast<chromeos::UserManagerImpl*>(chromeos::UserManager::Get())->
861 StopPolicyObserverForTesting(); 876 StopPolicyObserverForTesting();
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
1384 if (!IsSessionStarted()) { 1399 if (!IsSessionStarted()) {
1385 content::WindowedNotificationObserver(chrome::NOTIFICATION_SESSION_STARTED, 1400 content::WindowedNotificationObserver(chrome::NOTIFICATION_SESSION_STARTED,
1386 base::Bind(IsSessionStarted)).Wait(); 1401 base::Bind(IsSessionStarted)).Wait();
1387 } 1402 }
1388 } 1403 }
1389 1404
1390 INSTANTIATE_TEST_CASE_P(TermsOfServiceTestInstance, 1405 INSTANTIATE_TEST_CASE_P(TermsOfServiceTestInstance,
1391 TermsOfServiceTest, testing::Bool()); 1406 TermsOfServiceTest, testing::Bool());
1392 1407
1393 } // namespace policy 1408 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/extensions/device_local_account_external_policy_loader.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698