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