Revert 168224 - Update V8 to version 3.15.4.
[chromium-blink-merge.git] / chrome / browser / system_monitor / media_device_notifications_utils_unittest.cc
blob389f157a90548f0a4db374f4757f4e5703b5d159
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
3 // found in the LICENSE file.
5 #include "chrome/browser/system_monitor/media_device_notifications_utils.h"
7 #include "base/file_path.h"
8 #include "base/file_util.h"
9 #include "base/message_loop.h"
10 #include "base/scoped_temp_dir.h"
11 #include "chrome/browser/system_monitor/removable_device_constants.h"
12 #include "content/public/test/test_browser_thread.h"
13 #include "testing/gtest/include/gtest/gtest.h"
15 namespace chrome {
17 using content::BrowserThread;
19 class MediaDeviceNotificationUtilsTest : public testing::Test {
20 public:
21 MediaDeviceNotificationUtilsTest()
22 : ui_thread_(BrowserThread::UI, &message_loop_),
23 file_thread_(BrowserThread::FILE) { }
24 virtual ~MediaDeviceNotificationUtilsTest() { }
26 // Verify mounted device type.
27 void checkDeviceType(const FilePath::StringType& mount_point,
28 bool expected_val) {
29 if (expected_val)
30 EXPECT_TRUE(IsMediaDevice(mount_point));
31 else
32 EXPECT_FALSE(IsMediaDevice(mount_point));
35 protected:
36 // Create mount point for the test device.
37 FilePath CreateMountPoint(bool create_dcim_dir) {
38 FilePath path(scoped_temp_dir_.path());
39 if (create_dcim_dir)
40 path = path.Append(kDCIMDirectoryName);
41 if (!file_util::CreateDirectory(path))
42 return FilePath();
43 return scoped_temp_dir_.path();
46 virtual void SetUp() OVERRIDE {
47 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir());
48 file_thread_.Start();
51 virtual void TearDown() {
52 WaitForFileThread();
55 static void PostQuitToUIThread() {
56 BrowserThread::PostTask(BrowserThread::UI,
57 FROM_HERE,
58 MessageLoop::QuitClosure());
61 static void WaitForFileThread() {
62 BrowserThread::PostTask(BrowserThread::FILE,
63 FROM_HERE,
64 base::Bind(&PostQuitToUIThread));
65 MessageLoop::current()->Run();
68 MessageLoop message_loop_;
70 private:
71 content::TestBrowserThread ui_thread_;
72 content::TestBrowserThread file_thread_;
73 ScopedTempDir scoped_temp_dir_;
76 // Test to verify that IsMediaDevice() function returns true for the given
77 // media device mount point.
78 TEST_F(MediaDeviceNotificationUtilsTest, MediaDeviceAttached) {
79 // Create a dummy mount point with DCIM Directory.
80 FilePath mount_point(CreateMountPoint(true));
81 BrowserThread::PostTask(
82 BrowserThread::FILE, FROM_HERE,
83 base::Bind(&MediaDeviceNotificationUtilsTest::checkDeviceType,
84 base::Unretained(this), mount_point.value(), true));
85 message_loop_.RunAllPending();
88 // Test to verify that IsMediaDevice() function returns false for a given
89 // non-media device mount point.
90 TEST_F(MediaDeviceNotificationUtilsTest, NonMediaDeviceAttached) {
91 // Create a dummy mount point without DCIM Directory.
92 FilePath mount_point(CreateMountPoint(false));
93 BrowserThread::PostTask(
94 BrowserThread::FILE, FROM_HERE,
95 base::Bind(&MediaDeviceNotificationUtilsTest::checkDeviceType,
96 base::Unretained(this), mount_point.value(), false));
97 message_loop_.RunAllPending();
100 } // namespace chrome