[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] | 864b136 | 2010-08-19 03:49:38 | [diff] [blame] | 13 | class FilePath; |
[email protected] | 66ff735 | 2009-10-15 05:09:50 | [diff] [blame] | 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: |
[email protected] | cf5912b | 2011-02-01 22:20:44 | [diff] [blame] | 28 | enum RegistrationType { |
| 29 | PER_USER, |
| 30 | SYSTEM_LEVEL, |
| 31 | }; |
| 32 | |
| 33 | explicit ScopedChromeFrameRegistrar(RegistrationType registration_type); |
| 34 | ScopedChromeFrameRegistrar(const std::wstring& path, |
| 35 | RegistrationType registration_type); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 36 | virtual ~ScopedChromeFrameRegistrar(); |
| 37 | |
| 38 | void RegisterChromeFrameAtPath(const std::wstring& path); |
[email protected] | 43c698f | 2010-05-01 01:38:59 | [diff] [blame] | 39 | void UnegisterChromeFrameAtPath(const std::wstring& path); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 40 | void RegisterReferenceChromeFrameBuild(); |
| 41 | |
| 42 | std::wstring GetChromeFrameDllPath() const; |
| 43 | |
[email protected] | cf5912b | 2011-02-01 22:20:44 | [diff] [blame] | 44 | static void RegisterAtPath(const std::wstring& path, |
| 45 | RegistrationType registration_type); |
| 46 | static void UnregisterAtPath(const std::wstring& path, |
| 47 | RegistrationType registration_type); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 48 | static void RegisterDefaults(); |
[email protected] | bcd840c | 2010-05-27 10:43:00 | [diff] [blame] | 49 | static FilePath GetReferenceChromeFrameDllPath(); |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 50 | |
| 51 | private: |
[email protected] | ea9ed97d | 2010-01-05 19:16:23 | [diff] [blame] | 52 | // Contains the path of the most recently registered Chrome Frame DLL. |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 53 | std::wstring new_chrome_frame_dll_path_; |
| 54 | |
[email protected] | ea9ed97d | 2010-01-05 19:16:23 | [diff] [blame] | 55 | // Contains the path of the Chrome Frame DLL to be registered at destruction. |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 56 | std::wstring original_dll_path_; |
[email protected] | cf5912b | 2011-02-01 22:20:44 | [diff] [blame] | 57 | |
| 58 | // Indicates whether per user or per machine registration is needed. |
| 59 | RegistrationType registration_type_; |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 60 | }; |
| 61 | |
[email protected] | 87ba2e60 | 2011-03-01 02:25:11 | [diff] [blame^] | 62 | // Returns the path to the Chrome Frame DLL in the build directory. Assumes |
| 63 | // that the test executable is running from the build folder or a similar |
| 64 | // folder structure. |
| 65 | FilePath GetChromeFrameBuildPath(); |
| 66 | |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 67 | // Callback description for onload, onloaderror, onmessage |
| 68 | static _ATL_FUNC_INFO g_single_param = {CC_STDCALL, VT_EMPTY, 1, {VT_VARIANT}}; |
| 69 | // Simple class that forwards the callbacks. |
| 70 | template <typename T> |
| 71 | class DispCallback |
| 72 | : public IDispEventSimpleImpl<1, DispCallback<T>, &IID_IDispatch> { |
| 73 | public: |
| 74 | typedef HRESULT (T::*Method)(const VARIANT* param); |
| 75 | |
| 76 | DispCallback(T* owner, Method method) : owner_(owner), method_(method) { |
| 77 | } |
| 78 | |
| 79 | BEGIN_SINK_MAP(DispCallback) |
| 80 | SINK_ENTRY_INFO(1, IID_IDispatch, DISPID_VALUE, OnCallback, &g_single_param) |
| 81 | END_SINK_MAP() |
| 82 | |
| 83 | virtual ULONG STDMETHODCALLTYPE AddRef() { |
| 84 | return owner_->AddRef(); |
| 85 | } |
| 86 | virtual ULONG STDMETHODCALLTYPE Release() { |
| 87 | return owner_->Release(); |
| 88 | } |
| 89 | |
| 90 | STDMETHOD(OnCallback)(VARIANT param) { |
| 91 | return (owner_->*method_)(¶m); |
| 92 | } |
| 93 | |
| 94 | IDispatch* ToDispatch() { |
| 95 | return reinterpret_cast<IDispatch*>(this); |
| 96 | } |
| 97 | |
| 98 | T* owner_; |
| 99 | Method method_; |
| 100 | }; |
| 101 | |
[email protected] | 0b5a2f8 | 2009-12-07 21:20:19 | [diff] [blame] | 102 | // Kills all running processes named |process_name| that have the string |
| 103 | // |argument| on their command line. Useful for killing all Chrome Frame |
| 104 | // instances of Chrome that all have --chrome-frame in their command line. |
| 105 | bool KillAllNamedProcessesWithArgument(const std::wstring& process_name, |
| 106 | const std::wstring& argument); |
| 107 | |
[email protected] | 58d58c7b | 2010-11-05 23:34:03 | [diff] [blame] | 108 | // If the workstation is locked and cannot receive user input. |
| 109 | bool IsWorkstationLocked(); |
[email protected] | a1800e8 | 2009-11-19 00:53:23 | [diff] [blame] | 110 | |
[email protected] | f781782 | 2009-09-24 05:11:58 | [diff] [blame] | 111 | #endif // CHROME_FRAME_TEST_UTILS_H_ |