15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file. 45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// MediaGalleriesPreferences unit tests. 65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 72a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/media_galleries/media_galleries_preferences.h" 85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 95f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include <string> 105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include <vector> 115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/command_line.h" 135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/ref_counted.h" 145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 155f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "base/path_service.h" 165f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "base/prefs/scoped_user_pref_update.h" 174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "base/run_loop.h" 18868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/values.h" 205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/extensions/test_extension_system.h" 212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/media_galleries/media_file_system_registry.h" 222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/media_galleries/media_galleries_test_util.h" 235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "chrome/common/chrome_paths.h" 245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#include "chrome/common/pref_names.h" 2503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)#include "chrome/grit/generated_resources.h" 265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/testing_profile.h" 275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "components/storage_monitor/media_storage_util.h" 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "components/storage_monitor/storage_monitor.h" 295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "components/storage_monitor/test_storage_monitor.h" 30ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "content/public/test/test_browser_thread_bundle.h" 315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "extensions/browser/extension_system.h" 32f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "extensions/common/extension.h" 33f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "extensions/common/manifest_handlers/background_info.h" 34effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch#include "extensions/common/permissions/media_galleries_permission.h" 355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "sync/api/string_ordinal.h" 365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h" 37eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "ui/base/l10n/l10n_util.h" 385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 39c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#if defined(OS_CHROMEOS) 406e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)#include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h" 41c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/chromeos/settings/cros_settings.h" 42c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chrome/browser/chromeos/settings/device_settings_service.h" 43c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#endif 44c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)using base::ASCIIToUTF16; 46a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)using storage_monitor::MediaStorageUtil; 47a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)using storage_monitor::StorageInfo; 48a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)using storage_monitor::TestStorageMonitor; 495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace { 515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class MockGalleryChangeObserver 532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) : public MediaGalleriesPreferences::GalleryChangeObserver { 545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) explicit MockGalleryChangeObserver(MediaGalleriesPreferences* pref) 562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) : pref_(pref), 572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) notifications_(0) {} 582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) virtual ~MockGalleryChangeObserver() {} 592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int notifications() const { return notifications_;} 615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) private: 632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // MediaGalleriesPreferences::GalleryChangeObserver implementation. 64d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) virtual void OnPermissionAdded(MediaGalleriesPreferences* pref, 65d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) const std::string& extension_id, 66d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) MediaGalleryPrefId pref_id) OVERRIDE { 67d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) EXPECT_EQ(pref_, pref); 68d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) ++notifications_; 69d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) } 70d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 71d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) virtual void OnPermissionRemoved(MediaGalleriesPreferences* pref, 72d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) const std::string& extension_id, 73d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) MediaGalleryPrefId pref_id) OVERRIDE { 74d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) EXPECT_EQ(pref_, pref); 75d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) ++notifications_; 76d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) } 77d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 78d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) virtual void OnGalleryAdded(MediaGalleriesPreferences* pref, 79d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) MediaGalleryPrefId pref_id) OVERRIDE { 80d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) EXPECT_EQ(pref_, pref); 81d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) ++notifications_; 82d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) } 83d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 84d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) virtual void OnGalleryRemoved(MediaGalleriesPreferences* pref, 85d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) MediaGalleryPrefId pref_id) OVERRIDE { 86d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) EXPECT_EQ(pref_, pref); 87d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) ++notifications_; 88d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) } 89d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 90d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) virtual void OnGalleryInfoUpdated(MediaGalleriesPreferences* pref, 91d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) MediaGalleryPrefId pref_id) OVERRIDE { 922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(pref_, pref); 932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ++notifications_; 945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) MediaGalleriesPreferences* pref_; 972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) int notifications_; 982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(MockGalleryChangeObserver); 1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} // namespace 1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class MediaGalleriesPreferencesTest : public testing::Test { 1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public: 1065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) typedef std::map<std::string /*device id*/, MediaGalleryPrefIdSet> 1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DeviceIdPrefIdsMap; 1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MediaGalleriesPreferencesTest() 110ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch : profile_(new TestingProfile()), 1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) default_galleries_count_(0) { 1125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual ~MediaGalleriesPreferencesTest() { 1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void SetUp() OVERRIDE { 118d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) ASSERT_TRUE(TestStorageMonitor::CreateAndInstall()); 119558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch 1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extensions::TestExtensionSystem* extension_system( 1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) static_cast<extensions::TestExtensionSystem*>( 1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) extensions::ExtensionSystem::Get(profile_.get()))); 1232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) extension_system->CreateExtensionService( 1242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) CommandLine::ForCurrentProcess(), base::FilePath(), false); 1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ReinitPrefsAndExpectations(); 1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const MediaGalleriesPrefInfoMap& known_galleries = 1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gallery_prefs_->known_galleries(); 1305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) if (!known_galleries.empty()) { 1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ASSERT_EQ(3U, known_galleries.size()); 1325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::vector<std::string> all_permissions; 1355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) all_permissions.push_back( 1365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) extensions::MediaGalleriesPermission::kReadPermission); 1375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) all_permissions.push_back( 1385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) extensions::MediaGalleriesPermission::kAllAutoDetectedPermission); 1395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::vector<std::string> read_permissions; 1405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) read_permissions.push_back( 1415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) extensions::MediaGalleriesPermission::kReadPermission); 1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) all_permission_extension = 1442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) AddMediaGalleriesApp("all", all_permissions, profile_.get()); 1452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) regular_permission_extension = 1462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) AddMediaGalleriesApp("regular", read_permissions, profile_.get()); 1472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) no_permissions_extension = 1482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) AddMediaGalleriesApp("no", read_permissions, profile_.get()); 1495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) virtual void TearDown() OVERRIDE { 1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 1535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) TestStorageMonitor::Destroy(); 1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 1565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void ChangeMediaPathOverrides() { 1575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) mock_gallery_locations_.ChangeMediaPathOverrides(); 1585f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 1595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void ReinitPrefsAndExpectations() { 1615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) gallery_prefs_.reset(new MediaGalleriesPreferences(profile_.get())); 1625f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) base::RunLoop loop; 1635f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) gallery_prefs_->EnsureInitialized(loop.QuitClosure()); 1645f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) loop.Run(); 1655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Load the default galleries into the expectations. 1675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const MediaGalleriesPrefInfoMap& known_galleries = 1685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) gallery_prefs_->known_galleries(); 1695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) if (!known_galleries.empty()) { 1705f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) default_galleries_count_ = 3; 1715f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) MediaGalleriesPrefInfoMap::const_iterator it; 1725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) for (it = known_galleries.begin(); it != known_galleries.end(); ++it) { 1735f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) expected_galleries_[it->first] = it->second; 1745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) if (it->second.type == MediaGalleryPrefInfo::kAutoDetected) 1755f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) expected_galleries_for_all.insert(it->first); 1765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 1775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 1785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 1795f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1805f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void RemovePersistedDefaultGalleryValues() { 1815f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) PrefService* prefs = profile_->GetPrefs(); 1825f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) scoped_ptr<ListPrefUpdate> update(new ListPrefUpdate( 1835f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) prefs, prefs::kMediaGalleriesRememberedGalleries)); 1845f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) base::ListValue* list = update->Get(); 1855f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1865f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) for (base::ListValue::iterator iter = list->begin(); 1875f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) iter != list->end(); 1885f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ++iter) { 1895f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) base::DictionaryValue* dict; 1905f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 1915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) if ((*iter)->GetAsDictionary(&dict)) { 1925f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Setting the prefs version to 2 which is the version before 1935f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // default_gallery_type was added. 1945f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) dict->SetInteger(kMediaGalleriesPrefsVersionKey, 2); 1955f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) dict->Remove(kMediaGalleriesDefaultGalleryTypeKey, NULL); 1965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 1975f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 1985f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) update.reset(); 1995f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 2005f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 2015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) void Verify() { 2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) const MediaGalleriesPrefInfoMap& known_galleries = 2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gallery_prefs_->known_galleries(); 2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(expected_galleries_.size(), known_galleries.size()); 2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (MediaGalleriesPrefInfoMap::const_iterator it = known_galleries.begin(); 2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) it != known_galleries.end(); 2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ++it) { 2082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) VerifyGalleryInfo(it->second, it->first); 2095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (it->second.type != MediaGalleryPrefInfo::kAutoDetected && 2105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) it->second.type != MediaGalleryPrefInfo::kBlackListed) { 2115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) if (!ContainsKey(expected_galleries_for_all, it->first) && 2125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) !ContainsKey(expected_galleries_for_regular, it->first)) { 2135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_FALSE(gallery_prefs_->NonAutoGalleryHasPermission(it->first)); 2145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } else { 2155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(gallery_prefs_->NonAutoGalleryHasPermission(it->first)); 2165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 2175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) for (DeviceIdPrefIdsMap::const_iterator it = expected_device_map.begin(); 2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) it != expected_device_map.end(); 2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) ++it) { 2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MediaGalleryPrefIdSet actual_id_set = 2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gallery_prefs_->LookUpGalleriesByDeviceId(it->first); 2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(it->second, actual_id_set); 2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::set<MediaGalleryPrefId> galleries_for_all = 2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gallery_prefs_->GalleriesForExtension(*all_permission_extension.get()); 2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(expected_galleries_for_all, galleries_for_all); 2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::set<MediaGalleryPrefId> galleries_for_regular = 2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gallery_prefs_->GalleriesForExtension( 2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *regular_permission_extension.get()); 2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(expected_galleries_for_regular, galleries_for_regular); 2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::set<MediaGalleryPrefId> galleries_for_no = 2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gallery_prefs_->GalleriesForExtension(*no_permissions_extension.get()); 2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0U, galleries_for_no.size()); 2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) void VerifyGalleryInfo(const MediaGalleryPrefInfo& actual, 2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MediaGalleryPrefId expected_id) const { 2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MediaGalleriesPrefInfoMap::const_iterator in_expectation = 2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_galleries_.find(expected_id); 2462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASSERT_FALSE(in_expectation == expected_galleries_.end()) << expected_id; 2472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(in_expectation->second.pref_id, actual.pref_id); 2482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(in_expectation->second.display_name, actual.display_name); 2492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(in_expectation->second.device_id, actual.device_id); 2502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(in_expectation->second.path.value(), actual.path.value()); 2512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(in_expectation->second.type, actual.type); 2525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(in_expectation->second.audio_count, actual.audio_count); 2535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(in_expectation->second.image_count, actual.image_count); 2545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(in_expectation->second.video_count, actual.video_count); 2555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_EQ( 2565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) in_expectation->second.default_gallery_type, 2575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) actual.default_gallery_type); 2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MediaGalleriesPreferences* gallery_prefs() { 2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return gallery_prefs_.get(); 2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) uint64 default_galleries_count() { 2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) return default_galleries_count_; 2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 268a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) void AddGalleryExpectation(MediaGalleryPrefId id, base::string16 display_name, 2692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) std::string device_id, 2702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath relative_path, 2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MediaGalleryPrefInfo::Type type) { 2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_galleries_[id].pref_id = id; 2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_galleries_[id].display_name = display_name; 2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_galleries_[id].device_id = device_id; 2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_galleries_[id].path = relative_path.NormalizePathSeparators(); 2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_galleries_[id].type = type; 2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) if (type == MediaGalleryPrefInfo::kAutoDetected) 2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_galleries_for_all.insert(id); 2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_device_map[device_id].insert(id); 2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) } 2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 2845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void AddScanResultExpectation(MediaGalleryPrefId id, 2855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::string16 display_name, 2865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string device_id, 2875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::FilePath relative_path, 2885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int audio_count, 2895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int image_count, 2905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) int video_count) { 2915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AddGalleryExpectation(id, display_name, device_id, relative_path, 2925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefInfo::kScanResult); 2935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_galleries_[id].audio_count = audio_count; 2945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_galleries_[id].image_count = image_count; 2955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_galleries_[id].video_count = video_count; 2965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 2975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 2982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) MediaGalleryPrefId AddGalleryWithNameV0(const std::string& device_id, 299a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16& display_name, 300868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) const base::FilePath& relative_path, 301868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles) bool user_added) { 3025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefInfo::Type type = 3035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) user_added ? MediaGalleryPrefInfo::kUserAdded 3045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : MediaGalleryPrefInfo::kAutoDetected; 3055f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return gallery_prefs()->AddOrUpdateGalleryInternal( 3065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) device_id, display_name, relative_path, type, 307a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16(), base::string16(), base::string16(), 0, base::Time(), 3085f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) false, 0, 0, 0, 0, MediaGalleryPrefInfo::kNotDefault); 3092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) } 3102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 3117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) MediaGalleryPrefId AddGalleryWithNameV1(const std::string& device_id, 312a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16& display_name, 3137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const base::FilePath& relative_path, 3147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool user_added) { 3155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefInfo::Type type = 3165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) user_added ? MediaGalleryPrefInfo::kUserAdded 3175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) : MediaGalleryPrefInfo::kAutoDetected; 3185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return gallery_prefs()->AddOrUpdateGalleryInternal( 3195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) device_id, display_name, relative_path, type, 320a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16(), base::string16(), base::string16(), 0, base::Time(), 3215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) false, 0, 0, 0, 1, MediaGalleryPrefInfo::kNotDefault); 3227d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 3237d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 3247d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) MediaGalleryPrefId AddGalleryWithNameV2(const std::string& device_id, 325a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) const base::string16& display_name, 3267d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const base::FilePath& relative_path, 3275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefInfo::Type type) { 3285f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return gallery_prefs()->AddOrUpdateGalleryInternal( 3295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) device_id, display_name, relative_path, type, 330a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) base::string16(), base::string16(), base::string16(), 0, base::Time(), 3315f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) false, 0, 0, 0, 2, MediaGalleryPrefInfo::kNotDefault); 3325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 3335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 3345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefId AddFixedGalleryWithExepectation( 3355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string& path_name, const std::string& name, 3365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefInfo::Type type) { 3375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::FilePath path = MakeMediaGalleriesTestingPath(path_name); 3385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) StorageInfo info; 3395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::FilePath relative_path; 3405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 341a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::string16 gallery_name = base::ASCIIToUTF16(name); 342a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) MediaGalleryPrefId id = AddGalleryWithNameV2(info.device_id(), gallery_name, 3435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) relative_path, type); 344a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path, 3455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) type); 3465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 3475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return id; 3487d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 3497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 3507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) bool UpdateDeviceIDForSingletonType(const std::string& device_id) { 3517d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) return gallery_prefs()->UpdateDeviceIDForSingletonType(device_id); 3527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) } 3537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 3545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<extensions::Extension> all_permission_extension; 3555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<extensions::Extension> regular_permission_extension; 3565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_refptr<extensions::Extension> no_permissions_extension; 3575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::set<MediaGalleryPrefId> expected_galleries_for_all; 3595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) std::set<MediaGalleryPrefId> expected_galleries_for_regular; 3605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DeviceIdPrefIdsMap expected_device_map; 3625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MediaGalleriesPrefInfoMap expected_galleries_; 3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private: 3665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Needed for extension service & friends to work. 367ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch content::TestBrowserThreadBundle thread_bundle_; 3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EnsureMediaDirectoriesExists mock_gallery_locations_; 3701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 3715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#if defined(OS_CHROMEOS) 372c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; 373c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) chromeos::ScopedTestCrosSettings test_cros_settings_; 374c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) chromeos::ScopedTestUserManager test_user_manager_; 375c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#endif 376c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) 377d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) TestStorageMonitor monitor_; 3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<TestingProfile> profile_; 3795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) scoped_ptr<MediaGalleriesPreferences> gallery_prefs_; 3805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) uint64 default_galleries_count_; 3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(MediaGalleriesPreferencesTest); 3845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}; 3855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(MediaGalleriesPreferencesTest, GalleryManagement) { 3875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefId auto_id, user_added_id, scan_id, id; 3882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath path; 3892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath relative_path; 3905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 3915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 3925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Add a new auto detected gallery. 3935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) path = MakeMediaGalleriesTestingPath("new_auto"); 3942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StorageInfo info; 3952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 396a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery"); 397a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path, 398a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) MediaGalleryPrefInfo::kAutoDetected); 3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(default_galleries_count() + 1UL, id); 4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auto_id = id; 401a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path, 4025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MediaGalleryPrefInfo::kAutoDetected); 4035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Add it as other types, nothing should happen. 406a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path, 407a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) MediaGalleryPrefInfo::kUserAdded); 4085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(auto_id, id); 4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 410a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path, 411a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) MediaGalleryPrefInfo::kAutoDetected); 4125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(auto_id, id); 4135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 414a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path, 415a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) MediaGalleryPrefInfo::kScanResult); 4165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(auto_id, id); 4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Add a new user added gallery. 4195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) path = MakeMediaGalleriesTestingPath("new_user"); 4202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 421a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gallery_name = base::ASCIIToUTF16("NewUserGallery"); 422a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path, 423a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) MediaGalleryPrefInfo::kUserAdded); 4245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(default_galleries_count() + 2UL, id); 4255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) user_added_id = id; 4265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::string user_added_device_id = info.device_id(); 427a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path, 4285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MediaGalleryPrefInfo::kUserAdded); 4295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 4305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Add it as other types, nothing should happen. 432a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path, 433a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) MediaGalleryPrefInfo::kUserAdded); 4345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(user_added_id, id); 4355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 436a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path, 437a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) MediaGalleryPrefInfo::kAutoDetected); 4385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(user_added_id, id); 4395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 440a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path, 441a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) MediaGalleryPrefInfo::kScanResult); 4425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(user_added_id, id); 4435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 4445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Add a new scan result gallery. 4465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) path = MakeMediaGalleriesTestingPath("new_scan"); 4475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 448a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gallery_name = base::ASCIIToUTF16("NewScanGallery"); 449a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path, 450a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) MediaGalleryPrefInfo::kScanResult); 4515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(default_galleries_count() + 3UL, id); 4525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scan_id = id; 453a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path, 4545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefInfo::kScanResult); 4555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 4565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Add it as other types, nothing should happen. 458a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path, 459a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) MediaGalleryPrefInfo::kUserAdded); 4605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(scan_id, id); 4615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 462a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path, 463a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) MediaGalleryPrefInfo::kAutoDetected); 4645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(scan_id, id); 4655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 466a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path, 467a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) MediaGalleryPrefInfo::kScanResult); 4685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(scan_id, id); 4695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 4705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Lookup some galleries. 4725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath( 4735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MakeMediaGalleriesTestingPath("new_auto"), NULL)); 4745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath( 4755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MakeMediaGalleriesTestingPath("new_user"), NULL)); 4765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath( 4775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MakeMediaGalleriesTestingPath("new_scan"), NULL)); 4785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_FALSE(gallery_prefs()->LookUpGalleryByPath( 4795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MakeMediaGalleriesTestingPath("other"), NULL)); 4805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Check that we always get the gallery info. 4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MediaGalleryPrefInfo gallery_info; 4835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath( 4845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MakeMediaGalleriesTestingPath("new_auto"), &gallery_info)); 4852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) VerifyGalleryInfo(gallery_info, auto_id); 4862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(gallery_info.volume_metadata_valid); 4875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath( 4885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MakeMediaGalleriesTestingPath("new_user"), &gallery_info)); 4892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) VerifyGalleryInfo(gallery_info, user_added_id); 4902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_FALSE(gallery_info.volume_metadata_valid); 4915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath( 4925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MakeMediaGalleriesTestingPath("new_scan"), &gallery_info)); 4935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) VerifyGalleryInfo(gallery_info, scan_id); 4945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_FALSE(gallery_info.volume_metadata_valid); 4955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 4965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) path = MakeMediaGalleriesTestingPath("other"); 4975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_FALSE(gallery_prefs()->LookUpGalleryByPath(path, &gallery_info)); 4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(kInvalidMediaGalleryPrefId, gallery_info.pref_id); 4997d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 5002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StorageInfo other_info; 50190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) MediaStorageUtil::GetDeviceInfoFromPath(path, &other_info, &relative_path); 50290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) EXPECT_EQ(other_info.device_id(), gallery_info.device_id); 5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(relative_path.value(), gallery_info.path.value()); 5045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Remove an auto added gallery (i.e. make it blacklisted). 5065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gallery_prefs()->ForgetGalleryById(auto_id); 5075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_galleries_[auto_id].type = MediaGalleryPrefInfo::kBlackListed; 5085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_galleries_for_all.erase(auto_id); 5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 5115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Remove a scan result (i.e. make it blacklisted). 5125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gallery_prefs()->ForgetGalleryById(scan_id); 5135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_galleries_[scan_id].type = MediaGalleryPrefInfo::kRemovedScan; 5145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 5155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Remove a user added gallery and it should go away. 5175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gallery_prefs()->ForgetGalleryById(user_added_id); 5185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_galleries_.erase(user_added_id); 5195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_device_map[user_added_device_id].erase(user_added_id); 5205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 5215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 5225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(MediaGalleriesPreferencesTest, ForgetAndErase) { 5245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefId user_erase = 5255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AddFixedGalleryWithExepectation("user_erase", "UserErase", 5265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) MediaGalleryPrefInfo::kUserAdded); 5275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(default_galleries_count() + 1UL, user_erase); 5285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefId user_forget = 5295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AddFixedGalleryWithExepectation("user_forget", "UserForget", 5305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefInfo::kUserAdded); 5315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(default_galleries_count() + 2UL, user_forget); 5325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefId auto_erase = 5345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AddFixedGalleryWithExepectation("auto_erase", "AutoErase", 5355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefInfo::kAutoDetected); 5365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(default_galleries_count() + 3UL, auto_erase); 5375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefId auto_forget = 5385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AddFixedGalleryWithExepectation("auto_forget", "AutoForget", 5395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefInfo::kAutoDetected); 5405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(default_galleries_count() + 4UL, auto_forget); 5415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefId scan_erase = 5435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AddFixedGalleryWithExepectation("scan_erase", "ScanErase", 5445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefInfo::kScanResult); 5455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(default_galleries_count() + 5UL, scan_erase); 5465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefId scan_forget = 5475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AddFixedGalleryWithExepectation("scan_forget", "ScanForget", 5485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefInfo::kScanResult); 5495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(default_galleries_count() + 6UL, scan_forget); 5505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 5525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string device_id; 5535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gallery_prefs()->ForgetGalleryById(user_forget); 5555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) device_id = expected_galleries_[user_forget].device_id; 5565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_galleries_.erase(user_forget); 5575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_device_map[device_id].erase(user_forget); 5585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 5595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gallery_prefs()->ForgetGalleryById(auto_forget); 5615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_galleries_[auto_forget].type = MediaGalleryPrefInfo::kBlackListed; 5625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_galleries_for_all.erase(auto_forget); 5635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 5645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gallery_prefs()->ForgetGalleryById(scan_forget); 5665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_galleries_[scan_forget].type = MediaGalleryPrefInfo::kRemovedScan; 5675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 5685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gallery_prefs()->EraseGalleryById(user_erase); 5705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) device_id = expected_galleries_[user_erase].device_id; 5715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_galleries_.erase(user_erase); 5725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_device_map[device_id].erase(user_erase); 5735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 5745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gallery_prefs()->EraseGalleryById(auto_erase); 5765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) device_id = expected_galleries_[auto_erase].device_id; 5775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_galleries_.erase(auto_erase); 5785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_device_map[device_id].erase(auto_erase); 5795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_galleries_for_all.erase(auto_erase); 5805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 5815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gallery_prefs()->EraseGalleryById(scan_erase); 5835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) device_id = expected_galleries_[scan_erase].device_id; 5845d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_galleries_.erase(scan_erase); 5855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_device_map[device_id].erase(scan_erase); 5865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 5875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Also erase the previously forgetten ones to check erasing blacklisted ones. 5895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gallery_prefs()->EraseGalleryById(auto_forget); 5905d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) device_id = expected_galleries_[auto_forget].device_id; 5915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_galleries_.erase(auto_forget); 5925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_device_map[device_id].erase(auto_forget); 5935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 5945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 5955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gallery_prefs()->EraseGalleryById(scan_forget); 5965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) device_id = expected_galleries_[scan_forget].device_id; 5975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_galleries_.erase(scan_forget); 5985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_device_map[device_id].erase(scan_forget); 5992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Verify(); 6002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(MediaGalleriesPreferencesTest, AddGalleryWithVolumeMetadata) { 6032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) MediaGalleryPrefId id; 6042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StorageInfo info; 6052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath path; 6062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath relative_path; 6072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Time now = base::Time::Now(); 6082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Verify(); 6092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Add a new auto detected gallery. 6115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) path = MakeMediaGalleriesTestingPath("new_auto"); 61290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 61390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) id = gallery_prefs()->AddGallery(info.device_id(), relative_path, 6145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefInfo::kAutoDetected, 6152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASCIIToUTF16("volume label"), 6162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASCIIToUTF16("vendor name"), 6172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASCIIToUTF16("model name"), 6185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1000000ULL, now, 0, 0, 0); 6192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(default_galleries_count() + 1UL, id); 620a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) AddGalleryExpectation(id, base::string16(), info.device_id(), relative_path, 6212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) MediaGalleryPrefInfo::kAutoDetected); 6222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Verify(); 6232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) MediaGalleryPrefInfo gallery_info; 6255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath( 6265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MakeMediaGalleriesTestingPath("new_auto"), &gallery_info)); 6272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_TRUE(gallery_info.volume_metadata_valid); 6282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(ASCIIToUTF16("volume label"), gallery_info.volume_label); 6292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(ASCIIToUTF16("vendor name"), gallery_info.vendor_name); 6302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(ASCIIToUTF16("model name"), gallery_info.model_name); 6312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(1000000ULL, gallery_info.total_size_in_bytes); 6322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Note: we put the microseconds time into a double, so there'll 6332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // be some possible rounding errors. If it's less than 100, we don't 6342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // care. 635a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) EXPECT_LE(std::abs(now.ToInternalValue() - 636a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gallery_info.last_attach_time.ToInternalValue()), 637a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) 100); 6382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 6392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(MediaGalleriesPreferencesTest, ReplaceGalleryWithVolumeMetadata) { 6412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) MediaGalleryPrefId id, metadata_id; 6422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath path; 6432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StorageInfo info; 6442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath relative_path; 6452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::Time now = base::Time::Now(); 6462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Verify(); 6472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Add an auto detected gallery in the prefs version 0 format. 6495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) path = MakeMediaGalleriesTestingPath("new_auto"); 65090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 651a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery"); 652a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) id = AddGalleryWithNameV0(info.device_id(), gallery_name, relative_path, 653a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) false /*auto*/); 6542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(default_galleries_count() + 1UL, id); 655a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path, 6562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) MediaGalleryPrefInfo::kAutoDetected); 6572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Verify(); 6582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 65990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) metadata_id = gallery_prefs()->AddGallery(info.device_id(), 6602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) relative_path, 6615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefInfo::kAutoDetected, 6622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASCIIToUTF16("volume label"), 6632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASCIIToUTF16("vendor name"), 6642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) ASCIIToUTF16("model name"), 6655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1000000ULL, now, 0, 0, 0); 6662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(id, metadata_id); 667a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) AddGalleryExpectation(id, base::string16(), info.device_id(), relative_path, 6682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) MediaGalleryPrefInfo::kAutoDetected); 6692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 6702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Make sure the display_name is set to empty now, as the metadata 6712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // upgrade should set the manual override name empty. 6725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 6735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 6745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Whenever an "AutoDetected" gallery is removed, it is moved to a black listed 6765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// state. When the gallery is added again, the black listed state is updated 6775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// back to the "AutoDetected" type. 6785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(MediaGalleriesPreferencesTest, AutoAddedBlackListing) { 6795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MediaGalleryPrefId auto_id, id; 6802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath path; 6812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StorageInfo info; 6822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath relative_path; 6835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 6845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Add a new auto detect gallery to test with. 6865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) path = MakeMediaGalleriesTestingPath("new_auto"); 68790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 688a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery"); 689a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) id = AddGalleryWithNameV1(info.device_id(), gallery_name, 6907d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) relative_path, false /*auto*/); 6915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(default_galleries_count() + 1UL, id); 6925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auto_id = id; 693a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path, 6945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MediaGalleryPrefInfo::kAutoDetected); 6955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 6965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 6975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Remove an auto added gallery (i.e. make it blacklisted). 6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gallery_prefs()->ForgetGalleryById(auto_id); 6995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_galleries_[auto_id].type = MediaGalleryPrefInfo::kBlackListed; 7005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_galleries_for_all.erase(auto_id); 7015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 7025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Try adding the gallery again automatically and it should be a no-op. 704a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) id = AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path, 705a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) false /*auto*/); 7065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(auto_id, id); 7075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 7085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Add the gallery again as a user action. 7105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) id = gallery_prefs()->AddGalleryByPath(path, 7115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefInfo::kUserAdded); 7125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(auto_id, id); 713a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path, 7145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MediaGalleryPrefInfo::kAutoDetected); 7155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 7165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 7172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Whenever a "ScanResult" gallery is removed, it is moved to a black listed 7195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// state. When the gallery is added again, the black listed state is updated 7205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// back to the "ScanResult" type. 7215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(MediaGalleriesPreferencesTest, ScanResultBlackListing) { 7225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefId scan_id, id; 7235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::FilePath path; 7245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) StorageInfo info; 7255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::FilePath relative_path; 7262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Verify(); 7272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 7285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Add a new scan result gallery to test with. 7295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) path = MakeMediaGalleriesTestingPath("new_scan"); 7305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 731a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::string16 gallery_name = base::ASCIIToUTF16("NewScanGallery"); 732a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path, 733a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) MediaGalleryPrefInfo::kScanResult); 7345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(default_galleries_count() + 1UL, id); 7355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scan_id = id; 736a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path, 7375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefInfo::kScanResult); 7385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 7395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Remove a scan result gallery (i.e. make it blacklisted). 7415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gallery_prefs()->ForgetGalleryById(scan_id); 7425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_galleries_[scan_id].type = MediaGalleryPrefInfo::kRemovedScan; 7435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_galleries_for_all.erase(scan_id); 7445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 7455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Try adding the gallery again as a scan result it should be a no-op. 747a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path, 748a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) MediaGalleryPrefInfo::kScanResult); 7495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(scan_id, id); 7505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 7515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 7525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Add the gallery again as a user action. 7535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) id = gallery_prefs()->AddGalleryByPath(path, 7545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefInfo::kUserAdded); 7555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(scan_id, id); 756a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path, 7575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefInfo::kUserAdded); 7582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) Verify(); 7595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 7605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_F(MediaGalleriesPreferencesTest, UpdateGalleryNameV2) { 7627d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Add a new auto detect gallery to test with. 7635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::FilePath path = MakeMediaGalleriesTestingPath("new_auto"); 7647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) StorageInfo info; 7657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) base::FilePath relative_path; 7667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 767a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery"); 7687d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) MediaGalleryPrefId id = 769a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path, 770a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) MediaGalleryPrefInfo::kAutoDetected); 771a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path, 7727d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) MediaGalleryPrefInfo::kAutoDetected); 7737d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) Verify(); 7747d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 7757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Won't override the name -- don't change any expectation. 776a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gallery_name = base::string16(); 777a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path, 7785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefInfo::kAutoDetected); 7797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) Verify(); 7807d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 781a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gallery_name = base::ASCIIToUTF16("NewName"); 782a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path, 783a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) MediaGalleryPrefInfo::kAutoDetected); 7847d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Note: will really just update the existing expectation. 785a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path, 7867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) MediaGalleryPrefInfo::kAutoDetected); 7877d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) Verify(); 7887d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 7897d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 7905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(MediaGalleriesPreferencesTest, GalleryPermissions) { 7915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefId auto_id, user_added_id, to_blacklist_id, scan_id, 7925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) to_scan_remove_id, id; 7932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath path; 7942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StorageInfo info; 7952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath relative_path; 7965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 7975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 7985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Add some galleries to test with. 7995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) path = MakeMediaGalleriesTestingPath("new_user"); 80090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 801a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::string16 gallery_name = base::ASCIIToUTF16("NewUserGallery"); 802a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) id = AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path, 803a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) true /*user*/); 8045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(default_galleries_count() + 1UL, id); 8055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) user_added_id = id; 806a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path, 8075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MediaGalleryPrefInfo::kUserAdded); 8085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 8095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) path = MakeMediaGalleriesTestingPath("new_auto"); 81190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 812a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gallery_name = base::ASCIIToUTF16("NewAutoGallery"); 813a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) id = AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path, 814a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) false /*auto*/); 8155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(default_galleries_count() + 2UL, id); 8165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auto_id = id; 817a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path, 8185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MediaGalleryPrefInfo::kAutoDetected); 8195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 8205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) path = MakeMediaGalleriesTestingPath("to_blacklist"); 82290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 823a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gallery_name = base::ASCIIToUTF16("ToBlacklistGallery"); 824a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) id = AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path, 825a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) false /*auto*/); 8265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(default_galleries_count() + 3UL, id); 8275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) to_blacklist_id = id; 828a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path, 8295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MediaGalleryPrefInfo::kAutoDetected); 8305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 8315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) path = MakeMediaGalleriesTestingPath("new_scan"); 8335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 834a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gallery_name = base::ASCIIToUTF16("NewScanGallery"); 835a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path, 836a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) MediaGalleryPrefInfo::kScanResult); 8375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(default_galleries_count() + 4UL, id); 8385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scan_id = id; 839a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path, 8405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefInfo::kScanResult); 8415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 8425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 8435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) path = MakeMediaGalleriesTestingPath("to_scan_remove"); 8445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 845a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gallery_name = base::ASCIIToUTF16("ToScanRemoveGallery"); 846a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) id = AddGalleryWithNameV2(info.device_id(), gallery_name, relative_path, 847a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) MediaGalleryPrefInfo::kScanResult); 8485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(default_galleries_count() + 5UL, id); 8495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) to_scan_remove_id = id; 850a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path, 8515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefInfo::kScanResult); 8525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 8535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 8545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Remove permission for all galleries from the all-permission extension. 8555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gallery_prefs()->SetGalleryPermissionForExtension( 8565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *all_permission_extension.get(), auto_id, false); 8575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_galleries_for_all.erase(auto_id); 8585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 8595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gallery_prefs()->SetGalleryPermissionForExtension( 8615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *all_permission_extension.get(), user_added_id, false); 8625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_galleries_for_all.erase(user_added_id); 8635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 8645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gallery_prefs()->SetGalleryPermissionForExtension( 8665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *all_permission_extension.get(), to_blacklist_id, false); 8675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_galleries_for_all.erase(to_blacklist_id); 8685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 8695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gallery_prefs()->SetGalleryPermissionForExtension( 8715d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *all_permission_extension.get(), scan_id, false); 8725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_galleries_for_all.erase(scan_id); 8735d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 8745d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 8755d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gallery_prefs()->SetGalleryPermissionForExtension( 8765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *all_permission_extension.get(), to_scan_remove_id, false); 8775d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_galleries_for_all.erase(to_scan_remove_id); 8785d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 8795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 8805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Add permission back for all galleries to the all-permission extension. 8815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gallery_prefs()->SetGalleryPermissionForExtension( 8825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *all_permission_extension.get(), auto_id, true); 8835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_galleries_for_all.insert(auto_id); 8845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 8855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gallery_prefs()->SetGalleryPermissionForExtension( 8875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *all_permission_extension.get(), user_added_id, true); 8885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_galleries_for_all.insert(user_added_id); 8895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 8905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gallery_prefs()->SetGalleryPermissionForExtension( 8925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *all_permission_extension.get(), to_blacklist_id, true); 8935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_galleries_for_all.insert(to_blacklist_id); 8945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 8955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 8965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gallery_prefs()->SetGalleryPermissionForExtension( 8975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *all_permission_extension.get(), scan_id, true); 8985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_galleries_for_all.insert(scan_id); 8995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 9005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 9015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gallery_prefs()->SetGalleryPermissionForExtension( 9025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *all_permission_extension.get(), to_scan_remove_id, true); 9035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_galleries_for_all.insert(to_scan_remove_id); 9045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 9055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 9065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Add permission for all galleries to the regular permission extension. 9075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gallery_prefs()->SetGalleryPermissionForExtension( 9085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *regular_permission_extension.get(), auto_id, true); 9095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_galleries_for_regular.insert(auto_id); 9105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 9115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gallery_prefs()->SetGalleryPermissionForExtension( 9135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *regular_permission_extension.get(), user_added_id, true); 9145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_galleries_for_regular.insert(user_added_id); 9155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 9165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gallery_prefs()->SetGalleryPermissionForExtension( 9185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *regular_permission_extension.get(), to_blacklist_id, true); 9195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_galleries_for_regular.insert(to_blacklist_id); 9205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 9215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gallery_prefs()->SetGalleryPermissionForExtension( 9235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *regular_permission_extension.get(), scan_id, true); 9245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_galleries_for_regular.insert(scan_id); 9255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 9265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 9275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gallery_prefs()->SetGalleryPermissionForExtension( 9285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *regular_permission_extension.get(), to_scan_remove_id, true); 9295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_galleries_for_regular.insert(to_scan_remove_id); 9305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 9315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 9325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Blacklist the to be black listed gallery 9335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gallery_prefs()->ForgetGalleryById(to_blacklist_id); 9345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_galleries_[to_blacklist_id].type = 9355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MediaGalleryPrefInfo::kBlackListed; 9365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_galleries_for_all.erase(to_blacklist_id); 9375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_galleries_for_regular.erase(to_blacklist_id); 9385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 9395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gallery_prefs()->ForgetGalleryById(to_scan_remove_id); 9415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_galleries_[to_scan_remove_id].type = 9425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefInfo::kRemovedScan; 9435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_galleries_for_all.erase(to_scan_remove_id); 9445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_galleries_for_regular.erase(to_scan_remove_id); 9455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 9465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 9475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Remove permission for all galleries to the regular permission extension. 9485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gallery_prefs()->SetGalleryPermissionForExtension( 9495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *regular_permission_extension.get(), auto_id, false); 9505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_galleries_for_regular.erase(auto_id); 9515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 9525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gallery_prefs()->SetGalleryPermissionForExtension( 9545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *regular_permission_extension.get(), user_added_id, false); 9555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) expected_galleries_for_regular.erase(user_added_id); 9565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 9575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gallery_prefs()->SetGalleryPermissionForExtension( 9595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) *regular_permission_extension.get(), scan_id, false); 9605d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_galleries_for_regular.erase(scan_id); 9615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 9625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 9635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Add permission for an invalid gallery id. 9645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) gallery_prefs()->SetGalleryPermissionForExtension( 9655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) *regular_permission_extension.get(), 9999L, true); 9665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 9675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9695d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// What an existing gallery is added again, update the gallery information if 9705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// needed. 9715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(MediaGalleriesPreferencesTest, UpdateGalleryDetails) { 9725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MediaGalleryPrefId auto_id, id; 9732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath path; 9742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StorageInfo info; 9752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath relative_path; 9765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 9775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Add a new auto detect gallery to test with. 9795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) path = MakeMediaGalleriesTestingPath("new_auto"); 98090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 981a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery"); 982a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) id = AddGalleryWithNameV1(info.device_id(), gallery_name, 9837d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) relative_path, false /*auto*/); 9845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(default_galleries_count() + 1UL, id); 9855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) auto_id = id; 986a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path, 9875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MediaGalleryPrefInfo::kAutoDetected); 9885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 9895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 9905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Update the device name and add the gallery again. 991a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gallery_name = base::ASCIIToUTF16("AutoGallery2"); 992a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) id = AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path, 993a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) false /*auto*/); 9945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(auto_id, id); 995a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AddGalleryExpectation(id, gallery_name, info.device_id(), relative_path, 9965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MediaGalleryPrefInfo::kAutoDetected); 9975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 9985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 9995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(MediaGalleriesPreferencesTest, MultipleGalleriesPerDevices) { 10012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath path; 10022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StorageInfo info; 10032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath relative_path; 10045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 10055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Add a regular gallery 10075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) path = MakeMediaGalleriesTestingPath("new_user"); 100890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 1009a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::string16 gallery_name = base::ASCIIToUTF16("NewUserGallery"); 10105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MediaGalleryPrefId user_added_id = 1011a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path, 1012a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) true /*user*/); 10135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(default_galleries_count() + 1UL, user_added_id); 1014a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AddGalleryExpectation(user_added_id, gallery_name, info.device_id(), 10152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) relative_path, MediaGalleryPrefInfo::kUserAdded); 10165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 10175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Find it by device id and fail to find something related. 10195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MediaGalleryPrefIdSet pref_id_set; 102090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) pref_id_set = gallery_prefs()->LookUpGalleriesByDeviceId(info.device_id()); 10215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(1U, pref_id_set.size()); 10225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_TRUE(pref_id_set.find(user_added_id) != pref_id_set.end()); 10235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaStorageUtil::GetDeviceInfoFromPath( 10255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MakeMediaGalleriesTestingPath("new_user/foo"), &info, &relative_path); 102690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) pref_id_set = gallery_prefs()->LookUpGalleriesByDeviceId(info.device_id()); 10275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(0U, pref_id_set.size()); 10285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Add some galleries on the same device. 10302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) relative_path = base::FilePath(FILE_PATH_LITERAL("path1/on/device1")); 1031a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gallery_name = base::ASCIIToUTF16("Device1Path1"); 1032c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) std::string device_id = "path:device1"; 10337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) MediaGalleryPrefId dev1_path1_id = AddGalleryWithNameV1( 1034a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) device_id, gallery_name, relative_path, true /*user*/); 10355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(default_galleries_count() + 2UL, dev1_path1_id); 1036a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AddGalleryExpectation(dev1_path1_id, gallery_name, device_id, relative_path, 10375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MediaGalleryPrefInfo::kUserAdded); 10385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 10395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) relative_path = base::FilePath(FILE_PATH_LITERAL("path2/on/device1")); 1041a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gallery_name = base::ASCIIToUTF16("Device1Path2"); 10427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) MediaGalleryPrefId dev1_path2_id = AddGalleryWithNameV1( 1043a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) device_id, gallery_name, relative_path, true /*user*/); 10445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(default_galleries_count() + 3UL, dev1_path2_id); 1045a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AddGalleryExpectation(dev1_path2_id, gallery_name, device_id, relative_path, 10465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MediaGalleryPrefInfo::kUserAdded); 10475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 10485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10492a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) relative_path = base::FilePath(FILE_PATH_LITERAL("path1/on/device2")); 1050a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gallery_name = base::ASCIIToUTF16("Device2Path1"); 1051c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles) device_id = "path:device2"; 10527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) MediaGalleryPrefId dev2_path1_id = AddGalleryWithNameV1( 1053a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) device_id, gallery_name, relative_path, true /*user*/); 10545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(default_galleries_count() + 4UL, dev2_path1_id); 1055a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AddGalleryExpectation(dev2_path1_id, gallery_name, device_id, relative_path, 10565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MediaGalleryPrefInfo::kUserAdded); 10575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 10585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) relative_path = base::FilePath(FILE_PATH_LITERAL("path2/on/device2")); 1060a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gallery_name = base::ASCIIToUTF16("Device2Path2"); 10617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) MediaGalleryPrefId dev2_path2_id = AddGalleryWithNameV1( 1062a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) device_id, gallery_name, relative_path, true /*user*/); 10635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(default_galleries_count() + 5UL, dev2_path2_id); 1064a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AddGalleryExpectation(dev2_path2_id, gallery_name, device_id, relative_path, 10655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) MediaGalleryPrefInfo::kUserAdded); 10665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 10675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) // Check that adding one of them again works as expected. 10697d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) MediaGalleryPrefId id = AddGalleryWithNameV1( 1070a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) device_id, gallery_name, relative_path, true /*user*/); 10715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) EXPECT_EQ(dev2_path2_id, id); 10725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) Verify(); 10735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)} 10745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 10752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(MediaGalleriesPreferencesTest, GalleryChangeObserver) { 10762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Start with one observer. 10772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) MockGalleryChangeObserver observer1(gallery_prefs()); 10782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gallery_prefs()->AddGalleryChangeObserver(&observer1); 10792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 10802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Add a new auto detected gallery. 10815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::FilePath path = MakeMediaGalleriesTestingPath("new_auto"); 10822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) StorageInfo info; 10832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) base::FilePath relative_path; 108490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 1085a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery"); 10867d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) MediaGalleryPrefId auto_id = AddGalleryWithNameV1( 1087a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) info.device_id(), gallery_name, relative_path, false /*auto*/); 10882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(default_galleries_count() + 1UL, auto_id); 1089a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AddGalleryExpectation(auto_id, gallery_name, info.device_id(), 10902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) relative_path, MediaGalleryPrefInfo::kAutoDetected); 10912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(1, observer1.notifications()); 10922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 10932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Add a second observer. 10942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) MockGalleryChangeObserver observer2(gallery_prefs()); 10952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gallery_prefs()->AddGalleryChangeObserver(&observer2); 10962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 10972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Add a new user added gallery. 10985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) path = MakeMediaGalleriesTestingPath("new_user"); 109990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 1100a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) gallery_name = base::ASCIIToUTF16("NewUserGallery"); 11012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) MediaGalleryPrefId user_added_id = 1102a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AddGalleryWithNameV1(info.device_id(), gallery_name, relative_path, 1103a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) true /*user*/); 1104a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) AddGalleryExpectation(user_added_id, gallery_name, info.device_id(), 11052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) relative_path, MediaGalleryPrefInfo::kUserAdded); 11062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(default_galleries_count() + 2UL, user_added_id); 11072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(2, observer1.notifications()); 11082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(1, observer2.notifications()); 11092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Remove the first observer. 11112a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gallery_prefs()->RemoveGalleryChangeObserver(&observer1); 11122a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Remove an auto added gallery (i.e. make it blacklisted). 11142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gallery_prefs()->ForgetGalleryById(auto_id); 11152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) expected_galleries_[auto_id].type = MediaGalleryPrefInfo::kBlackListed; 11162a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) expected_galleries_for_all.erase(auto_id); 11172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(2, observer1.notifications()); 11192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(2, observer2.notifications()); 11202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) // Remove a user added gallery and it should go away. 11222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) gallery_prefs()->ForgetGalleryById(user_added_id); 11232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) expected_galleries_.erase(user_added_id); 112490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) expected_device_map[info.device_id()].erase(user_added_id); 11252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) 11262a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(2, observer1.notifications()); 11272a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles) EXPECT_EQ(3, observer2.notifications()); 11282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)} 11295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) 11307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)TEST_F(MediaGalleriesPreferencesTest, UpdateSingletonDeviceIdType) { 11317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) MediaGalleryPrefId id; 11327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) base::FilePath path; 11337d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) Verify(); 11347d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 11357d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Add a new auto detect gallery to test with. 11365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) path = MakeMediaGalleriesTestingPath("new_auto"); 1137a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery"); 1138f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) std::string device_id = StorageInfo::MakeDeviceId(StorageInfo::ITUNES, 1139f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) path.AsUTF8Unsafe()); 1140f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) id = AddGalleryWithNameV2(device_id, gallery_name, base::FilePath(), 11415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefInfo::kAutoDetected); 11427d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) EXPECT_EQ(default_galleries_count() + 1UL, id); 1143f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) AddGalleryExpectation(id, gallery_name, device_id, base::FilePath(), 11447d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) MediaGalleryPrefInfo::kAutoDetected); 11457d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) Verify(); 11467d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 11477d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // Update the device id. 11487d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) MockGalleryChangeObserver observer(gallery_prefs()); 11497d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) gallery_prefs()->AddGalleryChangeObserver(&observer); 11507d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 11515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) path = MakeMediaGalleriesTestingPath("updated_path"); 11527d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::string updated_device_id = 11537d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) StorageInfo::MakeDeviceId(StorageInfo::ITUNES, path.AsUTF8Unsafe()); 11547d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) EXPECT_TRUE(UpdateDeviceIDForSingletonType(updated_device_id)); 1155f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) AddGalleryExpectation(id, gallery_name, updated_device_id, base::FilePath(), 11567d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) MediaGalleryPrefInfo::kAutoDetected); 1157f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) expected_device_map[device_id].erase(id); 11587d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) expected_device_map[updated_device_id].insert(id); 11597d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) Verify(); 11607d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) EXPECT_EQ(1, observer.notifications()); 11617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 11627d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // No gallery for type. 11637d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::string new_device_id = 11647d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) StorageInfo::MakeDeviceId(StorageInfo::PICASA, path.AsUTF8Unsafe()); 11657d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) EXPECT_FALSE(UpdateDeviceIDForSingletonType(new_device_id)); 11667d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 11677d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1168f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)TEST_F(MediaGalleriesPreferencesTest, LookupImportedGalleryByPath) { 1169f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) MediaGalleryPrefId id; 1170f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) base::FilePath path; 1171f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) Verify(); 1172f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 1173f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // iTunes device path points to an XML file in the library directory. 1174f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) path = MakeMediaGalleriesTestingPath("new_auto").AppendASCII("library.xml"); 1175f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) base::string16 gallery_name = base::ASCIIToUTF16("NewAutoGallery"); 1176f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) std::string device_id = StorageInfo::MakeDeviceId(StorageInfo::ITUNES, 1177f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) path.AsUTF8Unsafe()); 1178f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) id = AddGalleryWithNameV2(device_id, gallery_name, base::FilePath(), 1179f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) MediaGalleryPrefInfo::kAutoDetected); 1180f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) EXPECT_EQ(default_galleries_count() + 1UL, id); 1181f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) AddGalleryExpectation(id, gallery_name, device_id, base::FilePath(), 1182f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) MediaGalleryPrefInfo::kAutoDetected); 1183f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) Verify(); 1184f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 1185f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) // Verify we can look up the imported gallery by its path. 1186f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) MediaGalleryPrefInfo gallery_info; 1187f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) EXPECT_TRUE(gallery_prefs()->LookUpGalleryByPath(path.DirName(), 1188f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) &gallery_info)); 1189f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) EXPECT_EQ(id, gallery_info.pref_id); 1190f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)} 1191f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles) 11925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST_F(MediaGalleriesPreferencesTest, ScanResults) { 11935d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefId id; 11945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::FilePath path; 11955d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) StorageInfo info; 11965d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::FilePath relative_path; 11975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::Time now = base::Time::Now(); 11985d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 11995d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 12005d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Add a new scan result gallery to test with. 12015d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) path = MakeMediaGalleriesTestingPath("new_scan"); 12025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaStorageUtil::GetDeviceInfoFromPath(path, &info, &relative_path); 12035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) id = gallery_prefs()->AddGallery(info.device_id(), relative_path, 12045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefInfo::kScanResult, 12055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("volume label"), 12065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("vendor name"), 12075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("model name"), 12085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1000000ULL, now, 1, 2, 3); 12095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(default_galleries_count() + 1UL, id); 12105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AddScanResultExpectation(id, base::string16(), info.device_id(), 12115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) relative_path, 1, 2, 3); 12125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 12135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 12145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Update the found media count. 12155d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) id = gallery_prefs()->AddGallery(info.device_id(), relative_path, 12165d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefInfo::kScanResult, 12175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("volume label"), 12185d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("vendor name"), 12195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("model name"), 12205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1000000ULL, now, 4, 5, 6); 12215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(default_galleries_count() + 1UL, id); 12225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AddScanResultExpectation(id, base::string16(), info.device_id(), 12235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) relative_path, 4, 5, 6); 12245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 12255d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 12265d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Remove a scan result (i.e. make it blacklisted). 12275d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) gallery_prefs()->ForgetGalleryById(id); 12285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_galleries_[id].type = MediaGalleryPrefInfo::kRemovedScan; 12295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_galleries_[id].audio_count = 0; 12305d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_galleries_[id].image_count = 0; 12315d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) expected_galleries_[id].video_count = 0; 12325d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 12335d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 12345d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Try adding the gallery again as a scan result it should be a no-op. 12355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) id = gallery_prefs()->AddGallery(info.device_id(), relative_path, 12365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefInfo::kScanResult, 12375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("volume label"), 12385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("vendor name"), 12395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ASCIIToUTF16("model name"), 12405d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1000000ULL, now, 7, 8, 9); 12415d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(default_galleries_count() + 1UL, id); 12425d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 12435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 12445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Add the gallery again as a user action. 12455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) id = gallery_prefs()->AddGalleryByPath(path, 12465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefInfo::kUserAdded); 12475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(default_galleries_count() + 1UL, id); 12485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) AddGalleryExpectation(id, base::string16(), info.device_id(), relative_path, 12495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) MediaGalleryPrefInfo::kUserAdded); 12505d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Verify(); 12515d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)} 12525d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 12535d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)TEST(MediaGalleriesPrefInfoTest, NameGeneration) { 1254d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) ASSERT_TRUE(TestStorageMonitor::CreateAndInstall()); 1255eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 1256eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch MediaGalleryPrefInfo info; 1257eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch info.pref_id = 1; 1258eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch info.display_name = ASCIIToUTF16("override"); 1259eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch info.device_id = StorageInfo::MakeDeviceId( 1260eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch StorageInfo::REMOVABLE_MASS_STORAGE_WITH_DCIM, "unique"); 1261eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 1262eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(ASCIIToUTF16("override"), info.GetGalleryDisplayName()); 1263eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 1264eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch info.display_name = ASCIIToUTF16("o2"); 1265eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(ASCIIToUTF16("o2"), info.GetGalleryDisplayName()); 1266eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 1267eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(l10n_util::GetStringUTF16( 1268eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch IDS_MEDIA_GALLERIES_DIALOG_DEVICE_NOT_ATTACHED), 1269eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch info.GetGalleryAdditionalDetails()); 1270eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 1271eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch info.last_attach_time = base::Time::Now(); 1272eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_NE(l10n_util::GetStringUTF16( 1273eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch IDS_MEDIA_GALLERIES_DIALOG_DEVICE_NOT_ATTACHED), 1274eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch info.GetGalleryAdditionalDetails()); 1275eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_NE(l10n_util::GetStringUTF16( 1276eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch IDS_MEDIA_GALLERIES_DIALOG_DEVICE_ATTACHED), 1277eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch info.GetGalleryAdditionalDetails()); 1278eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 1279eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch info.volume_label = ASCIIToUTF16("vol"); 1280eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch info.vendor_name = ASCIIToUTF16("vendor"); 1281eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch info.model_name = ASCIIToUTF16("model"); 1282eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(ASCIIToUTF16("o2"), info.GetGalleryDisplayName()); 1283eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 1284a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) info.display_name = base::string16(); 1285eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(ASCIIToUTF16("vol"), info.GetGalleryDisplayName()); 1286a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) info.volume_label = base::string16(); 1287eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(ASCIIToUTF16("vendor, model"), info.GetGalleryDisplayName()); 1288eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch 1289eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch info.device_id = StorageInfo::MakeDeviceId( 1290eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch StorageInfo::FIXED_MASS_STORAGE, "unique"); 1291eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch EXPECT_EQ(base::FilePath(FILE_PATH_LITERAL("unique")).AsUTF8Unsafe(), 12925d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::UTF16ToUTF8(info.GetGalleryTooltip())); 12933551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 12945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) TestStorageMonitor::Destroy(); 1295eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch} 12965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 12975f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)TEST_F(MediaGalleriesPreferencesTest, SetsDefaultGalleryTypeField) { 12985f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Tests that default galleries (Music, Pictures, Video) have the correct 12995f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // default_gallery field set. 13005f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 13015f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // No default galleries exist on CrOS so this test isn't relevant there. 13025f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#if defined(OS_CHROMEOS) 13035f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return; 13045f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#endif 13055f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 13065f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) base::FilePath music_path; 13075f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) base::FilePath pictures_path; 13085f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) base::FilePath videos_path; 13095f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool got_music_path = PathService::Get(chrome::DIR_USER_MUSIC, &music_path); 13105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool got_pictures_path = 13115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) PathService::Get(chrome::DIR_USER_PICTURES, &pictures_path); 13125f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool got_videos_path = 13135f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) PathService::Get(chrome::DIR_USER_VIDEOS, &videos_path); 13145f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 13155f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) int num_default_galleries = 0; 13165f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 13175f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const MediaGalleriesPrefInfoMap& known_galleries = 13185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) gallery_prefs()->known_galleries(); 13195f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) for (MediaGalleriesPrefInfoMap::const_iterator it = 13205f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) known_galleries.begin(); 13215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) it != known_galleries.end(); 13225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ++it) { 13235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) if (it->second.type != MediaGalleryPrefInfo::kAutoDetected) 13245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) continue; 13255f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 13265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) std::string unique_id; 13275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) if (!StorageInfo::CrackDeviceId(it->second.device_id, NULL, &unique_id)) 13285f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) continue; 13295f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 13305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) if (got_music_path && unique_id == music_path.AsUTF8Unsafe()) { 13315f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_EQ(MediaGalleryPrefInfo::DefaultGalleryType::kMusicDefault, 13325f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) it->second.default_gallery_type); 13335f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) num_default_galleries++; 13345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } else if (got_pictures_path && unique_id == pictures_path.AsUTF8Unsafe()) { 13355f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_EQ(MediaGalleryPrefInfo::DefaultGalleryType::kPicturesDefault, 13365f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) it->second.default_gallery_type); 13375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) num_default_galleries++; 13385f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } else if (got_videos_path && unique_id == videos_path.AsUTF8Unsafe()) { 13395f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_EQ(MediaGalleryPrefInfo::DefaultGalleryType::kVideosDefault, 13405f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) it->second.default_gallery_type); 13415f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) num_default_galleries++; 13425f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } else { 13435f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_EQ(MediaGalleryPrefInfo::DefaultGalleryType::kNotDefault, 13445f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) it->second.default_gallery_type); 13455f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 13465f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 13475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 13485f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_EQ(3, num_default_galleries); 13495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 13505f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 13515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)TEST_F(MediaGalleriesPreferencesTest, UpdatesDefaultGalleryType) { 13525f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Tests that if the path of a default gallery changed since last init, 13535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // then when the MediaGalleriesPreferences is initialized, it will 13545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // rewrite the device ID in prefs to include the new path. 13555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 13565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // No default galleries exist on CrOS so this test isn't relevant there. 13575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#if defined(OS_CHROMEOS) 13585f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return; 13595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#endif 13605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 13615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) base::FilePath old_music_path; 13625f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) base::FilePath old_pictures_path; 13635f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) base::FilePath old_videos_path; 13645f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool got_old_music_path = 13655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) PathService::Get(chrome::DIR_USER_MUSIC, &old_music_path); 13665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool got_old_pictures_path = 13675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) PathService::Get(chrome::DIR_USER_PICTURES, &old_pictures_path); 13685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool got_old_videos_path = 13695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) PathService::Get(chrome::DIR_USER_VIDEOS, &old_videos_path); 13705f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 13715f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool found_music = false; 13725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool found_pictures = false; 13735f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool found_videos = false; 13745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 13755f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const MediaGalleriesPrefInfoMap& old_known_galleries = 13765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) gallery_prefs()->known_galleries(); 13775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) for (MediaGalleriesPrefInfoMap::const_iterator it = 13785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) old_known_galleries.begin(); 13795f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) it != old_known_galleries.end(); 13805f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ++it) { 13815f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) if (it->second.type == MediaGalleryPrefInfo::kAutoDetected) { 13825f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) std::string unique_id; 13835f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) if (!StorageInfo::CrackDeviceId(it->second.device_id, NULL, &unique_id)) 13845f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) continue; 13855f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 13865f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) if (got_old_music_path && 13875f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) it->second.default_gallery_type == 13885f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) MediaGalleryPrefInfo::DefaultGalleryType::kMusicDefault) { 13895f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_EQ(old_music_path.AsUTF8Unsafe(), unique_id); 13905f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) found_music = true; 13915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } else if (got_old_pictures_path && 13925f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) it->second.default_gallery_type == 13935f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) MediaGalleryPrefInfo::DefaultGalleryType::kPicturesDefault) { 13945f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_EQ(old_pictures_path.AsUTF8Unsafe(), unique_id); 13955f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) found_pictures = true; 13965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } else if (got_old_videos_path && 13975f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) it->second.default_gallery_type == 13985f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) MediaGalleryPrefInfo::DefaultGalleryType::kVideosDefault) { 13995f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_EQ(old_videos_path.AsUTF8Unsafe(), unique_id); 14005f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) found_videos = true; 14015f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 14025f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 14035f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 14045f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 14055f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_TRUE(found_music); 14065f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_TRUE(found_pictures); 14075f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_TRUE(found_videos); 14085f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 14095f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ChangeMediaPathOverrides(); 14105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ReinitPrefsAndExpectations(); 14115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 14125f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) base::FilePath new_music_path; 14135f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) base::FilePath new_pictures_path; 14145f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) base::FilePath new_videos_path; 14155f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool got_new_music_path = 14165f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) PathService::Get(chrome::DIR_USER_MUSIC, &new_music_path); 14175f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool got_new_pictures_path = 14185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) PathService::Get(chrome::DIR_USER_PICTURES, &new_pictures_path); 14195f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool got_new_videos_path = 14205f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) PathService::Get(chrome::DIR_USER_VIDEOS, &new_videos_path); 14215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 14225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_NE(new_music_path, old_music_path); 14235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_NE(new_pictures_path, old_pictures_path); 14245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_NE(new_videos_path, old_videos_path); 14255f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 14265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) found_music = false; 14275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) found_pictures = false; 14285f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) found_videos = false; 14295f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 14305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const MediaGalleriesPrefInfoMap& known_galleries = 14315f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) gallery_prefs()->known_galleries(); 14325f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) for (MediaGalleriesPrefInfoMap::const_iterator it = known_galleries.begin(); 14335f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) it != known_galleries.end(); 14345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ++it) { 14355f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) if (it->second.type == MediaGalleryPrefInfo::kAutoDetected) { 14365f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) std::string unique_id; 14375f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) if (!StorageInfo::CrackDeviceId(it->second.device_id, NULL, &unique_id)) 14385f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) continue; 14395f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 14405f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) if (got_new_music_path && 14415f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) it->second.default_gallery_type == 14425f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) MediaGalleryPrefInfo::DefaultGalleryType::kMusicDefault) { 14435f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_EQ(new_music_path.AsUTF8Unsafe(), unique_id); 14445f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) found_music = true; 14455f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } else if (got_new_pictures_path && 14465f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) it->second.default_gallery_type == 14475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) MediaGalleryPrefInfo::DefaultGalleryType::kPicturesDefault) { 14485f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_EQ(new_pictures_path.AsUTF8Unsafe(), unique_id); 14495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) found_pictures = true; 14505f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } else if (got_new_videos_path && 14515f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) it->second.default_gallery_type == 14525f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) MediaGalleryPrefInfo::DefaultGalleryType::kVideosDefault) { 14535f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_EQ(new_videos_path.AsUTF8Unsafe(), unique_id); 14545f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) found_videos = true; 14555f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 14565f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 14575f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 14585f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 14595f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_TRUE(found_music); 14605f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_TRUE(found_pictures); 14615f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_TRUE(found_videos); 14625f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 14635f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 14645f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)TEST_F(MediaGalleriesPreferencesTest, UpdateAddsDefaultGalleryTypeIfMissing) { 14655f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Tests that if no default_gallery_type was specified for an existing prefs 14665f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // info object corresponding to a particular gallery, then when the 14675f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // MediaGalleriesPreferences is initialized, it assigns the proper one. 14685f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 14695f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // No default galleries exist on CrOS so this test isn't relevant there. 14705f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#if defined(OS_CHROMEOS) 14715f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) return; 14725f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)#endif 14735f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 14745f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Add a new user added gallery. 14755f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) AddFixedGalleryWithExepectation("user_added", "UserAdded", 14765f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) MediaGalleryPrefInfo::kUserAdded); 14775f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 14785f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Remove the "default_gallery_type" field completely from the persisted data 14795f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // for the prefs info object. This simulates the case where a user updated 14805f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Chrome from a version without that field to one with it. 14815f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) RemovePersistedDefaultGalleryValues(); 14825f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 14835f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Reinitializing the MediaGalleriesPreferences should populate the 14845f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // default_gallery_type field with the correct value for each gallery. 14855f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ReinitPrefsAndExpectations(); 14865f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 14875f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) base::FilePath music_path; 14885f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) base::FilePath pictures_path; 14895f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) base::FilePath videos_path; 14905f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool got_music_path = PathService::Get(chrome::DIR_USER_MUSIC, &music_path); 14915f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool got_pictures_path = 14925f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) PathService::Get(chrome::DIR_USER_PICTURES, &pictures_path); 14935f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool got_videos_path = 14945f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) PathService::Get(chrome::DIR_USER_VIDEOS, &videos_path); 14955f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 14965f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool found_music = false; 14975f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool found_pictures = false; 14985f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool found_videos = false; 14995f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) bool found_user_added = false; 15005f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 15015f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) const MediaGalleriesPrefInfoMap& known_galleries = 15025f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) gallery_prefs()->known_galleries(); 15035f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) for (MediaGalleriesPrefInfoMap::const_iterator it = known_galleries.begin(); 15045f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) it != known_galleries.end(); 15055f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) ++it) { 15065f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) std::string unique_id; 15075f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) if (!StorageInfo::CrackDeviceId(it->second.device_id, NULL, &unique_id)) 15085f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) continue; 15095f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 15105f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) if (got_music_path && 15115f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) it->second.default_gallery_type == 15125f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) MediaGalleryPrefInfo::DefaultGalleryType::kMusicDefault) { 15135f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_EQ(music_path.AsUTF8Unsafe(), unique_id); 15145f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) found_music = true; 15155f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } else if (got_pictures_path && 15165f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) it->second.default_gallery_type == 15175f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) MediaGalleryPrefInfo::DefaultGalleryType::kPicturesDefault) { 15185f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_EQ(pictures_path.AsUTF8Unsafe(), unique_id); 15195f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) found_pictures = true; 15205f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } else if (got_videos_path && 15215f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) it->second.default_gallery_type == 15225f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) MediaGalleryPrefInfo::DefaultGalleryType::kVideosDefault) { 15235f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_EQ(videos_path.AsUTF8Unsafe(), unique_id); 15245f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) found_videos = true; 15255f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } else if (it->second.default_gallery_type == 15265f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) MediaGalleryPrefInfo::DefaultGalleryType::kNotDefault) { 15275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) found_user_added = true; 15285f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 15295f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) } 15305f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 15315f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_TRUE(found_music); 15325f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_TRUE(found_pictures); 15335f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_TRUE(found_videos); 15345f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) EXPECT_TRUE(found_user_added); 15355f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)} 1536