| 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 extensions::StorageUnitInfoList; | 19 using extensions::StorageUnitInfoList; |
| 20 using extensions::test::TestStorageUnitInfo; | 20 using extensions::test::TestStorageUnitInfo; |
| 21 using extensions::test::kRemovableStorageData; | 21 using extensions::test::kRemovableStorageData; |
| 22 | 22 |
| 23 const struct TestStorageUnitInfo kTestingData[] = { | 23 const struct TestStorageUnitInfo kTestingData[] = { |
| 24 {"dcim:device:001", "0xbeaf", 4098, 1000}, | 24 {"dcim:device:001", "0xbeaf", 4098, 1}, |
| 25 {"path:device:002", "/home", 4098, 1000}, | 25 {"path:device:002", "/home", 4098, 2}, |
| 26 {"path:device:003", "/data", 10000, 1000} | 26 {"path:device:003", "/data", 10000, 3} |
| 27 }; | 27 }; |
| 28 | 28 |
| 29 } // namespace | 29 } // namespace |
| 30 | 30 |
| 31 class TestStorageInfoProvider : public extensions::StorageInfoProvider { |
| 32 public: |
| 33 TestStorageInfoProvider(const struct TestStorageUnitInfo* testing_data, |
| 34 size_t n); |
| 35 |
| 36 private: |
| 37 virtual ~TestStorageInfoProvider(); |
| 38 |
| 39 // StorageInfoProvider implementations. |
| 40 virtual double GetStorageFreeSpaceFromTransientIdOnFileThread( |
| 41 const std::string& transient_id) OVERRIDE; |
| 42 |
| 43 std::vector<struct TestStorageUnitInfo> testing_data_; |
| 44 }; |
| 45 |
| 46 TestStorageInfoProvider::TestStorageInfoProvider( |
| 47 const struct TestStorageUnitInfo* testing_data, size_t n) |
| 48 : testing_data_(testing_data, testing_data + n) { |
| 49 } |
| 50 |
| 51 TestStorageInfoProvider::~TestStorageInfoProvider() { |
| 52 } |
| 53 |
| 54 double TestStorageInfoProvider::GetStorageFreeSpaceFromTransientIdOnFileThread( |
| 55 const std::string& transient_id) { |
| 56 std::string device_id = |
| 57 StorageMonitor::GetInstance()->GetDeviceIdForTransientId( |
| 58 transient_id); |
| 59 for (size_t i = 0; i < testing_data_.size(); ++i) { |
| 60 if (testing_data_[i].device_id == device_id) { |
| 61 return static_cast<double>(testing_data_[i].available_capacity); |
| 62 } |
| 63 } |
| 64 return -1; |
| 65 } |
| 66 |
| 31 class SystemStorageApiTest : public ExtensionApiTest { | 67 class SystemStorageApiTest : public ExtensionApiTest { |
| 32 public: | 68 public: |
| 33 SystemStorageApiTest() {} | 69 SystemStorageApiTest() {} |
| 34 virtual ~SystemStorageApiTest() {} | 70 virtual ~SystemStorageApiTest() {} |
| 35 | 71 |
| 36 virtual void SetUpOnMainThread() OVERRIDE { | 72 virtual void SetUpOnMainThread() OVERRIDE { |
| 37 TestStorageMonitor::CreateForBrowserTests(); | 73 TestStorageMonitor::CreateForBrowserTests(); |
| 38 } | 74 } |
| 39 | 75 |
| 40 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 76 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 58 void DetachRemovableStorage(const std::string& id) { | 94 void DetachRemovableStorage(const std::string& id) { |
| 59 StorageMonitor::GetInstance()->receiver()->ProcessDetach(id); | 95 StorageMonitor::GetInstance()->receiver()->ProcessDetach(id); |
| 60 } | 96 } |
| 61 | 97 |
| 62 private: | 98 private: |
| 63 scoped_ptr<base::MessageLoop> message_loop_; | 99 scoped_ptr<base::MessageLoop> message_loop_; |
| 64 }; | 100 }; |
| 65 | 101 |
| 66 IN_PROC_BROWSER_TEST_F(SystemStorageApiTest, Storage) { | 102 IN_PROC_BROWSER_TEST_F(SystemStorageApiTest, Storage) { |
| 67 SetUpAllMockStorageDevices(); | 103 SetUpAllMockStorageDevices(); |
| 104 TestStorageInfoProvider* provider = |
| 105 new TestStorageInfoProvider(kTestingData, |
| 106 arraysize(kTestingData)); |
| 107 extensions::StorageInfoProvider::InitializeForTesting(provider); |
| 68 std::vector<linked_ptr<ExtensionTestMessageListener> > device_ids_listeners; | 108 std::vector<linked_ptr<ExtensionTestMessageListener> > device_ids_listeners; |
| 69 for (size_t i = 0; i < arraysize(kTestingData); ++i) { | 109 for (size_t i = 0; i < arraysize(kTestingData); ++i) { |
| 70 linked_ptr<ExtensionTestMessageListener> listener( | 110 linked_ptr<ExtensionTestMessageListener> listener( |
| 71 new ExtensionTestMessageListener( | 111 new ExtensionTestMessageListener( |
| 72 StorageMonitor::GetInstance()->GetTransientIdForDeviceId( | 112 StorageMonitor::GetInstance()->GetTransientIdForDeviceId( |
| 73 kTestingData[i].device_id), | 113 kTestingData[i].device_id), |
| 74 false)); | 114 false)); |
| 75 device_ids_listeners.push_back(listener); | 115 device_ids_listeners.push_back(listener); |
| 76 } | 116 } |
| 77 ASSERT_TRUE(RunPlatformAppTest("system/storage")) << message_; | 117 ASSERT_TRUE(RunPlatformAppTest("system/storage")) << message_; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 98 removable_storage_transient_id, false); | 138 removable_storage_transient_id, false); |
| 99 | 139 |
| 100 // Simulate triggering onDetached event. | 140 // Simulate triggering onDetached event. |
| 101 ASSERT_TRUE(detach_listener.WaitUntilSatisfied()); | 141 ASSERT_TRUE(detach_listener.WaitUntilSatisfied()); |
| 102 DetachRemovableStorage(kRemovableStorageData.device_id); | 142 DetachRemovableStorage(kRemovableStorageData.device_id); |
| 103 | 143 |
| 104 ASSERT_TRUE(detach_device_id_listener.WaitUntilSatisfied()); | 144 ASSERT_TRUE(detach_device_id_listener.WaitUntilSatisfied()); |
| 105 | 145 |
| 106 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 146 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 107 } | 147 } |
| OLD | NEW |