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

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

Issue 318733003: Use the media galleries controller interface for the scan result dialog. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: One more const 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/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/weak_ptr.h" 9 #include "base/memory/weak_ptr.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/time/time.h" 13 #include "base/time/time.h"
14 #include "chrome/browser/extensions/test_extension_system.h" 14 #include "chrome/browser/extensions/test_extension_system.h"
15 #include "chrome/browser/media_galleries/media_galleries_dialog_controller_test_ util.h"
15 #include "chrome/browser/media_galleries/media_galleries_preferences.h" 16 #include "chrome/browser/media_galleries/media_galleries_preferences.h"
16 #include "chrome/browser/media_galleries/media_galleries_scan_result_dialog_cont roller.h" 17 #include "chrome/browser/media_galleries/media_galleries_scan_result_controller. h"
17 #include "chrome/browser/media_galleries/media_galleries_test_util.h" 18 #include "chrome/browser/media_galleries/media_galleries_test_util.h"
18 #include "chrome/test/base/testing_profile.h" 19 #include "chrome/test/base/testing_profile.h"
19 #include "components/storage_monitor/test_storage_monitor.h" 20 #include "components/storage_monitor/test_storage_monitor.h"
20 #include "content/public/test/test_browser_thread_bundle.h" 21 #include "content/public/test/test_browser_thread_bundle.h"
21 #include "extensions/browser/extension_system.h" 22 #include "extensions/browser/extension_system.h"
22 #include "extensions/common/extension.h" 23 #include "extensions/common/extension.h"
23 #include "extensions/common/permissions/media_galleries_permission.h" 24 #include "extensions/common/permissions/media_galleries_permission.h"
24 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
25 26
26 #if defined(OS_CHROMEOS) 27 #if defined(OS_CHROMEOS)
27 #include "chrome/browser/chromeos/login/users/user_manager.h" 28 #include "chrome/browser/chromeos/login/users/user_manager.h"
28 #include "chrome/browser/chromeos/settings/cros_settings.h" 29 #include "chrome/browser/chromeos/settings/cros_settings.h"
29 #include "chrome/browser/chromeos/settings/device_settings_service.h" 30 #include "chrome/browser/chromeos/settings/device_settings_service.h"
30 #endif 31 #endif
31 32
32 namespace { 33 class MediaGalleriesScanResultControllerTest : public testing::Test {
33
34 class MockMediaGalleriesScanResultDialog
35 : public MediaGalleriesScanResultDialog {
36 public: 34 public:
37 typedef base::Callback<void(int update_count)> DialogDestroyedCallback; 35 MediaGalleriesScanResultControllerTest()
38
39 explicit MockMediaGalleriesScanResultDialog(
40 const DialogDestroyedCallback& callback)
41 : update_count_(0),
42 dialog_destroyed_callback_(callback) {
43 }
44
45 virtual ~MockMediaGalleriesScanResultDialog() {
46 dialog_destroyed_callback_.Run(update_count_);
47 }
48
49 // MediaGalleriesScanResultDialog implementation.
50 virtual void UpdateResults() OVERRIDE {
51 update_count_++;
52 }
53
54 // Number up times UpdateResults has been called.
55 int update_count() {
56 return update_count_;
57 }
58
59 private:
60 // MediaGalleriesScanResultDialog implementation.
61 virtual void AcceptDialogForTesting() OVERRIDE {
62 }
63
64 int update_count_;
65
66 DialogDestroyedCallback dialog_destroyed_callback_;
67
68 DISALLOW_COPY_AND_ASSIGN(MockMediaGalleriesScanResultDialog);
69 };
70
71 } // namespace
72
73 class MediaGalleriesScanResultDialogControllerTest : public testing::Test {
74 public:
75 MediaGalleriesScanResultDialogControllerTest()
76 : dialog_(NULL), 36 : dialog_(NULL),
77 dialog_update_count_at_destruction_(0), 37 dialog_update_count_at_destruction_(0),
78 controller_(NULL), 38 controller_(NULL),
79 profile_(new TestingProfile()), 39 profile_(new TestingProfile()),
80 weak_factory_(this) { 40 weak_factory_(this) {
81 } 41 }
82 42
83 virtual ~MediaGalleriesScanResultDialogControllerTest() { 43 virtual ~MediaGalleriesScanResultControllerTest() {
84 EXPECT_FALSE(controller_); 44 EXPECT_FALSE(controller_);
85 EXPECT_FALSE(dialog_); 45 EXPECT_FALSE(dialog_);
86 } 46 }
87 47
88 virtual void SetUp() OVERRIDE { 48 virtual void SetUp() OVERRIDE {
89 ASSERT_TRUE(storage_monitor::TestStorageMonitor::CreateAndInstall()); 49 ASSERT_TRUE(storage_monitor::TestStorageMonitor::CreateAndInstall());
90 50
91 extensions::TestExtensionSystem* extension_system( 51 extensions::TestExtensionSystem* extension_system(
92 static_cast<extensions::TestExtensionSystem*>( 52 static_cast<extensions::TestExtensionSystem*>(
93 extensions::ExtensionSystem::Get(profile_.get()))); 53 extensions::ExtensionSystem::Get(profile_.get())));
(...skipping 10 matching lines...) Expand all
104 extensions::MediaGalleriesPermission::kReadPermission); 64 extensions::MediaGalleriesPermission::kReadPermission);
105 extension_ = AddMediaGalleriesApp("read", read_permissions, profile_.get()); 65 extension_ = AddMediaGalleriesApp("read", read_permissions, profile_.get());
106 } 66 }
107 67
108 virtual void TearDown() OVERRIDE { 68 virtual void TearDown() OVERRIDE {
109 storage_monitor::TestStorageMonitor::Destroy(); 69 storage_monitor::TestStorageMonitor::Destroy();
110 } 70 }
111 71
112 void StartDialog() { 72 void StartDialog() {
113 ASSERT_FALSE(controller_); 73 ASSERT_FALSE(controller_);
114 controller_ = new MediaGalleriesScanResultDialogController( 74 controller_ = new MediaGalleriesScanResultController(
115 *extension_.get(), 75 *extension_.get(),
116 gallery_prefs_.get(), 76 gallery_prefs_.get(),
117 base::Bind( 77 base::Bind(
118 &MediaGalleriesScanResultDialogControllerTest::CreateMockDialog, 78 &MediaGalleriesScanResultControllerTest::CreateMockDialog,
119 base::Unretained(this)), 79 base::Unretained(this)),
120 base::Bind( 80 base::Bind(
121 &MediaGalleriesScanResultDialogControllerTest::OnControllerDone, 81 &MediaGalleriesScanResultControllerTest::OnControllerDone,
122 base::Unretained(this))); 82 base::Unretained(this)));
123 } 83 }
124 84
125 MediaGalleriesScanResultDialogController* controller() { 85 size_t GetFirstSectionSize() const {
86 return controller()->GetSectionEntries(0).size();
87 }
88
89 MediaGalleriesScanResultController* controller() const {
126 return controller_; 90 return controller_;
127 } 91 }
128 92
129 MockMediaGalleriesScanResultDialog* dialog() { 93 MockMediaGalleriesDialog* dialog() {
130 return dialog_; 94 return dialog_;
131 } 95 }
132 96
133 int dialog_update_count_at_destruction() { 97 int dialog_update_count_at_destruction() {
134 EXPECT_FALSE(dialog_); 98 EXPECT_FALSE(dialog_);
135 return dialog_update_count_at_destruction_; 99 return dialog_update_count_at_destruction_;
136 } 100 }
137 101
138 extensions::Extension* extension() { 102 extensions::Extension* extension() {
139 return extension_.get(); 103 return extension_.get();
(...skipping 22 matching lines...) Expand all
162 audio_count, image_count, video_count); 126 audio_count, image_count, video_count);
163 } 127 }
164 128
165 MediaGalleryPrefId AddScanResult(const std::string& path, int audio_count, 129 MediaGalleryPrefId AddScanResult(const std::string& path, int audio_count,
166 int image_count, int video_count) { 130 int image_count, int video_count) {
167 return AddGallery(path, MediaGalleryPrefInfo::kScanResult, audio_count, 131 return AddGallery(path, MediaGalleryPrefInfo::kScanResult, audio_count,
168 image_count, video_count); 132 image_count, video_count);
169 } 133 }
170 134
171 private: 135 private:
172 MediaGalleriesScanResultDialog* CreateMockDialog( 136 MediaGalleriesDialog* CreateMockDialog(
173 MediaGalleriesScanResultDialogController* controller) { 137 MediaGalleriesDialogController* controller) {
174 EXPECT_FALSE(dialog_); 138 EXPECT_FALSE(dialog_);
175 dialog_update_count_at_destruction_ = 0; 139 dialog_update_count_at_destruction_ = 0;
176 dialog_ = new MockMediaGalleriesScanResultDialog(base::Bind( 140 dialog_ = new MockMediaGalleriesDialog(base::Bind(
177 &MediaGalleriesScanResultDialogControllerTest::OnDialogDestroyed, 141 &MediaGalleriesScanResultControllerTest::OnDialogDestroyed,
178 weak_factory_.GetWeakPtr())); 142 weak_factory_.GetWeakPtr()));
179 return dialog_; 143 return dialog_;
180 } 144 }
181 145
182 void OnDialogDestroyed(int update_count) { 146 void OnDialogDestroyed(int update_count) {
183 EXPECT_TRUE(dialog_); 147 EXPECT_TRUE(dialog_);
184 dialog_update_count_at_destruction_ = update_count; 148 dialog_update_count_at_destruction_ = update_count;
185 dialog_ = NULL; 149 dialog_ = NULL;
186 } 150 }
187 151
188 void OnControllerDone() { 152 void OnControllerDone() {
189 controller_ = NULL; 153 controller_ = NULL;
190 } 154 }
191 155
192 // Needed for extension service & friends to work. 156 // Needed for extension service & friends to work.
193 content::TestBrowserThreadBundle thread_bundle_; 157 content::TestBrowserThreadBundle thread_bundle_;
194 158
195 // The dialog is owned by the controller, but this pointer should only be 159 // The dialog is owned by the controller, but this pointer should only be
196 // valid while the dialog is live within the controller. 160 // valid while the dialog is live within the controller.
197 MockMediaGalleriesScanResultDialog* dialog_; 161 MockMediaGalleriesDialog* dialog_;
198 int dialog_update_count_at_destruction_; 162 int dialog_update_count_at_destruction_;
199 163
200 // The controller owns itself. 164 // The controller owns itself.
201 MediaGalleriesScanResultDialogController* controller_; 165 MediaGalleriesScanResultController* controller_;
202 166
203 scoped_refptr<extensions::Extension> extension_; 167 scoped_refptr<extensions::Extension> extension_;
204 168
205 EnsureMediaDirectoriesExists mock_gallery_locations_; 169 EnsureMediaDirectoriesExists mock_gallery_locations_;
206 170
207 #if defined OS_CHROMEOS 171 #if defined OS_CHROMEOS
208 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; 172 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
209 chromeos::ScopedTestCrosSettings test_cros_settings_; 173 chromeos::ScopedTestCrosSettings test_cros_settings_;
210 chromeos::ScopedTestUserManager test_user_manager_; 174 chromeos::ScopedTestUserManager test_user_manager_;
211 #endif 175 #endif
212 176
213 storage_monitor::TestStorageMonitor monitor_; 177 storage_monitor::TestStorageMonitor monitor_;
214 scoped_ptr<TestingProfile> profile_; 178 scoped_ptr<TestingProfile> profile_;
215 scoped_ptr<MediaGalleriesPreferences> gallery_prefs_; 179 scoped_ptr<MediaGalleriesPreferences> gallery_prefs_;
216 180
217 base::WeakPtrFactory<MediaGalleriesScanResultDialogControllerTest> 181 base::WeakPtrFactory<MediaGalleriesScanResultControllerTest> weak_factory_;
218 weak_factory_;
219 182
220 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesScanResultDialogControllerTest); 183 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesScanResultControllerTest);
221 }; 184 };
222 185
223 TEST_F(MediaGalleriesScanResultDialogControllerTest, EmptyDialog) { 186 TEST_F(MediaGalleriesScanResultControllerTest, EmptyDialog) {
224 StartDialog(); 187 StartDialog();
225 EXPECT_TRUE(controller()); 188 EXPECT_TRUE(controller());
226 EXPECT_TRUE(dialog()); 189 EXPECT_TRUE(dialog());
227 EXPECT_EQ(0U, controller()->GetGalleryList().size()); 190 EXPECT_EQ(0U, GetFirstSectionSize());
228 191
229 controller()->DialogFinished(true); 192 controller()->DialogFinished(true);
230 EXPECT_FALSE(controller()); 193 EXPECT_FALSE(controller());
231 EXPECT_FALSE(dialog()); 194 EXPECT_FALSE(dialog());
232 EXPECT_EQ(0, dialog_update_count_at_destruction()); 195 EXPECT_EQ(0, dialog_update_count_at_destruction());
233 } 196 }
234 197
235 TEST_F(MediaGalleriesScanResultDialogControllerTest, AddScanResults) { 198 TEST_F(MediaGalleriesScanResultControllerTest, AddScanResults) {
236 // Start with two scan results. 199 // Start with two scan results.
237 MediaGalleryPrefId scan_id = AddScanResult("scan_id", 1, 0, 0); 200 MediaGalleryPrefId scan_id = AddScanResult("scan_id", 1, 0, 0);
238 MediaGalleryPrefId auto_id = 201 MediaGalleryPrefId auto_id =
239 AddGallery("auto_id", MediaGalleryPrefInfo::kAutoDetected, 2, 0, 0); 202 AddGallery("auto_id", MediaGalleryPrefInfo::kAutoDetected, 2, 0, 0);
240 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size()); 203 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size());
241 204
242 // Show the dialog, but cancel it. 205 // Show the dialog, but cancel it.
243 StartDialog(); 206 StartDialog();
244 EXPECT_EQ(2U, controller()->GetGalleryList().size()); 207 EXPECT_EQ(2U, GetFirstSectionSize());
245 controller()->DialogFinished(false); 208 controller()->DialogFinished(false);
246 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size()); 209 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size());
247 210
248 // Show the dialog, unselect both and accept it. 211 // Show the dialog, unselect both and accept it.
249 StartDialog(); 212 StartDialog();
250 EXPECT_EQ(2U, controller()->GetGalleryList().size()); 213 EXPECT_EQ(2U, GetFirstSectionSize());
251 controller()->DidToggleGalleryId(scan_id, false); 214 controller()->DidToggleEntry(scan_id, false);
252 controller()->DidToggleGalleryId(auto_id, false); 215 controller()->DidToggleEntry(auto_id, false);
253 controller()->DialogFinished(true); 216 controller()->DialogFinished(true);
254 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size()); 217 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size());
255 218
256 // Show the dialog, leave one selected and accept it. 219 // Show the dialog, leave one selected and accept it.
257 StartDialog(); 220 StartDialog();
258 EXPECT_EQ(2U, controller()->GetGalleryList().size()); 221 EXPECT_EQ(2U, GetFirstSectionSize());
259 controller()->DidToggleGalleryId(scan_id, false); 222 controller()->DidToggleEntry(scan_id, false);
260 controller()->DialogFinished(true); 223 controller()->DialogFinished(true);
261 MediaGalleryPrefIdSet permitted = 224 MediaGalleryPrefIdSet permitted =
262 gallery_prefs()->GalleriesForExtension(*extension()); 225 gallery_prefs()->GalleriesForExtension(*extension());
263 ASSERT_EQ(1U, permitted.size()); 226 ASSERT_EQ(1U, permitted.size());
264 EXPECT_EQ(auto_id, *permitted.begin()); 227 EXPECT_EQ(auto_id, *permitted.begin());
265 228
266 // Show the dialog, toggle the remaining entry twice and then accept it. 229 // Show the dialog, toggle the remaining entry twice and then accept it.
267 StartDialog(); 230 StartDialog();
268 EXPECT_EQ(1U, controller()->GetGalleryList().size()); 231 EXPECT_EQ(1U, GetFirstSectionSize());
269 controller()->DidToggleGalleryId(scan_id, false); 232 controller()->DidToggleEntry(scan_id, false);
270 controller()->DidToggleGalleryId(scan_id, true); 233 controller()->DidToggleEntry(scan_id, true);
271 controller()->DialogFinished(true); 234 controller()->DialogFinished(true);
272 EXPECT_EQ(2U, gallery_prefs()->GalleriesForExtension(*extension()).size()); 235 EXPECT_EQ(2U, gallery_prefs()->GalleriesForExtension(*extension()).size());
273 } 236 }
274 237
275 TEST_F(MediaGalleriesScanResultDialogControllerTest, Blacklisted) { 238 TEST_F(MediaGalleriesScanResultControllerTest, Blacklisted) {
276 // Start with two scan results. 239 // Start with two scan results.
277 MediaGalleryPrefId scan_id = AddScanResult("scan_id", 1, 0, 0); 240 MediaGalleryPrefId scan_id = AddScanResult("scan_id", 1, 0, 0);
278 MediaGalleryPrefId auto_id = 241 MediaGalleryPrefId auto_id =
279 AddGallery("auto_id", MediaGalleryPrefInfo::kAutoDetected, 2, 0, 0); 242 AddGallery("auto_id", MediaGalleryPrefInfo::kAutoDetected, 2, 0, 0);
280 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size()); 243 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size());
281 244
282 // Show the dialog, but cancel it. 245 // Show the dialog, but cancel it.
283 StartDialog(); 246 StartDialog();
284 EXPECT_EQ(2U, controller()->GetGalleryList().size()); 247 EXPECT_EQ(2U, GetFirstSectionSize());
285 controller()->DialogFinished(false); 248 controller()->DialogFinished(false);
286 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size()); 249 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size());
287 250
288 // Blacklist one and try again. 251 // Blacklist one and try again.
289 gallery_prefs()->ForgetGalleryById(scan_id); 252 gallery_prefs()->ForgetGalleryById(scan_id);
290 StartDialog(); 253 StartDialog();
291 EXPECT_EQ(1U, controller()->GetGalleryList().size()); 254 EXPECT_EQ(1U, GetFirstSectionSize());
292 controller()->DialogFinished(false); 255 controller()->DialogFinished(false);
293 256
294 // Adding it as a user gallery should change its type. 257 // Adding it as a user gallery should change its type.
295 AddGallery("scan_id", MediaGalleryPrefInfo::kUserAdded, 1, 0, 0); 258 AddGallery("scan_id", MediaGalleryPrefInfo::kUserAdded, 1, 0, 0);
296 StartDialog(); 259 StartDialog();
297 EXPECT_EQ(2U, controller()->GetGalleryList().size()); 260 EXPECT_EQ(2U, GetFirstSectionSize());
298 261
299 // Blacklisting the other while the dialog is open should remove it. 262 // Blacklisting the other while the dialog is open should remove it.
300 gallery_prefs()->ForgetGalleryById(auto_id); 263 gallery_prefs()->ForgetGalleryById(auto_id);
301 EXPECT_EQ(1U, controller()->GetGalleryList().size()); 264 EXPECT_EQ(1U, GetFirstSectionSize());
302 controller()->DialogFinished(false); 265 controller()->DialogFinished(false);
303 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size()); 266 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size());
304 EXPECT_EQ(1, dialog_update_count_at_destruction()); 267 EXPECT_EQ(1, dialog_update_count_at_destruction());
305 } 268 }
306 269
307 TEST_F(MediaGalleriesScanResultDialogControllerTest, PrefUpdates) { 270 TEST_F(MediaGalleriesScanResultControllerTest, PrefUpdates) {
308 MediaGalleryPrefId selected = AddScanResult("selected", 1, 0, 0); 271 MediaGalleryPrefId selected = AddScanResult("selected", 1, 0, 0);
309 MediaGalleryPrefId unselected = AddScanResult("unselected", 1, 0, 0); 272 MediaGalleryPrefId unselected = AddScanResult("unselected", 1, 0, 0);
310 MediaGalleryPrefId selected_add_permission = 273 MediaGalleryPrefId selected_add_permission =
311 AddScanResult("selected_add_permission", 1, 0, 0); 274 AddScanResult("selected_add_permission", 1, 0, 0);
312 MediaGalleryPrefId unselected_add_permission = 275 MediaGalleryPrefId unselected_add_permission =
313 AddScanResult("unselected_add_permission", 1, 0, 0); 276 AddScanResult("unselected_add_permission", 1, 0, 0);
314 MediaGalleryPrefId selected_removed = 277 MediaGalleryPrefId selected_removed =
315 AddScanResult("selected_removed", 1, 0, 0); 278 AddScanResult("selected_removed", 1, 0, 0);
316 MediaGalleryPrefId unselected_removed = 279 MediaGalleryPrefId unselected_removed =
317 AddScanResult("unselected_removed", 1, 0, 0); 280 AddScanResult("unselected_removed", 1, 0, 0);
318 MediaGalleryPrefId selected_update = 281 MediaGalleryPrefId selected_update =
319 AddScanResult("selected_update", 1, 0, 0); 282 AddScanResult("selected_update", 1, 0, 0);
320 MediaGalleryPrefId unselected_update = 283 MediaGalleryPrefId unselected_update =
321 AddScanResult("unselected_update", 1, 0, 0); 284 AddScanResult("unselected_update", 1, 0, 0);
322 285
323 gallery_prefs()->AddGalleryByPath(MakeMediaGalleriesTestingPath("user"), 286 gallery_prefs()->AddGalleryByPath(MakeMediaGalleriesTestingPath("user"),
324 MediaGalleryPrefInfo::kUserAdded); 287 MediaGalleryPrefInfo::kUserAdded);
325 gallery_prefs()->AddGalleryByPath( 288 gallery_prefs()->AddGalleryByPath(
326 MakeMediaGalleriesTestingPath("auto_detected"), 289 MakeMediaGalleriesTestingPath("auto_detected"),
327 MediaGalleryPrefInfo::kAutoDetected); 290 MediaGalleryPrefInfo::kAutoDetected);
328 MediaGalleryPrefId blacklisted = gallery_prefs()->AddGalleryByPath( 291 MediaGalleryPrefId blacklisted = gallery_prefs()->AddGalleryByPath(
329 MakeMediaGalleriesTestingPath("blacklisted"), 292 MakeMediaGalleriesTestingPath("blacklisted"),
330 MediaGalleryPrefInfo::kAutoDetected); 293 MediaGalleryPrefInfo::kAutoDetected);
331 gallery_prefs()->ForgetGalleryById(blacklisted); 294 gallery_prefs()->ForgetGalleryById(blacklisted);
332 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size()); 295 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size());
333 296
334 StartDialog(); 297 StartDialog();
335 EXPECT_EQ(8U, controller()->GetGalleryList().size()); 298 EXPECT_EQ(8U, GetFirstSectionSize());
336 controller()->DidToggleGalleryId(unselected, false); 299 controller()->DidToggleEntry(unselected, false);
337 controller()->DidToggleGalleryId(unselected_add_permission, false); 300 controller()->DidToggleEntry(unselected_add_permission, false);
338 controller()->DidToggleGalleryId(unselected_removed, false); 301 controller()->DidToggleEntry(unselected_removed, false);
339 controller()->DidToggleGalleryId(unselected_update, false); 302 controller()->DidToggleEntry(unselected_update, false);
340 EXPECT_EQ(0, dialog()->update_count()); 303 EXPECT_EQ(0, dialog()->update_count());
341 EXPECT_EQ(8U, controller()->GetGalleryList().size()); 304 EXPECT_EQ(8U, GetFirstSectionSize());
342 305
343 // Add permission. 306 // Add permission.
344 gallery_prefs()->SetGalleryPermissionForExtension(*extension(), 307 gallery_prefs()->SetGalleryPermissionForExtension(*extension(),
345 unselected_add_permission, 308 unselected_add_permission,
346 true); 309 true);
347 EXPECT_EQ(1, dialog()->update_count()); 310 EXPECT_EQ(1, dialog()->update_count());
348 EXPECT_EQ(7U, controller()->GetGalleryList().size()); 311 EXPECT_EQ(7U, GetFirstSectionSize());
349 gallery_prefs()->SetGalleryPermissionForExtension(*extension(), 312 gallery_prefs()->SetGalleryPermissionForExtension(*extension(),
350 selected_add_permission, 313 selected_add_permission,
351 true); 314 true);
352 EXPECT_EQ(2, dialog()->update_count()); 315 EXPECT_EQ(2, dialog()->update_count());
353 EXPECT_EQ(6U, controller()->GetGalleryList().size()); 316 EXPECT_EQ(6U, GetFirstSectionSize());
354 317
355 // Blacklist scan results. 318 // Blacklist scan results.
356 gallery_prefs()->ForgetGalleryById(unselected_removed); 319 gallery_prefs()->ForgetGalleryById(unselected_removed);
357 EXPECT_EQ(3, dialog()->update_count()); 320 EXPECT_EQ(3, dialog()->update_count());
358 EXPECT_EQ(5U, controller()->GetGalleryList().size()); 321 EXPECT_EQ(5U, GetFirstSectionSize());
359 gallery_prefs()->ForgetGalleryById(selected_removed); 322 gallery_prefs()->ForgetGalleryById(selected_removed);
360 EXPECT_EQ(4, dialog()->update_count()); 323 EXPECT_EQ(4, dialog()->update_count());
361 EXPECT_EQ(4U, controller()->GetGalleryList().size()); 324 EXPECT_EQ(4U, GetFirstSectionSize());
362 325
363 // Update names. 326 // Update names.
364 const MediaGalleryPrefInfo& unselected_update_info = 327 const MediaGalleryPrefInfo& unselected_update_info =
365 gallery_prefs()->known_galleries().find(unselected_update)->second; 328 gallery_prefs()->known_galleries().find(unselected_update)->second;
366 gallery_prefs()->AddGallery( 329 gallery_prefs()->AddGallery(
367 unselected_update_info.device_id, base::FilePath(), 330 unselected_update_info.device_id, base::FilePath(),
368 MediaGalleryPrefInfo::kScanResult, 331 MediaGalleryPrefInfo::kScanResult,
369 base::ASCIIToUTF16("Updated & Unselected"), 332 base::ASCIIToUTF16("Updated & Unselected"),
370 base::string16(), base::string16(), 0, base::Time(), 1, 0, 0); 333 base::string16(), base::string16(), 0, base::Time(), 1, 0, 0);
371 EXPECT_EQ(5, dialog()->update_count()); 334 EXPECT_EQ(5, dialog()->update_count());
372 EXPECT_EQ(4U, controller()->GetGalleryList().size()); 335 EXPECT_EQ(4U, GetFirstSectionSize());
373 const MediaGalleryPrefInfo& selected_update_info = 336 const MediaGalleryPrefInfo& selected_update_info =
374 gallery_prefs()->known_galleries().find(selected_update)->second; 337 gallery_prefs()->known_galleries().find(selected_update)->second;
375 gallery_prefs()->AddGallery( 338 gallery_prefs()->AddGallery(
376 selected_update_info.device_id, base::FilePath(), 339 selected_update_info.device_id, base::FilePath(),
377 MediaGalleryPrefInfo::kScanResult, 340 MediaGalleryPrefInfo::kScanResult,
378 base::ASCIIToUTF16("Updated & Selected"), 341 base::ASCIIToUTF16("Updated & Selected"),
379 base::string16(), base::string16(), 0, base::Time(), 1, 0, 0); 342 base::string16(), base::string16(), 0, base::Time(), 1, 0, 0);
380 EXPECT_EQ(6, dialog()->update_count()); 343 EXPECT_EQ(6, dialog()->update_count());
381 ASSERT_EQ(4U, controller()->GetGalleryList().size()); 344 EXPECT_EQ(4U, GetFirstSectionSize());
382 345
383 MediaGalleriesScanResultDialogController::OrderedScanResults results = 346 MediaGalleriesDialogController::Entries results =
384 controller()->GetGalleryList(); 347 controller()->GetSectionEntries(0);
385 EXPECT_EQ(selected, results[0].pref_info.pref_id); 348 EXPECT_EQ(selected, results[0].pref_info.pref_id);
386 EXPECT_TRUE(results[0].selected); 349 EXPECT_TRUE(results[0].selected);
387 EXPECT_EQ(selected_update, results[1].pref_info.pref_id); 350 EXPECT_EQ(selected_update, results[1].pref_info.pref_id);
388 EXPECT_TRUE(results[1].selected); 351 EXPECT_TRUE(results[1].selected);
389 EXPECT_EQ(base::ASCIIToUTF16("Updated & Selected"), 352 EXPECT_EQ(base::ASCIIToUTF16("Updated & Selected"),
390 results[1].pref_info.volume_label); 353 results[1].pref_info.volume_label);
391 EXPECT_EQ(unselected, results[2].pref_info.pref_id); 354 EXPECT_EQ(unselected, results[2].pref_info.pref_id);
392 EXPECT_FALSE(results[2].selected); 355 EXPECT_FALSE(results[2].selected);
393 EXPECT_EQ(unselected_update, results[3].pref_info.pref_id); 356 EXPECT_EQ(unselected_update, results[3].pref_info.pref_id);
394 EXPECT_FALSE(results[3].selected); 357 EXPECT_FALSE(results[3].selected);
395 EXPECT_EQ(base::ASCIIToUTF16("Updated & Unselected"), 358 EXPECT_EQ(base::ASCIIToUTF16("Updated & Unselected"),
396 results[3].pref_info.volume_label); 359 results[3].pref_info.volume_label);
397 360
398 controller()->DialogFinished(true); 361 controller()->DialogFinished(true);
399 EXPECT_EQ(4U, gallery_prefs()->GalleriesForExtension(*extension()).size()); 362 EXPECT_EQ(4U, gallery_prefs()->GalleriesForExtension(*extension()).size());
400 StartDialog(); 363 StartDialog();
401 EXPECT_EQ(2U, controller()->GetGalleryList().size()); 364 EXPECT_EQ(2U, GetFirstSectionSize());
402 controller()->DialogFinished(false); 365 controller()->DialogFinished(false);
403 } 366 }
404 367
405 TEST_F(MediaGalleriesScanResultDialogControllerTest, ForgetGallery) { 368 TEST_F(MediaGalleriesScanResultControllerTest, ForgetGallery) {
406 // Start with two scan results. 369 // Start with two scan results.
407 MediaGalleryPrefId scan1 = AddScanResult("scan1", 1, 0, 0); 370 MediaGalleryPrefId scan1 = AddScanResult("scan1", 1, 0, 0);
408 MediaGalleryPrefId scan2 = AddScanResult("scan2", 2, 0, 0); 371 MediaGalleryPrefId scan2 = AddScanResult("scan2", 2, 0, 0);
409 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size()); 372 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size());
410 373
411 // Remove one and then cancel. 374 // Remove one and then cancel.
412 StartDialog(); 375 StartDialog();
413 EXPECT_EQ(2U, controller()->GetGalleryList().size()); 376 EXPECT_EQ(2U, GetFirstSectionSize());
414 controller()->DidForgetGallery(scan1); 377 controller()->DidForgetEntry(scan1);
415 controller()->DialogFinished(false); 378 controller()->DialogFinished(false);
416 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size()); 379 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size());
417 380
418 // Remove one and then have it blacklisted from prefs. 381 // Remove one and then have it blacklisted from prefs.
419 StartDialog(); 382 StartDialog();
420 EXPECT_EQ(2U, controller()->GetGalleryList().size()); 383 EXPECT_EQ(2U, GetFirstSectionSize());
421 controller()->DidForgetGallery(scan1); 384 controller()->DidForgetEntry(scan1);
422 EXPECT_EQ(1, dialog()->update_count()); 385 EXPECT_EQ(1, dialog()->update_count());
423 controller()->DidToggleGalleryId(scan2, false); // Uncheck the second. 386 controller()->DidToggleEntry(scan2, false); // Uncheck the second.
424 gallery_prefs()->ForgetGalleryById(scan1); 387 gallery_prefs()->ForgetGalleryById(scan1);
425 controller()->DialogFinished(true); 388 controller()->DialogFinished(true);
426 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size()); 389 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size());
427 EXPECT_EQ(2, dialog_update_count_at_destruction()); 390 EXPECT_EQ(2, dialog_update_count_at_destruction());
428 391
429 // Remove the other. 392 // Remove the other.
430 StartDialog(); 393 StartDialog();
431 EXPECT_EQ(1U, controller()->GetGalleryList().size()); 394 EXPECT_EQ(1U, GetFirstSectionSize());
432 controller()->DidForgetGallery(scan2); 395 controller()->DidForgetEntry(scan2);
433 controller()->DialogFinished(true); 396 controller()->DialogFinished(true);
434 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size()); 397 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size());
435 398
436 // Check that nothing shows up. 399 // Check that nothing shows up.
437 StartDialog(); 400 StartDialog();
438 EXPECT_EQ(0U, controller()->GetGalleryList().size()); 401 EXPECT_EQ(0U, GetFirstSectionSize());
439 controller()->DialogFinished(false); 402 controller()->DialogFinished(false);
440 } 403 }
441 404
442 TEST_F(MediaGalleriesScanResultDialogControllerTest, SortOrder) { 405 TEST_F(MediaGalleriesScanResultControllerTest, SortOrder) {
443 // Intentionally out of order numerically and alphabetically. 406 // Intentionally out of order numerically and alphabetically.
444 MediaGalleryPrefId third = AddScanResult("third", 2, 2, 2); 407 MediaGalleryPrefId third = AddScanResult("third", 2, 2, 2);
445 MediaGalleryPrefId second = 408 MediaGalleryPrefId second =
446 AddGallery("second", MediaGalleryPrefInfo::kAutoDetected, 9, 0, 0); 409 AddGallery("second", MediaGalleryPrefInfo::kAutoDetected, 9, 0, 0);
447 MediaGalleryPrefId first = AddScanResult("first", 8, 2, 3); 410 MediaGalleryPrefId first = AddScanResult("first", 8, 2, 3);
448 MediaGalleryPrefId fifth = AddScanResult("abb", 3, 0, 0); 411 MediaGalleryPrefId fifth = AddScanResult("abb", 3, 0, 0);
449 MediaGalleryPrefId fourth = AddScanResult("aaa", 3, 0, 0); 412 MediaGalleryPrefId fourth = AddScanResult("aaa", 3, 0, 0);
450 413
451 StartDialog(); 414 StartDialog();
452 MediaGalleriesScanResultDialogController::OrderedScanResults results = 415 MediaGalleriesDialogController::Entries results =
453 controller()->GetGalleryList(); 416 controller()->GetSectionEntries(0);
454 ASSERT_EQ(5U, results.size()); 417 ASSERT_EQ(5U, results.size());
455 EXPECT_EQ(first, results[0].pref_info.pref_id); 418 EXPECT_EQ(first, results[0].pref_info.pref_id);
456 EXPECT_EQ(second, results[1].pref_info.pref_id); 419 EXPECT_EQ(second, results[1].pref_info.pref_id);
457 EXPECT_EQ(third, results[2].pref_info.pref_id); 420 EXPECT_EQ(third, results[2].pref_info.pref_id);
458 EXPECT_EQ(fourth, results[3].pref_info.pref_id); 421 EXPECT_EQ(fourth, results[3].pref_info.pref_id);
459 EXPECT_EQ(fifth, results[4].pref_info.pref_id); 422 EXPECT_EQ(fifth, results[4].pref_info.pref_id);
460 controller()->DialogFinished(false); 423 controller()->DialogFinished(false);
461 } 424 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698