Commit 0e3d869b authored by Hoch Hochkeppel's avatar Hoch Hochkeppel Committed by Commit Bot

WebShare: Centralize IsSupportedEnvironment for Windows Share tests

Centralizing the logic for checking for supported environments for
Windows Share related functionality. Also a small refactor to the
scoped_fake_data_transfer_manager_interop to make its initialization
explicit.

Bug: 1035527
Change-Id: Idee6f647745f95d415325a44856f09c5ff959af1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2495397Reviewed-by: default avatarEric Willigers <ericwilligers@chromium.org>
Commit-Queue: Hoch Hochkeppel <mhochk@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#820939}
parent 1285b168
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/win/core_winrt_util.h"
#include "base/win/windows_version.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
namespace webshare { namespace webshare {
...@@ -269,6 +271,15 @@ class FakeDataRequestedEventArgs ...@@ -269,6 +271,15 @@ class FakeDataRequestedEventArgs
} // namespace } // namespace
// static
bool FakeDataTransferManager::IsSupportedEnvironment() {
if (base::win::ResolveCoreWinRTDelayload() &&
base::win::ScopedHString::ResolveCoreWinRTStringDelayload())
return true;
EXPECT_LT(base::win::GetVersion(), base::win::Version::WIN8);
return false;
}
FakeDataTransferManager::FakeDataTransferManager() = default; FakeDataTransferManager::FakeDataTransferManager() = default;
FakeDataTransferManager::~FakeDataTransferManager() = default; FakeDataTransferManager::~FakeDataTransferManager() = default;
......
...@@ -19,6 +19,8 @@ class FakeDataTransferManager ...@@ -19,6 +19,8 @@ class FakeDataTransferManager
Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::WinRtClassicComMix>, Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::WinRtClassicComMix>,
ABI::Windows::ApplicationModel::DataTransfer::IDataTransferManager> { ABI::Windows::ApplicationModel::DataTransfer::IDataTransferManager> {
public: public:
static bool IsSupportedEnvironment();
FakeDataTransferManager(); FakeDataTransferManager();
FakeDataTransferManager(const FakeDataTransferManager&) = delete; FakeDataTransferManager(const FakeDataTransferManager&) = delete;
FakeDataTransferManager& operator=(const FakeDataTransferManager&) = delete; FakeDataTransferManager& operator=(const FakeDataTransferManager&) = delete;
......
...@@ -13,6 +13,11 @@ ...@@ -13,6 +13,11 @@
namespace webshare { namespace webshare {
// static
bool FakeDataTransferManagerInterop::IsSupportedEnvironment() {
return FakeDataTransferManager::IsSupportedEnvironment();
}
FakeDataTransferManagerInterop::FakeDataTransferManagerInterop() = default; FakeDataTransferManagerInterop::FakeDataTransferManagerInterop() = default;
FakeDataTransferManagerInterop::~FakeDataTransferManagerInterop() { FakeDataTransferManagerInterop::~FakeDataTransferManagerInterop() {
......
...@@ -47,6 +47,8 @@ class FakeDataTransferManagerInterop ...@@ -47,6 +47,8 @@ class FakeDataTransferManagerInterop
SucceedWithoutAction SucceedWithoutAction
}; };
static bool IsSupportedEnvironment();
FakeDataTransferManagerInterop(); FakeDataTransferManagerInterop();
FakeDataTransferManagerInterop(const FakeDataTransferManagerInterop&) = FakeDataTransferManagerInterop(const FakeDataTransferManagerInterop&) =
delete; delete;
......
...@@ -55,8 +55,7 @@ class DataRequestedTestCallback { ...@@ -55,8 +55,7 @@ class DataRequestedTestCallback {
class FakeDataTransferManagerInteropTest : public ::testing::Test { class FakeDataTransferManagerInteropTest : public ::testing::Test {
protected: protected:
bool IsSupportedEnvironment() { bool IsSupportedEnvironment() {
return base::win::ResolveCoreWinRTDelayload() && return FakeDataTransferManagerInterop::IsSupportedEnvironment();
base::win::ScopedHString::ResolveCoreWinRTStringDelayload();
} }
void SetUp() override { void SetUp() override {
......
...@@ -49,8 +49,7 @@ class DataRequestedTestCallback { ...@@ -49,8 +49,7 @@ class DataRequestedTestCallback {
class FakeDataTransferManagerTest : public ::testing::Test { class FakeDataTransferManagerTest : public ::testing::Test {
protected: protected:
bool IsSupportedEnvironment() { bool IsSupportedEnvironment() {
return base::win::ResolveCoreWinRTDelayload() && return FakeDataTransferManager::IsSupportedEnvironment();
base::win::ScopedHString::ResolveCoreWinRTStringDelayload();
} }
void SetUp() override { void SetUp() override {
......
...@@ -38,26 +38,25 @@ static HRESULT FakeRoGetActivationFactory(HSTRING class_id, ...@@ -38,26 +38,25 @@ static HRESULT FakeRoGetActivationFactory(HSTRING class_id,
} // namespace } // namespace
ScopedFakeDataTransferManagerInterop::ScopedFakeDataTransferManagerInterop() { // static
// Initialization work is done in an independent function so that the bool ScopedFakeDataTransferManagerInterop::IsSupportedEnvironment() {
// various test macros can be used. return FakeDataTransferManagerInterop::IsSupportedEnvironment();
Initialize();
} }
ScopedFakeDataTransferManagerInterop::ScopedFakeDataTransferManagerInterop() =
default;
ScopedFakeDataTransferManagerInterop::~ScopedFakeDataTransferManagerInterop() { ScopedFakeDataTransferManagerInterop::~ScopedFakeDataTransferManagerInterop() {
if (set_up_) {
g_current_fake_interop = nullptr; g_current_fake_interop = nullptr;
ShowShareUIForWindowOperation::SetRoGetActivationFactoryFunctionForTesting( ShowShareUIForWindowOperation::SetRoGetActivationFactoryFunctionForTesting(
&base::win::RoGetActivationFactory); &base::win::RoGetActivationFactory);
}
} }
FakeDataTransferManagerInterop& void ScopedFakeDataTransferManagerInterop::SetUp() {
ScopedFakeDataTransferManagerInterop::instance() { ASSERT_FALSE(set_up_);
return *(instance_.Get()); ASSERT_TRUE(IsSupportedEnvironment());
}
void ScopedFakeDataTransferManagerInterop::Initialize() {
ASSERT_TRUE(base::win::ResolveCoreWinRTDelayload());
ASSERT_TRUE(base::win::ScopedHString::ResolveCoreWinRTStringDelayload());
base::win::AssertComInitialized(); base::win::AssertComInitialized();
instance_ = Microsoft::WRL::Make<FakeDataTransferManagerInterop>(); instance_ = Microsoft::WRL::Make<FakeDataTransferManagerInterop>();
...@@ -68,6 +67,14 @@ void ScopedFakeDataTransferManagerInterop::Initialize() { ...@@ -68,6 +67,14 @@ void ScopedFakeDataTransferManagerInterop::Initialize() {
g_current_fake_interop = instance_.Get(); g_current_fake_interop = instance_.Get();
ShowShareUIForWindowOperation::SetRoGetActivationFactoryFunctionForTesting( ShowShareUIForWindowOperation::SetRoGetActivationFactoryFunctionForTesting(
&FakeRoGetActivationFactory); &FakeRoGetActivationFactory);
set_up_ = true;
}
FakeDataTransferManagerInterop&
ScopedFakeDataTransferManagerInterop::instance() {
EXPECT_TRUE(set_up_);
return *(instance_.Get());
} }
} // namespace webshare } // namespace webshare
...@@ -16,6 +16,8 @@ class FakeDataTransferManagerInterop; ...@@ -16,6 +16,8 @@ class FakeDataTransferManagerInterop;
// for the Share contract. // for the Share contract.
class ScopedFakeDataTransferManagerInterop { class ScopedFakeDataTransferManagerInterop {
public: public:
static bool IsSupportedEnvironment();
ScopedFakeDataTransferManagerInterop(); ScopedFakeDataTransferManagerInterop();
ScopedFakeDataTransferManagerInterop( ScopedFakeDataTransferManagerInterop(
const ScopedFakeDataTransferManagerInterop&) = delete; const ScopedFakeDataTransferManagerInterop&) = delete;
...@@ -23,11 +25,15 @@ class ScopedFakeDataTransferManagerInterop { ...@@ -23,11 +25,15 @@ class ScopedFakeDataTransferManagerInterop {
const ScopedFakeDataTransferManagerInterop&) = delete; const ScopedFakeDataTransferManagerInterop&) = delete;
~ScopedFakeDataTransferManagerInterop(); ~ScopedFakeDataTransferManagerInterop();
// Initializes this component, creating test failures if anything does not
// succeed. Intended to be called from a test's SetUp function, after having
// verified this is a supported environment.
void SetUp();
FakeDataTransferManagerInterop& instance(); FakeDataTransferManagerInterop& instance();
private: private:
void Initialize(); bool set_up_ = false;
Microsoft::WRL::ComPtr<FakeDataTransferManagerInterop> instance_; Microsoft::WRL::ComPtr<FakeDataTransferManagerInterop> instance_;
}; };
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include "chrome/browser/webshare/win/fake_data_transfer_manager_interop.h" #include "chrome/browser/webshare/win/fake_data_transfer_manager_interop.h"
#include "chrome/browser/webshare/win/scoped_fake_data_transfer_manager_interop.h" #include "chrome/browser/webshare/win/scoped_fake_data_transfer_manager_interop.h"
#include "content/public/test/browser_task_environment.h" #include "content/public/test/browser_task_environment.h"
#include "testing/gtest/include/gtest/gtest-spi.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using ABI::Windows::ApplicationModel::DataTransfer::IDataRequest; using ABI::Windows::ApplicationModel::DataTransfer::IDataRequest;
...@@ -40,14 +41,13 @@ class ShowShareUIForWindowOperationTest : public ::testing::Test { ...@@ -40,14 +41,13 @@ class ShowShareUIForWindowOperationTest : public ::testing::Test {
enum TestCallbackState { NotRun = 0, RunWithoutValue, RunWithValue }; enum TestCallbackState { NotRun = 0, RunWithoutValue, RunWithValue };
bool IsSupportedEnvironment() { bool IsSupportedEnvironment() {
return base::win::ResolveCoreWinRTDelayload() && return ScopedFakeDataTransferManagerInterop::IsSupportedEnvironment();
base::win::ScopedHString::ResolveCoreWinRTStringDelayload();
} }
void SetUp() override { void SetUp() override {
if (!IsSupportedEnvironment()) if (!IsSupportedEnvironment())
return; return;
scoped_interop_ = std::make_unique<ScopedFakeDataTransferManagerInterop>(); ASSERT_NO_FATAL_FAILURE(scoped_interop_.SetUp());
auto weak_ptr = weak_factory_.GetWeakPtr(); auto weak_ptr = weak_factory_.GetWeakPtr();
test_callback_ = base::BindOnce( test_callback_ = base::BindOnce(
[](base::WeakPtr<ShowShareUIForWindowOperationTest> weak_ptr, [](base::WeakPtr<ShowShareUIForWindowOperationTest> weak_ptr,
...@@ -71,11 +71,11 @@ class ShowShareUIForWindowOperationTest : public ::testing::Test { ...@@ -71,11 +71,11 @@ class ShowShareUIForWindowOperationTest : public ::testing::Test {
} }
FakeDataTransferManagerInterop& fake_interop() { FakeDataTransferManagerInterop& fake_interop() {
return scoped_interop_->instance(); return scoped_interop_.instance();
} }
const HWND hwnd_ = reinterpret_cast<HWND>(1); const HWND hwnd_ = reinterpret_cast<HWND>(1);
std::unique_ptr<ScopedFakeDataTransferManagerInterop> scoped_interop_; ScopedFakeDataTransferManagerInterop scoped_interop_;
content::BrowserTaskEnvironment task_environment_{ content::BrowserTaskEnvironment task_environment_{
base::test::TaskEnvironment::TimeSource::MOCK_TIME}; base::test::TaskEnvironment::TimeSource::MOCK_TIME};
DataRequestedCallback test_callback_; DataRequestedCallback test_callback_;
......
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