Commit 8ddf2391 authored by Joel Hockey's avatar Joel Hockey Committed by Commit Bot

Add exo TestFileHelper test utility

Refactor some duplicated code in a number of unit tests into a shared
test helper.

Bug: 1144138
Change-Id: I03b2b5eeb75b636014b60a683501d6f2498bf405
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2517403
Commit-Queue: Joel Hockey <joelhockey@chromium.org>
Reviewed-by: default avatarMitsuru Oshima <oshima@chromium.org>
Cr-Commit-Position: refs/heads/master@{#824220}
parent 3f3e178f
...@@ -224,6 +224,8 @@ source_set("test_support") { ...@@ -224,6 +224,8 @@ source_set("test_support") {
sources += [ sources += [
"test/exo_test_base.cc", "test/exo_test_base.cc",
"test/exo_test_base.h", "test/exo_test_base.h",
"test/exo_test_file_helper.cc",
"test/exo_test_file_helper.h",
"test/exo_test_helper.cc", "test/exo_test_helper.cc",
"test/exo_test_helper.h", "test/exo_test_helper.h",
] ]
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "components/exo/seat.h" #include "components/exo/seat.h"
#include "components/exo/surface.h" #include "components/exo/surface.h"
#include "components/exo/test/exo_test_base.h" #include "components/exo/test/exo_test_base.h"
#include "components/exo/test/exo_test_file_helper.h"
#include "components/exo/test/exo_test_helper.h" #include "components/exo/test/exo_test_helper.h"
#include "ui/aura/client/focus_client.h" #include "ui/aura/client/focus_client.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h" #include "ui/base/clipboard/scoped_clipboard_writer.h"
...@@ -107,26 +108,6 @@ class TestDataDeviceDelegate : public DataDeviceDelegate { ...@@ -107,26 +108,6 @@ class TestDataDeviceDelegate : public DataDeviceDelegate {
DISALLOW_COPY_AND_ASSIGN(TestDataDeviceDelegate); DISALLOW_COPY_AND_ASSIGN(TestDataDeviceDelegate);
}; };
class TestFileHelper : public FileHelper {
public:
TestFileHelper() = default;
// Overridden from FileHelper:
std::string GetMimeTypeForUriList() const override { return ""; }
bool GetUrlFromPath(const std::string& app_id,
const base::FilePath& path,
GURL* out) override {
return true;
}
bool HasUrlsInPickle(const base::Pickle& pickle) override { return false; }
void GetUrlsFromPickle(const std::string& app_id,
const base::Pickle& pickle,
UrlsFromPickleCallback callback) override {}
private:
DISALLOW_COPY_AND_ASSIGN(TestFileHelper);
};
class TestSeat : public Seat { class TestSeat : public Seat {
public: public:
TestSeat() {} TestSeat() {}
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "components/exo/data_offer_delegate.h" #include "components/exo/data_offer_delegate.h"
#include "components/exo/file_helper.h" #include "components/exo/file_helper.h"
#include "components/exo/test/exo_test_base.h" #include "components/exo/test/exo_test_base.h"
#include "components/exo/test/exo_test_file_helper.h"
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h" #include "ui/base/clipboard/scoped_clipboard_writer.h"
#include "ui/base/dragdrop/os_exchange_data.h" #include "ui/base/dragdrop/os_exchange_data.h"
...@@ -70,35 +71,6 @@ class TestDataOfferDelegate : public DataOfferDelegate { ...@@ -70,35 +71,6 @@ class TestDataOfferDelegate : public DataOfferDelegate {
DISALLOW_COPY_AND_ASSIGN(TestDataOfferDelegate); DISALLOW_COPY_AND_ASSIGN(TestDataOfferDelegate);
}; };
class TestFileHelper : public FileHelper {
public:
TestFileHelper() = default;
// Overridden from FileHelper:
std::string GetMimeTypeForUriList() const override { return "text/uri-list"; }
bool GetUrlFromPath(const std::string& app_id,
const base::FilePath& path,
GURL* out) override {
*out = GURL("file://" + path.AsUTF8Unsafe());
return true;
}
bool HasUrlsInPickle(const base::Pickle& pickle) override { return true; }
void GetUrlsFromPickle(const std::string& app_id,
const base::Pickle& pickle,
UrlsFromPickleCallback callback) override {
callback_ = std::move(callback);
}
void RunUrlsCallback(std::vector<GURL> urls) {
std::move(callback_).Run(urls);
}
private:
UrlsFromPickleCallback callback_;
DISALLOW_COPY_AND_ASSIGN(TestFileHelper);
};
bool ReadString(base::ScopedFD fd, std::string* out) { bool ReadString(base::ScopedFD fd, std::string* out) {
std::array<char, 128> buffer; std::array<char, 128> buffer;
char* it = buffer.begin(); char* it = buffer.begin();
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "components/exo/sub_surface.h" #include "components/exo/sub_surface.h"
#include "components/exo/surface.h" #include "components/exo/surface.h"
#include "components/exo/test/exo_test_base.h" #include "components/exo/test/exo_test_base.h"
#include "components/exo/test/exo_test_file_helper.h"
#include "components/exo/toast_surface_manager.h" #include "components/exo/toast_surface_manager.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -224,22 +225,6 @@ class TestDataDeviceDelegate : public DataDeviceDelegate { ...@@ -224,22 +225,6 @@ class TestDataDeviceDelegate : public DataDeviceDelegate {
} }
}; };
class TestFileHelper : public FileHelper {
public:
// Overriden from TestFileHelper:
TestFileHelper() {}
std::string GetMimeTypeForUriList() const override { return ""; }
bool GetUrlFromPath(const std::string& app_id,
const base::FilePath& path,
GURL* out) override {
return true;
}
bool HasUrlsInPickle(const base::Pickle& pickle) override { return false; }
void GetUrlsFromPickle(const std::string& app_id,
const base::Pickle& pickle,
UrlsFromPickleCallback callback) override {}
};
TEST_F(DisplayTest, CreateDataDevice) { TEST_F(DisplayTest, CreateDataDevice) {
TestDataDeviceDelegate device_delegate; TestDataDeviceDelegate device_delegate;
Display display(nullptr, nullptr, nullptr, Display display(nullptr, nullptr, nullptr,
......
...@@ -6,11 +6,15 @@ ...@@ -6,11 +6,15 @@
#define COMPONENTS_EXO_FILE_HELPER_H_ #define COMPONENTS_EXO_FILE_HELPER_H_
#include <string> #include <string>
#include <vector>
#include "base/callback.h"
class GURL; class GURL;
namespace base { namespace base {
class FilePath; class FilePath;
class Pickle;
} }
namespace exo { namespace exo {
......
// Copyright 2020 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 "components/exo/test/exo_test_file_helper.h"
#include <string>
#include <utility>
#include "base/callback.h"
#include "base/files/file_path.h"
#include "url/gurl.h"
namespace exo {
TestFileHelper::TestFileHelper() = default;
TestFileHelper::~TestFileHelper() = default;
std::string TestFileHelper::GetMimeTypeForUriList() const {
return "text/uri-list";
}
bool TestFileHelper::GetUrlFromPath(const std::string& app_id,
const base::FilePath& path,
GURL* out) {
*out = GURL("file://" + path.value());
return true;
}
bool TestFileHelper::HasUrlsInPickle(const base::Pickle& pickle) {
return true;
}
void TestFileHelper::GetUrlsFromPickle(const std::string& app_id,
const base::Pickle& pickle,
UrlsFromPickleCallback callback) {
urls_callback_ = std::move(callback);
}
void TestFileHelper::RunUrlsCallback(std::vector<GURL> urls) {
std::move(urls_callback_).Run(urls);
}
} // namespace exo
// Copyright 2020 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.
#ifndef COMPONENTS_EXO_TEST_EXO_TEST_FILE_HELPER_H_
#define COMPONENTS_EXO_TEST_EXO_TEST_FILE_HELPER_H_
#include "components/exo/file_helper.h"
namespace exo {
class TestFileHelper : public FileHelper {
public:
TestFileHelper();
TestFileHelper(const TestFileHelper&) = delete;
TestFileHelper& operator=(const TestFileHelper&) = delete;
~TestFileHelper() override;
// FileHelper:
std::string GetMimeTypeForUriList() const override;
bool GetUrlFromPath(const std::string& app_id,
const base::FilePath& path,
GURL* out) override;
bool HasUrlsInPickle(const base::Pickle& pickle) override;
void GetUrlsFromPickle(const std::string& app_id,
const base::Pickle& pickle,
UrlsFromPickleCallback callback) override;
void RunUrlsCallback(std::vector<GURL> urls);
private:
UrlsFromPickleCallback urls_callback_;
};
} // namespace exo
#endif // COMPONENTS_EXO_TEST_EXO_TEST_FILE_HELPER_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment