OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome_frame/test_utils.h" |
| 6 |
| 7 #include <atlbase.h> |
| 8 #include <atlwin.h> |
| 9 |
| 10 #include "base/file_path.h" |
| 11 #include "base/file_util.h" |
| 12 #include "base/path_service.h" |
| 13 #include "chrome/common/chrome_paths.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 |
| 16 // Statics |
| 17 |
| 18 std::wstring ScopedChromeFrameRegistrar::GetChromeFrameBuildPath() { |
| 19 std::wstring build_path; |
| 20 PathService::Get(chrome::DIR_APP, &build_path); |
| 21 file_util::AppendToPath(&build_path, L"servers\\npchrome_tab.dll"); |
| 22 file_util::PathExists(build_path); |
| 23 return build_path; |
| 24 } |
| 25 |
| 26 void ScopedChromeFrameRegistrar::RegisterDefaults() { |
| 27 std::wstring dll_path_ = GetChromeFrameBuildPath(); |
| 28 RegisterAtPath(dll_path_); |
| 29 } |
| 30 |
| 31 void ScopedChromeFrameRegistrar::RegisterAtPath( |
| 32 const std::wstring& path) { |
| 33 |
| 34 ASSERT_FALSE(path.empty()); |
| 35 HMODULE chrome_frame_dll_handle = LoadLibrary(path.c_str()); |
| 36 ASSERT_TRUE(chrome_frame_dll_handle != NULL); |
| 37 |
| 38 typedef HRESULT (STDAPICALLTYPE* DllRegisterServerFn)(); |
| 39 DllRegisterServerFn register_server = |
| 40 reinterpret_cast<DllRegisterServerFn>(GetProcAddress( |
| 41 chrome_frame_dll_handle, "DllRegisterServer")); |
| 42 |
| 43 ASSERT_TRUE(register_server != NULL); |
| 44 EXPECT_HRESULT_SUCCEEDED((*register_server)()); |
| 45 |
| 46 DllRegisterServerFn register_npapi_server = |
| 47 reinterpret_cast<DllRegisterServerFn>(GetProcAddress( |
| 48 chrome_frame_dll_handle, "RegisterNPAPIPlugin")); |
| 49 |
| 50 if (register_npapi_server != NULL) |
| 51 EXPECT_HRESULT_SUCCEEDED((*register_npapi_server)()); |
| 52 |
| 53 ASSERT_TRUE(FreeLibrary(chrome_frame_dll_handle)); |
| 54 } |
| 55 |
| 56 // Non-statics |
| 57 |
| 58 ScopedChromeFrameRegistrar::ScopedChromeFrameRegistrar() { |
| 59 original_dll_path_ = GetChromeFrameBuildPath(); |
| 60 RegisterChromeFrameAtPath(original_dll_path_); |
| 61 } |
| 62 |
| 63 ScopedChromeFrameRegistrar::~ScopedChromeFrameRegistrar() { |
| 64 if (FilePath(original_dll_path_) != FilePath(new_chrome_frame_dll_path_)) { |
| 65 RegisterChromeFrameAtPath(original_dll_path_); |
| 66 } |
| 67 } |
| 68 |
| 69 void ScopedChromeFrameRegistrar::RegisterChromeFrameAtPath( |
| 70 const std::wstring& path) { |
| 71 RegisterAtPath(path); |
| 72 new_chrome_frame_dll_path_ = path; |
| 73 } |
| 74 |
| 75 void ScopedChromeFrameRegistrar::RegisterReferenceChromeFrameBuild() { |
| 76 std::wstring reference_build_dir; |
| 77 ASSERT_TRUE(PathService::Get(chrome::DIR_APP, &reference_build_dir)); |
| 78 |
| 79 file_util::UpOneDirectory(&reference_build_dir); |
| 80 file_util::UpOneDirectory(&reference_build_dir); |
| 81 |
| 82 file_util::AppendToPath(&reference_build_dir, L"chrome_frame"); |
| 83 file_util::AppendToPath(&reference_build_dir, L"tools"); |
| 84 file_util::AppendToPath(&reference_build_dir, L"test"); |
| 85 file_util::AppendToPath(&reference_build_dir, L"reference_build"); |
| 86 file_util::AppendToPath(&reference_build_dir, L"chrome"); |
| 87 file_util::AppendToPath(&reference_build_dir, L"servers"); |
| 88 file_util::AppendToPath(&reference_build_dir, L"npchrome_tab.dll"); |
| 89 |
| 90 RegisterChromeFrameAtPath(reference_build_dir); |
| 91 } |
| 92 |
| 93 std::wstring ScopedChromeFrameRegistrar::GetChromeFrameDllPath() const { |
| 94 return new_chrome_frame_dll_path_; |
| 95 } |
OLD | NEW |