| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/extensions/api/system_storage/storage_api_test_util.h" | 9 #include "chrome/browser/extensions/api/system_storage/storage_api_test_util.h" |
| 10 #include "chrome/browser/extensions/api/system_storage/storage_info_provider.h" | 10 #include "chrome/browser/extensions/api/system_storage/storage_info_provider.h" |
| 11 #include "chrome/browser/extensions/extension_apitest.h" | 11 #include "chrome/browser/extensions/extension_apitest.h" |
| 12 #include "chrome/browser/extensions/extension_test_message_listener.h" | 12 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 13 #include "chrome/browser/storage_monitor/storage_info.h" | 13 #include "chrome/browser/storage_monitor/storage_info.h" |
| 14 #include "chrome/browser/storage_monitor/storage_monitor.h" | 14 #include "chrome/browser/storage_monitor/storage_monitor.h" |
| 15 #include "chrome/browser/storage_monitor/test_storage_monitor.h" | 15 #include "chrome/browser/storage_monitor/test_storage_monitor.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 using chrome::StorageMonitor; | 19 using chrome::StorageMonitor; |
| 20 using extensions::StorageUnitInfoList; | 20 using extensions::StorageUnitInfoList; |
| 21 using extensions::test::TestStorageUnitInfo; | 21 using extensions::test::TestStorageUnitInfo; |
| 22 using extensions::test::kRemovableStorageData; | 22 using extensions::test::kRemovableStorageData; |
| 23 | 23 |
| 24 const struct TestStorageUnitInfo kTestingData[] = { | 24 const struct TestStorageUnitInfo kTestingData[] = { |
| 25 {"dcim:device:001", "0xbeaf", 4098, 1000}, | 25 {"dcim:device:001", "0xbeaf", 4098, 1}, |
| 26 {"path:device:002", "/home", 4098, 1000}, | 26 {"path:device:002", "/home", 4098, 2}, |
| 27 {"path:device:003", "/data", 10000, 1000} | 27 {"path:device:003", "/data", 10000, 3} |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 class TestStorageInfoProvider : public extensions::StorageInfoProvider { |
| 33 public: |
| 34 TestStorageInfoProvider(const struct TestStorageUnitInfo* testing_data, |
| 35 size_t n); |
| 36 |
| 37 private: |
| 38 virtual ~TestStorageInfoProvider(); |
| 39 |
| 40 // StorageInfoProvider implementations. |
| 41 virtual double GetStorageFreeSpaceFromTransientIdOnFileThread( |
| 42 const std::string& transient_id) OVERRIDE; |
| 43 |
| 44 std::vector<struct TestStorageUnitInfo> testing_data_; |
| 45 }; |
| 46 |
| 47 TestStorageInfoProvider::TestStorageInfoProvider( |
| 48 const struct TestStorageUnitInfo* testing_data, size_t n) |
| 49 : testing_data_(testing_data, testing_data + n) { |
| 50 } |
| 51 |
| 52 TestStorageInfoProvider::~TestStorageInfoProvider() { |
| 53 } |
| 54 |
| 55 double TestStorageInfoProvider::GetStorageFreeSpaceFromTransientIdOnFileThread( |
| 56 const std::string& transient_id) { |
| 57 std::string device_id = |
| 58 chrome::StorageMonitor::GetInstance()->GetDeviceIdForTransientId( |
| 59 transient_id); |
| 60 for (size_t i = 0; i < testing_data_.size(); ++i) { |
| 61 if (testing_data_[i].device_id == device_id) { |
| 62 return static_cast<double>(testing_data_[i].available_capacity); |
| 63 } |
| 64 } |
| 65 return -1; |
| 66 } |
| 67 |
| 32 class SystemStorageApiTest : public ExtensionApiTest { | 68 class SystemStorageApiTest : public ExtensionApiTest { |
| 33 public: | 69 public: |
| 34 SystemStorageApiTest() {} | 70 SystemStorageApiTest() {} |
| 35 virtual ~SystemStorageApiTest() {} | 71 virtual ~SystemStorageApiTest() {} |
| 36 | 72 |
| 37 virtual void SetUpOnMainThread() OVERRIDE { | 73 virtual void SetUpOnMainThread() OVERRIDE { |
| 38 chrome::test::TestStorageMonitor::CreateForBrowserTests(); | 74 chrome::test::TestStorageMonitor::CreateForBrowserTests(); |
| 39 } | 75 } |
| 40 | 76 |
| 41 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 77 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 59 void DetachRemovableStorage(const std::string& id) { | 95 void DetachRemovableStorage(const std::string& id) { |
| 60 StorageMonitor::GetInstance()->receiver()->ProcessDetach(id); | 96 StorageMonitor::GetInstance()->receiver()->ProcessDetach(id); |
| 61 } | 97 } |
| 62 | 98 |
| 63 private: | 99 private: |
| 64 scoped_ptr<base::MessageLoop> message_loop_; | 100 scoped_ptr<base::MessageLoop> message_loop_; |
| 65 }; | 101 }; |
| 66 | 102 |
| 67 IN_PROC_BROWSER_TEST_F(SystemStorageApiTest, Storage) { | 103 IN_PROC_BROWSER_TEST_F(SystemStorageApiTest, Storage) { |
| 68 SetUpAllMockStorageDevices(); | 104 SetUpAllMockStorageDevices(); |
| 105 TestStorageInfoProvider* provider = |
| 106 new TestStorageInfoProvider(kTestingData, |
| 107 arraysize(kTestingData)); |
| 108 extensions::StorageInfoProvider::InitializeForTesting(provider); |
| 69 std::vector<linked_ptr<ExtensionTestMessageListener> > device_ids_listeners; | 109 std::vector<linked_ptr<ExtensionTestMessageListener> > device_ids_listeners; |
| 70 for (size_t i = 0; i < arraysize(kTestingData); ++i) { | 110 for (size_t i = 0; i < arraysize(kTestingData); ++i) { |
| 71 linked_ptr<ExtensionTestMessageListener> listener( | 111 linked_ptr<ExtensionTestMessageListener> listener( |
| 72 new ExtensionTestMessageListener( | 112 new ExtensionTestMessageListener( |
| 73 StorageMonitor::GetInstance()->GetTransientIdForDeviceId( | 113 StorageMonitor::GetInstance()->GetTransientIdForDeviceId( |
| 74 kTestingData[i].device_id), | 114 kTestingData[i].device_id), |
| 75 false)); | 115 false)); |
| 76 device_ids_listeners.push_back(listener); | 116 device_ids_listeners.push_back(listener); |
| 77 } | 117 } |
| 78 ASSERT_TRUE(RunPlatformAppTest("system/storage")) << message_; | 118 ASSERT_TRUE(RunPlatformAppTest("system/storage")) << message_; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 99 removable_storage_transient_id, false); | 139 removable_storage_transient_id, false); |
| 100 | 140 |
| 101 // Simulate triggering onDetached event. | 141 // Simulate triggering onDetached event. |
| 102 ASSERT_TRUE(detach_listener.WaitUntilSatisfied()); | 142 ASSERT_TRUE(detach_listener.WaitUntilSatisfied()); |
| 103 DetachRemovableStorage(kRemovableStorageData.device_id); | 143 DetachRemovableStorage(kRemovableStorageData.device_id); |
| 104 | 144 |
| 105 ASSERT_TRUE(detach_device_id_listener.WaitUntilSatisfied()); | 145 ASSERT_TRUE(detach_device_id_listener.WaitUntilSatisfied()); |
| 106 | 146 |
| 107 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 147 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 108 } | 148 } |
| OLD | NEW |