blob: 741d5417161cfcf948cb2cf4bcc31ff30bcf5cf5 [file] [log] [blame]
[email protected]bcd840c2010-05-27 10:43:001// Copyright (c) 2010 The Chromium Authors. All rights reserved.
[email protected]f7817822009-09-24 05:11:582// 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]a1800e82009-11-19 00:53:2310#include <atlbase.h>
11#include <atlcom.h>
12
[email protected]66ff7352009-10-15 05:09:5013#include "base/file_path.h"
14
[email protected]ea9ed97d2010-01-05 19:16:2315extern const wchar_t kChromeFrameDllName[];
[email protected]43c698f2010-05-01 01:38:5916extern const wchar_t kChromeLauncherExeName[];
[email protected]ea9ed97d2010-01-05 19:16:2317
[email protected]f7817822009-09-24 05:11:5818// Helper class used to register different chrome frame DLLs while running
[email protected]39b3349e2010-02-24 18:54:1219// tests. The default constructor registers the DLL found in the build path.
20
[email protected]f7817822009-09-24 05:11:5821// 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.
26class ScopedChromeFrameRegistrar {
27 public:
28 ScopedChromeFrameRegistrar();
[email protected]39b3349e2010-02-24 18:54:1229 ScopedChromeFrameRegistrar(const std::wstring& path);
[email protected]f7817822009-09-24 05:11:5830 virtual ~ScopedChromeFrameRegistrar();
31
32 void RegisterChromeFrameAtPath(const std::wstring& path);
[email protected]43c698f2010-05-01 01:38:5933 void UnegisterChromeFrameAtPath(const std::wstring& path);
[email protected]f7817822009-09-24 05:11:5834 void RegisterReferenceChromeFrameBuild();
35
36 std::wstring GetChromeFrameDllPath() const;
37
[email protected]66ff7352009-10-15 05:09:5038 static FilePath GetChromeFrameBuildPath();
[email protected]f7817822009-09-24 05:11:5839 static void RegisterAtPath(const std::wstring& path);
[email protected]43c698f2010-05-01 01:38:5940 static void UnregisterAtPath(const std::wstring& path);
[email protected]f7817822009-09-24 05:11:5841 static void RegisterDefaults();
[email protected]bcd840c2010-05-27 10:43:0042 static FilePath GetReferenceChromeFrameDllPath();
[email protected]f7817822009-09-24 05:11:5843
44 private:
[email protected]ea9ed97d2010-01-05 19:16:2345 // Contains the path of the most recently registered Chrome Frame DLL.
[email protected]f7817822009-09-24 05:11:5846 std::wstring new_chrome_frame_dll_path_;
47
[email protected]ea9ed97d2010-01-05 19:16:2348 // Contains the path of the Chrome Frame DLL to be registered at destruction.
[email protected]f7817822009-09-24 05:11:5849 std::wstring original_dll_path_;
50};
51
[email protected]a1800e82009-11-19 00:53:2352// Callback description for onload, onloaderror, onmessage
53static _ATL_FUNC_INFO g_single_param = {CC_STDCALL, VT_EMPTY, 1, {VT_VARIANT}};
54// Simple class that forwards the callbacks.
55template <typename T>
56class 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_)(&param);
77 }
78
79 IDispatch* ToDispatch() {
80 return reinterpret_cast<IDispatch*>(this);
81 }
82
83 T* owner_;
84 Method method_;
85};
86
[email protected]0b5a2f82009-12-07 21:20:1987// 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.
90bool KillAllNamedProcessesWithArgument(const std::wstring& process_name,
91 const std::wstring& argument);
92
[email protected]a1800e82009-11-19 00:53:2393
[email protected]f7817822009-09-24 05:11:5894#endif // CHROME_FRAME_TEST_UTILS_H_