From f781782dd67077478e117c61dca4ea5eefce3544 Mon Sep 17 00:00:00 2001 From: "slightlyoff@chromium.org" Date: Thu, 24 Sep 2009 05:11:58 +0000 Subject: Initial import of the Chrome Frame codebase. Integration in chrome.gyp coming in a separate CL. BUG=None TEST=None Review URL: http://codereview.chromium.org/218019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27042 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome_frame/test_utils.cc | 95 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 chrome_frame/test_utils.cc (limited to 'chrome_frame/test_utils.cc') diff --git a/chrome_frame/test_utils.cc b/chrome_frame/test_utils.cc new file mode 100644 index 0000000..2d47c71 --- /dev/null +++ b/chrome_frame/test_utils.cc @@ -0,0 +1,95 @@ +// Copyright (c) 2009 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 "chrome_frame/test_utils.h" + +#include +#include + +#include "base/file_path.h" +#include "base/file_util.h" +#include "base/path_service.h" +#include "chrome/common/chrome_paths.h" +#include "testing/gtest/include/gtest/gtest.h" + +// Statics + +std::wstring ScopedChromeFrameRegistrar::GetChromeFrameBuildPath() { + std::wstring build_path; + PathService::Get(chrome::DIR_APP, &build_path); + file_util::AppendToPath(&build_path, L"servers\\npchrome_tab.dll"); + file_util::PathExists(build_path); + return build_path; +} + +void ScopedChromeFrameRegistrar::RegisterDefaults() { + std::wstring dll_path_ = GetChromeFrameBuildPath(); + RegisterAtPath(dll_path_); +} + +void ScopedChromeFrameRegistrar::RegisterAtPath( + const std::wstring& path) { + + ASSERT_FALSE(path.empty()); + HMODULE chrome_frame_dll_handle = LoadLibrary(path.c_str()); + ASSERT_TRUE(chrome_frame_dll_handle != NULL); + + typedef HRESULT (STDAPICALLTYPE* DllRegisterServerFn)(); + DllRegisterServerFn register_server = + reinterpret_cast(GetProcAddress( + chrome_frame_dll_handle, "DllRegisterServer")); + + ASSERT_TRUE(register_server != NULL); + EXPECT_HRESULT_SUCCEEDED((*register_server)()); + + DllRegisterServerFn register_npapi_server = + reinterpret_cast(GetProcAddress( + chrome_frame_dll_handle, "RegisterNPAPIPlugin")); + + if (register_npapi_server != NULL) + EXPECT_HRESULT_SUCCEEDED((*register_npapi_server)()); + + ASSERT_TRUE(FreeLibrary(chrome_frame_dll_handle)); +} + +// Non-statics + +ScopedChromeFrameRegistrar::ScopedChromeFrameRegistrar() { + original_dll_path_ = GetChromeFrameBuildPath(); + RegisterChromeFrameAtPath(original_dll_path_); +} + +ScopedChromeFrameRegistrar::~ScopedChromeFrameRegistrar() { + if (FilePath(original_dll_path_) != FilePath(new_chrome_frame_dll_path_)) { + RegisterChromeFrameAtPath(original_dll_path_); + } +} + +void ScopedChromeFrameRegistrar::RegisterChromeFrameAtPath( + const std::wstring& path) { + RegisterAtPath(path); + new_chrome_frame_dll_path_ = path; +} + +void ScopedChromeFrameRegistrar::RegisterReferenceChromeFrameBuild() { + std::wstring reference_build_dir; + ASSERT_TRUE(PathService::Get(chrome::DIR_APP, &reference_build_dir)); + + file_util::UpOneDirectory(&reference_build_dir); + file_util::UpOneDirectory(&reference_build_dir); + + file_util::AppendToPath(&reference_build_dir, L"chrome_frame"); + file_util::AppendToPath(&reference_build_dir, L"tools"); + file_util::AppendToPath(&reference_build_dir, L"test"); + file_util::AppendToPath(&reference_build_dir, L"reference_build"); + file_util::AppendToPath(&reference_build_dir, L"chrome"); + file_util::AppendToPath(&reference_build_dir, L"servers"); + file_util::AppendToPath(&reference_build_dir, L"npchrome_tab.dll"); + + RegisterChromeFrameAtPath(reference_build_dir); +} + +std::wstring ScopedChromeFrameRegistrar::GetChromeFrameDllPath() const { + return new_chrome_frame_dll_path_; +} -- cgit v1.1