OLD | NEW |
1 // Copyright 2014 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 // MediaGalleries gallery watch API browser tests. | 5 // MediaGalleries gallery watch API browser tests. |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/file_path_watcher.h" | 8 #include "base/files/file_path_watcher.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 void ExecuteCmdAndCheckReply(const std::string& js_command, | 103 void ExecuteCmdAndCheckReply(const std::string& js_command, |
104 const std::string& ok_message) { | 104 const std::string& ok_message) { |
105 ExtensionTestMessageListener listener(ok_message, false); | 105 ExtensionTestMessageListener listener(ok_message, false); |
106 background_host_->GetMainFrame()->ExecuteJavaScriptForTests( | 106 background_host_->GetMainFrame()->ExecuteJavaScriptForTests( |
107 base::ASCIIToUTF16(js_command)); | 107 base::ASCIIToUTF16(js_command)); |
108 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 108 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
109 } | 109 } |
110 | 110 |
111 bool AddNewFileInTestGallery() { | 111 bool AddNewFileInTestGallery() { |
112 base::FilePath gallery_file = | 112 base::FilePath gallery_file = |
113 test_gallery_.path().Append(FILE_PATH_LITERAL("test1.txt")); | 113 test_gallery_.GetPath().Append(FILE_PATH_LITERAL("test1.txt")); |
114 std::string content("new content"); | 114 std::string content("new content"); |
115 int write_size = | 115 int write_size = |
116 base::WriteFile(gallery_file, content.c_str(), content.length()); | 116 base::WriteFile(gallery_file, content.c_str(), content.length()); |
117 return (write_size == static_cast<int>(content.length())); | 117 return (write_size == static_cast<int>(content.length())); |
118 } | 118 } |
119 | 119 |
120 void SetupGalleryWatches() { | 120 void SetupGalleryWatches() { |
121 std::string expected_result = GalleryWatchesSupported() | 121 std::string expected_result = GalleryWatchesSupported() |
122 ? kAddGalleryWatchRequestSucceeded | 122 ? kAddGalleryWatchRequestSucceeded |
123 : kAddGalleryWatchRequestFailed; | 123 : kAddGalleryWatchRequestFailed; |
(...skipping 16 matching lines...) Expand all Loading... |
140 void CreateTestGallery() { | 140 void CreateTestGallery() { |
141 MediaGalleriesPreferences* preferences = | 141 MediaGalleriesPreferences* preferences = |
142 g_browser_process->media_file_system_registry()->GetPreferences( | 142 g_browser_process->media_file_system_registry()->GetPreferences( |
143 browser()->profile()); | 143 browser()->profile()); |
144 base::RunLoop runloop; | 144 base::RunLoop runloop; |
145 preferences->EnsureInitialized(runloop.QuitClosure()); | 145 preferences->EnsureInitialized(runloop.QuitClosure()); |
146 runloop.Run(); | 146 runloop.Run(); |
147 | 147 |
148 ASSERT_TRUE(test_gallery_.CreateUniqueTempDir()); | 148 ASSERT_TRUE(test_gallery_.CreateUniqueTempDir()); |
149 MediaGalleryPrefInfo gallery_info; | 149 MediaGalleryPrefInfo gallery_info; |
150 ASSERT_FALSE( | 150 ASSERT_FALSE(preferences->LookUpGalleryByPath(test_gallery_.GetPath(), |
151 preferences->LookUpGalleryByPath(test_gallery_.path(), &gallery_info)); | 151 &gallery_info)); |
152 MediaGalleryPrefId id = | 152 MediaGalleryPrefId id = |
153 preferences->AddGallery(gallery_info.device_id, | 153 preferences->AddGallery(gallery_info.device_id, |
154 gallery_info.path, | 154 gallery_info.path, |
155 MediaGalleryPrefInfo::kAutoDetected, | 155 MediaGalleryPrefInfo::kAutoDetected, |
156 gallery_info.volume_label, | 156 gallery_info.volume_label, |
157 gallery_info.vendor_name, | 157 gallery_info.vendor_name, |
158 gallery_info.model_name, | 158 gallery_info.model_name, |
159 gallery_info.total_size_in_bytes, | 159 gallery_info.total_size_in_bytes, |
160 gallery_info.last_attach_time, | 160 gallery_info.last_attach_time, |
161 0, | 161 0, |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 | 281 |
282 IN_PROC_BROWSER_TEST_F(MediaGalleriesGalleryWatchApiTest, | 282 IN_PROC_BROWSER_TEST_F(MediaGalleriesGalleryWatchApiTest, |
283 SetupWatchOnInvalidGallery) { | 283 SetupWatchOnInvalidGallery) { |
284 // Add gallery watch listener. | 284 // Add gallery watch listener. |
285 ExecuteCmdAndCheckReply(kAddGalleryChangedListenerCmd, | 285 ExecuteCmdAndCheckReply(kAddGalleryChangedListenerCmd, |
286 kAddGalleryChangedListenerOK); | 286 kAddGalleryChangedListenerOK); |
287 // Set up a invalid gallery watch. | 287 // Set up a invalid gallery watch. |
288 ExecuteCmdAndCheckReply( | 288 ExecuteCmdAndCheckReply( |
289 kSetupWatchOnInvalidGalleryCmd, kAddGalleryWatchRequestFailed); | 289 kSetupWatchOnInvalidGalleryCmd, kAddGalleryWatchRequestFailed); |
290 } | 290 } |
OLD | NEW |