Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: chrome/browser/media_galleries/media_galleries_permission_controller_unittest.cc

Issue 329643002: Media Galleries: Allow readding blacklisted iApps libraries. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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(0U, controller()->GetSectionEntries(0).size()); 188 EXPECT_EQ(0U, controller()->GetSectionEntries(0).size());
188 EXPECT_EQ(mock_gallery_locations_.num_galleries() + 2U, 189 EXPECT_EQ(mock_gallery_locations_.num_galleries() + 2U,
(...skipping 12 matching lines...) Expand all
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 EXPECT_EQ(2U, controller()->GetSectionEntries(0).size()); 206 EXPECT_EQ(2U, controller()->GetSectionEntries(0).size());
206 controller()->DidForgetEntry(GetDialogIdFromPrefId(forgotten1)); 207 controller()->DidForgetEntry(GetDialogIdFromPrefId(forgotten1));
207 EXPECT_EQ(1U, controller()->GetSectionEntries(0).size()); 208 EXPECT_EQ(1U, 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(1U, controller()->GetSectionEntries(0).size()); 227 EXPECT_EQ(2U, controller()->GetSectionEntries(0).size());
216 EXPECT_EQ(mock_gallery_locations_.num_galleries() + 1U, 228 EXPECT_EQ(mock_gallery_locations_.num_galleries() + 1U,
217 controller()->GetSectionEntries(1).size()); 229 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(1U, controller()->GetSectionEntries(0).size()); 232 EXPECT_EQ(2U, controller()->GetSectionEntries(0).size());
221 EXPECT_EQ(static_cast<unsigned long>(mock_gallery_locations_.num_galleries()), 233 EXPECT_EQ(static_cast<unsigned long>(mock_gallery_locations_.num_galleries()),
222 controller()->GetSectionEntries(1).size()); 234 controller()->GetSectionEntries(1).size());
223 controller()->DialogFinished(true); 235 controller()->DialogFinished(true);
224 EXPECT_EQ(1U, gallery_prefs()->GalleriesForExtension(*extension()).size()); 236 EXPECT_EQ(2U, gallery_prefs()->GalleriesForExtension(*extension()).size());
225 } 237 }
226 238
227 TEST_F(MediaGalleriesPermissionControllerTest, TestForgottenUserAdded) { 239 TEST_F(MediaGalleriesPermissionControllerTest, TestForgottenUserAdded) {
228 TestForgottenType(MediaGalleryPrefInfo::kUserAdded); 240 TestForgottenType(MediaGalleryPrefInfo::kUserAdded,
241 false /* forget_preserves_pref_id */);
229 } 242 }
230 243
231 TEST_F(MediaGalleriesPermissionControllerTest, TestForgottenAutoDetected) { 244 TEST_F(MediaGalleriesPermissionControllerTest, TestForgottenAutoDetected) {
232 TestForgottenType(MediaGalleryPrefInfo::kAutoDetected); 245 TestForgottenType(MediaGalleryPrefInfo::kAutoDetected,
246 true /* forget_preserves_pref_id */);
233 } 247 }
234 248
235 TEST_F(MediaGalleriesPermissionControllerTest, TestForgottenScanResult) { 249 TEST_F(MediaGalleriesPermissionControllerTest, TestForgottenScanResult) {
236 TestForgottenType(MediaGalleryPrefInfo::kScanResult); 250 TestForgottenType(MediaGalleryPrefInfo::kScanResult,
251 true /* forget_preserves_pref_id */);
237 } 252 }
238 253
239 TEST_F(MediaGalleriesPermissionControllerTest, TestNameGeneration) { 254 TEST_F(MediaGalleriesPermissionControllerTest, TestNameGeneration) {
240 MediaGalleryPrefInfo gallery; 255 MediaGalleryPrefInfo gallery;
241 gallery.pref_id = 1; 256 gallery.pref_id = 1;
242 gallery.device_id = StorageInfo::MakeDeviceId( 257 gallery.device_id = StorageInfo::MakeDeviceId(
243 StorageInfo::FIXED_MASS_STORAGE, "/path/to/gallery"); 258 StorageInfo::FIXED_MASS_STORAGE, "/path/to/gallery");
244 gallery.type = MediaGalleryPrefInfo::kAutoDetected; 259 gallery.type = MediaGalleryPrefInfo::kAutoDetected;
245 std::string galleryName("/path/to/gallery"); 260 std::string galleryName("/path/to/gallery");
246 #if defined(OS_CHROMEOS) 261 #if defined(OS_CHROMEOS)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 298
284 gallery.volume_label = base::string16(); 299 gallery.volume_label = base::string16();
285 EXPECT_EQ("vendor, model", GalleryName(gallery)); 300 EXPECT_EQ("vendor, model", GalleryName(gallery));
286 301
287 gallery.total_size_in_bytes = 1000000; 302 gallery.total_size_in_bytes = 1000000;
288 EXPECT_EQ("977 KB vendor, model", GalleryName(gallery)); 303 EXPECT_EQ("977 KB vendor, model", GalleryName(gallery));
289 304
290 gallery.path = base::FilePath(FILE_PATH_LITERAL("sub/path")); 305 gallery.path = base::FilePath(FILE_PATH_LITERAL("sub/path"));
291 EXPECT_EQ("path - 977 KB vendor, model", GalleryName(gallery)); 306 EXPECT_EQ("path - 977 KB vendor, model", GalleryName(gallery));
292 } 307 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698