| 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 void MediaGalleriesPermissionControllerTest::TestForgottenType( | 177 void MediaGalleriesPermissionControllerTest::TestForgottenType( |
| 178 MediaGalleryPrefInfo::Type type) { | 178 MediaGalleryPrefInfo::Type type) { |
| 179 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size()); | 179 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size()); |
| 180 | 180 |
| 181 MediaGalleryPrefId forgotten1 = gallery_prefs()->AddGalleryByPath( | 181 MediaGalleryPrefId forgotten1 = gallery_prefs()->AddGalleryByPath( |
| 182 MakeMediaGalleriesTestingPath("forgotten1"), type); | 182 MakeMediaGalleriesTestingPath("forgotten1"), type); |
| 183 MediaGalleryPrefId forgotten2 = gallery_prefs()->AddGalleryByPath( | 183 MediaGalleryPrefId forgotten2 = gallery_prefs()->AddGalleryByPath( |
| 184 MakeMediaGalleriesTestingPath("forgotten2"), type); | 184 MakeMediaGalleriesTestingPath("forgotten2"), type); |
| 185 // Show dialog and accept to verify 2 entries | 185 // Show dialog and accept to verify 2 entries |
| 186 StartDialog(); | 186 StartDialog(); |
| 187 EXPECT_EQ(0U, controller()->GetSectionEntries(0).size()); |
| 187 EXPECT_EQ(mock_gallery_locations_.num_galleries() + 2U, | 188 EXPECT_EQ(mock_gallery_locations_.num_galleries() + 2U, |
| 188 controller()->GetSectionEntries(0).size()); | 189 controller()->GetSectionEntries(1).size()); |
| 189 EXPECT_EQ(0U, controller()->GetSectionEntries(1).size()); | |
| 190 controller()->DidToggleEntry(GetDialogIdFromPrefId(forgotten1), true); | 190 controller()->DidToggleEntry(GetDialogIdFromPrefId(forgotten1), true); |
| 191 controller()->DidToggleEntry(GetDialogIdFromPrefId(forgotten2), true); | 191 controller()->DidToggleEntry(GetDialogIdFromPrefId(forgotten2), true); |
| 192 controller()->DialogFinished(true); | 192 controller()->DialogFinished(true); |
| 193 EXPECT_EQ(2U, gallery_prefs()->GalleriesForExtension(*extension()).size()); | 193 EXPECT_EQ(2U, gallery_prefs()->GalleriesForExtension(*extension()).size()); |
| 194 | 194 |
| 195 // Forget one and cancel to see that it's still there. | 195 // Forget one and cancel to see that it's still there. |
| 196 StartDialog(); | 196 StartDialog(); |
| 197 EXPECT_EQ(2U, controller()->GetSectionEntries(0).size()); |
| 197 controller()->DidForgetEntry(GetDialogIdFromPrefId(forgotten1)); | 198 controller()->DidForgetEntry(GetDialogIdFromPrefId(forgotten1)); |
| 198 EXPECT_EQ(mock_gallery_locations_.num_galleries() + 1U, | 199 EXPECT_EQ(1U, controller()->GetSectionEntries(0).size()); |
| 199 controller()->GetSectionEntries(0).size()); | |
| 200 controller()->DialogFinished(false); | 200 controller()->DialogFinished(false); |
| 201 EXPECT_EQ(2U, gallery_prefs()->GalleriesForExtension(*extension()).size()); | 201 EXPECT_EQ(2U, gallery_prefs()->GalleriesForExtension(*extension()).size()); |
| 202 | 202 |
| 203 // Forget one and confirm to see that it's gone. | 203 // Forget one and confirm to see that it's gone. |
| 204 StartDialog(); | 204 StartDialog(); |
| 205 EXPECT_EQ(2U, controller()->GetSectionEntries(0).size()); |
| 205 controller()->DidForgetEntry(GetDialogIdFromPrefId(forgotten1)); | 206 controller()->DidForgetEntry(GetDialogIdFromPrefId(forgotten1)); |
| 206 EXPECT_EQ(mock_gallery_locations_.num_galleries() + 1U, | 207 EXPECT_EQ(1U, controller()->GetSectionEntries(0).size()); |
| 207 controller()->GetSectionEntries(0).size()); | |
| 208 controller()->DialogFinished(true); | 208 controller()->DialogFinished(true); |
| 209 EXPECT_EQ(1U, gallery_prefs()->GalleriesForExtension(*extension()).size()); | 209 EXPECT_EQ(1U, gallery_prefs()->GalleriesForExtension(*extension()).size()); |
| 210 | 210 |
| 211 // Add a new one and forget it & see that it's gone. | 211 // Add a new one and forget it & see that it's gone. |
| 212 MediaGalleryPrefId forgotten3 = gallery_prefs()->AddGalleryByPath( | 212 MediaGalleryPrefId forgotten3 = gallery_prefs()->AddGalleryByPath( |
| 213 MakeMediaGalleriesTestingPath("forgotten3"), type); | 213 MakeMediaGalleriesTestingPath("forgotten3"), type); |
| 214 StartDialog(); | 214 StartDialog(); |
| 215 EXPECT_EQ(mock_gallery_locations_.num_galleries() + 2U, | 215 EXPECT_EQ(1U, controller()->GetSectionEntries(0).size()); |
| 216 controller()->GetSectionEntries(0).size()); | 216 EXPECT_EQ(mock_gallery_locations_.num_galleries() + 1U, |
| 217 EXPECT_EQ(0U, controller()->GetSectionEntries(1).size()); | 217 controller()->GetSectionEntries(1).size()); |
| 218 controller()->DidToggleEntry(GetDialogIdFromPrefId(forgotten3), true); | 218 controller()->DidToggleEntry(GetDialogIdFromPrefId(forgotten3), true); |
| 219 controller()->DidForgetEntry(GetDialogIdFromPrefId(forgotten3)); | 219 controller()->DidForgetEntry(GetDialogIdFromPrefId(forgotten3)); |
| 220 EXPECT_EQ(mock_gallery_locations_.num_galleries() + 1U, | 220 EXPECT_EQ(1U, controller()->GetSectionEntries(0).size()); |
| 221 controller()->GetSectionEntries(0).size()); | 221 EXPECT_EQ(static_cast<unsigned long>(mock_gallery_locations_.num_galleries()), |
| 222 controller()->GetSectionEntries(1).size()); |
| 222 controller()->DialogFinished(true); | 223 controller()->DialogFinished(true); |
| 223 EXPECT_EQ(1U, gallery_prefs()->GalleriesForExtension(*extension()).size()); | 224 EXPECT_EQ(1U, gallery_prefs()->GalleriesForExtension(*extension()).size()); |
| 224 } | 225 } |
| 225 | 226 |
| 226 TEST_F(MediaGalleriesPermissionControllerTest, TestForgottenUserAdded) { | 227 TEST_F(MediaGalleriesPermissionControllerTest, TestForgottenUserAdded) { |
| 227 TestForgottenType(MediaGalleryPrefInfo::kUserAdded); | 228 TestForgottenType(MediaGalleryPrefInfo::kUserAdded); |
| 228 } | 229 } |
| 229 | 230 |
| 230 TEST_F(MediaGalleriesPermissionControllerTest, TestForgottenAutoDetected) { | 231 TEST_F(MediaGalleriesPermissionControllerTest, TestForgottenAutoDetected) { |
| 231 TestForgottenType(MediaGalleryPrefInfo::kAutoDetected); | 232 TestForgottenType(MediaGalleryPrefInfo::kAutoDetected); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 | 283 |
| 283 gallery.volume_label = base::string16(); | 284 gallery.volume_label = base::string16(); |
| 284 EXPECT_EQ("vendor, model", GalleryName(gallery)); | 285 EXPECT_EQ("vendor, model", GalleryName(gallery)); |
| 285 | 286 |
| 286 gallery.total_size_in_bytes = 1000000; | 287 gallery.total_size_in_bytes = 1000000; |
| 287 EXPECT_EQ("977 KB vendor, model", GalleryName(gallery)); | 288 EXPECT_EQ("977 KB vendor, model", GalleryName(gallery)); |
| 288 | 289 |
| 289 gallery.path = base::FilePath(FILE_PATH_LITERAL("sub/path")); | 290 gallery.path = base::FilePath(FILE_PATH_LITERAL("sub/path")); |
| 290 EXPECT_EQ("path - 977 KB vendor, model", GalleryName(gallery)); | 291 EXPECT_EQ("path - 977 KB vendor, model", GalleryName(gallery)); |
| 291 } | 292 } |
| OLD | NEW |