| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/extensions/api/system_info_storage/storage_info_provide
r.h" | 8 #include "chrome/browser/extensions/api/system_storage/storage_info_provider.h" |
| 9 #include "chrome/browser/extensions/api/system_info_storage/test_storage_info_pr
ovider.h" | 9 #include "chrome/browser/extensions/api/system_storage/test_storage_info_provide
r.h" |
| 10 #include "chrome/browser/extensions/extension_apitest.h" | 10 #include "chrome/browser/extensions/extension_apitest.h" |
| 11 #include "chrome/browser/extensions/extension_test_message_listener.h" | 11 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 12 #include "chrome/browser/storage_monitor/storage_info.h" | 12 #include "chrome/browser/storage_monitor/storage_info.h" |
| 13 #include "chrome/browser/storage_monitor/storage_monitor.h" | 13 #include "chrome/browser/storage_monitor/storage_monitor.h" |
| 14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
| 15 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 using chrome::StorageMonitor; | 19 using chrome::StorageMonitor; |
| 20 using extensions::api::experimental_system_info_storage::ParseStorageUnitType; | 20 using extensions::api::system_storage::ParseStorageUnitType; |
| 21 using extensions::api::experimental_system_info_storage::StorageUnitInfo; | 21 using extensions::api::system_storage::StorageUnitInfo; |
| 22 using extensions::StorageInfoProvider; | 22 using extensions::StorageInfoProvider; |
| 23 using extensions::StorageUnitInfoList; | 23 using extensions::StorageUnitInfoList; |
| 24 using extensions::systeminfo::kStorageTypeFixed; | 24 using extensions::systeminfo::kStorageTypeFixed; |
| 25 using extensions::systeminfo::kStorageTypeRemovable; | 25 using extensions::systeminfo::kStorageTypeRemovable; |
| 26 using extensions::systeminfo::kStorageTypeUnknown; | 26 using extensions::systeminfo::kStorageTypeUnknown; |
| 27 using extensions::TestStorageUnitInfo; | 27 using extensions::TestStorageUnitInfo; |
| 28 using extensions::TestStorageInfoProvider; | 28 using extensions::TestStorageInfoProvider; |
| 29 | 29 |
| 30 const struct TestStorageUnitInfo kTestingData[] = { | 30 const struct TestStorageUnitInfo kTestingData[] = { |
| 31 {"dcim:device:0004", "transient:0004", "0xbeaf", kStorageTypeUnknown, | 31 {"dcim:device:0004", "transient:0004", "0xbeaf", kStorageTypeUnknown, |
| 32 4098, 1000, 0}, | 32 4098, 1000, 0}, |
| 33 {"path:device:002", "transient:002", "/home", kStorageTypeFixed, | 33 {"path:device:002", "transient:002", "/home", kStorageTypeFixed, |
| 34 4098, 1000, 10}, | 34 4098, 1000, 10}, |
| 35 {"path:device:003", "transient:003", "/data", kStorageTypeFixed, | 35 {"path:device:003", "transient:003", "/data", kStorageTypeFixed, |
| 36 10000, 1000, 4097} | 36 10000, 1000, 4097} |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 const struct TestStorageUnitInfo kRemovableStorageData[] = { | 39 const struct TestStorageUnitInfo kRemovableStorageData[] = { |
| 40 {"dcim:device:0004", "transient:0004", "/media/usb1", | 40 {"dcim:device:0004", "transient:0004", "/media/usb1", |
| 41 kStorageTypeRemovable, 4098, 1000, 1} | 41 kStorageTypeRemovable, 4098, 1000, 1} |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 } // namespace | 44 } // namespace |
| 45 | 45 |
| 46 class SystemInfoStorageApiTest : public ExtensionApiTest { | 46 class SystemStorageApiTest : public ExtensionApiTest { |
| 47 public: | 47 public: |
| 48 SystemInfoStorageApiTest() {} | 48 SystemStorageApiTest() {} |
| 49 virtual ~SystemInfoStorageApiTest() {} | 49 virtual ~SystemStorageApiTest() {} |
| 50 | 50 |
| 51 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 51 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 52 ExtensionApiTest::SetUpCommandLine(command_line); | 52 ExtensionApiTest::SetUpCommandLine(command_line); |
| 53 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); | 53 command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis); |
| 54 } | 54 } |
| 55 | 55 |
| 56 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 56 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { |
| 57 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | 57 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
| 58 message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_UI)); | 58 message_loop_.reset(new base::MessageLoop(base::MessageLoop::TYPE_UI)); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void AttachRemovableStorage(const std::string& device_id) { | 61 void AttachRemovableStorage(const std::string& device_id) { |
| 62 for (size_t i = 0; i < arraysize(kRemovableStorageData); ++i) { | 62 for (size_t i = 0; i < arraysize(kRemovableStorageData); ++i) { |
| 63 if (kRemovableStorageData[i].device_id != device_id) | 63 if (kRemovableStorageData[i].device_id != device_id) |
| 64 continue; | 64 continue; |
| 65 | 65 |
| 66 StorageMonitor::GetInstance()->receiver()->ProcessAttach( | 66 StorageMonitor::GetInstance()->receiver()->ProcessAttach( |
| 67 TestStorageInfoProvider::BuildStorageInfo(kRemovableStorageData[i])); | 67 TestStorageInfoProvider::BuildStorageInfo(kRemovableStorageData[i])); |
| 68 } | 68 } |
| 69 } | 69 } |
| 70 | 70 |
| 71 void DetachRemovableStorage(const std::string& id) { | 71 void DetachRemovableStorage(const std::string& id) { |
| 72 StorageMonitor::GetInstance()->receiver()->ProcessDetach(id); | 72 StorageMonitor::GetInstance()->receiver()->ProcessDetach(id); |
| 73 } | 73 } |
| 74 | 74 |
| 75 private: | 75 private: |
| 76 scoped_ptr<base::MessageLoop> message_loop_; | 76 scoped_ptr<base::MessageLoop> message_loop_; |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 IN_PROC_BROWSER_TEST_F(SystemInfoStorageApiTest, Storage) { | 79 IN_PROC_BROWSER_TEST_F(SystemStorageApiTest, Storage) { |
| 80 TestStorageInfoProvider* provider = | 80 TestStorageInfoProvider* provider = |
| 81 new TestStorageInfoProvider(kTestingData, arraysize(kTestingData)); | 81 new TestStorageInfoProvider(kTestingData, arraysize(kTestingData)); |
| 82 StorageInfoProvider::InitializeForTesting(provider); | 82 StorageInfoProvider::InitializeForTesting(provider); |
| 83 ASSERT_TRUE(RunPlatformAppTest("systeminfo/storage")) << message_; | 83 ASSERT_TRUE(RunPlatformAppTest("system/storage")) << message_; |
| 84 } | 84 } |
| 85 | 85 |
| 86 IN_PROC_BROWSER_TEST_F(SystemInfoStorageApiTest, StorageAttachment) { | 86 IN_PROC_BROWSER_TEST_F(SystemStorageApiTest, StorageAttachment) { |
| 87 TestStorageInfoProvider* provider = | 87 TestStorageInfoProvider* provider = |
| 88 new TestStorageInfoProvider(kRemovableStorageData, | 88 new TestStorageInfoProvider(kRemovableStorageData, |
| 89 arraysize(kRemovableStorageData)); | 89 arraysize(kRemovableStorageData)); |
| 90 StorageInfoProvider::InitializeForTesting(provider); | 90 StorageInfoProvider::InitializeForTesting(provider); |
| 91 | 91 |
| 92 ResultCatcher catcher; | 92 ResultCatcher catcher; |
| 93 ExtensionTestMessageListener attach_listener("attach", false); | 93 ExtensionTestMessageListener attach_listener("attach", false); |
| 94 ExtensionTestMessageListener detach_listener("detach", false); | 94 ExtensionTestMessageListener detach_listener("detach", false); |
| 95 | 95 |
| 96 EXPECT_TRUE(LoadExtension( | 96 EXPECT_TRUE(LoadExtension( |
| 97 test_data_dir_.AppendASCII("systeminfo/storage_attachment"))); | 97 test_data_dir_.AppendASCII("system/storage_attachment"))); |
| 98 | 98 |
| 99 // Simulate triggering onAttached event. | 99 // Simulate triggering onAttached event. |
| 100 ASSERT_TRUE(attach_listener.WaitUntilSatisfied()); | 100 ASSERT_TRUE(attach_listener.WaitUntilSatisfied()); |
| 101 AttachRemovableStorage(kRemovableStorageData[0].device_id); | 101 AttachRemovableStorage(kRemovableStorageData[0].device_id); |
| 102 // Simulate triggering onDetached event. | 102 // Simulate triggering onDetached event. |
| 103 ASSERT_TRUE(detach_listener.WaitUntilSatisfied()); | 103 ASSERT_TRUE(detach_listener.WaitUntilSatisfied()); |
| 104 DetachRemovableStorage(kRemovableStorageData[0].device_id); | 104 DetachRemovableStorage(kRemovableStorageData[0].device_id); |
| 105 | 105 |
| 106 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); | 106 EXPECT_TRUE(catcher.GetNextResult()) << catcher.message(); |
| 107 } | 107 } |
| OLD | NEW |