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

Side by Side Diff: apps/app_restore_service_browsertest.cc

Issue 12391006: Give an app the file entries it had back on restart. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix compile (chromium style) Created 7 years, 9 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
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 "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 "chrome/browser/extensions/api/file_handlers/app_file_handler_util.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"
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 // One for the read-only file entry and one for the writable file entry. 91 // One for the read-only file entry and one for the writable file entry.
92 ASSERT_EQ(2u, file_entries.size()); 92 ASSERT_EQ(2u, file_entries.size());
93 93
94 extension_suspended.Wait(); 94 extension_suspended.Wait();
95 file_entries.clear(); 95 file_entries.clear();
96 extension_prefs->GetSavedFileEntries(extension->id(), &file_entries); 96 extension_prefs->GetSavedFileEntries(extension->id(), &file_entries);
97 // File entries should be cleared when the extension is suspended. 97 // File entries should be cleared when the extension is suspended.
98 ASSERT_TRUE(file_entries.empty()); 98 ASSERT_TRUE(file_entries.empty());
99 } 99 }
100 100
101 IN_PROC_BROWSER_TEST_F(PlatformAppBrowserTest, FileAccessIsRestored) {
102 content::WindowedNotificationObserver extension_suspended(
103 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
104 content::NotificationService::AllSources());
105
106 base::ScopedTempDir temp_directory;
107 ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
108 base::FilePath temp_file;
109 ASSERT_TRUE(file_util::CreateTemporaryFileInDir(temp_directory.path(),
110 &temp_file));
111
112 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest(
113 &temp_file);
114
115 ExtensionTestMessageListener file_written_listener("fileWritten", false);
116 ExtensionTestMessageListener access_ok_listener(
117 "restartedFileAccessOK", false);
118
119 const Extension* extension =
120 LoadAndLaunchPlatformApp("file_access_restored_test");
121 ASSERT_TRUE(extension);
122 file_written_listener.WaitUntilSatisfied();
123
124 ExtensionService* extension_service =
125 ExtensionSystem::Get(browser()->profile())->extension_service();
126 ExtensionPrefs* extension_prefs = extension_service->extension_prefs();
127
128 // Record the file entries in prefs because when the app gets suspended it
129 // will have them all cleared.
130 std::vector<SavedFileEntry> file_entries;
131 extension_prefs->GetSavedFileEntries(extension->id(), &file_entries);
132 extension_suspended.Wait();
133
134 // Simulate a restart by populating the preferences as if the browser didn't
135 // get time to clean itself up.
136 extension_prefs->SetExtensionRunning(extension->id(), true);
137 for (std::vector<SavedFileEntry>::const_iterator it = file_entries.begin();
138 it != file_entries.end(); ++it) {
139 extension_prefs->AddSavedFileEntry(
140 extension->id(), it->id, it->path, it->writable);
141 }
142
143 apps::AppRestoreServiceFactory::GetForProfile(browser()->profile())->
144 HandleStartup(true);
145
146 access_ok_listener.WaitUntilSatisfied();
147 }
148
101 } // namespace apps 149 } // namespace apps
OLDNEW
« no previous file with comments | « apps/app_restore_service.cc ('k') | chrome/browser/extensions/api/app_runtime/app_runtime_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698