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