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_test_message_listener.h" | 10 #include "chrome/browser/extensions/extension_test_message_listener.h" |
11 #include "chrome/browser/extensions/platform_app_browsertest_util.h" | 11 #include "chrome/browser/extensions/platform_app_browsertest_util.h" |
12 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
13 #include "content/public/test/test_utils.h" | 13 #include "content/public/test/test_utils.h" |
14 | 14 |
15 using extensions::app_file_handler_util::SavedFileEntry; | |
16 using extensions::Extension; | 15 using extensions::Extension; |
17 using extensions::ExtensionPrefs; | 16 using extensions::ExtensionPrefs; |
18 using extensions::ExtensionSystem; | 17 using extensions::ExtensionSystem; |
19 using extensions::FileSystemChooseEntryFunction; | 18 using extensions::FileSystemChooseEntryFunction; |
20 | 19 |
21 // TODO(benwells): Move PlatformAppBrowserTest to apps namespace in apps | 20 // TODO(benwells): Move PlatformAppBrowserTest to apps namespace in apps |
22 // component. | 21 // component. |
23 using extensions::PlatformAppBrowserTest; | 22 using extensions::PlatformAppBrowserTest; |
24 | 23 |
25 namespace apps { | 24 namespace apps { |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 | 70 |
72 ExtensionTestMessageListener file_written_listener("fileWritten", false); | 71 ExtensionTestMessageListener file_written_listener("fileWritten", false); |
73 ExtensionTestMessageListener access_ok_listener( | 72 ExtensionTestMessageListener access_ok_listener( |
74 "restartedFileAccessOK", false); | 73 "restartedFileAccessOK", false); |
75 | 74 |
76 const Extension* extension = | 75 const Extension* extension = |
77 LoadAndLaunchPlatformApp("file_access_saved_to_prefs_test"); | 76 LoadAndLaunchPlatformApp("file_access_saved_to_prefs_test"); |
78 ASSERT_TRUE(extension); | 77 ASSERT_TRUE(extension); |
79 file_written_listener.WaitUntilSatisfied(); | 78 file_written_listener.WaitUntilSatisfied(); |
80 | 79 |
81 ExtensionPrefs* extension_prefs = | 80 SavedFilesService* saved_files_service = SavedFilesService::Get(profile()); |
82 ExtensionPrefs::Get(browser()->profile()); | |
83 | 81 |
84 // Record the file entries in prefs because when the app gets suspended it | 82 // Record the file entries in prefs because when the app gets suspended it |
85 // will have them all cleared. | 83 // will have them all cleared. |
koz (OOO until 15th September)
2013/05/20 05:33:51
This comment is probably doing more harm than good
Sam McNally
2013/05/20 07:13:33
Done.
| |
86 std::vector<SavedFileEntry> file_entries; | 84 std::vector<SavedFileEntry> file_entries = |
87 extensions::app_file_handler_util::GetSavedFileEntries( | 85 saved_files_service->GetAllFileEntries(extension->id()); |
88 extension_prefs, extension->id(), &file_entries); | |
89 // One for the read-only file entry and one for the writable file entry. | 86 // One for the read-only file entry and one for the writable file entry. |
90 ASSERT_EQ(2u, file_entries.size()); | 87 ASSERT_EQ(2u, file_entries.size()); |
91 | 88 |
92 extension_suspended.Wait(); | 89 extension_suspended.Wait(); |
93 file_entries.clear(); | 90 file_entries.clear(); |
koz (OOO until 15th September)
2013/05/20 05:33:51
No need to clear file_entries here.
Sam McNally
2013/05/20 07:13:33
Done.
| |
94 extensions::app_file_handler_util::GetSavedFileEntries( | 91 file_entries = saved_files_service->GetAllFileEntries(extension->id()); |
95 extension_prefs, extension->id(), &file_entries); | |
96 // File entries should be cleared when the extension is suspended. | 92 // File entries should be cleared when the extension is suspended. |
97 ASSERT_TRUE(file_entries.empty()); | 93 ASSERT_TRUE(file_entries.empty()); |
98 } | 94 } |
99 | 95 |
100 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, FileAccessIsRestored) { | 96 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, FileAccessIsRestored) { |
101 content::WindowedNotificationObserver extension_suspended( | 97 content::WindowedNotificationObserver extension_suspended( |
102 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, | 98 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED, |
103 content::NotificationService::AllSources()); | 99 content::NotificationService::AllSources()); |
104 | 100 |
105 base::ScopedTempDir temp_directory; | 101 base::ScopedTempDir temp_directory; |
(...skipping 11 matching lines...) Expand all Loading... | |
117 ExtensionTestMessageListener access_ok_listener( | 113 ExtensionTestMessageListener access_ok_listener( |
118 "restartedFileAccessOK", false); | 114 "restartedFileAccessOK", false); |
119 | 115 |
120 const Extension* extension = | 116 const Extension* extension = |
121 LoadAndLaunchPlatformApp("file_access_restored_test"); | 117 LoadAndLaunchPlatformApp("file_access_restored_test"); |
122 ASSERT_TRUE(extension); | 118 ASSERT_TRUE(extension); |
123 file_written_listener.WaitUntilSatisfied(); | 119 file_written_listener.WaitUntilSatisfied(); |
124 | 120 |
125 ExtensionPrefs* extension_prefs = | 121 ExtensionPrefs* extension_prefs = |
126 ExtensionPrefs::Get(browser()->profile()); | 122 ExtensionPrefs::Get(browser()->profile()); |
123 SavedFilesService* saved_files_service = SavedFilesService::Get(profile()); | |
127 // Record the file entries in prefs because when the app gets suspended it | 124 // Record the file entries in prefs because when the app gets suspended it |
128 // will have them all cleared. | 125 // will have them all cleared. |
koz (OOO until 15th September)
2013/05/20 05:33:51
Same here.
Sam McNally
2013/05/20 07:13:33
Done.
| |
129 std::vector<SavedFileEntry> file_entries; | 126 std::vector<SavedFileEntry> file_entries = |
130 extensions::app_file_handler_util::GetSavedFileEntries(extension_prefs, | 127 saved_files_service->GetAllFileEntries(extension->id()); |
131 extension->id(), | |
132 &file_entries); | |
133 extension_suspended.Wait(); | 128 extension_suspended.Wait(); |
134 | 129 |
135 // Simulate a restart by populating the preferences as if the browser didn't | 130 // Simulate a restart by populating the preferences as if the browser didn't |
136 // get time to clean itself up. | 131 // get time to clean itself up. |
137 extension_prefs->SetExtensionRunning(extension->id(), true); | 132 extension_prefs->SetExtensionRunning(extension->id(), true); |
138 for (std::vector<SavedFileEntry>::const_iterator it = file_entries.begin(); | 133 for (std::vector<SavedFileEntry>::const_iterator it = file_entries.begin(); |
139 it != file_entries.end(); ++it) { | 134 it != file_entries.end(); ++it) { |
140 extensions::app_file_handler_util::AddSavedFileEntry( | 135 saved_files_service->RetainFileEntry( |
141 extension_prefs, extension->id(), it->id, it->path, it->writable); | 136 extension->id(), it->id, it->path, it->writable); |
142 } | 137 } |
143 | 138 |
144 apps::AppRestoreServiceFactory::GetForProfile(browser()->profile())-> | 139 apps::AppRestoreServiceFactory::GetForProfile(browser()->profile())-> |
145 HandleStartup(true); | 140 HandleStartup(true); |
146 | 141 |
147 access_ok_listener.WaitUntilSatisfied(); | 142 access_ok_listener.WaitUntilSatisfied(); |
148 } | 143 } |
149 | 144 |
150 } // namespace apps | 145 } // namespace apps |
OLD | NEW |