| OLD | NEW |
| 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 "apps/app_restore_service.h" | 5 #include "apps/app_restore_service.h" |
| 6 #include "apps/app_restore_service_factory.h" | 6 #include "apps/app_restore_service_factory.h" |
| 7 #include "chrome/browser/extensions/api/file_handlers/app_file_handler_util.h" | |
| 8 #include "chrome/browser/extensions/api/file_system/file_system_api.h" | 7 #include "chrome/browser/extensions/api/file_system/file_system_api.h" |
| 8 #include "chrome/browser/extensions/api/file_system/saved_files_service.h" |
| 9 #include "chrome/browser/extensions/extension_prefs.h" | 9 #include "chrome/browser/extensions/extension_prefs.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/extensions/extension_system.h" | 11 #include "chrome/browser/extensions/extension_system.h" |
| 12 #include "chrome/browser/extensions/extension_test_message_listener.h" | 12 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 13 #include "chrome/browser/extensions/platform_app_browsertest_util.h" | 13 #include "chrome/browser/extensions/platform_app_browsertest_util.h" |
| 14 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
| 15 #include "content/public/test/test_utils.h" | 15 #include "content/public/test/test_utils.h" |
| 16 | 16 |
| 17 using extensions::app_file_handler_util::SavedFileEntry; | 17 using extensions::SavedFileEntry; |
| 18 using extensions::SavedFilesService; |
| 18 using extensions::Extension; | 19 using extensions::Extension; |
| 19 using extensions::ExtensionPrefs; | 20 using extensions::ExtensionPrefs; |
| 20 using extensions::ExtensionSystem; | 21 using extensions::ExtensionSystem; |
| 21 using extensions::FileSystemChooseEntryFunction; | 22 using extensions::FileSystemChooseEntryFunction; |
| 22 | 23 |
| 23 // TODO(benwells): Move PlatformAppBrowserTest to apps namespace in apps | 24 // TODO(benwells): Move PlatformAppBrowserTest to apps namespace in apps |
| 24 // component. | 25 // component. |
| 25 using extensions::PlatformAppBrowserTest; | 26 using extensions::PlatformAppBrowserTest; |
| 26 | 27 |
| 27 namespace apps { | 28 namespace apps { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 76 |
| 76 ExtensionTestMessageListener file_written_listener("fileWritten", false); | 77 ExtensionTestMessageListener file_written_listener("fileWritten", false); |
| 77 ExtensionTestMessageListener access_ok_listener( | 78 ExtensionTestMessageListener access_ok_listener( |
| 78 "restartedFileAccessOK", false); | 79 "restartedFileAccessOK", false); |
| 79 | 80 |
| 80 const Extension* extension = | 81 const Extension* extension = |
| 81 LoadAndLaunchPlatformApp("file_access_saved_to_prefs_test"); | 82 LoadAndLaunchPlatformApp("file_access_saved_to_prefs_test"); |
| 82 ASSERT_TRUE(extension); | 83 ASSERT_TRUE(extension); |
| 83 file_written_listener.WaitUntilSatisfied(); | 84 file_written_listener.WaitUntilSatisfied(); |
| 84 | 85 |
| 85 ExtensionPrefs* extension_prefs = | 86 SavedFilesService* saved_files_service = SavedFilesService::Get(profile()); |
| 86 ExtensionSystem::Get(browser()->profile())->extension_prefs(); | |
| 87 | 87 |
| 88 // Record the file entries in prefs because when the app gets suspended it | 88 // Record the file entries in prefs because when the app gets suspended it |
| 89 // will have them all cleared. | 89 // will have them all cleared. |
| 90 std::vector<SavedFileEntry> file_entries; | 90 std::vector<SavedFileEntry> file_entries; |
| 91 extensions::app_file_handler_util::GetSavedFileEntries( | 91 saved_files_service->GetFileEntries(extension->id(), &file_entries); |
| 92 extension_prefs, extension->id(), &file_entries); | |
| 93 // One for the read-only file entry and one for the writable file entry. | 92 // One for the read-only file entry and one for the writable file entry. |
| 94 ASSERT_EQ(2u, file_entries.size()); | 93 ASSERT_EQ(2u, file_entries.size()); |
| 95 | 94 |
| 96 extension_suspended.Wait(); | 95 extension_suspended.Wait(); |
| 97 file_entries.clear(); | 96 file_entries.clear(); |
| 98 extensions::app_file_handler_util::GetSavedFileEntries( | 97 saved_files_service->GetFileEntries(extension->id(), &file_entries); |
| 99 extension_prefs, extension->id(), &file_entries); | |
| 100 // File entries should be cleared when the extension is suspended. | 98 // File entries should be cleared when the extension is suspended. |
| 101 ASSERT_TRUE(file_entries.empty()); | 99 ASSERT_TRUE(file_entries.empty()); |
| 102 } | 100 } |
| 103 | 101 |
| 104 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, FileAccessIsRestored) { | 102 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, FileAccessIsRestored) { |
| 105 content::WindowedNotificationObserver extension_suspended( | 103 content::WindowedNotificationObserver extension_suspended( |
| 106 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 104 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
| 107 content::NotificationService::AllSources()); | 105 content::NotificationService::AllSources()); |
| 108 | 106 |
| 109 base::ScopedTempDir temp_directory; | 107 base::ScopedTempDir temp_directory; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 121 ExtensionTestMessageListener access_ok_listener( | 119 ExtensionTestMessageListener access_ok_listener( |
| 122 "restartedFileAccessOK", false); | 120 "restartedFileAccessOK", false); |
| 123 | 121 |
| 124 const Extension* extension = | 122 const Extension* extension = |
| 125 LoadAndLaunchPlatformApp("file_access_restored_test"); | 123 LoadAndLaunchPlatformApp("file_access_restored_test"); |
| 126 ASSERT_TRUE(extension); | 124 ASSERT_TRUE(extension); |
| 127 file_written_listener.WaitUntilSatisfied(); | 125 file_written_listener.WaitUntilSatisfied(); |
| 128 | 126 |
| 129 ExtensionPrefs* extension_prefs = | 127 ExtensionPrefs* extension_prefs = |
| 130 ExtensionSystem::Get(browser()->profile())->extension_prefs(); | 128 ExtensionSystem::Get(browser()->profile())->extension_prefs(); |
| 129 SavedFilesService* saved_files_service = SavedFilesService::Get(profile()); |
| 131 // Record the file entries in prefs because when the app gets suspended it | 130 // Record the file entries in prefs because when the app gets suspended it |
| 132 // will have them all cleared. | 131 // will have them all cleared. |
| 133 std::vector<SavedFileEntry> file_entries; | 132 std::vector<SavedFileEntry> file_entries; |
| 134 extensions::app_file_handler_util::GetSavedFileEntries(extension_prefs, | 133 saved_files_service->GetFileEntries(extension->id(), &file_entries); |
| 135 extension->id(), | |
| 136 &file_entries); | |
| 137 extension_suspended.Wait(); | 134 extension_suspended.Wait(); |
| 138 | 135 |
| 139 // Simulate a restart by populating the preferences as if the browser didn't | 136 // Simulate a restart by populating the preferences as if the browser didn't |
| 140 // get time to clean itself up. | 137 // get time to clean itself up. |
| 141 extension_prefs->SetExtensionRunning(extension->id(), true); | 138 extension_prefs->SetExtensionRunning(extension->id(), true); |
| 142 for (std::vector<SavedFileEntry>::const_iterator it = file_entries.begin(); | 139 for (std::vector<SavedFileEntry>::const_iterator it = file_entries.begin(); |
| 143 it != file_entries.end(); ++it) { | 140 it != file_entries.end(); ++it) { |
| 144 extensions::app_file_handler_util::AddSavedFileEntry( | 141 saved_files_service->AddFileEntry( |
| 145 extension_prefs, extension->id(), it->id, it->path, it->writable); | 142 extension->id(), it->id, it->path, it->writable); |
| 146 } | 143 } |
| 147 | 144 |
| 148 apps::AppRestoreServiceFactory::GetForProfile(browser()->profile())-> | 145 apps::AppRestoreServiceFactory::GetForProfile(browser()->profile())-> |
| 149 HandleStartup(true); | 146 HandleStartup(true); |
| 150 | 147 |
| 151 access_ok_listener.WaitUntilSatisfied(); | 148 access_ok_listener.WaitUntilSatisfied(); |
| 152 } | 149 } |
| 153 | 150 |
| 154 } // namespace apps | 151 } // namespace apps |
| OLD | NEW |