blob: 260b4b522f98d636d4715bcf664b36a1ac6fb08c [file] [log] [blame]
[email protected]f7817822009-09-24 05:11:581// 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#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]f7817822009-09-24 05:11:5815// Helper class used to register different chrome frame DLLs while running
16// tests. At construction, this registers the DLL found in the build path.
17// At destruction, again registers the DLL found in the build path if another
18// DLL has since been registered. Triggers GTEST asserts on failure.
19//
20// TODO(robertshield): Ideally, make this class restore the originally
21// registered chrome frame DLL (e.g. by looking in HKCR) on destruction.
22class ScopedChromeFrameRegistrar {
23 public:
24 ScopedChromeFrameRegistrar();
25 virtual ~ScopedChromeFrameRegistrar();
26
27 void RegisterChromeFrameAtPath(const std::wstring& path);
28 void RegisterReferenceChromeFrameBuild();
29
30 std::wstring GetChromeFrameDllPath() const;
31
[email protected]66ff7352009-10-15 05:09:5032 static FilePath GetChromeFrameBuildPath();
[email protected]f7817822009-09-24 05:11:5833 static void RegisterAtPath(const std::wstring& path);
34 static void RegisterDefaults();
35
36 private:
37 // Contains the path of the most recently registered npchrome_tab.dll.
38 std::wstring new_chrome_frame_dll_path_;
39
40 // Contains the path of the npchrome_tab.dll to be registered at destruction.
41 std::wstring original_dll_path_;
42};
43
[email protected]a1800e82009-11-19 00:53:2344// Callback description for onload, onloaderror, onmessage
45static _ATL_FUNC_INFO g_single_param = {CC_STDCALL, VT_EMPTY, 1, {VT_VARIANT}};
46// Simple class that forwards the callbacks.
47template <typename T>
48class DispCallback
49 : public IDispEventSimpleImpl<1, DispCallback<T>, &IID_IDispatch> {
50 public:
51 typedef HRESULT (T::*Method)(const VARIANT* param);
52
53 DispCallback(T* owner, Method method) : owner_(owner), method_(method) {
54 }
55
56 BEGIN_SINK_MAP(DispCallback)
57 SINK_ENTRY_INFO(1, IID_IDispatch, DISPID_VALUE, OnCallback, &g_single_param)
58 END_SINK_MAP()
59
60 virtual ULONG STDMETHODCALLTYPE AddRef() {
61 return owner_->AddRef();
62 }
63 virtual ULONG STDMETHODCALLTYPE Release() {
64 return owner_->Release();
65 }
66
67 STDMETHOD(OnCallback)(VARIANT param) {
68 return (owner_->*method_)(&param);
69 }
70
71 IDispatch* ToDispatch() {
72 return reinterpret_cast<IDispatch*>(this);
73 }
74
75 T* owner_;
76 Method method_;
77};
78
79
[email protected]f7817822009-09-24 05:11:5880#endif // CHROME_FRAME_TEST_UTILS_H_