Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(412)

Side by Side Diff: chrome_frame/test/mock_ie_event_sink_test.h

Issue 3061036: Handle automation server crashes. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_FRAME_TEST_MOCK_IE_EVENT_SINK_TEST_H_ 5 #ifndef CHROME_FRAME_TEST_MOCK_IE_EVENT_SINK_TEST_H_
6 #define CHROME_FRAME_TEST_MOCK_IE_EVENT_SINK_TEST_H_ 6 #define CHROME_FRAME_TEST_MOCK_IE_EVENT_SINK_TEST_H_
7 7
8 #include <atlbase.h> 8 #include <atlbase.h>
9 #include <atlcom.h> 9 #include <atlcom.h>
10 #include <string> 10 #include <string>
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 void ExpectJavascriptWindowOpenNavigation(bool parent_cf, bool new_window_cf, 107 void ExpectJavascriptWindowOpenNavigation(bool parent_cf, bool new_window_cf,
108 const std::wstring& url); 108 const std::wstring& url);
109 109
110 // Expect a new window to open. The new event sink will be attached to 110 // Expect a new window to open. The new event sink will be attached to
111 // |new_window_mock|. 111 // |new_window_mock|.
112 void ExpectNewWindow(MockIEEventSink* new_window_mock); 112 void ExpectNewWindow(MockIEEventSink* new_window_mock);
113 113
114 // Expects any and all navigations. 114 // Expects any and all navigations.
115 void ExpectAnyNavigations(); 115 void ExpectAnyNavigations();
116 116
117 void ExpectDocumentReadystate(int ready_state);
118
117 IEEventSink* event_sink() { return event_sink_; } 119 IEEventSink* event_sink() { return event_sink_; }
118 120
119 private: 121 private:
120 // Override IE's OnDocumentComplete to call our OnLoad, iff it is IE actually 122 // Override IE's OnDocumentComplete to call our OnLoad, iff it is IE actually
121 // rendering the page. 123 // rendering the page.
122 virtual void OnDocumentComplete(IDispatch* dispatch, VARIANT* url) { 124 virtual void OnDocumentComplete(IDispatch* dispatch, VARIANT* url) {
123 if (!event_sink_->IsCFRendering()) 125 if (!event_sink_->IsCFRendering())
124 OnLoad(IN_IE, V_BSTR(url)); 126 OnLoad(IN_IE, V_BSTR(url));
125 } 127 }
126 128
(...skipping 13 matching lines...) Expand all
140 142
141 // It may be necessary to create this on the heap. Otherwise, if the 143 // It may be necessary to create this on the heap. Otherwise, if the
142 // reference count is greater than zero, a debug assert will be triggered 144 // reference count is greater than zero, a debug assert will be triggered
143 // in the destructor. This happens at least when IE crashes. In that case, 145 // in the destructor. This happens at least when IE crashes. In that case,
144 // DispEventUnadvise and CoDisconnectObject are not sufficient to decrement 146 // DispEventUnadvise and CoDisconnectObject are not sufficient to decrement
145 // the reference count. 147 // the reference count.
146 // TODO(kkania): Investigate if the above is true. 148 // TODO(kkania): Investigate if the above is true.
147 CComObject<IEEventSink>* event_sink_; 149 CComObject<IEEventSink>* event_sink_;
148 }; 150 };
149 151
152 // This mocks a PropertyNotifySinkListener, providing methods for
153 // expecting certain sequences of events.
154 class MockPropertyNotifySinkListener : public PropertyNotifySinkListener {
155 public:
156 MockPropertyNotifySinkListener() : cookie_(0), sink_(NULL) {
157 CComObject<PropertyNotifySinkImpl>::CreateInstance(&sink_);
158 sink_->AddRef();
159 sink_->set_listener(this);
160 }
161
162 ~MockPropertyNotifySinkListener() {
163 Detach();
164 sink_->set_listener(NULL);
165 DLOG_IF(ERROR, sink_->m_dwRef != 1)
166 << "Event sink is still referenced externally: ref count = "
167 << sink_->m_dwRef;
168 sink_->Release();
169 }
170
171 // Override PropertyNotifySinkListener methods.
172 MOCK_METHOD1(OnChanged, void (DISPID dispid)); // NOLINT
173
174 bool Attach(IUnknown* obj) {
175 DCHECK_EQ(cookie_, 0UL);
176 DCHECK(obj);
177 HRESULT hr = AtlAdvise(obj, sink_->GetUnknown(), IID_IPropertyNotifySink,
178 &cookie_);
179 if (SUCCEEDED(hr)) {
180 event_source_ = obj;
181 } else {
182 LOG(ERROR) << StringPrintf("AtlAdvise: 0x%08X", hr);
183 cookie_ = 0;
184 }
185
186 return SUCCEEDED(hr);
187 }
188
189 void Detach() {
190 if (event_source_) {
191 DCHECK_NE(cookie_, 0UL);
192 AtlUnadvise(event_source_, IID_IPropertyNotifySink, cookie_);
193 event_source_.Release();
194 cookie_ = 0;
195 }
196 }
197
198 private:
199 CComObject<PropertyNotifySinkImpl>* sink_;
200 DWORD cookie_;
201 ScopedComPtr<IUnknown> event_source_;
202 };
203
204
150 // Mocks a window observer so that tests can detect new windows. 205 // Mocks a window observer so that tests can detect new windows.
151 class MockWindowObserver : public WindowObserver { 206 class MockWindowObserver : public WindowObserver {
152 public: 207 public:
153 // Override WindowObserver methods. 208 // Override WindowObserver methods.
154 MOCK_METHOD2(OnWindowDetected, void (HWND hwnd, // NOLINT 209 MOCK_METHOD2(OnWindowDetected, void (HWND hwnd, // NOLINT
155 const std::string& caption)); 210 const std::string& caption));
156 211
157 // Watch for all windows of the given class type. 212 // Watch for all windows of the given class type.
158 void WatchWindow(const wchar_t* window_class) { 213 void WatchWindow(const wchar_t* window_class) {
159 DCHECK(window_class); 214 DCHECK(window_class);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 testing::StrictMock<MockIEEventSink> ie_mock_; 279 testing::StrictMock<MockIEEventSink> ie_mock_;
225 testing::StrictMock<MockWebServer> server_mock_; 280 testing::StrictMock<MockWebServer> server_mock_;
226 281
227 private: 282 private:
228 DISALLOW_COPY_AND_ASSIGN(MockIEEventSinkTest); 283 DISALLOW_COPY_AND_ASSIGN(MockIEEventSinkTest);
229 }; 284 };
230 285
231 } // namespace chrome_frame_test 286 } // namespace chrome_frame_test
232 287
233 #endif // CHROME_FRAME_TEST_MOCK_IE_EVENT_SINK_TEST_H_ 288 #endif // CHROME_FRAME_TEST_MOCK_IE_EVENT_SINK_TEST_H_
OLDNEW
« no previous file with comments | « chrome_frame/test/mock_ie_event_sink_actions.h ('k') | chrome_frame/test/mock_ie_event_sink_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698