Add CefScopedTempDir and file utility functions for unit tests (issue #1632)

This commit is contained in:
Marshall Greenblatt
2016-11-15 12:56:02 -05:00
parent a7195c0103
commit 04642e0480
22 changed files with 1539 additions and 194 deletions

View File

@@ -12,6 +12,8 @@
#include "include/cef_app.h"
#include "include/capi/cef_app_capi.h"
#include "include/cef_file_util.h"
#include "include/capi/cef_file_util_capi.h"
#include "include/cef_geolocation.h"
#include "include/capi/cef_geolocation_capi.h"
#include "include/cef_origin_whitelist.h"
@@ -387,6 +389,147 @@ CEF_EXPORT void cef_enable_highdpi_support() {
CefEnableHighDPISupport();
}
CEF_EXPORT int cef_create_directory(const cef_string_t* full_path) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: full_path; type: string_byref_const
DCHECK(full_path);
if (!full_path)
return 0;
// Execute
bool _retval = CefCreateDirectory(
CefString(full_path));
// Return type: bool
return _retval;
}
CEF_EXPORT int cef_get_temp_directory(cef_string_t* temp_dir) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: temp_dir; type: string_byref
DCHECK(temp_dir);
if (!temp_dir)
return 0;
// Translate param: temp_dir; type: string_byref
CefString temp_dirStr(temp_dir);
// Execute
bool _retval = CefGetTempDirectory(
temp_dirStr);
// Return type: bool
return _retval;
}
CEF_EXPORT int cef_create_new_temp_directory(const cef_string_t* prefix,
cef_string_t* new_temp_path) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: new_temp_path; type: string_byref
DCHECK(new_temp_path);
if (!new_temp_path)
return 0;
// Unverified params: prefix
// Translate param: new_temp_path; type: string_byref
CefString new_temp_pathStr(new_temp_path);
// Execute
bool _retval = CefCreateNewTempDirectory(
CefString(prefix),
new_temp_pathStr);
// Return type: bool
return _retval;
}
CEF_EXPORT int cef_create_temp_directory_in_directory(
const cef_string_t* base_dir, const cef_string_t* prefix,
cef_string_t* new_dir) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: base_dir; type: string_byref_const
DCHECK(base_dir);
if (!base_dir)
return 0;
// Verify param: new_dir; type: string_byref
DCHECK(new_dir);
if (!new_dir)
return 0;
// Unverified params: prefix
// Translate param: new_dir; type: string_byref
CefString new_dirStr(new_dir);
// Execute
bool _retval = CefCreateTempDirectoryInDirectory(
CefString(base_dir),
CefString(prefix),
new_dirStr);
// Return type: bool
return _retval;
}
CEF_EXPORT int cef_directory_exists(const cef_string_t* path) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: path; type: string_byref_const
DCHECK(path);
if (!path)
return 0;
// Execute
bool _retval = CefDirectoryExists(
CefString(path));
// Return type: bool
return _retval;
}
CEF_EXPORT int cef_delete_file(const cef_string_t* path, int recursive) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: path; type: string_byref_const
DCHECK(path);
if (!path)
return 0;
// Execute
bool _retval = CefDeleteFile(
CefString(path),
recursive?true:false);
// Return type: bool
return _retval;
}
CEF_EXPORT int cef_zip_directory(const cef_string_t* src_dir,
const cef_string_t* dest_file, int include_hidden_files) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: src_dir; type: string_byref_const
DCHECK(src_dir);
if (!src_dir)
return 0;
// Verify param: dest_file; type: string_byref_const
DCHECK(dest_file);
if (!dest_file)
return 0;
// Execute
bool _retval = CefZipDirectory(
CefString(src_dir),
CefString(dest_file),
include_hidden_files?true:false);
// Return type: bool
return _retval;
}
CEF_EXPORT int cef_get_geolocation(
struct _cef_get_geolocation_callback_t* callback) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING

View File

