Initialize all data members in HTTPResponseInfo's new ctor and remove the related...
[chromium-blink-merge.git] / chrome_frame / test_utils.h
blob741d5417161cfcf948cb2cf4bcc31ff30bcf5cf5
1 // Copyright (c) 2010 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.
5 #ifndef CHROME_FRAME_TEST_UTILS_H_
6 #define CHROME_FRAME_TEST_UTILS_H_
8 #include <string>
10 #include <atlbase.h>
11 #include <atlcom.h>
13 #include "base/file_path.h"
15 extern const wchar_t kChromeFrameDllName[];
16 extern const wchar_t kChromeLauncherExeName[];
18 // Helper class used to register different chrome frame DLLs while running
19 // tests. The default constructor registers the DLL found in the build path.
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.
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();
29 ScopedChromeFrameRegistrar(const std::wstring& path);
30 virtual ~ScopedChromeFrameRegistrar();
32 void RegisterChromeFrameAtPath(const std::wstring& path);
33 void UnegisterChromeFrameAtPath(const std::wstring& path);
34 void RegisterReferenceChromeFrameBuild();
36 std::wstring GetChromeFrameDllPath() const;
38 static FilePath GetChromeFrameBuildPath();
39 static void RegisterAtPath(const std::wstring& path);
40 static void UnregisterAtPath(const std::wstring& path);
41 static void RegisterDefaults();
42 static FilePath GetReferenceChromeFrameDllPath();
44 private:
45 // Contains the path of the most recently registered Chrome Frame DLL.
46 std::wstring new_chrome_frame_dll_path_;
48 // Contains the path of the Chrome Frame DLL to be registered at destruction.
49 std::wstring original_dll_path_;
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);
61 DispCallback(T* owner, Method method) : owner_(owner), method_(method) {
64 BEGIN_SINK_MAP(DispCallback)
65 SINK_ENTRY_INFO(1, IID_IDispatch, DISPID_VALUE, OnCallback, &g_single_param)
66 END_SINK_MAP()
68 virtual ULONG STDMETHODCALLTYPE AddRef() {
69 return owner_->AddRef();
71 virtual ULONG STDMETHODCALLTYPE Release() {
72 return owner_->Release();
75 STDMETHOD(OnCallback)(VARIANT param) {
76 return (owner_->*method_)(&param);
79 IDispatch* ToDispatch() {
80 return reinterpret_cast<IDispatch*>(this);
83 T* owner_;
84 Method method_;
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);
94 #endif // CHROME_FRAME_TEST_UTILS_H_