#ifndef WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_H_
#define WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_H_
#include <list>
#include <map>
#include <string>
#include <vector>
#include "base/basictypes.h"
#include "base/file_path.h"
#include "base/scoped_temp_dir.h"
#include "base/string_piece.h"
#if defined(OS_MACOSX)
#include "base/lazy_instance.h"
#endif
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebNavigationPolicy.h"
#include "ui/gfx/native_widget_types.h"
#include "webkit/tools/test_shell/webview_host.h"
#include "webkit/tools/test_shell/webwidget_host.h"
typedef std::list<gfx::NativeWindow> WindowList;
namespace webkit_glue {
struct WebPreferences;
}
class GURL;
class TestNavigationEntry;
class TestNavigationController;
class TestNotificationPresenter;
class TestShellDevToolsAgent;
class TestShellDevToolsClient;
class TestWebViewDelegate;
namespace WebKit {
class WebDeviceOrientationClientMock;
class WebGeolocationClientMock;
}
class TestShell : public base::SupportsWeakPtr<TestShell> {
public:
struct TestParams {
TestParams();
bool dump_tree;
bool dump_pixels;
FilePath pixel_file_name;
std::string pixel_hash;
std::string test_url;
};
TestShell();
virtual ~TestShell();
static void InitLogging(bool suppress_error_dialogs,
bool running_layout_tests,
bool enable_gp_fault_error_box);
static void CleanupLogging();
static void InitializeTestShell(bool layout_test_mode,
bool allow_external_pages);
static void ShutdownTestShell();
static bool layout_test_mode() { return layout_test_mode_; }
static bool allow_external_pages() { return allow_external_pages_; }
void PlatformCleanUp();
WebKit::WebView* webView() {
return m_webViewHost.get() ? m_webViewHost->webview() : NULL;
}
WebViewHost* webViewHost() { return m_webViewHost.get(); }
WebKit::WebWidget* popup() {
return m_popupHost ? m_popupHost->webwidget() : NULL;
}
WebWidgetHost* popupHost() { return m_popupHost; }
bool is_loading() const { return is_loading_; }
void set_is_loading(bool is_loading) { is_loading_ = is_loading; }
bool allow_images() const { return allow_images_; }
void set_allow_images(bool allow) { allow_images_ = allow; }
bool allow_plugins() const { return allow_plugins_; }
void set_allow_plugins(bool allow) { allow_plugins_ = allow; }
bool allow_scripts() const { return allow_scripts_; }
void set_allow_scripts(bool allow) { allow_scripts_ = allow; }
void UpdateNavigationControls();
void ShowDevTools();
void CloseDevTools();
void TestFinished();
void TestTimedOut();
void WaitTestFinished();
void Show(WebKit::WebNavigationPolicy policy);
void SetFocus(WebWidgetHost* host, bool enable);
TestWebViewDelegate* delegate() { return delegate_.get(); }
TestWebViewDelegate* popup_delegate() { return popup_delegate_.get(); }
TestNavigationController* navigation_controller() {
return navigation_controller_.get();
}
TestNotificationPresenter* notification_presenter() {
return notification_presenter_.get();
}
void ResetTestController();
bool AcceptsEditing() {
return true;
}
void LoadFile(const FilePath& file);
void LoadURL(const GURL& url);
void LoadURLForFrame(const GURL& url, const string16& frame_name);
void GoBackOrForward(int offset);
void Reload();
bool Navigate(const TestNavigationEntry& entry, bool reload);
bool PromptForSaveFile(const wchar_t* prompt_title, FilePath* result);
string16 GetDocumentText();
void DumpDocumentText();
void DumpRenderTree();
gfx::NativeWindow mainWnd() const { return m_mainWnd; }
gfx::NativeView webViewWnd() const { return m_webViewHost->view_handle(); }
gfx::NativeEditView editWnd() const { return m_editWnd; }
gfx::NativeView popupWnd() const { return m_popupHost->view_handle(); }
static WindowList* windowList() { return window_list_; }
static bool CreateNewWindow(const GURL& starting_url,
TestShell** shell = NULL);
static void DestroyWindow(gfx::NativeWindow windowHandle);
static bool RemoveWindowFromList(gfx::NativeWindow window);
WebKit::WebView* CreateWebView();
WebKit::WebWidget* CreatePopupWidget();
void ClosePopup();
#if defined(OS_WIN)
static ATOM RegisterWindowClass();
#endif
static void DumpAllBackForwardLists(string16* result);
void DumpBackForwardEntry(int index, string16* result);
void DumpBackForwardList(string16* result);
static void ResetWebPreferences();
static void SetAllowScriptsToCloseWindows();
static void SetAccelerated2dCanvasEnabled(bool enabled);
static void SetAcceleratedCompositingEnabled(bool enabled);
static webkit_glue::WebPreferences* GetWebPreferences();
static std::string RewriteLocalUrl(const std::string& url);
static void SetFileTestTimeout(int timeout_ms) {
file_test_timeout_ms_ = timeout_ms;
}
static int GetLayoutTestTimeout() { return file_test_timeout_ms_; }
static int GetLayoutTestTimeoutForWatchDog() {
return (load_count_ * file_test_timeout_ms_) + 1000;
}
static void SetJavaScriptFlags(std::vector<std::string> js_flags) {
js_flags_ = js_flags;
}
static void SetMultipleLoad(int load_count) {
load_count_ = load_count;
}
static int GetLoadCount() { return load_count_; }
static std::string GetJSFlagsForLoad(size_t load) {
if (load >= js_flags_.size()) return "";
return js_flags_[load];
}
#if defined(OS_WIN)
HANDLE finished_event() { return finished_event_; }
#endif
void DumpStatsTableOnExit() { dump_stats_table_on_exit_ = true; }
void CallJSGC();
void set_is_modal(bool value) { is_modal_ = value; }
bool is_modal() const { return is_modal_; }
const TestParams* test_params() { return test_params_; }
void set_test_params(const TestParams* test_params) {
test_params_ = test_params;
}
#if defined(OS_MACOSX)
static void DestroyAssociatedShell(gfx::NativeWindow handle);
#endif
static void ShowStartupDebuggingDialog();
static base::StringPiece ResourceProvider(int key);
TestShellDevToolsAgent* dev_tools_agent() {
return dev_tools_agent_.get();
}
WebKit::WebDeviceOrientationClientMock* device_orientation_client_mock();
WebKit::WebGeolocationClientMock* geolocation_client_mock();
protected:
void CreateDevToolsClient(TestShellDevToolsAgent* agent);
bool Initialize(const GURL& starting_url);
bool IsSVGTestURL(const GURL& url);
void SizeToSVG();
void SizeToDefault();
void SizeTo(int width, int height);
void ResizeSubViews();
void InteractiveSetFocus(WebWidgetHost* host, bool enable);
enum UIControl {
BACK_BUTTON,
FORWARD_BUTTON,
STOP_BUTTON
};
void EnableUIControl(UIControl control, bool is_enabled);
#if defined(OS_WIN)
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
static LRESULT CALLBACK EditWndProc(HWND, UINT, WPARAM, LPARAM);
#endif
static void PlatformShutdown();
protected:
gfx::NativeWindow m_mainWnd;
gfx::NativeEditView m_editWnd;
scoped_ptr<WebViewHost> m_webViewHost;
WebWidgetHost* m_popupHost;
#if defined(OS_WIN)
WNDPROC default_edit_wnd_proc_;
#endif
WebWidgetHost* m_focusedWidgetHost;
private:
static WindowList* window_list_;
#if defined(OS_MACOSX)
typedef std::map<gfx::NativeWindow, TestShell *> WindowMap;
static base::LazyInstance<WindowMap> window_map_;
#endif
#if defined(OS_WIN)
static HINSTANCE instance_handle_;
#endif
static bool developer_extras_enabled_;
static bool layout_test_mode_;
static bool allow_external_pages_;
static int file_test_timeout_ms_;
scoped_ptr<TestNavigationController> navigation_controller_;
scoped_ptr<TestNotificationPresenter> notification_presenter_;
scoped_ptr<TestWebViewDelegate> delegate_;
scoped_ptr<TestWebViewDelegate> popup_delegate_;
base::WeakPtr<TestShell> devtools_shell_;
scoped_ptr<TestShellDevToolsAgent> dev_tools_agent_;
scoped_ptr<TestShellDevToolsClient> dev_tools_client_;
scoped_ptr<WebKit::WebDeviceOrientationClientMock>
device_orientation_client_mock_;
scoped_ptr<WebKit::WebGeolocationClientMock> geolocation_client_mock_;
const TestParams* test_params_;
static bool test_is_preparing_;
static bool test_is_pending_;
static int load_count_;
static std::vector<std::string> js_flags_;
static bool accelerated_2d_canvas_enabled_;
static bool accelerated_compositing_enabled_;
bool is_modal_;
bool is_loading_;
bool allow_images_;
bool allow_plugins_;
bool allow_scripts_;
static webkit_glue::WebPreferences* web_prefs_;
#if defined(OS_WIN)
HANDLE finished_event_;
#endif
bool dump_stats_table_on_exit_;
};
#endif