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

Side by Side Diff: cloud_print/virtual_driver/win/port_monitor/port_monitor_unittest.cc

Issue 12294008: Fix more remaining FilePath -> base::FilePath. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
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 "cloud_print/virtual_driver/win/port_monitor/port_monitor.h" 5 #include "cloud_print/virtual_driver/win/port_monitor/port_monitor.h"
6 #include <winspool.h> 6 #include <winspool.h>
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/path_service.h" 8 #include "base/path_service.h"
9 #include "base/string16.h" 9 #include "base/string16.h"
10 #include "base/win/registry.h" 10 #include "base/win/registry.h"
(...skipping 21 matching lines...) Expand all
32 public: 32 public:
33 PortMonitorTest() {} 33 PortMonitorTest() {}
34 protected: 34 protected:
35 // Creates a registry entry pointing at a chrome 35 // Creates a registry entry pointing at a chrome
36 virtual void SetUpChromeExeRegistry() { 36 virtual void SetUpChromeExeRegistry() {
37 // Create a temporary chrome.exe location value. 37 // Create a temporary chrome.exe location value.
38 base::win::RegKey key(HKEY_CURRENT_USER, 38 base::win::RegKey key(HKEY_CURRENT_USER,
39 cloud_print::kCloudPrintRegKey, 39 cloud_print::kCloudPrintRegKey,
40 KEY_ALL_ACCESS); 40 KEY_ALL_ACCESS);
41 41
42 FilePath path; 42 base::FilePath path;
43 PathService::Get(base::DIR_LOCAL_APP_DATA, &path); 43 PathService::Get(base::DIR_LOCAL_APP_DATA, &path);
44 path = path.Append(kAlternateChromeExePath); 44 path = path.Append(kAlternateChromeExePath);
45 ASSERT_EQ(ERROR_SUCCESS, 45 ASSERT_EQ(ERROR_SUCCESS,
46 key.WriteValue(cloud_print::kChromeExePathRegValue, 46 key.WriteValue(cloud_print::kChromeExePathRegValue,
47 path.value().c_str())); 47 path.value().c_str()));
48 FilePath temp; 48 base::FilePath temp;
49 PathService::Get(base::DIR_TEMP, &temp); 49 PathService::Get(base::DIR_TEMP, &temp);
50 // Write any dir here. 50 // Write any dir here.
51 ASSERT_EQ(ERROR_SUCCESS, 51 ASSERT_EQ(ERROR_SUCCESS,
52 key.WriteValue(cloud_print::kChromeProfilePathRegValue, 52 key.WriteValue(cloud_print::kChromeProfilePathRegValue,
53 temp.value().c_str())); 53 temp.value().c_str()));
54 } 54 }
55 // Deletes the registry entry created in SetUpChromeExeRegistry 55 // Deletes the registry entry created in SetUpChromeExeRegistry
56 virtual void DeleteChromeExeRegistry() { 56 virtual void DeleteChromeExeRegistry() {
57 base::win::RegKey key(HKEY_CURRENT_USER, 57 base::win::RegKey key(HKEY_CURRENT_USER,
58 cloud_print::kCloudPrintRegKey, 58 cloud_print::kCloudPrintRegKey,
59 KEY_ALL_ACCESS); 59 KEY_ALL_ACCESS);
60 key.DeleteValue(cloud_print::kChromeExePathRegValue); 60 key.DeleteValue(cloud_print::kChromeExePathRegValue);
61 key.DeleteValue(cloud_print::kChromeProfilePathRegValue); 61 key.DeleteValue(cloud_print::kChromeProfilePathRegValue);
62 } 62 }
63 63
64 virtual void CreateTempChromeExeFiles() { 64 virtual void CreateTempChromeExeFiles() {
65 FilePath path; 65 base::FilePath path;
66 PathService::Get(base::DIR_LOCAL_APP_DATA, &path); 66 PathService::Get(base::DIR_LOCAL_APP_DATA, &path);
67 FilePath main_path = path.Append(kChromeExePath); 67 base::FilePath main_path = path.Append(kChromeExePath);
68 ASSERT_TRUE(file_util::CreateDirectory(main_path)); 68 ASSERT_TRUE(file_util::CreateDirectory(main_path));
69 FilePath alternate_path = path.Append(kAlternateChromeExePath); 69 base::FilePath alternate_path = path.Append(kAlternateChromeExePath);
70 ASSERT_TRUE(file_util::CreateDirectory(alternate_path)); 70 ASSERT_TRUE(file_util::CreateDirectory(alternate_path));
71 } 71 }
72 72
73 virtual void DeleteTempChromeExeFiles() { 73 virtual void DeleteTempChromeExeFiles() {
74 FilePath path; 74 base::FilePath path;
75 PathService::Get(base::DIR_LOCAL_APP_DATA, &path); 75 PathService::Get(base::DIR_LOCAL_APP_DATA, &path);
76 FilePath main_path = path.Append(kChromeExePath); 76 base::FilePath main_path = path.Append(kChromeExePath);
77 ASSERT_TRUE(file_util::Delete(main_path, true)); 77 ASSERT_TRUE(file_util::Delete(main_path, true));
78 PathService::Get(base::DIR_LOCAL_APP_DATA, &path); 78 PathService::Get(base::DIR_LOCAL_APP_DATA, &path);
79 FilePath alternate_path = path.Append(kAlternateChromeExePath); 79 base::FilePath alternate_path = path.Append(kAlternateChromeExePath);
80 ASSERT_TRUE(file_util::Delete(alternate_path, true)); 80 ASSERT_TRUE(file_util::Delete(alternate_path, true));
81 } 81 }
82 82
83 protected: 83 protected:
84 virtual void SetUp() { 84 virtual void SetUp() {
85 SetUpChromeExeRegistry(); 85 SetUpChromeExeRegistry();
86 } 86 }
87 87
88 virtual void TearDown() { 88 virtual void TearDown() {
89 DeleteChromeExeRegistry(); 89 DeleteChromeExeRegistry();
90 } 90 }
91 91
92 private: 92 private:
93 DISALLOW_COPY_AND_ASSIGN(PortMonitorTest); 93 DISALLOW_COPY_AND_ASSIGN(PortMonitorTest);
94 }; 94 };
95 95
96 TEST_F(PortMonitorTest, GetChromeExePathTest) { 96 TEST_F(PortMonitorTest, GetChromeExePathTest) {
97 CreateTempChromeExeFiles(); 97 CreateTempChromeExeFiles();
98 FilePath chrome_path = cloud_print::GetChromeExePath(); 98 base::FilePath chrome_path = cloud_print::GetChromeExePath();
99 EXPECT_FALSE(chrome_path.empty()); 99 EXPECT_FALSE(chrome_path.empty());
100 EXPECT_TRUE( 100 EXPECT_TRUE(
101 chrome_path.value().rfind(kAlternateChromeExePath) != std::string::npos); 101 chrome_path.value().rfind(kAlternateChromeExePath) != std::string::npos);
102 EXPECT_TRUE(file_util::PathExists(chrome_path)); 102 EXPECT_TRUE(file_util::PathExists(chrome_path));
103 DeleteChromeExeRegistry(); 103 DeleteChromeExeRegistry();
104 chrome_path = cloud_print::GetChromeExePath(); 104 chrome_path = cloud_print::GetChromeExePath();
105 // No Chrome or regular chrome path. 105 // No Chrome or regular chrome path.
106 EXPECT_TRUE(chrome_path.empty() || 106 EXPECT_TRUE(chrome_path.empty() ||
107 chrome_path.value().rfind(kChromeExePath) == std::string::npos); 107 chrome_path.value().rfind(kChromeExePath) == std::string::npos);
108 } 108 }
109 109
110 TEST_F(PortMonitorTest, GetChromeProfilePathTest) { 110 TEST_F(PortMonitorTest, GetChromeProfilePathTest) {
111 FilePath data_path = cloud_print::GetChromeProfilePath(); 111 base::FilePath data_path = cloud_print::GetChromeProfilePath();
112 EXPECT_FALSE(data_path.empty()); 112 EXPECT_FALSE(data_path.empty());
113 FilePath temp; 113 base::FilePath temp;
114 PathService::Get(base::DIR_TEMP, &temp); 114 PathService::Get(base::DIR_TEMP, &temp);
115 EXPECT_EQ(data_path, temp); 115 EXPECT_EQ(data_path, temp);
116 EXPECT_TRUE(file_util::DirectoryExists(data_path)); 116 EXPECT_TRUE(file_util::DirectoryExists(data_path));
117 DeleteChromeExeRegistry(); 117 DeleteChromeExeRegistry();
118 data_path = cloud_print::GetChromeProfilePath(); 118 data_path = cloud_print::GetChromeProfilePath();
119 EXPECT_TRUE(data_path.empty()); 119 EXPECT_TRUE(data_path.empty());
120 } 120 }
121 121
122 TEST_F(PortMonitorTest, EnumPortsTest) { 122 TEST_F(PortMonitorTest, EnumPortsTest) {
123 DWORD needed_bytes = 0; 123 DWORD needed_bytes = 0;
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 EXPECT_TRUE(monitor2->pfnEndDocPort(port_handle)); 265 EXPECT_TRUE(monitor2->pfnEndDocPort(port_handle));
266 RevertToSelf(); 266 RevertToSelf();
267 EXPECT_TRUE(monitor2->pfnClosePort != NULL); 267 EXPECT_TRUE(monitor2->pfnClosePort != NULL);
268 EXPECT_TRUE(monitor2->pfnClosePort(port_handle)); 268 EXPECT_TRUE(monitor2->pfnClosePort(port_handle));
269 // Shutdown the port monitor. 269 // Shutdown the port monitor.
270 Monitor2Shutdown(monitor_handle); 270 Monitor2Shutdown(monitor_handle);
271 } 271 }
272 272
273 } // namespace cloud_print 273 } // namespace cloud_print
274 274
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698