Use Histogram algorithm to calculate DNS timeout.
[chromium-blink-merge.git] / chrome_frame / test_utils.h
blob804f069f73ae95f0e9681598b47c2d8303d493b2
1 // Copyright (c) 2012 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/strings/string16.h"
15 namespace base {
16 class FilePath;
19 extern const wchar_t kChromeFrameDllName[];
20 extern const wchar_t kChromeLauncherExeName[];
22 // Helper class used to register different chrome frame DLLs while running
23 // tests. The default constructor registers the DLL found in the build path.
24 // Programs that use this class MUST include a call to the class's
25 // RegisterAndExitProcessIfDirected method at the top of their main entrypoint.
27 // At destruction, again registers the DLL found in the build path if another
28 // DLL has since been registered. Triggers GTEST asserts on failure.
30 // TODO(robertshield): Ideally, make this class restore the originally
31 // registered chrome frame DLL (e.g. by looking in HKCR) on destruction.
32 class ScopedChromeFrameRegistrar {
33 public:
34 enum RegistrationType {
35 PER_USER,
36 SYSTEM_LEVEL,
39 explicit ScopedChromeFrameRegistrar(RegistrationType registration_type);
40 ScopedChromeFrameRegistrar(const std::wstring& path,
41 RegistrationType registration_type);
42 virtual ~ScopedChromeFrameRegistrar();
44 void RegisterChromeFrameAtPath(const std::wstring& path);
45 void UnegisterChromeFrameAtPath(const std::wstring& path);
46 void RegisterReferenceChromeFrameBuild();
48 std::wstring GetChromeFrameDllPath() const;
50 static void RegisterAtPath(const std::wstring& path,
51 RegistrationType registration_type);
52 static void UnregisterAtPath(const std::wstring& path,
53 RegistrationType registration_type);
54 static void RegisterDefaults();
55 static base::FilePath GetReferenceChromeFrameDllPath();
57 // Registers or unregisters a COM DLL and exits the process if the process's
58 // command line is:
59 // this.exe --call-registration-entrypoint path_to_dll entrypoint
60 // Otherwise simply returns. This method should be invoked at the start of the
61 // entrypoint in each executable that uses ScopedChromeFrameRegistrar to
62 // register or unregister DLLs.
63 static void RegisterAndExitProcessIfDirected();
65 private:
66 enum RegistrationOperation {
67 REGISTER,
68 UNREGISTER,
71 // The string "--call-registration-entrypoint".
72 static const wchar_t kCallRegistrationEntrypointSwitch[];
74 static void DoRegistration(const string16& path,
75 RegistrationType registration_type,
76 RegistrationOperation registration_operation);
78 // Contains the path of the most recently registered Chrome Frame DLL.
79 std::wstring new_chrome_frame_dll_path_;
81 // Contains the path of the Chrome Frame DLL to be registered at destruction.
82 std::wstring original_dll_path_;
84 // Indicates whether per user or per machine registration is needed.
85 RegistrationType registration_type_;
86 // We need to register the chrome path provider only once per process. This
87 // flag keeps track of that.
88 static bool register_chrome_path_provider_;
91 // Returns the path to the Chrome Frame DLL in the build directory. Assumes
92 // that the test executable is running from the build folder or a similar
93 // folder structure.
94 base::FilePath GetChromeFrameBuildPath();
96 // Callback description for onload, onloaderror, onmessage
97 static _ATL_FUNC_INFO g_single_param = {CC_STDCALL, VT_EMPTY, 1, {VT_VARIANT}};
98 // Simple class that forwards the callbacks.
99 template <typename T>
100 class DispCallback
101 : public IDispEventSimpleImpl<1, DispCallback<T>, &IID_IDispatch> {
102 public:
103 typedef HRESULT (T::*Method)(const VARIANT* param);
105 DispCallback(T* owner, Method method) : owner_(owner), method_(method) {
108 BEGIN_SINK_MAP(DispCallback)
109 SINK_ENTRY_INFO(1, IID_IDispatch, DISPID_VALUE, OnCallback, &g_single_param)
110 END_SINK_MAP()
112 virtual ULONG STDMETHODCALLTYPE AddRef() {
113 return owner_->AddRef();
115 virtual ULONG STDMETHODCALLTYPE Release() {
116 return owner_->Release();
119 STDMETHOD(OnCallback)(VARIANT param) {
120 return (owner_->*method_)(&param);
123 IDispatch* ToDispatch() {
124 return reinterpret_cast<IDispatch*>(this);
127 T* owner_;
128 Method method_;
131 // If the workstation is locked and cannot receive user input.
132 bool IsWorkstationLocked();
134 #endif // CHROME_FRAME_TEST_UTILS_H_