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

Side by Side Diff: chrome/browser/storage_monitor/media_storage_util_unittest.cc

Issue 16703025: [StorageMonitor] Move StorageMonitor ownership to BrowserProcessImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 7 years, 5 months 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 unified diff | Download patch
OLDNEW
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 <string> 5 #include <string>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "base/synchronization/waitable_event.h" 11 #include "base/synchronization/waitable_event.h"
12 #include "chrome/browser/storage_monitor/media_storage_util.h" 12 #include "chrome/browser/storage_monitor/media_storage_util.h"
13 #include "chrome/browser/storage_monitor/removable_device_constants.h" 13 #include "chrome/browser/storage_monitor/removable_device_constants.h"
14 #include "chrome/browser/storage_monitor/storage_monitor.h" 14 #include "chrome/browser/storage_monitor/storage_monitor.h"
15 #include "chrome/browser/storage_monitor/test_storage_monitor.h" 15 #include "chrome/browser/storage_monitor/test_storage_monitor.h"
16 #include "chrome/test/base/testing_browser_process.h"
16 #include "content/public/browser/browser_thread.h" 17 #include "content/public/browser/browser_thread.h"
17 #include "content/public/test/test_browser_thread.h" 18 #include "content/public/test/test_browser_thread.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 20
20 namespace chrome { 21 namespace chrome {
21 22
22 namespace { 23 namespace {
23 24
24 const char kImageCaptureDeviceId[] = "ic:xyz"; 25 const char kImageCaptureDeviceId[] = "ic:xyz";
25 26
(...skipping 14 matching lines...) Expand all
40 if (expected_val) 41 if (expected_val)
41 EXPECT_TRUE(MediaStorageUtil::HasDcim(mount_point)); 42 EXPECT_TRUE(MediaStorageUtil::HasDcim(mount_point));
42 else 43 else
43 EXPECT_FALSE(MediaStorageUtil::HasDcim(mount_point)); 44 EXPECT_FALSE(MediaStorageUtil::HasDcim(mount_point));
44 } 45 }
45 46
46 void ProcessAttach(const std::string& id, 47 void ProcessAttach(const std::string& id,
47 const string16& name, 48 const string16& name,
48 const base::FilePath::StringType& location) { 49 const base::FilePath::StringType& location) {
49 StorageInfo info(id, name, location, string16(), string16(), string16(), 0); 50 StorageInfo info(id, name, location, string16(), string16(), string16(), 0);
50 monitor_.receiver()->ProcessAttach(info); 51 monitor_->receiver()->ProcessAttach(info);
51 } 52 }
52 53
53 protected: 54 protected:
54 // Create mount point for the test device. 55 // Create mount point for the test device.
55 base::FilePath CreateMountPoint(bool create_dcim_dir) { 56 base::FilePath CreateMountPoint(bool create_dcim_dir) {
56 base::FilePath path(scoped_temp_dir_.path()); 57 base::FilePath path(scoped_temp_dir_.path());
57 if (create_dcim_dir) 58 if (create_dcim_dir)
58 path = path.Append(kDCIMDirectoryName); 59 path = path.Append(kDCIMDirectoryName);
59 if (!file_util::CreateDirectory(path)) 60 if (!file_util::CreateDirectory(path))
60 return base::FilePath(); 61 return base::FilePath();
61 return scoped_temp_dir_.path(); 62 return scoped_temp_dir_.path();
62 } 63 }
63 64
64 virtual void SetUp() OVERRIDE { 65 virtual void SetUp() OVERRIDE {
66 monitor_ = chrome::test::TestStorageMonitor::Create();
vandebo (ex-Chrome) 2013/07/10 16:57:45 leak?
Greg Billock 2013/07/10 21:11:16 no
65 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir()); 67 ASSERT_TRUE(scoped_temp_dir_.CreateUniqueTempDir());
66 file_thread_.Start(); 68 file_thread_.Start();
67 } 69 }
68 70
69 virtual void TearDown() { 71 virtual void TearDown() OVERRIDE {
70 WaitForFileThread(); 72 WaitForFileThread();
71 } 73 }
72 74
73 static void PostQuitToUIThread() { 75 static void PostQuitToUIThread() {
74 BrowserThread::PostTask(BrowserThread::UI, 76 BrowserThread::PostTask(BrowserThread::UI,
75 FROM_HERE, 77 FROM_HERE,
76 base::MessageLoop::QuitClosure()); 78 base::MessageLoop::QuitClosure());
77 } 79 }
78 80
79 static void WaitForFileThread() { 81 static void WaitForFileThread() {
80 BrowserThread::PostTask(BrowserThread::FILE, 82 BrowserThread::PostTask(BrowserThread::FILE,
81 FROM_HERE, 83 FROM_HERE,
82 base::Bind(&PostQuitToUIThread)); 84 base::Bind(&PostQuitToUIThread));
83 base::MessageLoop::current()->Run(); 85 base::MessageLoop::current()->Run();
84 } 86 }
85 87
86 base::MessageLoop message_loop_; 88 base::MessageLoop message_loop_;
87 89
88 private: 90 private:
89 chrome::test::TestStorageMonitor monitor_; 91 // Weak pointer to TestingBrowserProcess-owned storage monitor.
vandebo (ex-Chrome) 2013/07/10 16:57:45 not weak ptr
Greg Billock 2013/07/10 21:11:16 Done.
92 chrome::test::TestStorageMonitor* monitor_;
90 content::TestBrowserThread ui_thread_; 93 content::TestBrowserThread ui_thread_;
91 content::TestBrowserThread file_thread_; 94 content::TestBrowserThread file_thread_;
92 base::ScopedTempDir scoped_temp_dir_; 95 base::ScopedTempDir scoped_temp_dir_;
93 }; 96 };
94 97
95 // Test to verify that HasDcim() function returns true for the given media 98 // Test to verify that HasDcim() function returns true for the given media
96 // device mount point. 99 // device mount point.
97 TEST_F(MediaStorageUtilTest, MediaDeviceAttached) { 100 TEST_F(MediaStorageUtilTest, MediaDeviceAttached) {
98 // Create a dummy mount point with DCIM Directory. 101 // Create a dummy mount point with DCIM Directory.
99 base::FilePath mount_point(CreateMountPoint(true)); 102 base::FilePath mount_point(CreateMountPoint(true));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 event.Reset(); 150 event.Reset();
148 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, 151 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE,
149 base::Bind(&MediaStorageUtil::FilterAttachedDevices, 152 base::Bind(&MediaStorageUtil::FilterAttachedDevices,
150 base::Unretained(&devices), signal_event)); 153 base::Unretained(&devices), signal_event));
151 event.Wait(); 154 event.Wait();
152 155
153 EXPECT_TRUE(devices.find(kImageCaptureDeviceId) != devices.end()); 156 EXPECT_TRUE(devices.find(kImageCaptureDeviceId) != devices.end());
154 } 157 }
155 158
156 } // namespace chrome 159 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698