2011-12-29 21:32:02 +01:00
|
|
|
// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights
|
2010-10-03 23:04:50 +02:00
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
#ifndef CEF_TESTS_UNITTESTS_TEST_HANDLER_H_
|
|
|
|
#define CEF_TESTS_UNITTESTS_TEST_HANDLER_H_
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-12-23 18:36:30 +01:00
|
|
|
#include "include/cef_browser.h"
|
|
|
|
#include "include/cef_client.h"
|
2011-12-29 21:32:02 +01:00
|
|
|
#include "include/cef_frame.h"
|
|
|
|
#include "include/cef_task.h"
|
2011-01-07 22:34:20 +01:00
|
|
|
#include "base/synchronization/waitable_event.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "testing/gtest/include/gtest/gtest.h"
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
class TrackCallback {
|
|
|
|
public:
|
2011-02-21 23:44:06 +01:00
|
|
|
TrackCallback(): gotit_(false) {}
|
|
|
|
void yes() { gotit_ = true; }
|
|
|
|
bool isSet() { return gotit_; }
|
2011-04-21 18:46:16 +02:00
|
|
|
void reset() { gotit_ = false; }
|
2011-02-21 23:44:06 +01:00
|
|
|
operator bool() const { return gotit_; }
|
2012-01-10 00:46:23 +01:00
|
|
|
protected:
|
2011-02-21 23:44:06 +01:00
|
|
|
bool gotit_;
|
|
|
|
};
|
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
// Base implementation of CefClient for unit tests. Add new interfaces as needed
|
|
|
|
// by test cases.
|
|
|
|
class TestHandler : public CefClient,
|
2011-10-04 13:49:36 +02:00
|
|
|
public CefDisplayHandler,
|
2011-05-20 16:42:25 +02:00
|
|
|
public CefLifeSpanHandler,
|
|
|
|
public CefLoadHandler,
|
|
|
|
public CefRequestHandler,
|
2012-01-05 20:34:20 +01:00
|
|
|
public CefV8ContextHandler,
|
2012-01-10 00:46:23 +01:00
|
|
|
public CefPermissionHandler {
|
|
|
|
public:
|
2011-12-29 21:32:02 +01:00
|
|
|
TestHandler();
|
|
|
|
virtual ~TestHandler();
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
// Implement this method to run the test
|
|
|
|
virtual void RunTest() =0;
|
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
// CefClient methods. Add new methods as needed by test cases.
|
2012-01-10 00:46:23 +01:00
|
|
|
virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() OVERRIDE {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() OVERRIDE {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
virtual CefRefPtr<CefRequestHandler> GetRequestHandler() OVERRIDE {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
virtual CefRefPtr<CefV8ContextHandler> GetV8ContextHandler() OVERRIDE {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
virtual CefRefPtr<CefPermissionHandler> GetPermissionHandler() OVERRIDE {
|
|
|
|
return this;
|
|
|
|
}
|
2012-01-05 20:34:20 +01:00
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
// CefLifeSpanHandler methods
|
2011-12-29 21:32:02 +01:00
|
|
|
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
|
|
|
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
2011-03-24 21:36:47 +01:00
|
|
|
|
2011-05-20 16:42:25 +02:00
|
|
|
// CefRequestHandler methods
|
|
|
|
virtual bool OnBeforeResourceLoad(CefRefPtr<CefBrowser> browser,
|
2010-10-03 23:04:50 +02:00
|
|
|
CefRefPtr<CefRequest> request,
|
2011-05-20 16:42:25 +02:00
|
|
|
CefString& redirectUrl,
|
|
|
|
CefRefPtr<CefStreamReader>& resourceStream,
|
|
|
|
CefRefPtr<CefResponse> response,
|
2011-12-29 21:32:02 +01:00
|
|
|
int loadFlags) OVERRIDE;
|
|
|
|
|
|
|
|
CefRefPtr<CefBrowser> GetBrowser() { return browser_; }
|
|
|
|
CefWindowHandle GetBrowserHwnd() { return browser_hwnd_; }
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
// Called by the test function to execute the test. This method blocks until
|
|
|
|
// the test is complete. Do not reference the object after this method
|
|
|
|
// returns.
|
2011-12-29 21:32:02 +01:00
|
|
|
void ExecuteTest();
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
protected:
|
2010-10-03 23:04:50 +02:00
|
|
|
// Destroy the browser window. Once the window is destroyed test completion
|
|
|
|
// will be signaled.
|
2011-12-29 21:32:02 +01:00
|
|
|
void DestroyTest();
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-12-29 21:32:02 +01:00
|
|
|
void CreateBrowser(const CefString& url);
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-12-29 21:32:02 +01:00
|
|
|
void AddResource(const CefString& key, const std::string& value,
|
|
|
|
const CefString& mimeType);
|
|
|
|
void ClearResources();
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
private:
|
2010-10-03 23:04:50 +02:00
|
|
|
// The child browser window
|
|
|
|
CefRefPtr<CefBrowser> browser_;
|
|
|
|
|
|
|
|
// The browser window handle
|
|
|
|
CefWindowHandle browser_hwnd_;
|
|
|
|
|
|
|
|
// Handle used to notify when the test is complete
|
|
|
|
base::WaitableEvent completion_event_;
|
|
|
|
|
|
|
|
// Map of resources that can be automatically loaded
|
2010-11-22 18:49:46 +01:00
|
|
|
typedef std::map<CefString, std::pair<std::string, CefString> > ResourceMap;
|
2010-10-03 23:04:50 +02:00
|
|
|
ResourceMap resource_map_;
|
2011-05-20 16:42:25 +02:00
|
|
|
|
|
|
|
// Include the default reference counting implementation.
|
|
|
|
IMPLEMENT_REFCOUNTING(TestHandler);
|
|
|
|
// Include the default locking implementation.
|
|
|
|
IMPLEMENT_LOCKING(TestHandler);
|
2010-10-03 23:04:50 +02:00
|
|
|
};
|
|
|
|
|
2011-12-15 15:47:23 +01:00
|
|
|
|
|
|
|
// Post a task to the specified thread and wait for the task to execute as
|
|
|
|
// indication that all previously pending tasks on that thread have completed.
|
2011-12-29 21:32:02 +01:00
|
|
|
void WaitForThread(CefThreadId thread_id);
|
2011-12-15 15:47:23 +01:00
|
|
|
|
|
|
|
#define WaitForIOThread() WaitForThread(TID_IO)
|
|
|
|
#define WaitForUIThread() WaitForThread(TID_UI)
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
#endif // CEF_TESTS_UNITTESTS_TEST_HANDLER_H_
|