| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/extensions/file_browser_event_router.h" | |
| 6 | |
| 7 #include "base/prefs/pref_service.h" | |
| 8 #include "chrome/browser/chromeos/extensions/file_browser_private_api.h" | |
| 9 #include "chrome/browser/chromeos/extensions/file_browser_private_api_factory.h" | |
| 10 #include "chrome/browser/profiles/profile.h" | |
| 11 #include "chrome/browser/ui/browser.h" | |
| 12 #include "chrome/common/pref_names.h" | |
| 13 #include "chrome/test/base/in_process_browser_test.h" | |
| 14 #include "chromeos/disks/disk_mount_manager.h" | |
| 15 #include "chromeos/disks/mock_disk_mount_manager.h" | |
| 16 | |
| 17 using testing::_; | |
| 18 | |
| 19 namespace chromeos { | |
| 20 namespace disks { | |
| 21 namespace { | |
| 22 | |
| 23 class FileBrowserEventRouterBrowserTest : public InProcessBrowserTest { | |
| 24 public: | |
| 25 // ExtensionApiTest override | |
| 26 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | |
| 27 InProcessBrowserTest::SetUpInProcessBrowserTestFixture(); | |
| 28 | |
| 29 disk_mount_manager_mock_ = new MockDiskMountManager; | |
| 30 chromeos::disks::DiskMountManager::InitializeForTesting( | |
| 31 disk_mount_manager_mock_); | |
| 32 disk_mount_manager_mock_->SetupDefaultReplies(); | |
| 33 } | |
| 34 | |
| 35 MockDiskMountManager* disk_mount_manager_mock_; | |
| 36 }; | |
| 37 | |
| 38 IN_PROC_BROWSER_TEST_F(FileBrowserEventRouterBrowserTest, | |
| 39 ExternalStoragePolicyTest) { | |
| 40 FileBrowserPrivateAPI* file_browser = | |
| 41 FileBrowserPrivateAPIFactory::GetForProfile(browser()->profile()); | |
| 42 FileBrowserEventRouter* event_router = | |
| 43 file_browser->event_router(); | |
| 44 | |
| 45 DiskMountManager::DiskEvent event = DiskMountManager::DISK_ADDED; | |
| 46 // Prepare a fake disk. All that matters here is that the mount point is empty | |
| 47 // but the device path is not so that it will exercise the path we care about. | |
| 48 DiskMountManager::Disk disk( | |
| 49 "fake_path", "", "X", "X", "X", "X", "X", "X", "X", "X", "X", "X", | |
| 50 chromeos::DEVICE_TYPE_USB, 1, false, false, true, false, false); | |
| 51 | |
| 52 // First we set the policy to prevent storage mounting and check that the | |
| 53 // callback is not called. | |
| 54 browser()->profile()->GetPrefs()->SetBoolean(prefs::kExternalStorageDisabled, | |
| 55 true); | |
| 56 | |
| 57 EXPECT_CALL(*disk_mount_manager_mock_, MountPath(_, _, _, _)).Times(0); | |
| 58 | |
| 59 event_router->OnDiskEvent(event, &disk); | |
| 60 | |
| 61 // Next we repeat but with the policy not active this time. | |
| 62 browser()->profile()->GetPrefs()->SetBoolean(prefs::kExternalStorageDisabled, | |
| 63 false); | |
| 64 | |
| 65 EXPECT_CALL(*disk_mount_manager_mock_, | |
| 66 MountPath("fake_path", "", "", chromeos::MOUNT_TYPE_DEVICE)) | |
| 67 .Times(1); | |
| 68 | |
| 69 event_router->OnDiskEvent(event, &disk); | |
| 70 } | |
| 71 | |
| 72 } // namespace | |
| 73 } // namespace disks | |
| 74 } // namespace chromeos | |
| OLD | NEW |