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/strings/stringprintf.h" | 5 #include "base/strings/stringprintf.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "chrome/browser/extensions/api/media_galleries_private/media_galleries_
private_api.h" | 7 #include "chrome/browser/extensions/api/media_galleries_private/media_galleries_
private_api.h" |
8 #include "chrome/browser/extensions/extension_apitest.h" | 8 #include "chrome/browser/extensions/extension_apitest.h" |
9 #include "chrome/browser/extensions/extension_service.h" | 9 #include "chrome/browser/extensions/extension_service.h" |
10 #include "chrome/browser/extensions/extension_test_message_listener.h" | 10 #include "chrome/browser/extensions/extension_test_message_listener.h" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/common/chrome_switches.h" | 12 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/test/base/ui_test_utils.h" | 13 #include "chrome/test/base/ui_test_utils.h" |
14 #include "components/storage_monitor/storage_info.h" | 14 #include "components/storage_monitor/storage_info.h" |
15 #include "components/storage_monitor/storage_monitor.h" | 15 #include "components/storage_monitor/storage_monitor.h" |
16 #include "components/storage_monitor/test_storage_monitor.h" | 16 #include "components/storage_monitor/test_storage_monitor.h" |
17 #include "content/public/browser/render_view_host.h" | 17 #include "content/public/browser/render_view_host.h" |
18 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
19 #include "content/public/test/browser_test_utils.h" | 19 #include "content/public/test/browser_test_utils.h" |
20 #include "extensions/browser/extension_system.h" | 20 #include "extensions/browser/extension_system.h" |
21 #include "extensions/common/extension.h" | 21 #include "extensions/common/extension.h" |
22 #include "url/gurl.h" | |
23 | 22 |
24 using storage_monitor::StorageInfo; | 23 using storage_monitor::StorageInfo; |
25 using storage_monitor::StorageMonitor; | 24 using storage_monitor::StorageMonitor; |
26 using storage_monitor::TestStorageMonitor; | 25 using storage_monitor::TestStorageMonitor; |
27 | 26 |
28 namespace { | 27 namespace { |
29 | 28 |
30 // Id of test extension from | 29 // Id of test extension from |
31 // chrome/test/data/extensions/api_test/|kTestExtensionPath| | 30 // chrome/test/data/extensions/api_test/|kTestExtensionPath| |
32 const char kTestExtensionId[] = "lkegdcleigedmkiikoijjgfchobofdbe"; | 31 const char kTestExtensionId[] = "lkegdcleigedmkiikoijjgfchobofdbe"; |
(...skipping 12 matching lines...) Expand all Loading... |
45 const char kAddDummyDetachListenerOk[] = "add_dummy_detach_ok"; | 44 const char kAddDummyDetachListenerOk[] = "add_dummy_detach_ok"; |
46 const char kRemoveAttachListenerOk[] = "remove_attach_ok"; | 45 const char kRemoveAttachListenerOk[] = "remove_attach_ok"; |
47 const char kRemoveDummyDetachListenerOk[] = "remove_dummy_detach_ok"; | 46 const char kRemoveDummyDetachListenerOk[] = "remove_dummy_detach_ok"; |
48 | 47 |
49 // Test reply messages. | 48 // Test reply messages. |
50 const char kAttachTestOk[] = "attach_test_ok"; | 49 const char kAttachTestOk[] = "attach_test_ok"; |
51 const char kDetachTestOk[] = "detach_test_ok"; | 50 const char kDetachTestOk[] = "detach_test_ok"; |
52 | 51 |
53 // Dummy device properties. | 52 // Dummy device properties. |
54 const char kDeviceId[] = "testDeviceId"; | 53 const char kDeviceId[] = "testDeviceId"; |
55 const char kDeviceName[] = "foobar"; | 54 const char kVolumeLabel[] = "foobar"; |
56 base::FilePath::CharType kDevicePath[] = FILE_PATH_LITERAL("/qux"); | 55 base::FilePath::CharType kDevicePath[] = FILE_PATH_LITERAL("/qux"); |
57 | 56 |
58 } // namespace | 57 } // namespace |
59 | 58 |
60 class MediaGalleriesPrivateApiTest : public ExtensionApiTest { | 59 class MediaGalleriesPrivateApiTest : public ExtensionApiTest { |
61 public: | 60 public: |
62 MediaGalleriesPrivateApiTest() {} | 61 MediaGalleriesPrivateApiTest() {} |
63 virtual ~MediaGalleriesPrivateApiTest() {} | 62 virtual ~MediaGalleriesPrivateApiTest() {} |
64 | 63 |
65 // ExtensionApiTest overrides. | 64 // ExtensionApiTest overrides. |
(...skipping 20 matching lines...) Expand all Loading... |
86 EXPECT_TRUE(listener.WaitUntilSatisfied()); | 85 EXPECT_TRUE(listener.WaitUntilSatisfied()); |
87 } | 86 } |
88 | 87 |
89 void AttachDetach() { | 88 void AttachDetach() { |
90 Attach(); | 89 Attach(); |
91 Detach(); | 90 Detach(); |
92 } | 91 } |
93 | 92 |
94 void Attach() { | 93 void Attach() { |
95 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); | 94 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); |
96 StorageInfo info(device_id_, base::ASCIIToUTF16(kDeviceName), kDevicePath, | 95 const StorageInfo info(device_id_, kDevicePath, |
97 base::string16(), base::string16(), base::string16(), 0); | 96 base::ASCIIToUTF16(kVolumeLabel), base::string16(), |
| 97 base::string16(), 0); |
98 StorageMonitor::GetInstance()->receiver()->ProcessAttach(info); | 98 StorageMonitor::GetInstance()->receiver()->ProcessAttach(info); |
99 content::RunAllPendingInMessageLoop(); | 99 content::RunAllPendingInMessageLoop(); |
100 } | 100 } |
101 | 101 |
102 void Detach() { | 102 void Detach() { |
103 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); | 103 DCHECK(StorageMonitor::GetInstance()->IsInitialized()); |
104 StorageMonitor::GetInstance()->receiver()->ProcessDetach(device_id_); | 104 StorageMonitor::GetInstance()->receiver()->ProcessDetach(device_id_); |
105 content::RunAllPendingInMessageLoop(); | 105 content::RunAllPendingInMessageLoop(); |
106 } | 106 } |
107 | 107 |
(...skipping 26 matching lines...) Expand all Loading... |
134 | 134 |
135 // No listeners, attach and detach a couple times. | 135 // No listeners, attach and detach a couple times. |
136 AttachDetach(); | 136 AttachDetach(); |
137 AttachDetach(); | 137 AttachDetach(); |
138 | 138 |
139 // Add attach listener. | 139 // Add attach listener. |
140 ChangeListener(host, kAddAttachListenerCmd, kAddAttachListenerOk); | 140 ChangeListener(host, kAddAttachListenerCmd, kAddAttachListenerOk); |
141 | 141 |
142 // Attach / detach | 142 // Attach / detach |
143 const std::string expect_attach_msg = | 143 const std::string expect_attach_msg = |
144 base::StringPrintf("%s,%s", kAttachTestOk, kDeviceName); | 144 base::StringPrintf("%s,%s", kAttachTestOk, kVolumeLabel); |
145 ExtensionTestMessageListener attach_finished_listener(expect_attach_msg, | 145 ExtensionTestMessageListener attach_finished_listener(expect_attach_msg, |
146 false /* no reply */); | 146 false /* no reply */); |
147 Attach(); | 147 Attach(); |
148 EXPECT_TRUE(attach_finished_listener.WaitUntilSatisfied()); | 148 EXPECT_TRUE(attach_finished_listener.WaitUntilSatisfied()); |
149 Detach(); | 149 Detach(); |
150 | 150 |
151 // Attach / detach | 151 // Attach / detach |
152 Attach(); | 152 Attach(); |
153 EXPECT_TRUE(attach_finished_listener.WaitUntilSatisfied()); | 153 EXPECT_TRUE(attach_finished_listener.WaitUntilSatisfied()); |
154 // Detach | 154 // Detach |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 Attach(); | 188 Attach(); |
189 EXPECT_TRUE(attach_finished_listener.WaitUntilSatisfied()); | 189 EXPECT_TRUE(attach_finished_listener.WaitUntilSatisfied()); |
190 Detach(); | 190 Detach(); |
191 EXPECT_TRUE(detach_finished_listener.WaitUntilSatisfied()); | 191 EXPECT_TRUE(detach_finished_listener.WaitUntilSatisfied()); |
192 | 192 |
193 Attach(); | 193 Attach(); |
194 EXPECT_TRUE(attach_finished_listener.WaitUntilSatisfied()); | 194 EXPECT_TRUE(attach_finished_listener.WaitUntilSatisfied()); |
195 Detach(); | 195 Detach(); |
196 EXPECT_TRUE(detach_finished_listener.WaitUntilSatisfied()); | 196 EXPECT_TRUE(detach_finished_listener.WaitUntilSatisfied()); |
197 } | 197 } |
OLD | NEW |