Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2829)

Unified Diff: chrome/browser/system_monitor/removable_device_notifications_window_win_unittest.cc

Issue 11297002: [Media Gallery] Added code to support mtp device media file system on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed DCHECK, added lock in PortableDeviceWatcherWin and fixed tests. Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/system_monitor/removable_device_notifications_window_win_unittest.cc
diff --git a/chrome/browser/system_monitor/removable_device_notifications_window_win_unittest.cc b/chrome/browser/system_monitor/removable_device_notifications_window_win_unittest.cc
index 88f770c69458a02377a1a64dee826ab81b5be791..628d0de788c3cda080e903e9d039a90cfa00a81f 100644
--- a/chrome/browser/system_monitor/removable_device_notifications_window_win_unittest.cc
+++ b/chrome/browser/system_monitor/removable_device_notifications_window_win_unittest.cc
@@ -9,13 +9,17 @@
#include <string>
#include <vector>
+#include "base/bind.h"
#include "base/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
+#include "base/sequenced_task_runner.h"
+#include "base/synchronization/waitable_event.h"
#include "base/system_monitor/system_monitor.h"
#include "base/test/mock_devices_changed_observer.h"
+#include "base/threading/sequenced_worker_pool.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/system_monitor/media_storage_util.h"
#include "chrome/browser/system_monitor/portable_device_watcher_win.h"
@@ -326,13 +330,30 @@ class RemovableDeviceNotificationsWindowWinTest : public testing::Test {
// |test_attach|) and tests that the appropriate handler is called.
void DoMTPDeviceTest(const string16& pnp_device_id, bool test_attach);
+ // Gets the MTP details of the storage specified by the |storage_device_id|.
+ // On success, returns true and fills in |pnp_device_id| and
+ // |storage_object_id|.
+ bool GetMTPStorageInfo(const std::string& storage_device_id,
+ string16* pnp_device_id,
+ string16* storage_object_id);
+
+ scoped_ptr<TestRemovableDeviceNotificationsWindowWin> window_;
+
+ private:
+ // Gets the MTP details of the storage on the blocking pool thread.
+ void GetMTPStorageInfoOnBlockingThread(const std::string& storage_device_id,
+ string16* pnp_device_id,
+ string16* storage_object_id,
+ bool* result,
+ base::WaitableEvent* completion);
+
MessageLoopForUI message_loop_;
content::TestBrowserThread ui_thread_;
content::TestBrowserThread file_thread_;
+ scoped_refptr<base::SequencedTaskRunner> blocking_task_runner_;
base::SystemMonitor system_monitor_;
base::MockDevicesChangedObserver observer_;
- scoped_ptr<TestRemovableDeviceNotificationsWindowWin> window_;
scoped_refptr<TestVolumeMountWatcherWin> volume_mount_watcher_;
};
@@ -351,6 +372,10 @@ void RemovableDeviceNotificationsWindowWinTest::SetUp() {
volume_mount_watcher_ = new TestVolumeMountWatcherWin;
window_.reset(new TestRemovableDeviceNotificationsWindowWin(
volume_mount_watcher_.get(), new TestPortableDeviceWatcherWin));
+ scoped_refptr<base::SequencedWorkerPool> pool =
+ content::BrowserThread::GetBlockingPool();
+ blocking_task_runner_ =
+ pool->GetSequencedTaskRunner(pool->GetSequenceToken());
window_->InitWithTestData(false);
RunUntilIdle();
system_monitor_.AddDevicesChangedObserver(&observer_);
@@ -491,6 +516,39 @@ void RemovableDeviceNotificationsWindowWinTest::DoMTPDeviceTest(
RunUntilIdle();
}
+bool RemovableDeviceNotificationsWindowWinTest::GetMTPStorageInfo(
+ const std::string& storage_device_id,
+ string16* pnp_device_id,
+ string16* storage_object_id) {
+ base::WaitableEvent completion(false, false);
+ bool result = false;
+ blocking_task_runner_->PostTask(
+ FROM_HERE,
+ base::Bind(&RemovableDeviceNotificationsWindowWinTest::
+ GetMTPStorageInfoOnBlockingThread,
+ base::Unretained(this),
+ storage_device_id,
+ pnp_device_id,
+ storage_object_id,
+ &result,
+ &completion));
+ completion.Wait();
+ return result;
+}
+
+void RemovableDeviceNotificationsWindowWinTest::
+ GetMTPStorageInfoOnBlockingThread(
+ const std::string& storage_device_id,
+ string16* pnp_device_id,
+ string16* storage_object_id,
+ bool* result,
+ base::WaitableEvent* completion) {
+ *result = window_->GetMTPStorageInfoFromDeviceId(storage_device_id,
+ pnp_device_id,
+ storage_object_id);
+ completion->Signal();
+}
+
TEST_F(RemovableDeviceNotificationsWindowWinTest, RandomMessage) {
window_->InjectDeviceChange(DBT_DEVICEQUERYREMOVE, NULL);
RunUntilIdle();
@@ -642,4 +700,24 @@ TEST_F(RemovableDeviceNotificationsWindowWinTest,
DoMTPDeviceTest(kMTPDeviceWithMultipleStorageObjects, false);
}
+// Given a MTP storage persistent id, GetMTPStorageInfo() should fetch the
+// device interface path and local storage object identifier.
+TEST_F(RemovableDeviceNotificationsWindowWinTest, GetMTPStorageInfo) {
+ DoMTPDeviceTest(kMTPDeviceWithValidInfo, true);
+ PortableDeviceWatcherWin::StorageObjects storage_objects =
+ GetDeviceStorageObjects(kMTPDeviceWithValidInfo);
+ for (PortableDeviceWatcherWin::StorageObjects::const_iterator it =
+ storage_objects.begin(); it != storage_objects.end(); ++it) {
+ string16 pnp_device_id;
+ string16 storage_object_id;
+ ASSERT_TRUE(GetMTPStorageInfo(it->object_persistent_id, &pnp_device_id,
+ &storage_object_id));
+ EXPECT_EQ(kMTPDeviceWithValidInfo, pnp_device_id);
+ EXPECT_EQ(it->object_persistent_id,
+ GetMTPStorageUniqueId(pnp_device_id, storage_object_id));
+ }
+
+ DoMTPDeviceTest(kMTPDeviceWithValidInfo, false);
+}
+
} // namespace chrome

Powered by Google App Engine
This is Rietveld 408576698