[Android] Always use pixels for gestures handled in ContentViewCore
[chromium-blink-merge.git] / components / storage_monitor / test_portable_device_watcher_win.cc
blob5a85a25c99a904a91d7ee9f6342c9517ea48b1f1
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 //
5 // TestPortableDeviceWatcherWin implementation.
7 #include "components/storage_monitor/test_portable_device_watcher_win.h"
9 #include <vector>
11 #include "base/strings/utf_string_conversions.h"
13 namespace {
15 // Sample MTP device storage information.
16 const base::char16 kMTPDeviceFriendlyName[] = L"Camera V1.1";
17 const base::char16 kStorageLabelA[] = L"Camera V1.1 (s10001)";
18 const base::char16 kStorageLabelB[] = L"Camera V1.1 (s20001)";
19 const base::char16 kStorageObjectIdA[] = L"s10001";
20 const base::char16 kStorageObjectIdB[] = L"s20001";
21 const char kStorageUniqueIdB[] =
22 "mtp:StorageSerial:SID-{s20001, S, 2238}:123123";
24 // Returns the storage name of the device specified by |pnp_device_id|.
25 // |storage_object_id| specifies the string ID that uniquely identifies the
26 // object on the device.
27 base::string16 GetMTPStorageName(const base::string16& pnp_device_id,
28 const base::string16& storage_object_id) {
29 if (pnp_device_id == TestPortableDeviceWatcherWin::kMTPDeviceWithInvalidInfo)
30 return base::string16();
32 if (storage_object_id == kStorageObjectIdA)
33 return kStorageLabelA;
34 return (storage_object_id == kStorageObjectIdB) ?
35 kStorageLabelB : base::string16();
38 } // namespace
40 // TestPortableDeviceWatcherWin ------------------------------------------------
42 // static
43 const base::char16
44 TestPortableDeviceWatcherWin::kMTPDeviceWithMultipleStorages[] =
45 L"\\?\\usb#vid_ff&pid_18#32&2&1#{ab33-1de4-f22e-1882-9724})";
46 const base::char16 TestPortableDeviceWatcherWin::kMTPDeviceWithInvalidInfo[] =
47 L"\\?\\usb#vid_00&pid_00#0&2&1#{0000-0000-0000-0000-0000})";
48 const base::char16 TestPortableDeviceWatcherWin::kMTPDeviceWithValidInfo[] =
49 L"\\?\\usb#vid_ff&pid_000f#32&2&1#{abcd-1234-ffde-1112-9172})";
50 const char TestPortableDeviceWatcherWin::kStorageUniqueIdA[] =
51 "mtp:StorageSerial:SID-{s10001, D, 12378}:123123";
53 TestPortableDeviceWatcherWin::TestPortableDeviceWatcherWin()
54 : use_dummy_mtp_storage_info_(false) {
57 TestPortableDeviceWatcherWin::~TestPortableDeviceWatcherWin() {
60 // static
61 std::string TestPortableDeviceWatcherWin::GetMTPStorageUniqueId(
62 const base::string16& pnp_device_id,
63 const base::string16& storage_object_id) {
64 if (storage_object_id == kStorageObjectIdA)
65 return TestPortableDeviceWatcherWin::kStorageUniqueIdA;
66 return (storage_object_id == kStorageObjectIdB) ?
67 kStorageUniqueIdB : std::string();
70 // static
71 PortableDeviceWatcherWin::StorageObjectIDs
72 TestPortableDeviceWatcherWin::GetMTPStorageObjectIds(
73 const base::string16& pnp_device_id) {
74 PortableDeviceWatcherWin::StorageObjectIDs storage_object_ids;
75 storage_object_ids.push_back(kStorageObjectIdA);
76 if (pnp_device_id == kMTPDeviceWithMultipleStorages)
77 storage_object_ids.push_back(kStorageObjectIdB);
78 return storage_object_ids;
81 // static
82 void TestPortableDeviceWatcherWin::GetMTPStorageDetails(
83 const base::string16& pnp_device_id,
84 const base::string16& storage_object_id,
85 base::string16* device_location,
86 std::string* unique_id,
87 base::string16* name) {
88 std::string storage_unique_id = GetMTPStorageUniqueId(pnp_device_id,
89 storage_object_id);
90 if (device_location)
91 *device_location = base::UTF8ToUTF16("\\\\" + storage_unique_id);
93 if (unique_id)
94 *unique_id = storage_unique_id;
96 if (name)
97 *name = GetMTPStorageName(pnp_device_id, storage_object_id);
100 // static
101 PortableDeviceWatcherWin::StorageObjects
102 TestPortableDeviceWatcherWin::GetDeviceStorageObjects(
103 const base::string16& pnp_device_id) {
104 PortableDeviceWatcherWin::StorageObjects storage_objects;
105 PortableDeviceWatcherWin::StorageObjectIDs storage_object_ids =
106 GetMTPStorageObjectIds(pnp_device_id);
107 for (PortableDeviceWatcherWin::StorageObjectIDs::const_iterator it =
108 storage_object_ids.begin();
109 it != storage_object_ids.end(); ++it) {
110 storage_objects.push_back(DeviceStorageObject(
111 *it, GetMTPStorageUniqueId(pnp_device_id, *it)));
113 return storage_objects;
116 void TestPortableDeviceWatcherWin::EnumerateAttachedDevices() {
119 void TestPortableDeviceWatcherWin::HandleDeviceAttachEvent(
120 const base::string16& pnp_device_id) {
121 DeviceDetails device_details = {
122 (pnp_device_id != kMTPDeviceWithInvalidInfo) ?
123 kMTPDeviceFriendlyName : base::string16(),
124 pnp_device_id,
125 GetDeviceStorageObjects(pnp_device_id)
127 OnDidHandleDeviceAttachEvent(&device_details, true);
130 bool TestPortableDeviceWatcherWin::GetMTPStorageInfoFromDeviceId(
131 const std::string& storage_device_id,
132 base::string16* device_location,
133 base::string16* storage_object_id) const {
134 DCHECK(!storage_device_id.empty());
135 if (use_dummy_mtp_storage_info_) {
136 if (storage_device_id == TestPortableDeviceWatcherWin::kStorageUniqueIdA) {
137 *device_location = kMTPDeviceWithValidInfo;
138 *storage_object_id = kStorageObjectIdA;
139 return true;
141 return false;
143 return PortableDeviceWatcherWin::GetMTPStorageInfoFromDeviceId(
144 storage_device_id, device_location, storage_object_id);