[email protected] | bcd840c | 2010-05-27 10:43:00 | [diff] [blame^] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_FRAME_TEST_UTILS_H_ |
| 6 | #define CHROME_FRAME_TEST_UTILS_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 10 | #include <atlbase.h> |
| 11 | #include <atlcom.h> |
| 12 | |
[email protected] | 66ff735 | 2009-10-15 05:09:50 | [diff] [blame] | 13 | #include "base/file_path.h" |
| 14 | |
[email protected] | ea9ed97d | 2010-01-05 19:16:23 | [diff] [blame] | 15 | extern const wchar_t kChromeFrameDllName[]; |
[email protected] | 43c698f | 2010-05-01 01:38:59 | [diff] [blame] | 16 | extern const wchar_t kChromeLauncherExeName[]; |
[email protected] | ea9ed97d | 2010-01-05 19:16:23 | [diff] [blame] | 17 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 18 | // Helper class used to register different chrome frame DLLs while running |
[email protected] | 39b3349e | 2010-02-24 18:54:12 | [diff] [blame] | 19 | // tests. The default constructor registers the DLL found in the build path. |
| 20 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 21 | // At destruction, again registers the DLL found in the build path if another |
| 22 | // DLL has since been registered. Triggers GTEST asserts on failure. |
| 23 | // |
| 24 | // TODO(robertshield): Ideally, make this class restore the originally |
| 25 | // registered chrome frame DLL (e.g. by looking in HKCR) on destruction. |
| 26 | class ScopedChromeFrameRegistrar { |
| 27 | public: |
| 28 | ScopedChromeFrameRegistrar(); |
[email protected] | 39b3349e | 2010-02-24 18:54:12 | [diff] [blame] | 29 | ScopedChromeFrameRegistrar(const std::wstring& path); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 30 | virtual ~ScopedChromeFrameRegistrar(); |
| 31 | |
| 32 | void RegisterChromeFrameAtPath(const std::wstring& path); |
[email protected] | 43c698f | 2010-05-01 01:38:59 | [diff] [blame] | 33 | void UnegisterChromeFrameAtPath(const std::wstring& path); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 34 | void RegisterReferenceChromeFrameBuild(); |
| 35 | |
| 36 | std::wstring GetChromeFrameDllPath() const; |
| 37 | |
[email protected] | 66ff735 | 2009-10-15 05:09:50 | [diff] [blame] | 38 | static FilePath GetChromeFrameBuildPath(); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 39 | static void RegisterAtPath(const std::wstring& path); |
[email protected] | 43c698f | 2010-05-01 01:38:59 | [diff] [blame] | 40 | static void UnregisterAtPath(const std::wstring& path); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 41 | static void RegisterDefaults(); |
[email protected] | bcd840c | 2010-05-27 10:43:00 | [diff] [blame^] | 42 | static FilePath GetReferenceChromeFrameDllPath(); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 43 | |
| 44 | private: |
[email protected] | ea9ed97d | 2010-01-05 19:16:23 | [diff] [blame] | 45 | // Contains the path of the most recently registered Chrome Frame DLL. |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 46 | std::wstring new_chrome_frame_dll_path_; |
| 47 | |
[email protected] | ea9ed97d | 2010-01-05 19:16:23 | [diff] [blame] | 48 | // Contains the path of the Chrome Frame DLL to be registered at destruction. |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 49 | std::wstring original_dll_path_; |
| 50 | }; |
| 51 | |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 52 | // Callback description for onload, onloaderror, onmessage |
| 53 | static _ATL_FUNC_INFO g_single_param = {CC_STDCALL, VT_EMPTY, 1, {VT_VARIANT}}; |
| 54 | // Simple class that forwards the callbacks. |
| 55 | template <typename T> |
| 56 | class DispCallback |
| 57 | : public IDispEventSimpleImpl<1, DispCallback<T>, &IID_IDispatch> { |
| 58 | public: |
| 59 | typedef HRESULT (T::*Method)(const VARIANT* param); |
| 60 | |
| 61 | DispCallback(T* owner, Method method) : owner_(owner), method_(method) { |
| 62 | } |
| 63 | |
| 64 | BEGIN_SINK_MAP(DispCallback) |
| 65 | SINK_ENTRY_INFO(1, IID_IDispatch, DISPID_VALUE, OnCallback, &g_single_param) |
| 66 | END_SINK_MAP() |
| 67 | |
| 68 | virtual ULONG STDMETHODCALLTYPE AddRef() { |
| 69 | return owner_->AddRef(); |
| 70 | } |
| 71 | virtual ULONG STDMETHODCALLTYPE Release() { |
| 72 | return owner_->Release(); |
| 73 | } |
| 74 | |
| 75 | STDMETHOD(OnCallback)(VARIANT param) { |
| 76 | return (owner_->*method_)(¶m); |
| 77 | } |
| 78 | |
| 79 | IDispatch* ToDispatch() { |
| 80 | return reinterpret_cast<IDispatch*>(this); |
| 81 | } |
| 82 | |
| 83 | T* owner_; |
| 84 | Method method_; |
| 85 | }; |
| 86 | |
[email protected] | 0b5a2f8 | 2009-12-07 21:20:19 | [diff] [blame] | 87 | // Kills all running processes named |process_name| that have the string |
| 88 | // |argument| on their command line. Useful for killing all Chrome Frame |
| 89 | // instances of Chrome that all have --chrome-frame in their command line. |
| 90 | bool KillAllNamedProcessesWithArgument(const std::wstring& process_name, |
| 91 | const std::wstring& argument); |
| 92 | |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 93 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 94 | #endif // CHROME_FRAME_TEST_UTILS_H_ |