OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/saved_files_service.h" | 5 #include "apps/saved_files_service.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/path_service.h" | 7 #include "base/path_service.h" |
8 #include "base/scoped_observer.h" | |
8 #include "build/build_config.h" | 9 #include "build/build_config.h" |
9 #include "chrome/browser/apps/app_browsertest_util.h" | 10 #include "chrome/browser/apps/app_browsertest_util.h" |
10 #include "chrome/browser/chrome_notification_types.h" | |
11 #include "chrome/browser/extensions/api/file_system/file_system_api.h" | 11 #include "chrome/browser/extensions/api/file_system/file_system_api.h" |
12 #include "chrome/browser/profiles/profile.h" | 12 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
14 #include "content/public/browser/notification_observer.h" | |
15 #include "content/public/browser/notification_service.h" | |
16 #include "extensions/browser/extension_prefs.h" | 14 #include "extensions/browser/extension_prefs.h" |
15 #include "extensions/browser/extension_registry.h" | |
16 #include "extensions/browser/extension_registry_observer.h" | |
17 | 17 |
18 namespace extensions { | 18 namespace extensions { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 class AppInstallObserver : public content::NotificationObserver { | 22 class AppLoadObserver : public ExtensionRegistryObserver { |
23 public: | 23 public: |
24 AppInstallObserver( | 24 AppLoadObserver(Profile* profile, |
Devlin
2014/06/17 16:28:31
nit: This could actually just be a BrowserContext.
limasdf
2014/06/17 18:25:43
Done.
| |
25 base::Callback<void(const Extension*)> callback) | 25 base::Callback<void(const Extension*)> callback) |
26 : callback_(callback) { | 26 : callback_(callback), extension_registry_observer_(this) { |
27 registrar_.Add(this, | 27 extension_registry_observer_.Add(ExtensionRegistry::Get(profile)); |
28 chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, | |
29 content::NotificationService::AllSources()); | |
30 } | 28 } |
31 | 29 |
32 virtual void Observe(int type, | 30 virtual void OnExtensionLoaded(content::BrowserContext* browser_context, |
33 const content::NotificationSource& source, | 31 const Extension* extension) OVERRIDE { |
Devlin
2014/06/17 16:28:31
nit: indentation is off
limasdf
2014/06/17 18:25:43
Done.
| |
34 const content::NotificationDetails& details) OVERRIDE { | 32 callback_.Run(extension); |
35 EXPECT_EQ(chrome::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, type); | |
36 callback_.Run(content::Details<const Extension>(details).ptr()); | |
37 } | 33 } |
38 | 34 |
39 private: | 35 private: |
40 content::NotificationRegistrar registrar_; | |
41 base::Callback<void(const Extension*)> callback_; | 36 base::Callback<void(const Extension*)> callback_; |
42 DISALLOW_COPY_AND_ASSIGN(AppInstallObserver); | 37 ScopedObserver<ExtensionRegistry, ExtensionRegistryObserver> |
38 extension_registry_observer_; | |
39 DISALLOW_COPY_AND_ASSIGN(AppLoadObserver); | |
43 }; | 40 }; |
44 | 41 |
45 void SetLastChooseEntryDirectory(const base::FilePath& choose_entry_directory, | 42 void SetLastChooseEntryDirectory(const base::FilePath& choose_entry_directory, |
46 ExtensionPrefs* prefs, | 43 ExtensionPrefs* prefs, |
47 const Extension* extension) { | 44 const Extension* extension) { |
48 file_system_api::SetLastChooseEntryDirectory( | 45 file_system_api::SetLastChooseEntryDirectory( |
49 prefs, extension->id(), choose_entry_directory); | 46 prefs, extension->id(), choose_entry_directory); |
50 } | 47 } |
51 | 48 |
52 void AddSavedEntry(const base::FilePath& path_to_save, | 49 void AddSavedEntry(const base::FilePath& path_to_save, |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 CheckStoredDirectoryMatches(test_file); | 187 CheckStoredDirectoryMatches(test_file); |
191 } | 188 } |
192 | 189 |
193 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, | 190 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, |
194 FileSystemApiOpenExistingFileUsingPreviousPathTest) { | 191 FileSystemApiOpenExistingFileUsingPreviousPathTest) { |
195 base::FilePath test_file = TempFilePath("open_existing.txt", true); | 192 base::FilePath test_file = TempFilePath("open_existing.txt", true); |
196 ASSERT_FALSE(test_file.empty()); | 193 ASSERT_FALSE(test_file.empty()); |
197 FileSystemChooseEntryFunction:: | 194 FileSystemChooseEntryFunction:: |
198 SkipPickerAndSelectSuggestedPathForTest(); | 195 SkipPickerAndSelectSuggestedPathForTest(); |
199 { | 196 { |
200 AppInstallObserver observer( | 197 AppLoadObserver observer(profile(), |
limasdf
2014/06/17 18:25:43
I'm actually like to pass something like a browser
Devlin
2014/06/18 16:04:34
Yeah, that's kind of annoying. What we could (and
limasdf
2014/06/19 01:48:42
one day I'll do it!
| |
201 base::Bind(SetLastChooseEntryDirectory, | 198 base::Bind(SetLastChooseEntryDirectory, |
202 test_file.DirName(), | 199 test_file.DirName(), |
203 ExtensionPrefs::Get(profile()))); | 200 ExtensionPrefs::Get(profile()))); |
204 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing")) | 201 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing")) |
205 << message_; | 202 << message_; |
206 } | 203 } |
207 CheckStoredDirectoryMatches(test_file); | 204 CheckStoredDirectoryMatches(test_file); |
208 } | 205 } |
209 | 206 |
210 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, | 207 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, |
211 FileSystemApiOpenExistingFilePreviousPathDoesNotExistTest) { | 208 FileSystemApiOpenExistingFilePreviousPathDoesNotExistTest) { |
212 base::FilePath test_file = TempFilePath("open_existing.txt", true); | 209 base::FilePath test_file = TempFilePath("open_existing.txt", true); |
213 ASSERT_FALSE(test_file.empty()); | 210 ASSERT_FALSE(test_file.empty()); |
214 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded( | 211 ASSERT_TRUE(PathService::OverrideAndCreateIfNeeded( |
215 chrome::DIR_USER_DOCUMENTS, test_file.DirName(), false, false)); | 212 chrome::DIR_USER_DOCUMENTS, test_file.DirName(), false, false)); |
216 FileSystemChooseEntryFunction:: | 213 FileSystemChooseEntryFunction:: |
217 SkipPickerAndSelectSuggestedPathForTest(); | 214 SkipPickerAndSelectSuggestedPathForTest(); |
218 { | 215 { |
219 AppInstallObserver observer(base::Bind( | 216 AppLoadObserver observer( |
220 SetLastChooseEntryDirectory, | 217 profile(), |
221 test_file.DirName().Append( | 218 base::Bind(SetLastChooseEntryDirectory, |
222 base::FilePath::FromUTF8Unsafe("fake_directory_does_not_exist")), | 219 test_file.DirName().Append(base::FilePath::FromUTF8Unsafe( |
223 ExtensionPrefs::Get(profile()))); | 220 "fake_directory_does_not_exist")), |
221 ExtensionPrefs::Get(profile()))); | |
224 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing")) | 222 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing")) |
225 << message_; | 223 << message_; |
226 } | 224 } |
227 CheckStoredDirectoryMatches(test_file); | 225 CheckStoredDirectoryMatches(test_file); |
228 } | 226 } |
229 | 227 |
230 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, | 228 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, |
231 FileSystemApiOpenExistingFileDefaultPathTest) { | 229 FileSystemApiOpenExistingFileDefaultPathTest) { |
232 base::FilePath test_file = TempFilePath("open_existing.txt", true); | 230 base::FilePath test_file = TempFilePath("open_existing.txt", true); |
233 ASSERT_FALSE(test_file.empty()); | 231 ASSERT_FALSE(test_file.empty()); |
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
601 EXPECT_EQ(test_directory, file_entries[0].path); | 599 EXPECT_EQ(test_directory, file_entries[0].path); |
602 EXPECT_EQ(1, file_entries[0].sequence_number); | 600 EXPECT_EQ(1, file_entries[0].sequence_number); |
603 EXPECT_TRUE(file_entries[0].is_directory); | 601 EXPECT_TRUE(file_entries[0].is_directory); |
604 } | 602 } |
605 | 603 |
606 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRestoreEntry) { | 604 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRestoreEntry) { |
607 base::FilePath test_file = TempFilePath("writable.txt", true); | 605 base::FilePath test_file = TempFilePath("writable.txt", true); |
608 ASSERT_FALSE(test_file.empty()); | 606 ASSERT_FALSE(test_file.empty()); |
609 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( | 607 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
610 &test_file); | 608 &test_file); |
611 AppInstallObserver observer( | 609 AppLoadObserver observer(profile(), |
612 base::Bind(AddSavedEntry, | 610 base::Bind(AddSavedEntry, |
613 test_file, | 611 test_file, |
614 false, | 612 false, |
615 apps::SavedFilesService::Get(profile()))); | 613 apps::SavedFilesService::Get(profile()))); |
616 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/restore_entry")) | 614 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/restore_entry")) |
617 << message_; | 615 << message_; |
618 } | 616 } |
619 | 617 |
620 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRestoreDirectoryEntry) { | 618 IN_PROC_BROWSER_TEST_F(FileSystemApiTest, FileSystemApiRestoreDirectoryEntry) { |
621 base::FilePath test_file = TempFilePath("writable.txt", true); | 619 base::FilePath test_file = TempFilePath("writable.txt", true); |
622 ASSERT_FALSE(test_file.empty()); | 620 ASSERT_FALSE(test_file.empty()); |
623 base::FilePath test_directory = test_file.DirName(); | 621 base::FilePath test_directory = test_file.DirName(); |
624 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( | 622 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
625 &test_file); | 623 &test_file); |
626 AppInstallObserver observer( | 624 AppLoadObserver observer(profile(), |
627 base::Bind(AddSavedEntry, | 625 base::Bind(AddSavedEntry, |
628 test_directory, | 626 test_directory, |
629 true, | 627 true, |
630 apps::SavedFilesService::Get(profile()))); | 628 apps::SavedFilesService::Get(profile()))); |
631 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/restore_directory")) | 629 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/restore_directory")) |
632 << message_; | 630 << message_; |
633 } | 631 } |
634 | 632 |
635 } // namespace extensions | 633 } // namespace extensions |
OLD | NEW |