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

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: Rebase 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 MediaGalleriesScanResultController* controller() {
126 return controller_; 86 return controller_;
127 } 87 }
128 88
129 MockMediaGalleriesScanResultDialog* dialog() { 89 MockMediaGalleriesDialog* dialog() {
130 return dialog_; 90 return dialog_;
131 } 91 }
132 92
133 int dialog_update_count_at_destruction() { 93 int dialog_update_count_at_destruction() {
134 EXPECT_FALSE(dialog_); 94 EXPECT_FALSE(dialog_);
135 return dialog_update_count_at_destruction_; 95 return dialog_update_count_at_destruction_;
136 } 96 }
137 97
138 extensions::Extension* extension() { 98 extensions::Extension* extension() {
139 return extension_.get(); 99 return extension_.get();
(...skipping 22 matching lines...) Expand all
162 audio_count, image_count, video_count); 122 audio_count, image_count, video_count);
163 } 123 }
164 124
165 MediaGalleryPrefId AddScanResult(const std::string& path, int audio_count, 125 MediaGalleryPrefId AddScanResult(const std::string& path, int audio_count,
166 int image_count, int video_count) { 126 int image_count, int video_count) {
167 return AddGallery(path, MediaGalleryPrefInfo::kScanResult, audio_count, 127 return AddGallery(path, MediaGalleryPrefInfo::kScanResult, audio_count,
168 image_count, video_count); 128 image_count, video_count);
169 } 129 }
170 130
171 private: 131 private:
172 MediaGalleriesScanResultDialog* CreateMockDialog( 132 MediaGalleriesDialog* CreateMockDialog(
173 MediaGalleriesScanResultDialogController* controller) { 133 MediaGalleriesDialogController* controller) {
174 EXPECT_FALSE(dialog_); 134 EXPECT_FALSE(dialog_);
175 dialog_update_count_at_destruction_ = 0; 135 dialog_update_count_at_destruction_ = 0;
176 dialog_ = new MockMediaGalleriesScanResultDialog(base::Bind( 136 dialog_ = new MockMediaGalleriesDialog(base::Bind(
177 &MediaGalleriesScanResultDialogControllerTest::OnDialogDestroyed, 137 &MediaGalleriesScanResultControllerTest::OnDialogDestroyed,
178 weak_factory_.GetWeakPtr())); 138 weak_factory_.GetWeakPtr()));
179 return dialog_; 139 return dialog_;
180 } 140 }
181 141
182 void OnDialogDestroyed(int update_count) { 142 void OnDialogDestroyed(int update_count) {
183 EXPECT_TRUE(dialog_); 143 EXPECT_TRUE(dialog_);
184 dialog_update_count_at_destruction_ = update_count; 144 dialog_update_count_at_destruction_ = update_count;
185 dialog_ = NULL; 145 dialog_ = NULL;
186 } 146 }
187 147
188 void OnControllerDone() { 148 void OnControllerDone() {
189 controller_ = NULL; 149 controller_ = NULL;
190 } 150 }
191 151
192 // Needed for extension service & friends to work. 152 // Needed for extension service & friends to work.
193 content::TestBrowserThreadBundle thread_bundle_; 153 content::TestBrowserThreadBundle thread_bundle_;
194 154
195 // The dialog is owned by the controller, but this pointer should only be 155 // The dialog is owned by the controller, but this pointer should only be
196 // valid while the dialog is live within the controller. 156 // valid while the dialog is live within the controller.
197 MockMediaGalleriesScanResultDialog* dialog_; 157 MockMediaGalleriesDialog* dialog_;
198 int dialog_update_count_at_destruction_; 158 int dialog_update_count_at_destruction_;
199 159
200 // The controller owns itself. 160 // The controller owns itself.
201 MediaGalleriesScanResultDialogController* controller_; 161 MediaGalleriesScanResultController* controller_;
202 162
203 scoped_refptr<extensions::Extension> extension_; 163 scoped_refptr<extensions::Extension> extension_;
204 164
205 EnsureMediaDirectoriesExists mock_gallery_locations_; 165 EnsureMediaDirectoriesExists mock_gallery_locations_;
206 166
207 #if defined OS_CHROMEOS 167 #if defined OS_CHROMEOS
208 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; 168 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
209 chromeos::ScopedTestCrosSettings test_cros_settings_; 169 chromeos::ScopedTestCrosSettings test_cros_settings_;
210 chromeos::ScopedTestUserManager test_user_manager_; 170 chromeos::ScopedTestUserManager test_user_manager_;
211 #endif 171 #endif
212 172
213 storage_monitor::TestStorageMonitor monitor_; 173 storage_monitor::TestStorageMonitor monitor_;
214 scoped_ptr<TestingProfile> profile_; 174 scoped_ptr<TestingProfile> profile_;
215 scoped_ptr<MediaGalleriesPreferences> gallery_prefs_; 175 scoped_ptr<MediaGalleriesPreferences> gallery_prefs_;
216 176
217 base::WeakPtrFactory<MediaGalleriesScanResultDialogControllerTest> 177 base::WeakPtrFactory<MediaGalleriesScanResultControllerTest> weak_factory_;
218 weak_factory_;
219 178
220 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesScanResultDialogControllerTest); 179 DISALLOW_COPY_AND_ASSIGN(MediaGalleriesScanResultControllerTest);
221 }; 180 };
222 181
223 TEST_F(MediaGalleriesScanResultDialogControllerTest, EmptyDialog) { 182 TEST_F(MediaGalleriesScanResultControllerTest, EmptyDialog) {
224 StartDialog(); 183 StartDialog();
225 EXPECT_TRUE(controller()); 184 EXPECT_TRUE(controller());
226 EXPECT_TRUE(dialog()); 185 EXPECT_TRUE(dialog());
227 EXPECT_EQ(0U, controller()->GetGalleryList().size()); 186 EXPECT_EQ(0U, controller()->GetSectionEntries(0).size());
228 187
229 controller()->DialogFinished(true); 188 controller()->DialogFinished(true);
230 EXPECT_FALSE(controller()); 189 EXPECT_FALSE(controller());
231 EXPECT_FALSE(dialog()); 190 EXPECT_FALSE(dialog());
232 EXPECT_EQ(0, dialog_update_count_at_destruction()); 191 EXPECT_EQ(0, dialog_update_count_at_destruction());
233 } 192 }
234 193
235 TEST_F(MediaGalleriesScanResultDialogControllerTest, AddScanResults) { 194 TEST_F(MediaGalleriesScanResultControllerTest, AddScanResults) {
236 // Start with two scan results. 195 // Start with two scan results.
237 MediaGalleryPrefId scan_id = AddScanResult("scan_id", 1, 0, 0); 196 MediaGalleryPrefId scan_id = AddScanResult("scan_id", 1, 0, 0);
238 MediaGalleryPrefId auto_id = 197 MediaGalleryPrefId auto_id =
239 AddGallery("auto_id", MediaGalleryPrefInfo::kAutoDetected, 2, 0, 0); 198 AddGallery("auto_id", MediaGalleryPrefInfo::kAutoDetected, 2, 0, 0);
240 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size()); 199 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size());
241 200
242 // Show the dialog, but cancel it. 201 // Show the dialog, but cancel it.
243 StartDialog(); 202 StartDialog();
244 EXPECT_EQ(2U, controller()->GetGalleryList().size()); 203 EXPECT_EQ(2U, controller()->GetSectionEntries(0).size());
Lei Zhang 2014/06/06 07:03:10 controller()->GetSectionEntries(0).size() is used
vandebo (ex-Chrome) 2014/06/06 17:43:30 Done.
245 controller()->DialogFinished(false); 204 controller()->DialogFinished(false);
246 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size()); 205 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size());
247 206
248 // Show the dialog, unselect both and accept it. 207 // Show the dialog, unselect both and accept it.
249 StartDialog(); 208 StartDialog();
250 EXPECT_EQ(2U, controller()->GetGalleryList().size()); 209 EXPECT_EQ(2U, controller()->GetSectionEntries(0).size());
251 controller()->DidToggleGalleryId(scan_id, false); 210 controller()->DidToggleEntry(scan_id, false);
252 controller()->DidToggleGalleryId(auto_id, false); 211 controller()->DidToggleEntry(auto_id, false);
253 controller()->DialogFinished(true); 212 controller()->DialogFinished(true);
254 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size()); 213 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size());
255 214
256 // Show the dialog, leave one selected and accept it. 215 // Show the dialog, leave one selected and accept it.
257 StartDialog(); 216 StartDialog();
258 EXPECT_EQ(2U, controller()->GetGalleryList().size()); 217 EXPECT_EQ(2U, controller()->GetSectionEntries(0).size());
259 controller()->DidToggleGalleryId(scan_id, false); 218 controller()->DidToggleEntry(scan_id, false);
260 controller()->DialogFinished(true); 219 controller()->DialogFinished(true);
261 MediaGalleryPrefIdSet permitted = 220 MediaGalleryPrefIdSet permitted =
262 gallery_prefs()->GalleriesForExtension(*extension()); 221 gallery_prefs()->GalleriesForExtension(*extension());
263 ASSERT_EQ(1U, permitted.size()); 222 ASSERT_EQ(1U, permitted.size());
264 EXPECT_EQ(auto_id, *permitted.begin()); 223 EXPECT_EQ(auto_id, *permitted.begin());
265 224
266 // Show the dialog, toggle the remaining entry twice and then accept it. 225 // Show the dialog, toggle the remaining entry twice and then accept it.
267 StartDialog(); 226 StartDialog();
268 EXPECT_EQ(1U, controller()->GetGalleryList().size()); 227 EXPECT_EQ(1U, controller()->GetSectionEntries(0).size());
269 controller()->DidToggleGalleryId(scan_id, false); 228 controller()->DidToggleEntry(scan_id, false);
270 controller()->DidToggleGalleryId(scan_id, true); 229 controller()->DidToggleEntry(scan_id, true);
271 controller()->DialogFinished(true); 230 controller()->DialogFinished(true);
272 EXPECT_EQ(2U, gallery_prefs()->GalleriesForExtension(*extension()).size()); 231 EXPECT_EQ(2U, gallery_prefs()->GalleriesForExtension(*extension()).size());
273 } 232 }
274 233
275 TEST_F(MediaGalleriesScanResultDialogControllerTest, Blacklisted) { 234 TEST_F(MediaGalleriesScanResultControllerTest, Blacklisted) {
276 // Start with two scan results. 235 // Start with two scan results.
277 MediaGalleryPrefId scan_id = AddScanResult("scan_id", 1, 0, 0); 236 MediaGalleryPrefId scan_id = AddScanResult("scan_id", 1, 0, 0);
278 MediaGalleryPrefId auto_id = 237 MediaGalleryPrefId auto_id =
279 AddGallery("auto_id", MediaGalleryPrefInfo::kAutoDetected, 2, 0, 0); 238 AddGallery("auto_id", MediaGalleryPrefInfo::kAutoDetected, 2, 0, 0);
280 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size()); 239 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size());
281 240
282 // Show the dialog, but cancel it. 241 // Show the dialog, but cancel it.
283 StartDialog(); 242 StartDialog();
284 EXPECT_EQ(2U, controller()->GetGalleryList().size()); 243 EXPECT_EQ(2U, controller()->GetSectionEntries(0).size());
285 controller()->DialogFinished(false); 244 controller()->DialogFinished(false);
286 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size()); 245 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size());
287 246
288 // Blacklist one and try again. 247 // Blacklist one and try again.
289 gallery_prefs()->ForgetGalleryById(scan_id); 248 gallery_prefs()->ForgetGalleryById(scan_id);
290 StartDialog(); 249 StartDialog();
291 EXPECT_EQ(1U, controller()->GetGalleryList().size()); 250 EXPECT_EQ(1U, controller()->GetSectionEntries(0).size());
292 controller()->DialogFinished(false); 251 controller()->DialogFinished(false);
293 252
294 // Adding it as a user gallery should change its type. 253 // Adding it as a user gallery should change its type.
295 AddGallery("scan_id", MediaGalleryPrefInfo::kUserAdded, 1, 0, 0); 254 AddGallery("scan_id", MediaGalleryPrefInfo::kUserAdded, 1, 0, 0);
296 StartDialog(); 255 StartDialog();
297 EXPECT_EQ(2U, controller()->GetGalleryList().size()); 256 EXPECT_EQ(2U, controller()->GetSectionEntries(0).size());
298 257
299 // Blacklisting the other while the dialog is open should remove it. 258 // Blacklisting the other while the dialog is open should remove it.
300 gallery_prefs()->ForgetGalleryById(auto_id); 259 gallery_prefs()->ForgetGalleryById(auto_id);
301 EXPECT_EQ(1U, controller()->GetGalleryList().size()); 260 EXPECT_EQ(1U, controller()->GetSectionEntries(0).size());
302 controller()->DialogFinished(false); 261 controller()->DialogFinished(false);
303 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size()); 262 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size());
304 EXPECT_EQ(1, dialog_update_count_at_destruction()); 263 EXPECT_EQ(1, dialog_update_count_at_destruction());
305 } 264 }
306 265
307 TEST_F(MediaGalleriesScanResultDialogControllerTest, PrefUpdates) { 266 TEST_F(MediaGalleriesScanResultControllerTest, PrefUpdates) {
308 MediaGalleryPrefId selected = AddScanResult("selected", 1, 0, 0); 267 MediaGalleryPrefId selected = AddScanResult("selected", 1, 0, 0);
309 MediaGalleryPrefId unselected = AddScanResult("unselected", 1, 0, 0); 268 MediaGalleryPrefId unselected = AddScanResult("unselected", 1, 0, 0);
310 MediaGalleryPrefId selected_add_permission = 269 MediaGalleryPrefId selected_add_permission =
311 AddScanResult("selected_add_permission", 1, 0, 0); 270 AddScanResult("selected_add_permission", 1, 0, 0);
312 MediaGalleryPrefId unselected_add_permission = 271 MediaGalleryPrefId unselected_add_permission =
313 AddScanResult("unselected_add_permission", 1, 0, 0); 272 AddScanResult("unselected_add_permission", 1, 0, 0);
314 MediaGalleryPrefId selected_removed = 273 MediaGalleryPrefId selected_removed =
315 AddScanResult("selected_removed", 1, 0, 0); 274 AddScanResult("selected_removed", 1, 0, 0);
316 MediaGalleryPrefId unselected_removed = 275 MediaGalleryPrefId unselected_removed =
317 AddScanResult("unselected_removed", 1, 0, 0); 276 AddScanResult("unselected_removed", 1, 0, 0);
318 MediaGalleryPrefId selected_update = 277 MediaGalleryPrefId selected_update =
319 AddScanResult("selected_update", 1, 0, 0); 278 AddScanResult("selected_update", 1, 0, 0);
320 MediaGalleryPrefId unselected_update = 279 MediaGalleryPrefId unselected_update =
321 AddScanResult("unselected_update", 1, 0, 0); 280 AddScanResult("unselected_update", 1, 0, 0);
322 281
323 gallery_prefs()->AddGalleryByPath(MakeMediaGalleriesTestingPath("user"), 282 gallery_prefs()->AddGalleryByPath(MakeMediaGalleriesTestingPath("user"),
324 MediaGalleryPrefInfo::kUserAdded); 283 MediaGalleryPrefInfo::kUserAdded);
325 gallery_prefs()->AddGalleryByPath( 284 gallery_prefs()->AddGalleryByPath(
326 MakeMediaGalleriesTestingPath("auto_detected"), 285 MakeMediaGalleriesTestingPath("auto_detected"),
327 MediaGalleryPrefInfo::kAutoDetected); 286 MediaGalleryPrefInfo::kAutoDetected);
328 MediaGalleryPrefId blacklisted = gallery_prefs()->AddGalleryByPath( 287 MediaGalleryPrefId blacklisted = gallery_prefs()->AddGalleryByPath(
329 MakeMediaGalleriesTestingPath("blacklisted"), 288 MakeMediaGalleriesTestingPath("blacklisted"),
330 MediaGalleryPrefInfo::kAutoDetected); 289 MediaGalleryPrefInfo::kAutoDetected);
331 gallery_prefs()->ForgetGalleryById(blacklisted); 290 gallery_prefs()->ForgetGalleryById(blacklisted);
332 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size()); 291 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size());
333 292
334 StartDialog(); 293 StartDialog();
335 EXPECT_EQ(8U, controller()->GetGalleryList().size()); 294 EXPECT_EQ(8U, controller()->GetSectionEntries(0).size());
336 controller()->DidToggleGalleryId(unselected, false); 295 controller()->DidToggleEntry(unselected, false);
337 controller()->DidToggleGalleryId(unselected_add_permission, false); 296 controller()->DidToggleEntry(unselected_add_permission, false);
338 controller()->DidToggleGalleryId(unselected_removed, false); 297 controller()->DidToggleEntry(unselected_removed, false);
339 controller()->DidToggleGalleryId(unselected_update, false); 298 controller()->DidToggleEntry(unselected_update, false);
340 EXPECT_EQ(0, dialog()->update_count()); 299 EXPECT_EQ(0, dialog()->update_count());
341 EXPECT_EQ(8U, controller()->GetGalleryList().size()); 300 EXPECT_EQ(8U, controller()->GetSectionEntries(0).size());
342 301
343 // Add permission. 302 // Add permission.
344 gallery_prefs()->SetGalleryPermissionForExtension(*extension(), 303 gallery_prefs()->SetGalleryPermissionForExtension(*extension(),
345 unselected_add_permission, 304 unselected_add_permission,
346 true); 305 true);
347 EXPECT_EQ(1, dialog()->update_count()); 306 EXPECT_EQ(1, dialog()->update_count());
348 EXPECT_EQ(7U, controller()->GetGalleryList().size()); 307 EXPECT_EQ(7U, controller()->GetSectionEntries(0).size());
349 gallery_prefs()->SetGalleryPermissionForExtension(*extension(), 308 gallery_prefs()->SetGalleryPermissionForExtension(*extension(),
350 selected_add_permission, 309 selected_add_permission,
351 true); 310 true);
352 EXPECT_EQ(2, dialog()->update_count()); 311 EXPECT_EQ(2, dialog()->update_count());
353 EXPECT_EQ(6U, controller()->GetGalleryList().size()); 312 EXPECT_EQ(6U, controller()->GetSectionEntries(0).size());
354 313
355 // Blacklist scan results. 314 // Blacklist scan results.
356 gallery_prefs()->ForgetGalleryById(unselected_removed); 315 gallery_prefs()->ForgetGalleryById(unselected_removed);
357 EXPECT_EQ(3, dialog()->update_count()); 316 EXPECT_EQ(3, dialog()->update_count());
358 EXPECT_EQ(5U, controller()->GetGalleryList().size()); 317 EXPECT_EQ(5U, controller()->GetSectionEntries(0).size());
359 gallery_prefs()->ForgetGalleryById(selected_removed); 318 gallery_prefs()->ForgetGalleryById(selected_removed);
360 EXPECT_EQ(4, dialog()->update_count()); 319 EXPECT_EQ(4, dialog()->update_count());
361 EXPECT_EQ(4U, controller()->GetGalleryList().size()); 320 EXPECT_EQ(4U, controller()->GetSectionEntries(0).size());
362 321
363 // Update names. 322 // Update names.
364 const MediaGalleryPrefInfo& unselected_update_info = 323 const MediaGalleryPrefInfo& unselected_update_info =
365 gallery_prefs()->known_galleries().find(unselected_update)->second; 324 gallery_prefs()->known_galleries().find(unselected_update)->second;
366 gallery_prefs()->AddGallery( 325 gallery_prefs()->AddGallery(
367 unselected_update_info.device_id, base::FilePath(), 326 unselected_update_info.device_id, base::FilePath(),
368 MediaGalleryPrefInfo::kScanResult, 327 MediaGalleryPrefInfo::kScanResult,
369 base::ASCIIToUTF16("Updated & Unselected"), 328 base::ASCIIToUTF16("Updated & Unselected"),
370 base::string16(), base::string16(), 0, base::Time(), 1, 0, 0); 329 base::string16(), base::string16(), 0, base::Time(), 1, 0, 0);
371 EXPECT_EQ(5, dialog()->update_count()); 330 EXPECT_EQ(5, dialog()->update_count());
372 EXPECT_EQ(4U, controller()->GetGalleryList().size()); 331 EXPECT_EQ(4U, controller()->GetSectionEntries(0).size());
373 const MediaGalleryPrefInfo& selected_update_info = 332 const MediaGalleryPrefInfo& selected_update_info =
374 gallery_prefs()->known_galleries().find(selected_update)->second; 333 gallery_prefs()->known_galleries().find(selected_update)->second;
375 gallery_prefs()->AddGallery( 334 gallery_prefs()->AddGallery(
376 selected_update_info.device_id, base::FilePath(), 335 selected_update_info.device_id, base::FilePath(),
377 MediaGalleryPrefInfo::kScanResult, 336 MediaGalleryPrefInfo::kScanResult,
378 base::ASCIIToUTF16("Updated & Selected"), 337 base::ASCIIToUTF16("Updated & Selected"),
379 base::string16(), base::string16(), 0, base::Time(), 1, 0, 0); 338 base::string16(), base::string16(), 0, base::Time(), 1, 0, 0);
380 EXPECT_EQ(6, dialog()->update_count()); 339 EXPECT_EQ(6, dialog()->update_count());
381 ASSERT_EQ(4U, controller()->GetGalleryList().size()); 340 ASSERT_EQ(4U, controller()->GetSectionEntries(0).size());
382 341
383 MediaGalleriesScanResultDialogController::OrderedScanResults results = 342 MediaGalleriesDialogController::Entries results =
384 controller()->GetGalleryList(); 343 controller()->GetSectionEntries(0);
385 EXPECT_EQ(selected, results[0].pref_info.pref_id); 344 EXPECT_EQ(selected, results[0].pref_info.pref_id);
386 EXPECT_TRUE(results[0].selected); 345 EXPECT_TRUE(results[0].selected);
387 EXPECT_EQ(selected_update, results[1].pref_info.pref_id); 346 EXPECT_EQ(selected_update, results[1].pref_info.pref_id);
388 EXPECT_TRUE(results[1].selected); 347 EXPECT_TRUE(results[1].selected);
389 EXPECT_EQ(base::ASCIIToUTF16("Updated & Selected"), 348 EXPECT_EQ(base::ASCIIToUTF16("Updated & Selected"),
390 results[1].pref_info.volume_label); 349 results[1].pref_info.volume_label);
391 EXPECT_EQ(unselected, results[2].pref_info.pref_id); 350 EXPECT_EQ(unselected, results[2].pref_info.pref_id);
392 EXPECT_FALSE(results[2].selected); 351 EXPECT_FALSE(results[2].selected);
393 EXPECT_EQ(unselected_update, results[3].pref_info.pref_id); 352 EXPECT_EQ(unselected_update, results[3].pref_info.pref_id);
394 EXPECT_FALSE(results[3].selected); 353 EXPECT_FALSE(results[3].selected);
395 EXPECT_EQ(base::ASCIIToUTF16("Updated & Unselected"), 354 EXPECT_EQ(base::ASCIIToUTF16("Updated & Unselected"),
396 results[3].pref_info.volume_label); 355 results[3].pref_info.volume_label);
397 356
398 controller()->DialogFinished(true); 357 controller()->DialogFinished(true);
399 EXPECT_EQ(4U, gallery_prefs()->GalleriesForExtension(*extension()).size()); 358 EXPECT_EQ(4U, gallery_prefs()->GalleriesForExtension(*extension()).size());
400 StartDialog(); 359 StartDialog();
401 EXPECT_EQ(2U, controller()->GetGalleryList().size()); 360 EXPECT_EQ(2U, controller()->GetSectionEntries(0).size());
402 controller()->DialogFinished(false); 361 controller()->DialogFinished(false);
403 } 362 }
404 363
405 TEST_F(MediaGalleriesScanResultDialogControllerTest, ForgetGallery) { 364 TEST_F(MediaGalleriesScanResultControllerTest, ForgetGallery) {
406 // Start with two scan results. 365 // Start with two scan results.
407 MediaGalleryPrefId scan1 = AddScanResult("scan1", 1, 0, 0); 366 MediaGalleryPrefId scan1 = AddScanResult("scan1", 1, 0, 0);
408 MediaGalleryPrefId scan2 = AddScanResult("scan2", 2, 0, 0); 367 MediaGalleryPrefId scan2 = AddScanResult("scan2", 2, 0, 0);
409 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size()); 368 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size());
410 369
411 // Remove one and then cancel. 370 // Remove one and then cancel.
412 StartDialog(); 371 StartDialog();
413 EXPECT_EQ(2U, controller()->GetGalleryList().size()); 372 EXPECT_EQ(2U, controller()->GetSectionEntries(0).size());
414 controller()->DidForgetGallery(scan1); 373 controller()->DidForgetEntry(scan1);
415 controller()->DialogFinished(false); 374 controller()->DialogFinished(false);
416 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size()); 375 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size());
417 376
418 // Remove one and then have it blacklisted from prefs. 377 // Remove one and then have it blacklisted from prefs.
419 StartDialog(); 378 StartDialog();
420 EXPECT_EQ(2U, controller()->GetGalleryList().size()); 379 EXPECT_EQ(2U, controller()->GetSectionEntries(0).size());
421 controller()->DidForgetGallery(scan1); 380 controller()->DidForgetEntry(scan1);
422 EXPECT_EQ(1, dialog()->update_count()); 381 EXPECT_EQ(1, dialog()->update_count());
423 controller()->DidToggleGalleryId(scan2, false); // Uncheck the second. 382 controller()->DidToggleEntry(scan2, false); // Uncheck the second.
424 gallery_prefs()->ForgetGalleryById(scan1); 383 gallery_prefs()->ForgetGalleryById(scan1);
425 controller()->DialogFinished(true); 384 controller()->DialogFinished(true);
426 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size()); 385 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size());
427 EXPECT_EQ(2, dialog_update_count_at_destruction()); 386 EXPECT_EQ(2, dialog_update_count_at_destruction());
428 387
429 // Remove the other. 388 // Remove the other.
430 StartDialog(); 389 StartDialog();
431 EXPECT_EQ(1U, controller()->GetGalleryList().size()); 390 EXPECT_EQ(1U, controller()->GetSectionEntries(0).size());
432 controller()->DidForgetGallery(scan2); 391 controller()->DidForgetEntry(scan2);
433 controller()->DialogFinished(true); 392 controller()->DialogFinished(true);
434 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size()); 393 EXPECT_EQ(0U, gallery_prefs()->GalleriesForExtension(*extension()).size());
435 394
436 // Check that nothing shows up. 395 // Check that nothing shows up.
437 StartDialog(); 396 StartDialog();
438 EXPECT_EQ(0U, controller()->GetGalleryList().size()); 397 EXPECT_EQ(0U, controller()->GetSectionEntries(0).size());
439 controller()->DialogFinished(false); 398 controller()->DialogFinished(false);
440 } 399 }
441 400
442 TEST_F(MediaGalleriesScanResultDialogControllerTest, SortOrder) { 401 TEST_F(MediaGalleriesScanResultControllerTest, SortOrder) {
443 // Intentionally out of order numerically and alphabetically. 402 // Intentionally out of order numerically and alphabetically.
444 MediaGalleryPrefId third = AddScanResult("third", 2, 2, 2); 403 MediaGalleryPrefId third = AddScanResult("third", 2, 2, 2);
445 MediaGalleryPrefId second = 404 MediaGalleryPrefId second =
446 AddGallery("second", MediaGalleryPrefInfo::kAutoDetected, 9, 0, 0); 405 AddGallery("second", MediaGalleryPrefInfo::kAutoDetected, 9, 0, 0);
447 MediaGalleryPrefId first = AddScanResult("first", 8, 2, 3); 406 MediaGalleryPrefId first = AddScanResult("first", 8, 2, 3);
448 MediaGalleryPrefId fifth = AddScanResult("abb", 3, 0, 0); 407 MediaGalleryPrefId fifth = AddScanResult("abb", 3, 0, 0);
449 MediaGalleryPrefId fourth = AddScanResult("aaa", 3, 0, 0); 408 MediaGalleryPrefId fourth = AddScanResult("aaa", 3, 0, 0);
450 409
451 StartDialog(); 410 StartDialog();
452 MediaGalleriesScanResultDialogController::OrderedScanResults results = 411 MediaGalleriesDialogController::Entries results =
453 controller()->GetGalleryList(); 412 controller()->GetSectionEntries(0);
454 ASSERT_EQ(5U, results.size()); 413 ASSERT_EQ(5U, results.size());
455 EXPECT_EQ(first, results[0].pref_info.pref_id); 414 EXPECT_EQ(first, results[0].pref_info.pref_id);
456 EXPECT_EQ(second, results[1].pref_info.pref_id); 415 EXPECT_EQ(second, results[1].pref_info.pref_id);
457 EXPECT_EQ(third, results[2].pref_info.pref_id); 416 EXPECT_EQ(third, results[2].pref_info.pref_id);
458 EXPECT_EQ(fourth, results[3].pref_info.pref_id); 417 EXPECT_EQ(fourth, results[3].pref_info.pref_id);
459 EXPECT_EQ(fifth, results[4].pref_info.pref_id); 418 EXPECT_EQ(fifth, results[4].pref_info.pref_id);
460 controller()->DialogFinished(false); 419 controller()->DialogFinished(false);
461 } 420 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698