| 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 // MediaGalleriesPrivate gallery watch API browser tests. | 5 // MediaGalleriesPrivate gallery watch API browser tests. |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
| 9 #include "base/files/file_path_watcher.h" |
| 9 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 11 #include "base/run_loop.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 11 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "chrome/browser/browser_process.h" |
| 12 #include "chrome/browser/extensions/extension_apitest.h" | 15 #include "chrome/browser/extensions/extension_apitest.h" |
| 13 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
| 14 #include "chrome/browser/extensions/extension_test_message_listener.h" | 17 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 18 #include "chrome/browser/media_galleries/media_file_system_registry.h" |
| 19 #include "chrome/browser/media_galleries/media_galleries_preferences.h" |
| 15 #include "chrome/browser/media_galleries/media_galleries_test_util.h" | 20 #include "chrome/browser/media_galleries/media_galleries_test_util.h" |
| 16 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
| 17 #include "content/public/browser/render_frame_host.h" | 22 #include "content/public/browser/render_frame_host.h" |
| 18 #include "content/public/browser/render_view_host.h" | 23 #include "content/public/browser/render_view_host.h" |
| 19 #include "extensions/browser/extension_system.h" | 24 #include "extensions/browser/extension_system.h" |
| 20 #include "extensions/common/extension.h" | 25 #include "extensions/common/extension.h" |
| 21 #include "extensions/common/switches.h" | 26 #include "extensions/common/switches.h" |
| 22 | 27 |
| 23 namespace { | 28 namespace { |
| 24 | 29 |
| 25 // Id of test extension from | 30 // Id of test extension from |
| 26 // chrome/test/data/extensions/api_test/|kTestExtensionPath| | 31 // chrome/test/data/extensions/api_test/|kTestExtensionPath| |
| 27 const char kTestExtensionId[] = "gceegfkgibmgpfopknlcgleimclbknie"; | 32 const char kTestExtensionId[] = "gceegfkgibmgpfopknlcgleimclbknie"; |
| 28 const char kTestExtensionPath[] = "media_galleries_private/gallerywatch"; | 33 const char kTestExtensionPath[] = "media_galleries_private/gallerywatch"; |
| 29 | 34 |
| 30 #if !defined(OS_CHROMEOS) | |
| 31 // JS commands. | 35 // JS commands. |
| 32 const char kGetAllWatchedGalleryIdsCmd[] = "getAllWatchedGalleryIds()"; | 36 const char kGetAllWatchedGalleryIdsCmd[] = "getAllWatchedGalleryIds()"; |
| 33 const char kGetMediaFileSystemsCmd[] = "getMediaFileSystems()"; | 37 const char kGetMediaFileSystemsCmd[] = "getMediaFileSystems()"; |
| 34 const char kSetupWatchOnValidGalleriesCmd[] = "setupWatchOnValidGalleries()"; | 38 const char kSetupWatchOnValidGalleriesCmd[] = "setupWatchOnValidGalleries()"; |
| 35 #if defined(OS_WIN) || defined(OS_LINUX) | |
| 36 const char kAddGalleryChangedListenerCmd[] = "addGalleryChangedListener()"; | 39 const char kAddGalleryChangedListenerCmd[] = "addGalleryChangedListener()"; |
| 37 const char kRemoveAllGalleryWatchCmd[] = "removeAllGalleryWatch()"; | 40 const char kRemoveAllGalleryWatchCmd[] = "removeAllGalleryWatch()"; |
| 38 const char kRemoveGalleryChangedListenerCmd[] = | 41 const char kRemoveGalleryChangedListenerCmd[] = |
| 39 "removeGalleryChangedListener()"; | 42 "removeGalleryChangedListener()"; |
| 40 const char kRemoveGalleryWatchCmd[] = "removeGalleryWatch()"; | 43 const char kRemoveGalleryWatchCmd[] = "removeGalleryWatch()"; |
| 41 const char kSetupWatchOnInvalidGalleryCmd[] = "setupWatchOnInvalidGallery()"; | 44 const char kSetupWatchOnInvalidGalleryCmd[] = "setupWatchOnInvalidGallery()"; |
| 42 #endif // defined(OS_WIN) || defined(OS_LINUX) | |
| 43 | 45 |
| 44 // And JS reply messages. | 46 // And JS reply messages. |
| 45 const char kAddGalleryWatchOK[] = "add_gallery_watch_ok"; | 47 const char kAddGalleryWatchOK[] = "add_gallery_watch_ok"; |
| 46 const char kGetAllGalleryWatchOK[] = "get_all_gallery_watch_ok"; | 48 const char kGetAllGalleryWatchOK[] = "get_all_gallery_watch_ok"; |
| 47 const char kGetMediaFileSystemsCallbackOK[] = | 49 const char kGetMediaFileSystemsCallbackOK[] = |
| 48 "get_media_file_systems_callback_ok"; | 50 "get_media_file_systems_callback_ok"; |
| 49 const char kGetMediaFileSystemsOK[] = "get_media_file_systems_ok"; | 51 const char kGetMediaFileSystemsOK[] = "get_media_file_systems_ok"; |
| 50 #if defined(OS_WIN) || defined(OS_LINUX) | |
| 51 const char kAddGalleryChangedListenerOK[] = "add_gallery_changed_listener_ok"; | 52 const char kAddGalleryChangedListenerOK[] = "add_gallery_changed_listener_ok"; |
| 52 const char kRemoveAllGalleryWatchOK[] = "remove_all_gallery_watch_ok"; | 53 const char kRemoveAllGalleryWatchOK[] = "remove_all_gallery_watch_ok"; |
| 53 const char kRemoveGalleryChangedListenerOK[] = | 54 const char kRemoveGalleryChangedListenerOK[] = |
| 54 "remove_gallery_changed_listener_ok"; | 55 "remove_gallery_changed_listener_ok"; |
| 55 const char kRemoveGalleryWatchOK[] = "remove_gallery_watch_ok"; | 56 const char kRemoveGalleryWatchOK[] = "remove_gallery_watch_ok"; |
| 56 #endif // defined(OS_WIN) || defined(OS_LINUX) | |
| 57 | 57 |
| 58 // Test reply messages. | 58 // Test reply messages. |
| 59 const char kGetAllGalleryWatchResultA[] = "gallery_watchers_does_not_exists"; | 59 const char kNoGalleryWatchesInstalled[] = "gallery_watchers_does_not_exists"; |
| 60 const char kAddGalleryWatchRequestFailed[] = "add_watch_request_failed"; | 60 const char kAddGalleryWatchRequestFailed[] = "add_watch_request_failed"; |
| 61 #if defined(OS_WIN) || defined(OS_LINUX) | |
| 62 const char kAddGalleryWatchRequestSucceeded[] = "add_watch_request_succeeded"; | 61 const char kAddGalleryWatchRequestSucceeded[] = "add_watch_request_succeeded"; |
| 63 const char kGalleryChangedEventReceived[] = "gallery_changed_event_received"; | 62 const char kGalleryChangedEventReceived[] = "gallery_changed_event_received"; |
| 64 const char kGetAllGalleryWatchResultB[] = | 63 const char kGalleryWatchesCheck[] = "gallery_watcher_checks"; |
| 65 "watchers_for_galleries_{1, 2, 3}_found"; | |
| 66 #endif // defined(OS_WIN) || defined(OS_LINUX) | |
| 67 #endif // !defined(OS_CHROMEOS) | |
| 68 | 64 |
| 69 } // namespace | 65 } // namespace |
| 70 | 66 |
| 71 | 67 |
| 72 /////////////////////////////////////////////////////////////////////////////// | 68 /////////////////////////////////////////////////////////////////////////////// |
| 73 // MediaGalleriesPrivateGalleryWatchApiTest // | 69 // MediaGalleriesPrivateGalleryWatchApiTest // |
| 74 /////////////////////////////////////////////////////////////////////////////// | 70 /////////////////////////////////////////////////////////////////////////////// |
| 75 | 71 |
| 76 class MediaGalleriesPrivateGalleryWatchApiTest : public ExtensionApiTest { | 72 class MediaGalleriesPrivateGalleryWatchApiTest : public ExtensionApiTest { |
| 77 public: | 73 public: |
| 78 MediaGalleriesPrivateGalleryWatchApiTest() {} | 74 MediaGalleriesPrivateGalleryWatchApiTest() |
| 75 : extension_(NULL), |
| 76 background_host_(NULL) { |
| 77 } |
| 79 virtual ~MediaGalleriesPrivateGalleryWatchApiTest() {} | 78 virtual ~MediaGalleriesPrivateGalleryWatchApiTest() {} |
| 80 | 79 |
| 81 protected: | 80 protected: |
| 82 // ExtensionApiTest overrides. | 81 // ExtensionApiTest overrides. |
| 83 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 82 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 84 ExtensionApiTest::SetUpCommandLine(command_line); | 83 ExtensionApiTest::SetUpCommandLine(command_line); |
| 85 command_line->AppendSwitchASCII( | 84 command_line->AppendSwitchASCII( |
| 86 extensions::switches::kWhitelistedExtensionID, | 85 extensions::switches::kWhitelistedExtensionID, |
| 87 kTestExtensionId); | 86 kTestExtensionId); |
| 88 } | 87 } |
| 89 | 88 virtual void SetUpOnMainThread() OVERRIDE { |
| 90 void ExecuteCmdAndCheckReply(content::RenderViewHost* host, | 89 ExtensionApiTest::SetUpOnMainThread(); |
| 91 const std::string& js_command, | 90 ensure_media_directories_exists_.reset(new EnsureMediaDirectoriesExists); |
| 92 const std::string& ok_message) { | 91 extension_ = LoadExtension(test_data_dir_.AppendASCII(kTestExtensionPath)); |
| 92 GetBackgroundHostForTestExtension(); |
| 93 CreateTestGallery(); |
| 94 FetchMediaGalleriesList(); |
| 95 } |
| 96 virtual void TearDownOnMainThread() OVERRIDE { |
| 97 extension_ = NULL; |
| 98 background_host_ = NULL; |
| 99 ensure_media_directories_exists_.reset(); |
| 100 ExtensionApiTest::TearDownOnMainThread(); |
| 101 } |
| 102 |
| 103 bool GalleryWatchesSupported() { |
| 104 return base::FilePathWatcher::RecursiveWatchAvailable(); |
| 105 } |
| 106 |
| 107 void ExecuteCmdAndCheckReply(const std::string& js_command, |
| 108 const std::string& ok_message) { |
| 93 ExtensionTestMessageListener listener(ok_message, false); | 109 ExtensionTestMessageListener listener(ok_message, false); |
| 94 host->GetMainFrame()->ExecuteJavaScript(base::ASCIIToUTF16(js_command)); | 110 background_host_->GetMainFrame()->ExecuteJavaScript( |
| 111 base::ASCIIToUTF16(js_command)); |
| 95 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 112 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
| 96 } | 113 } |
| 97 | 114 |
| 98 bool AddNewFileInGallery(int gallery_directory_key) { | 115 bool AddNewFileInTestGallery() { |
| 99 if ((gallery_directory_key != chrome::DIR_USER_MUSIC) && | |
| 100 (gallery_directory_key != chrome::DIR_USER_PICTURES) && | |
| 101 (gallery_directory_key != chrome::DIR_USER_VIDEOS)) | |
| 102 return false; | |
| 103 | |
| 104 base::FilePath gallery_dir; | |
| 105 if (!PathService::Get(gallery_directory_key, &gallery_dir)) | |
| 106 return false; | |
| 107 base::FilePath gallery_file = | 116 base::FilePath gallery_file = |
| 108 gallery_dir.Append(FILE_PATH_LITERAL("test1.txt")); | 117 test_gallery_.path().Append(FILE_PATH_LITERAL("test1.txt")); |
| 109 std::string content("new content"); | 118 std::string content("new content"); |
| 110 int write_size = base::WriteFile(gallery_file, content.c_str(), | 119 int write_size = base::WriteFile(gallery_file, content.c_str(), |
| 111 content.length()); | 120 content.length()); |
| 112 return (write_size == static_cast<int>(content.length())); | 121 return (write_size == static_cast<int>(content.length())); |
| 113 } | 122 } |
| 114 | 123 |
| 115 // Loads the test extension and returns the RenderViewHost of the extension. | 124 void SetupGalleryWatches() { |
| 116 // Returns NULL if the extension load operation failed. | 125 std::string expected_result = GalleryWatchesSupported() ? |
| 117 content::RenderViewHost* GetBackgroundHostForTestExtension() { | 126 kAddGalleryWatchRequestSucceeded : kAddGalleryWatchRequestFailed; |
| 118 const extensions::Extension* extension = | 127 |
| 119 LoadExtension(test_data_dir_.AppendASCII(kTestExtensionPath)); | 128 ExtensionTestMessageListener add_gallery_watch_finished( |
| 120 if (!extension) | 129 expected_result, false /* no reply */); |
| 121 return NULL; | 130 ExecuteCmdAndCheckReply(kSetupWatchOnValidGalleriesCmd, kAddGalleryWatchOK); |
| 122 return extensions::ExtensionSystem::Get(browser()->profile())-> | 131 EXPECT_TRUE(add_gallery_watch_finished.WaitUntilSatisfied()); |
| 123 process_manager()->GetBackgroundHostForExtension(extension->id())-> | |
| 124 render_view_host(); | |
| 125 } | 132 } |
| 126 | 133 |
| 127 private: | 134 private: |
| 135 void GetBackgroundHostForTestExtension() { |
| 136 ASSERT_TRUE(extension_); |
| 137 extensions::ExtensionSystem* extension_system = |
| 138 extensions::ExtensionSystem::Get(browser()->profile()); |
| 139 background_host_ = |
| 140 extension_system->process_manager()->GetBackgroundHostForExtension( |
| 141 extension_->id())->render_view_host(); |
| 142 ASSERT_TRUE(background_host_); |
| 143 } |
| 144 |
| 145 void CreateTestGallery() { |
| 146 MediaGalleriesPreferences* preferences = |
| 147 g_browser_process->media_file_system_registry()->GetPreferences( |
| 148 browser()->profile()); |
| 149 base::RunLoop runloop; |
| 150 preferences->EnsureInitialized(runloop.QuitClosure()); |
| 151 runloop.Run(); |
| 152 |
| 153 ASSERT_TRUE(test_gallery_.CreateUniqueTempDir()); |
| 154 MediaGalleryPrefInfo gallery_info; |
| 155 ASSERT_FALSE(preferences->LookUpGalleryByPath(test_gallery_.path(), |
| 156 &gallery_info)); |
| 157 MediaGalleryPrefId id = preferences->AddGallery( |
| 158 gallery_info.device_id, |
| 159 gallery_info.path, |
| 160 MediaGalleryPrefInfo::kAutoDetected, |
| 161 gallery_info.volume_label, |
| 162 gallery_info.vendor_name, |
| 163 gallery_info.model_name, |
| 164 gallery_info.total_size_in_bytes, |
| 165 gallery_info.last_attach_time, |
| 166 0, 0, 0); |
| 167 |
| 168 preferences->SetGalleryPermissionForExtension(*extension_, id, true); |
| 169 } |
| 170 |
| 171 void FetchMediaGalleriesList() { |
| 172 ExtensionTestMessageListener get_media_systems_finished( |
| 173 kGetMediaFileSystemsCallbackOK, false /* no reply */); |
| 174 ExecuteCmdAndCheckReply(kGetMediaFileSystemsCmd, kGetMediaFileSystemsOK); |
| 175 EXPECT_TRUE(get_media_systems_finished.WaitUntilSatisfied()); |
| 176 } |
| 177 |
| 178 scoped_ptr<EnsureMediaDirectoriesExists> ensure_media_directories_exists_; |
| 179 |
| 180 base::ScopedTempDir test_gallery_; |
| 181 |
| 182 const extensions::Extension* extension_; |
| 183 |
| 184 content::RenderViewHost* background_host_; |
| 185 |
| 128 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPrivateGalleryWatchApiTest); | 186 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPrivateGalleryWatchApiTest); |
| 129 }; | 187 }; |
| 130 | 188 |
| 131 | |
| 132 #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS)) | |
| 133 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateGalleryWatchApiTest, | 189 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateGalleryWatchApiTest, |
| 134 BasicGalleryWatch) { | 190 BasicGalleryWatch) { |
| 135 EnsureMediaDirectoriesExists media_directories; | 191 SetupGalleryWatches(); |
| 136 content::RenderViewHost* host = GetBackgroundHostForTestExtension(); | |
| 137 ASSERT_TRUE(host); | |
| 138 | |
| 139 // Get media file systems. | |
| 140 ExtensionTestMessageListener get_media_systems_finished( | |
| 141 kGetMediaFileSystemsCallbackOK, false /* no reply */); | |
| 142 ExecuteCmdAndCheckReply(host, kGetMediaFileSystemsCmd, | |
| 143 kGetMediaFileSystemsOK); | |
| 144 EXPECT_TRUE(get_media_systems_finished.WaitUntilSatisfied()); | |
| 145 | |
| 146 // Set up gallery watch. | |
| 147 ExtensionTestMessageListener add_gallery_watch_finished( | |
| 148 kAddGalleryWatchRequestSucceeded, false /* no reply */); | |
| 149 ExecuteCmdAndCheckReply(host, kSetupWatchOnValidGalleriesCmd, | |
| 150 kAddGalleryWatchOK); | |
| 151 EXPECT_TRUE(add_gallery_watch_finished.WaitUntilSatisfied()); | |
| 152 | 192 |
| 153 // Add gallery watch listener. | 193 // Add gallery watch listener. |
| 154 ExecuteCmdAndCheckReply(host, kAddGalleryChangedListenerCmd, | 194 ExecuteCmdAndCheckReply(kAddGalleryChangedListenerCmd, |
| 155 kAddGalleryChangedListenerOK); | 195 kAddGalleryChangedListenerOK); |
| 156 | 196 |
| 157 // Modify gallery contents. | 197 // Modify gallery contents. |
| 158 ExtensionTestMessageListener music_gallery_change_event_received( | 198 ExtensionTestMessageListener gallery_change_event_received( |
| 159 kGalleryChangedEventReceived, false /* no reply */); | 199 kGalleryChangedEventReceived, false /* no reply */); |
| 160 ASSERT_TRUE(AddNewFileInGallery(chrome::DIR_USER_MUSIC)); | 200 ASSERT_TRUE(AddNewFileInTestGallery()); |
| 161 EXPECT_TRUE(music_gallery_change_event_received.WaitUntilSatisfied()); | 201 if (GalleryWatchesSupported()) |
| 162 | 202 EXPECT_TRUE(gallery_change_event_received.WaitUntilSatisfied()); |
| 163 ExtensionTestMessageListener pictures_gallery_change_event_received( | |
| 164 kGalleryChangedEventReceived, false /* no reply */); | |
| 165 ASSERT_TRUE(AddNewFileInGallery(chrome::DIR_USER_PICTURES)); | |
| 166 EXPECT_TRUE(pictures_gallery_change_event_received.WaitUntilSatisfied()); | |
| 167 | |
| 168 ExtensionTestMessageListener videos_gallery_change_event_received( | |
| 169 kGalleryChangedEventReceived, false /* no reply */); | |
| 170 ASSERT_TRUE(AddNewFileInGallery(chrome::DIR_USER_VIDEOS)); | |
| 171 EXPECT_TRUE(videos_gallery_change_event_received.WaitUntilSatisfied()); | |
| 172 | 203 |
| 173 // Remove gallery watch listener. | 204 // Remove gallery watch listener. |
| 174 ExecuteCmdAndCheckReply(host, kRemoveGalleryChangedListenerCmd, | 205 ExecuteCmdAndCheckReply(kRemoveGalleryChangedListenerCmd, |
| 175 kRemoveGalleryChangedListenerOK); | 206 kRemoveGalleryChangedListenerOK); |
| 176 | 207 |
| 177 // Remove gallery watch request. | 208 // Remove gallery watch request. |
| 178 ExecuteCmdAndCheckReply(host, kRemoveGalleryWatchCmd, kRemoveGalleryWatchOK); | 209 if (GalleryWatchesSupported()) |
| 210 ExecuteCmdAndCheckReply(kRemoveGalleryWatchCmd, kRemoveGalleryWatchOK); |
| 179 } | 211 } |
| 180 | 212 |
| 181 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateGalleryWatchApiTest, | 213 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateGalleryWatchApiTest, |
| 182 RemoveListenerAndModifyGallery) { | 214 RemoveListenerAndModifyGallery) { |
| 183 EnsureMediaDirectoriesExists media_directories; | 215 if (!GalleryWatchesSupported()) |
| 184 content::RenderViewHost* host = GetBackgroundHostForTestExtension(); | 216 return; |
| 185 ASSERT_TRUE(host); | 217 |
| 186 | 218 SetupGalleryWatches(); |
| 187 // Get media file systems. | |
| 188 ExtensionTestMessageListener get_media_systems_finished( | |
| 189 kGetMediaFileSystemsCallbackOK, false /* no reply */); | |
| 190 ExecuteCmdAndCheckReply(host, kGetMediaFileSystemsCmd, | |
| 191 kGetMediaFileSystemsOK); | |
| 192 EXPECT_TRUE(get_media_systems_finished.WaitUntilSatisfied()); | |
| 193 | |
| 194 // Set up gallery watch. | |
| 195 ExtensionTestMessageListener add_gallery_watch_finished( | |
| 196 kAddGalleryWatchRequestSucceeded, false /* no reply */); | |
| 197 ExecuteCmdAndCheckReply(host, kSetupWatchOnValidGalleriesCmd, | |
| 198 kAddGalleryWatchOK); | |
| 199 EXPECT_TRUE(add_gallery_watch_finished.WaitUntilSatisfied()); | |
| 200 | 219 |
| 201 // Add a gallery watch listener. | 220 // Add a gallery watch listener. |
| 202 ExecuteCmdAndCheckReply(host, kAddGalleryChangedListenerCmd, | 221 ExecuteCmdAndCheckReply(kAddGalleryChangedListenerCmd, |
| 203 kAddGalleryChangedListenerOK); | 222 kAddGalleryChangedListenerOK); |
| 204 // Modify gallery contents. | 223 // Modify gallery contents. |
| 205 ExtensionTestMessageListener music_gallery_change_event_received( | 224 ExtensionTestMessageListener gallery_change_event_received( |
| 206 kGalleryChangedEventReceived, false /* no reply */); | 225 kGalleryChangedEventReceived, false /* no reply */); |
| 207 ASSERT_TRUE(AddNewFileInGallery(chrome::DIR_USER_MUSIC)); | 226 ASSERT_TRUE(AddNewFileInTestGallery()); |
| 208 EXPECT_TRUE(music_gallery_change_event_received.WaitUntilSatisfied()); | 227 EXPECT_TRUE(gallery_change_event_received.WaitUntilSatisfied()); |
| 209 | 228 |
| 210 // Remove gallery watch listener. | 229 // Remove gallery watch listener. |
| 211 ExecuteCmdAndCheckReply(host, kRemoveGalleryChangedListenerCmd, | 230 ExecuteCmdAndCheckReply(kRemoveGalleryChangedListenerCmd, |
| 212 kRemoveGalleryChangedListenerOK); | 231 kRemoveGalleryChangedListenerOK); |
| 213 | 232 |
| 214 // No listener, modify gallery contents. | 233 // No listener, modify gallery contents. |
| 215 ASSERT_TRUE(AddNewFileInGallery(chrome::DIR_USER_MUSIC)); | 234 ASSERT_TRUE(AddNewFileInTestGallery()); |
| 216 | 235 |
| 217 // Remove gallery watch. | 236 // Remove gallery watch. |
| 218 ExecuteCmdAndCheckReply(host, kRemoveGalleryWatchCmd, kRemoveGalleryWatchOK); | 237 ExecuteCmdAndCheckReply(kRemoveGalleryWatchCmd, kRemoveGalleryWatchOK); |
| 219 } | 238 } |
| 220 | 239 |
| 221 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateGalleryWatchApiTest, | 240 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateGalleryWatchApiTest, |
| 222 SetupGalleryWatchWithoutListeners) { | 241 SetupGalleryWatchWithoutListeners) { |
| 223 EnsureMediaDirectoriesExists media_directories; | 242 if (!GalleryWatchesSupported()) |
| 224 content::RenderViewHost* host = GetBackgroundHostForTestExtension(); | 243 return; |
| 225 ASSERT_TRUE(host); | 244 |
| 226 | 245 SetupGalleryWatches(); |
| 227 // Get media file systems. | |
| 228 ExtensionTestMessageListener get_media_systems_finished( | |
| 229 kGetMediaFileSystemsCallbackOK, false /* no reply */); | |
| 230 ExecuteCmdAndCheckReply(host, kGetMediaFileSystemsCmd, | |
| 231 kGetMediaFileSystemsOK); | |
| 232 EXPECT_TRUE(get_media_systems_finished.WaitUntilSatisfied()); | |
| 233 | |
| 234 // Set up gallery watch. | |
| 235 ExecuteCmdAndCheckReply(host, kSetupWatchOnValidGalleriesCmd, | |
| 236 kAddGalleryWatchOK); | |
| 237 | 246 |
| 238 // No listeners, modify gallery contents. | 247 // No listeners, modify gallery contents. |
| 239 ExtensionTestMessageListener music_gallery_change_event_received( | 248 ExtensionTestMessageListener gallery_change_event_received( |
| 240 kGalleryChangedEventReceived, false /* no reply */); | 249 kGalleryChangedEventReceived, false /* no reply */); |
| 241 ASSERT_TRUE(AddNewFileInGallery(chrome::DIR_USER_MUSIC)); | 250 ASSERT_TRUE(AddNewFileInTestGallery()); |
| 242 | 251 |
| 243 // Remove gallery watch. | 252 // Remove gallery watch. |
| 244 ExecuteCmdAndCheckReply(host, kRemoveGalleryWatchCmd, kRemoveGalleryWatchOK); | 253 ExecuteCmdAndCheckReply(kRemoveGalleryWatchCmd, kRemoveGalleryWatchOK); |
| 245 } | 254 } |
| 246 | 255 |
| 247 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateGalleryWatchApiTest, | 256 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateGalleryWatchApiTest, |
| 248 SetupGalleryChangedListenerWithoutWatchers) { | 257 SetupGalleryChangedListenerWithoutWatchers) { |
| 249 EnsureMediaDirectoriesExists media_directories; | |
| 250 content::RenderViewHost* host = GetBackgroundHostForTestExtension(); | |
| 251 ASSERT_TRUE(host); | |
| 252 | |
| 253 // Get media file systems. | |
| 254 ExtensionTestMessageListener get_media_systems_finished( | |
| 255 kGetMediaFileSystemsCallbackOK, false /* no reply */); | |
| 256 ExecuteCmdAndCheckReply(host, kGetMediaFileSystemsCmd, | |
| 257 kGetMediaFileSystemsOK); | |
| 258 EXPECT_TRUE(get_media_systems_finished.WaitUntilSatisfied()); | |
| 259 | |
| 260 // Add gallery watch listener. | 258 // Add gallery watch listener. |
| 261 ExecuteCmdAndCheckReply(host, kAddGalleryChangedListenerCmd, | 259 ExecuteCmdAndCheckReply(kAddGalleryChangedListenerCmd, |
| 262 kAddGalleryChangedListenerOK); | 260 kAddGalleryChangedListenerOK); |
| 263 | 261 |
| 264 // Modify gallery contents. Listener should not get called because add watch | 262 // Modify gallery contents. Listener should not get called because add watch |
| 265 // request was not called. | 263 // request was not called. |
| 266 ExtensionTestMessageListener music_gallery_change_event_received( | 264 ExtensionTestMessageListener gallery_change_event_received( |
| 267 kGalleryChangedEventReceived, false /* no reply */); | 265 kGalleryChangedEventReceived, false /* no reply */); |
| 268 ASSERT_TRUE(AddNewFileInGallery(chrome::DIR_USER_MUSIC)); | 266 ASSERT_TRUE(AddNewFileInTestGallery()); |
| 269 | 267 |
| 270 // Remove gallery watch listener. | 268 // Remove gallery watch listener. |
| 271 ExecuteCmdAndCheckReply(host, kRemoveGalleryChangedListenerCmd, | 269 ExecuteCmdAndCheckReply(kRemoveGalleryChangedListenerCmd, |
| 272 kRemoveGalleryChangedListenerOK); | 270 kRemoveGalleryChangedListenerOK); |
| 273 } | 271 } |
| 274 | 272 |
| 275 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateGalleryWatchApiTest, | 273 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateGalleryWatchApiTest, |
| 276 SetupWatchOnInvalidGallery) { | 274 SetupWatchOnInvalidGallery) { |
| 277 content::RenderViewHost* host = GetBackgroundHostForTestExtension(); | |
| 278 ASSERT_TRUE(host); | |
| 279 | |
| 280 // Set up a invalid gallery watch. | 275 // Set up a invalid gallery watch. |
| 281 ExtensionTestMessageListener invalid_gallery_watch_request_finished( | 276 ExtensionTestMessageListener invalid_gallery_watch_request_finished( |
| 282 kAddGalleryWatchRequestFailed, false /* no reply */); | 277 kAddGalleryWatchRequestFailed, false /* no reply */); |
| 283 ExecuteCmdAndCheckReply(host, kSetupWatchOnInvalidGalleryCmd, | 278 ExecuteCmdAndCheckReply(kSetupWatchOnInvalidGalleryCmd, kAddGalleryWatchOK); |
| 284 kAddGalleryWatchOK); | |
| 285 EXPECT_TRUE(invalid_gallery_watch_request_finished.WaitUntilSatisfied()); | 279 EXPECT_TRUE(invalid_gallery_watch_request_finished.WaitUntilSatisfied()); |
| 286 } | 280 } |
| 287 | 281 |
| 288 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateGalleryWatchApiTest, | 282 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateGalleryWatchApiTest, |
| 289 GetAllGalleryWatch) { | 283 GetAllGalleryWatch) { |
| 290 EnsureMediaDirectoriesExists media_directories; | |
| 291 content::RenderViewHost* host = GetBackgroundHostForTestExtension(); | |
| 292 ASSERT_TRUE(host); | |
| 293 | |
| 294 // Get media file systems. | |
| 295 ExtensionTestMessageListener get_media_systems_finished( | |
| 296 kGetMediaFileSystemsCallbackOK, false /* no reply */); | |
| 297 ExecuteCmdAndCheckReply(host, kGetMediaFileSystemsCmd, | |
| 298 kGetMediaFileSystemsOK); | |
| 299 EXPECT_TRUE(get_media_systems_finished.WaitUntilSatisfied()); | |
| 300 | |
| 301 // Gallery watchers are not yet added. | 284 // Gallery watchers are not yet added. |
| 302 // chrome.mediaGalleriesPrivate.getAllGalleryWatch should return an empty | 285 // chrome.mediaGalleriesPrivate.getAllGalleryWatch should return an empty |
| 303 // list. | 286 // list. |
| 304 ExtensionTestMessageListener initial_get_all_check_finished( | 287 ExtensionTestMessageListener initial_get_all_check_finished( |
| 305 kGetAllGalleryWatchResultA, false /* no reply */); | 288 kNoGalleryWatchesInstalled, false /* no reply */); |
| 306 ExecuteCmdAndCheckReply(host, kGetAllWatchedGalleryIdsCmd, | 289 ExecuteCmdAndCheckReply(kGetAllWatchedGalleryIdsCmd, kGetAllGalleryWatchOK); |
| 307 kGetAllGalleryWatchOK); | |
| 308 EXPECT_TRUE(initial_get_all_check_finished.WaitUntilSatisfied()); | 290 EXPECT_TRUE(initial_get_all_check_finished.WaitUntilSatisfied()); |
| 309 | 291 |
| 310 // Set up gallery watchers. | 292 if (!GalleryWatchesSupported()) |
| 311 ExtensionTestMessageListener add_gallery_watch_finished( | 293 return; |
| 312 kAddGalleryWatchRequestSucceeded, false /* no reply */); | 294 |
| 313 ExecuteCmdAndCheckReply(host, kSetupWatchOnValidGalleriesCmd, | 295 SetupGalleryWatches(); |
| 314 kAddGalleryWatchOK); | |
| 315 EXPECT_TRUE(add_gallery_watch_finished.WaitUntilSatisfied()); | |
| 316 | 296 |
| 317 // chrome.mediaGalleriesPrivate.getAllGalleryWatch should return the | 297 // chrome.mediaGalleriesPrivate.getAllGalleryWatch should return the |
| 318 // gallery identifiers. | 298 // gallery identifiers. |
| 319 ExtensionTestMessageListener get_all_watched_galleries_finished( | 299 ExtensionTestMessageListener get_all_watched_galleries_finished( |
| 320 kGetAllGalleryWatchResultB, false /* no reply */); | 300 kGalleryWatchesCheck, false /* no reply */); |
| 321 ExecuteCmdAndCheckReply(host, kGetAllWatchedGalleryIdsCmd, | 301 ExecuteCmdAndCheckReply(kGetAllWatchedGalleryIdsCmd, kGetAllGalleryWatchOK); |
| 322 kGetAllGalleryWatchOK); | |
| 323 EXPECT_TRUE(get_all_watched_galleries_finished.WaitUntilSatisfied()); | 302 EXPECT_TRUE(get_all_watched_galleries_finished.WaitUntilSatisfied()); |
| 324 | 303 |
| 325 // Remove gallery watch request. | 304 // Remove gallery watch request. |
| 326 ExecuteCmdAndCheckReply(host, kRemoveGalleryWatchCmd, kRemoveGalleryWatchOK); | 305 ExecuteCmdAndCheckReply(kRemoveGalleryWatchCmd, kRemoveGalleryWatchOK); |
| 327 | 306 |
| 328 // Gallery watchers removed. | 307 // Gallery watchers removed. |
| 329 // chrome.mediaGalleriesPrivate.getAllGalleryWatch() should return an empty | 308 // chrome.mediaGalleriesPrivate.getAllGalleryWatch() should return an empty |
| 330 // list. | 309 // list. |
| 331 ExtensionTestMessageListener final_get_all_check_finished( | 310 ExtensionTestMessageListener final_get_all_check_finished( |
| 332 kGetAllGalleryWatchResultA, false /* no reply */); | 311 kNoGalleryWatchesInstalled, false /* no reply */); |
| 333 ExecuteCmdAndCheckReply(host, kGetAllWatchedGalleryIdsCmd, | 312 ExecuteCmdAndCheckReply(kGetAllWatchedGalleryIdsCmd, kGetAllGalleryWatchOK); |
| 334 kGetAllGalleryWatchOK); | |
| 335 EXPECT_TRUE(final_get_all_check_finished.WaitUntilSatisfied()); | 313 EXPECT_TRUE(final_get_all_check_finished.WaitUntilSatisfied()); |
| 336 } | 314 } |
| 337 | 315 |
| 338 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateGalleryWatchApiTest, | 316 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateGalleryWatchApiTest, |
| 339 RemoveAllGalleryWatch) { | 317 RemoveAllGalleryWatch) { |
| 340 EnsureMediaDirectoriesExists media_directories; | 318 if (!GalleryWatchesSupported()) |
| 341 content::RenderViewHost* host = GetBackgroundHostForTestExtension(); | 319 return; |
| 342 ASSERT_TRUE(host); | 320 |
| 343 | 321 SetupGalleryWatches(); |
| 344 // Get media file systems. | |
| 345 ExtensionTestMessageListener get_media_systems_finished( | |
| 346 kGetMediaFileSystemsCallbackOK, false /* no reply */); | |
| 347 ExecuteCmdAndCheckReply(host, kGetMediaFileSystemsCmd, | |
| 348 kGetMediaFileSystemsOK); | |
| 349 EXPECT_TRUE(get_media_systems_finished.WaitUntilSatisfied()); | |
| 350 | |
| 351 // Set up gallery watchers. | |
| 352 ExtensionTestMessageListener add_gallery_watch_finished( | |
| 353 kAddGalleryWatchRequestSucceeded, false /* no reply */); | |
| 354 ExecuteCmdAndCheckReply(host, kSetupWatchOnValidGalleriesCmd, | |
| 355 kAddGalleryWatchOK); | |
| 356 EXPECT_TRUE(add_gallery_watch_finished.WaitUntilSatisfied()); | |
| 357 | 322 |
| 358 // chrome.mediaGalleriesPrivate.getAllGalleryWatch should return the watched | 323 // chrome.mediaGalleriesPrivate.getAllGalleryWatch should return the watched |
| 359 // gallery identifiers. | 324 // gallery identifiers. |
| 360 ExtensionTestMessageListener get_all_watched_galleries_finished( | 325 ExtensionTestMessageListener get_all_watched_galleries_finished( |
| 361 kGetAllGalleryWatchResultB, false /* no reply */); | 326 kGalleryWatchesCheck, false /* no reply */); |
| 362 ExecuteCmdAndCheckReply(host, kGetAllWatchedGalleryIdsCmd, | 327 ExecuteCmdAndCheckReply(kGetAllWatchedGalleryIdsCmd, kGetAllGalleryWatchOK); |
| 363 kGetAllGalleryWatchOK); | |
| 364 EXPECT_TRUE(get_all_watched_galleries_finished.WaitUntilSatisfied()); | 328 EXPECT_TRUE(get_all_watched_galleries_finished.WaitUntilSatisfied()); |
| 365 | 329 |
| 366 // Remove all gallery watchers. | 330 // Remove all gallery watchers. |
| 367 ExecuteCmdAndCheckReply(host, kRemoveAllGalleryWatchCmd, | 331 ExecuteCmdAndCheckReply(kRemoveAllGalleryWatchCmd, kRemoveAllGalleryWatchOK); |
| 368 kRemoveAllGalleryWatchOK); | |
| 369 | 332 |
| 370 // Gallery watchers removed. chrome.mediaGalleriesPrivate.getAllGalleryWatch | 333 // Gallery watchers removed. chrome.mediaGalleriesPrivate.getAllGalleryWatch |
| 371 // should return an empty list. | 334 // should return an empty list. |
| 372 ExtensionTestMessageListener final_get_all_check_finished( | 335 ExtensionTestMessageListener final_get_all_check_finished( |
| 373 kGetAllGalleryWatchResultA, false /* no reply */); | 336 kNoGalleryWatchesInstalled, false /* no reply */); |
| 374 ExecuteCmdAndCheckReply(host, kGetAllWatchedGalleryIdsCmd, | 337 ExecuteCmdAndCheckReply(kGetAllWatchedGalleryIdsCmd, kGetAllGalleryWatchOK); |
| 375 kGetAllGalleryWatchOK); | |
| 376 EXPECT_TRUE(final_get_all_check_finished.WaitUntilSatisfied()); | 338 EXPECT_TRUE(final_get_all_check_finished.WaitUntilSatisfied()); |
| 377 } | 339 } |
| 378 #endif // defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS)) | |
| 379 | |
| 380 #if defined(OS_MACOSX) | |
| 381 // Gallery watch request is not enabled on Mac: crbug.com/144491. | |
| 382 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateGalleryWatchApiTest, | |
| 383 SetupGalleryWatch) { | |
| 384 EnsureMediaDirectoriesExists media_directories; | |
| 385 content::RenderViewHost* host = GetBackgroundHostForTestExtension(); | |
| 386 ASSERT_TRUE(host); | |
| 387 | |
| 388 // Get media file systems. | |
| 389 ExtensionTestMessageListener get_media_systems_finished( | |
| 390 kGetMediaFileSystemsCallbackOK, false /* no reply */); | |
| 391 ExecuteCmdAndCheckReply(host, kGetMediaFileSystemsCmd, | |
| 392 kGetMediaFileSystemsOK); | |
| 393 EXPECT_TRUE(get_media_systems_finished.WaitUntilSatisfied()); | |
| 394 | |
| 395 // Set up a invalid gallery watch. | |
| 396 ExtensionTestMessageListener gallery_watch_request_finished( | |
| 397 kAddGalleryWatchRequestFailed, false /* no reply */); | |
| 398 // Set up gallery watch. | |
| 399 ExecuteCmdAndCheckReply(host, kSetupWatchOnValidGalleriesCmd, | |
| 400 kAddGalleryWatchOK); | |
| 401 EXPECT_TRUE(gallery_watch_request_finished.WaitUntilSatisfied()); | |
| 402 } | |
| 403 | |
| 404 IN_PROC_BROWSER_TEST_F(MediaGalleriesPrivateGalleryWatchApiTest, | |
| 405 GetAllGalleryWatch) { | |
| 406 EnsureMediaDirectoriesExists media_directories; | |
| 407 content::RenderViewHost* host = GetBackgroundHostForTestExtension(); | |
| 408 ASSERT_TRUE(host); | |
| 409 | |
| 410 // Get media file systems. | |
| 411 ExtensionTestMessageListener get_media_systems_finished( | |
| 412 kGetMediaFileSystemsCallbackOK, false /* no reply */); | |
| 413 ExecuteCmdAndCheckReply(host, kGetMediaFileSystemsCmd, | |
| 414 kGetMediaFileSystemsOK); | |
| 415 EXPECT_TRUE(get_media_systems_finished.WaitUntilSatisfied()); | |
| 416 | |
| 417 // Set up gallery watch. | |
| 418 ExecuteCmdAndCheckReply(host, kSetupWatchOnValidGalleriesCmd, | |
| 419 kAddGalleryWatchOK); | |
| 420 | |
| 421 // Gallery watchers does not exists. | |
| 422 // chrome.mediaGalleriesPrivate.getAllGalleryWatch should return an empty | |
| 423 // list. | |
| 424 ExtensionTestMessageListener get_all_gallery_watch_finished( | |
| 425 kGetAllGalleryWatchResultA, false /* no reply */); | |
| 426 ExecuteCmdAndCheckReply(host, kGetAllWatchedGalleryIdsCmd, | |
| 427 kGetAllGalleryWatchOK); | |
| 428 EXPECT_TRUE(get_all_gallery_watch_finished.WaitUntilSatisfied()); | |
| 429 } | |
| 430 #endif // defined(OS_MACOSX) | |
| OLD | NEW |