@@ -0,0 +1,87 @@
// Copyright 2016 The Chromium Embedded Framework Authors. Portions copyright
// 2011 The Chromium Authors. All rights reserved. Use of this source code is
// governed by a BSD-style license that can be found in the LICENSE file.
#include "include/wrapper/cef_scoped_temp_dir.h"
#include "include/base/cef_logging.h"
#include "include/cef_file_util.h"
CefScopedTempDir::CefScopedTempDir() {
}
CefScopedTempDir::~CefScopedTempDir() {
if (!path_.empty() && !Delete())
DLOG(WARNING) << "Could not delete temp dir in dtor.";
}
bool CefScopedTempDir::CreateUniqueTempDir() {
if (!path_.empty())
return false;
// This "scoped_dir" prefix is only used on Windows and serves as a template
// for the unique name.
if (!CefCreateNewTempDirectory("scoped_dir", path_))
return false;
return true;
}
bool CefScopedTempDir::CreateUniqueTempDirUnderPath(
const CefString& base_path) {
if (!path_.empty())
return false;
// If |base_path| does not exist, create it.
if (!CefCreateDirectory(base_path))
return false;
// Create a new, uniquely named directory under |base_path|.
if (!CefCreateTempDirectoryInDirectory(base_path, "scoped_dir_", path_))
return false;
return true;
}
bool CefScopedTempDir::Set(const CefString& path) {
if (!path_.empty())
return false;
if (!CefDirectoryExists(path) && !CefCreateDirectory(path))
return false;
path_ = path;
return true;
}
bool CefScopedTempDir::Delete() {
if (path_.empty())
return false;
bool ret = CefDeleteFile(path_, true);
if (ret) {
// We only clear the path if deleted the directory.
path_.clear();
}
return ret;
}
CefString CefScopedTempDir::Take() {
CefString ret = path_;
path_.clear();
return ret;
}
const CefString& CefScopedTempDir::GetPath() const {
DCHECK(!path_.empty()) << "Did you call CreateUniqueTempDir* before?";
return path_;
}
bool CefScopedTempDir::IsEmpty() const {
return path_.empty();
}
bool CefScopedTempDir::IsValid() const {
return !path_.empty() && CefDirectoryExists(path_);
}

View File

@@ -12,6 +12,8 @@
#include "include/cef_app.h"
#include "include/capi/cef_app_capi.h"
#include "include/cef_file_util.h"
#include "include/capi/cef_file_util_capi.h"
#include "include/cef_geolocation.h"
#include "include/capi/cef_geolocation_capi.h"
#include "include/cef_origin_whitelist.h"
@@ -379,6 +381,124 @@ CEF_GLOBAL void CefEnableHighDPISupport() {
cef_enable_highdpi_support();
}
CEF_GLOBAL bool CefCreateDirectory(const CefString& full_path) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: full_path; type: string_byref_const
DCHECK(!full_path.empty());
if (full_path.empty())
return false;
// Execute
int _retval = cef_create_directory(
full_path.GetStruct());
// Return type: bool
return _retval?true:false;
}
CEF_GLOBAL bool CefGetTempDirectory(CefString& temp_dir) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Execute
int _retval = cef_get_temp_directory(
temp_dir.GetWritableStruct());
// Return type: bool
return _retval?true:false;
}
CEF_GLOBAL bool CefCreateNewTempDirectory(const CefString& prefix,
CefString& new_temp_path) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Unverified params: prefix
// Execute
int _retval = cef_create_new_temp_directory(
prefix.GetStruct(),
new_temp_path.GetWritableStruct());
// Return type: bool
return _retval?true:false;
}
CEF_GLOBAL bool CefCreateTempDirectoryInDirectory(const CefString& base_dir,
const CefString& prefix, CefString& new_dir) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: base_dir; type: string_byref_const
DCHECK(!base_dir.empty());
if (base_dir.empty())
return false;
// Unverified params: prefix
// Execute
int _retval = cef_create_temp_directory_in_directory(
base_dir.GetStruct(),
prefix.GetStruct(),
new_dir.GetWritableStruct());
// Return type: bool
return _retval?true:false;
}
CEF_GLOBAL bool CefDirectoryExists(const CefString& path) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: path; type: string_byref_const
DCHECK(!path.empty());
if (path.empty())
return false;
// Execute
int _retval = cef_directory_exists(
path.GetStruct());
// Return type: bool
return _retval?true:false;
}
CEF_GLOBAL bool CefDeleteFile(const CefString& path, bool recursive) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: path; type: string_byref_const
DCHECK(!path.empty());
if (path.empty())
return false;
// Execute
int _retval = cef_delete_file(
path.GetStruct(),
recursive);
// Return type: bool
return _retval?true:false;
}
CEF_GLOBAL bool CefZipDirectory(const CefString& src_dir,
const CefString& dest_file, bool include_hidden_files) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: src_dir; type: string_byref_const
DCHECK(!src_dir.empty());
if (src_dir.empty())
return false;
// Verify param: dest_file; type: string_byref_const
DCHECK(!dest_file.empty());
if (dest_file.empty())
return false;
// Execute
int _retval = cef_zip_directory(
src_dir.GetStruct(),
dest_file.GetStruct(),
include_hidden_files);
// Return type: bool
return _retval?true:false;
}
CEF_GLOBAL bool CefGetGeolocation(
CefRefPtr<CefGetGeolocationCallback> callback) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING