diff options
author | slightlyoff@chromium.org <slightlyoff@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-24 05:11:58 +0000 |
---|---|---|
committer | slightlyoff@chromium.org <slightlyoff@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-24 05:11:58 +0000 |
commit | f781782dd67077478e117c61dca4ea5eefce3544 (patch) | |
tree | 4801f724123cfdcbb69c4e7fe40a565b331723ae /chrome_frame/test_utils.cc | |
parent | 63cf4759efa2373e33436fb5df6849f930081226 (diff) | |
download | chromium_src-f781782dd67077478e117c61dca4ea5eefce3544.zip chromium_src-f781782dd67077478e117c61dca4ea5eefce3544.tar.gz chromium_src-f781782dd67077478e117c61dca4ea5eefce3544.tar.bz2 |
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
Diffstat (limited to 'chrome_frame/test_utils.cc')
-rw-r--r-- | chrome_frame/test_utils.cc | 95 |
1 files changed, 95 insertions, 0 deletions
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 <atlbase.h> +#include <atlwin.h> + +#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<DllRegisterServerFn>(GetProcAddress( + chrome_frame_dll_handle, "DllRegisterServer")); + + ASSERT_TRUE(register_server != NULL); + EXPECT_HRESULT_SUCCEEDED((*register_server)()); + + DllRegisterServerFn register_npapi_server = + reinterpret_cast<DllRegisterServerFn>(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_; +} |