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