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