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 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 extensions::Extension* extension() { | 106 extensions::Extension* extension() { |
107 return extension_.get(); | 107 return extension_.get(); |
108 } | 108 } |
109 | 109 |
110 MediaGalleriesPreferences* gallery_prefs() { | 110 MediaGalleriesPreferences* gallery_prefs() { |
111 return gallery_prefs_.get(); | 111 return gallery_prefs_.get(); |
112 } | 112 } |
113 | 113 |
114 GalleryDialogId GetDialogIdFromPrefId(MediaGalleryPrefId pref_id); | 114 GalleryDialogId GetDialogIdFromPrefId(MediaGalleryPrefId pref_id); |
115 | 115 |
116 void TestForgottenType(MediaGalleryPrefInfo::Type type); | 116 void TestForgottenType(MediaGalleryPrefInfo::Type type, |
117 bool forget_preserves_pref_id); | |
117 | 118 |
118 protected: | 119 protected: |
119 EnsureMediaDirectoriesExists mock_gallery_locations_; | 120 EnsureMediaDirectoriesExists mock_gallery_locations_; |
120 | 121 |
121 private: | 122 private: |
122 MediaGalleriesDialog* CreateMockDialog( | 123 MediaGalleriesDialog* CreateMockDialog( |
123 MediaGalleriesDialogController* controller) { | 124 MediaGalleriesDialogController* controller) { |
124 EXPECT_FALSE(dialog_); | 125 EXPECT_FALSE(dialog_); |
125 dialog_update_count_at_destruction_ = 0; | 126 dialog_update_count_at_destruction_ = 0; |
126 dialog_ = new MockMediaGalleriesDialog(base::Bind( | 127 dialog_ = new MockMediaGalleriesDialog(base::Bind( |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
168 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPermissionControllerTest); | 169 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPermissionControllerTest); |
169 }; | 170 }; |
170 | 171 |
171 GalleryDialogId | 172 GalleryDialogId |
172 MediaGalleriesPermissionControllerTest::GetDialogIdFromPrefId( | 173 MediaGalleriesPermissionControllerTest::GetDialogIdFromPrefId( |
173 MediaGalleryPrefId pref_id) { | 174 MediaGalleryPrefId pref_id) { |
174 return controller_->GetDialogId(pref_id); | 175 return controller_->GetDialogId(pref_id); |
175 } | 176 } |
176 | 177 |
177 void MediaGalleriesPermissionControllerTest::TestForgottenType( | 178 void MediaGalleriesPermissionControllerTest::TestForgottenType( |
178 MediaGalleryPrefInfo::Type type) { | 179 MediaGalleryPrefInfo::Type type, bool forget_preserves_pref_id) { |
179 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size()); | 180 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size()); |
180 | 181 |
181 MediaGalleryPrefId forgotten1 = gallery_prefs()->AddGalleryByPath( | 182 MediaGalleryPrefId forgotten1 = gallery_prefs()->AddGalleryByPath( |
182 MakeMediaGalleriesTestingPath("forgotten1"), type); | 183 MakeMediaGalleriesTestingPath("forgotten1"), type); |
183 MediaGalleryPrefId forgotten2 = gallery_prefs()->AddGalleryByPath( | 184 MediaGalleryPrefId forgotten2 = gallery_prefs()->AddGalleryByPath( |
184 MakeMediaGalleriesTestingPath("forgotten2"), type); | 185 MakeMediaGalleriesTestingPath("forgotten2"), type); |
185 // Show dialog and accept to verify 2 entries | 186 // Show dialog and accept to verify 2 entries |
186 StartDialog(); | 187 StartDialog(); |
187 EXPECT_EQ(mock_gallery_locations_.num_galleries() + 2U, | 188 EXPECT_EQ(mock_gallery_locations_.num_galleries() + 2U, |
vandebo (ex-Chrome)
2014/06/11 16:40:56
You're going to need to rebase.
tommycli
2014/06/11 18:17:56
Done.
| |
188 controller()->GetSectionEntries(0).size()); | 189 controller()->GetSectionEntries(0).size()); |
189 EXPECT_EQ(0U, controller()->GetSectionEntries(1).size()); | 190 EXPECT_EQ(0U, controller()->GetSectionEntries(1).size()); |
190 controller()->DidToggleEntry(GetDialogIdFromPrefId(forgotten1), true); | 191 controller()->DidToggleEntry(GetDialogIdFromPrefId(forgotten1), true); |
191 controller()->DidToggleEntry(GetDialogIdFromPrefId(forgotten2), true); | 192 controller()->DidToggleEntry(GetDialogIdFromPrefId(forgotten2), true); |
192 controller()->DialogFinished(true); | 193 controller()->DialogFinished(true); |
193 EXPECT_EQ(2U, gallery_prefs()->GalleriesForExtension(*extension()).size()); | 194 EXPECT_EQ(2U, gallery_prefs()->GalleriesForExtension(*extension()).size()); |
194 | 195 |
195 // Forget one and cancel to see that it's still there. | 196 // Forget one and cancel to see that it's still there. |
196 StartDialog(); | 197 StartDialog(); |
197 controller()->DidForgetEntry(GetDialogIdFromPrefId(forgotten1)); | 198 controller()->DidForgetEntry(GetDialogIdFromPrefId(forgotten1)); |
198 EXPECT_EQ(mock_gallery_locations_.num_galleries() + 1U, | 199 EXPECT_EQ(mock_gallery_locations_.num_galleries() + 1U, |
199 controller()->GetSectionEntries(0).size()); | 200 controller()->GetSectionEntries(0).size()); |
200 controller()->DialogFinished(false); | 201 controller()->DialogFinished(false); |
201 EXPECT_EQ(2U, gallery_prefs()->GalleriesForExtension(*extension()).size()); | 202 EXPECT_EQ(2U, gallery_prefs()->GalleriesForExtension(*extension()).size()); |
202 | 203 |
203 // Forget one and confirm to see that it's gone. | 204 // Forget one and confirm to see that it's gone. |
204 StartDialog(); | 205 StartDialog(); |
205 controller()->DidForgetEntry(GetDialogIdFromPrefId(forgotten1)); | 206 controller()->DidForgetEntry(GetDialogIdFromPrefId(forgotten1)); |
206 EXPECT_EQ(mock_gallery_locations_.num_galleries() + 1U, | 207 EXPECT_EQ(mock_gallery_locations_.num_galleries() + 1U, |
207 controller()->GetSectionEntries(0).size()); | 208 controller()->GetSectionEntries(0).size()); |
208 controller()->DialogFinished(true); | 209 controller()->DialogFinished(true); |
209 EXPECT_EQ(1U, gallery_prefs()->GalleriesForExtension(*extension()).size()); | 210 EXPECT_EQ(1U, gallery_prefs()->GalleriesForExtension(*extension()).size()); |
210 | 211 |
212 // Add back and test whether the same pref id is preserved. | |
213 StartDialog(); | |
214 controller()->FileSelected( | |
215 MakeMediaGalleriesTestingPath("forgotten1"), 0, NULL); | |
216 controller()->DialogFinished(true); | |
217 EXPECT_EQ(2U, gallery_prefs()->GalleriesForExtension(*extension()).size()); | |
218 MediaGalleryPrefInfo retrieved_info; | |
219 EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath( | |
220 MakeMediaGalleriesTestingPath("forgotten1"), &retrieved_info)); | |
221 EXPECT_EQ(forget_preserves_pref_id, retrieved_info.pref_id == forgotten1); | |
222 | |
211 // Add a new one and forget it & see that it's gone. | 223 // Add a new one and forget it & see that it's gone. |
212 MediaGalleryPrefId forgotten3 = gallery_prefs()->AddGalleryByPath( | 224 MediaGalleryPrefId forgotten3 = gallery_prefs()->AddGalleryByPath( |
213 MakeMediaGalleriesTestingPath("forgotten3"), type); | 225 MakeMediaGalleriesTestingPath("forgotten3"), type); |
214 StartDialog(); | 226 StartDialog(); |
215 EXPECT_EQ(mock_gallery_locations_.num_galleries() + 2U, | 227 EXPECT_EQ(mock_gallery_locations_.num_galleries() + 3U, |
216 controller()->GetSectionEntries(0).size()); | 228 controller()->GetSectionEntries(0).size()); |
217 EXPECT_EQ(0U, controller()->GetSectionEntries(1).size()); | 229 EXPECT_EQ(0U, controller()->GetSectionEntries(1).size()); |
218 controller()->DidToggleEntry(GetDialogIdFromPrefId(forgotten3), true); | 230 controller()->DidToggleEntry(GetDialogIdFromPrefId(forgotten3), true); |
219 controller()->DidForgetEntry(GetDialogIdFromPrefId(forgotten3)); | 231 controller()->DidForgetEntry(GetDialogIdFromPrefId(forgotten3)); |
220 EXPECT_EQ(mock_gallery_locations_.num_galleries() + 1U, | 232 EXPECT_EQ(mock_gallery_locations_.num_galleries() + 2U, |
221 controller()->GetSectionEntries(0).size()); | 233 controller()->GetSectionEntries(0).size()); |
222 controller()->DialogFinished(true); | 234 controller()->DialogFinished(true); |
223 EXPECT_EQ(1U, gallery_prefs()->GalleriesForExtension(*extension()).size()); | 235 EXPECT_EQ(2U, gallery_prefs()->GalleriesForExtension(*extension()).size()); |
224 } | 236 } |
225 | 237 |
226 TEST_F(MediaGalleriesPermissionControllerTest, TestForgottenUserAdded) { | 238 TEST_F(MediaGalleriesPermissionControllerTest, TestForgottenUserAdded) { |
227 TestForgottenType(MediaGalleryPrefInfo::kUserAdded); | 239 TestForgottenType(MediaGalleryPrefInfo::kUserAdded, |
240 false /* forget_preserves_pref_id */); | |
228 } | 241 } |
229 | 242 |
230 TEST_F(MediaGalleriesPermissionControllerTest, TestForgottenAutoDetected) { | 243 TEST_F(MediaGalleriesPermissionControllerTest, TestForgottenAutoDetected) { |
231 TestForgottenType(MediaGalleryPrefInfo::kAutoDetected); | 244 TestForgottenType(MediaGalleryPrefInfo::kAutoDetected, |
245 true /* forget_preserves_pref_id */); | |
232 } | 246 } |
233 | 247 |
234 TEST_F(MediaGalleriesPermissionControllerTest, TestForgottenScanResult) { | 248 TEST_F(MediaGalleriesPermissionControllerTest, TestForgottenScanResult) { |
235 TestForgottenType(MediaGalleryPrefInfo::kScanResult); | 249 TestForgottenType(MediaGalleryPrefInfo::kScanResult, |
250 true /* forget_preserves_pref_id */); | |
236 } | 251 } |
237 | 252 |
238 TEST_F(MediaGalleriesPermissionControllerTest, TestNameGeneration) { | 253 TEST_F(MediaGalleriesPermissionControllerTest, TestNameGeneration) { |
239 MediaGalleryPrefInfo gallery; | 254 MediaGalleryPrefInfo gallery; |
240 gallery.pref_id = 1; | 255 gallery.pref_id = 1; |
241 gallery.device_id = StorageInfo::MakeDeviceId( | 256 gallery.device_id = StorageInfo::MakeDeviceId( |
242 StorageInfo::FIXED_MASS_STORAGE, "/path/to/gallery"); | 257 StorageInfo::FIXED_MASS_STORAGE, "/path/to/gallery"); |
243 gallery.type = MediaGalleryPrefInfo::kAutoDetected; | 258 gallery.type = MediaGalleryPrefInfo::kAutoDetected; |
244 std::string galleryName("/path/to/gallery"); | 259 std::string galleryName("/path/to/gallery"); |
245 #if defined(OS_CHROMEOS) | 260 #if defined(OS_CHROMEOS) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 | 297 |
283 gallery.volume_label = base::string16(); | 298 gallery.volume_label = base::string16(); |
284 EXPECT_EQ("vendor, model", GalleryName(gallery)); | 299 EXPECT_EQ("vendor, model", GalleryName(gallery)); |
285 | 300 |
286 gallery.total_size_in_bytes = 1000000; | 301 gallery.total_size_in_bytes = 1000000; |
287 EXPECT_EQ("977 KB vendor, model", GalleryName(gallery)); | 302 EXPECT_EQ("977 KB vendor, model", GalleryName(gallery)); |
288 | 303 |
289 gallery.path = base::FilePath(FILE_PATH_LITERAL("sub/path")); | 304 gallery.path = base::FilePath(FILE_PATH_LITERAL("sub/path")); |
290 EXPECT_EQ("path - 977 KB vendor, model", GalleryName(gallery)); | 305 EXPECT_EQ("path - 977 KB vendor, model", GalleryName(gallery)); |
291 } | 306 } |
OLD | NEW |