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