blob: 7b66083b5cbd252d36be225de4738da819ffbb9a [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]864b1362010-08-19 03:49:3813class FilePath;
[email protected]66ff7352009-10-15 05:09:5014
[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:
[email protected]cf5912b2011-02-01 22:20:4428 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]f7817822009-09-24 05:11:5836 virtual ~ScopedChromeFrameRegistrar();
37
38 void RegisterChromeFrameAtPath(const std::wstring& path);
[email protected]43c698f2010-05-01 01:38:5939 void UnegisterChromeFrameAtPath(const std::wstring& path);
[email protected]f7817822009-09-24 05:11:5840 void RegisterReferenceChromeFrameBuild();
41
42 std::wstring GetChromeFrameDllPath() const;
43
[email protected]cf5912b2011-02-01 22:20:4444 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]f7817822009-09-24 05:11:5848 static void RegisterDefaults();
[email protected]bcd840c2010-05-27 10:43:0049 static FilePath GetReferenceChromeFrameDllPath();
[email protected]f7817822009-09-24 05:11:5850
51 private:
[email protected]ea9ed97d2010-01-05 19:16:2352 // Contains the path of the most recently registered Chrome Frame DLL.
[email protected]f7817822009-09-24 05:11:5853 std::wstring new_chrome_frame_dll_path_;
54
[email protected]ea9ed97d2010-01-05 19:16:2355 // Contains the path of the Chrome Frame DLL to be registered at destruction.
[email protected]f7817822009-09-24 05:11:5856 std::wstring original_dll_path_;
[email protected]cf5912b2011-02-01 22:20:4457
58 // Indicates whether per user or per machine registration is needed.
59 RegistrationType registration_type_;
[email protected]f7817822009-09-24 05:11:5860};
61
[email protected]87ba2e602011-03-01 02:25:1162// 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.
65FilePath GetChromeFrameBuildPath();
66
[email protected]a1800e82009-11-19 00:53:2367// Callback description for onload, onloaderror, onmessage
68static _ATL_FUNC_INFO g_single_param = {CC_STDCALL, VT_EMPTY, 1, {VT_VARIANT}};
69// Simple class that forwards the callbacks.
70template <typename T>
71class 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_)(&param);
92 }
93
94 IDispatch* ToDispatch() {
95 return reinterpret_cast<IDispatch*>(this);
96 }
97
98 T* owner_;
99 Method method_;
100};
101
[email protected]0b5a2f82009-12-07 21:20:19102// 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.
105bool KillAllNamedProcessesWithArgument(const std::wstring& process_name,
106 const std::wstring& argument);
107
[email protected]58d58c7b2010-11-05 23:34:03108// If the workstation is locked and cannot receive user input.
109bool IsWorkstationLocked();
[email protected]a1800e82009-11-19 00:53:23110
[email protected]f7817822009-09-24 05:11:58111#endif // CHROME_FRAME_TEST_UTILS_H_