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