Fix svn:eol-style property.

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@1470 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt
2013-10-18 16:33:56 +00:00
parent bc90a7f854
commit 6a52564668
27 changed files with 4397 additions and 4397 deletions

View File

@@ -1,493 +1,493 @@
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "cefclient/cefclient_osr_widget_gtk.h"
// This value is defined in build/common.gypi and must be undefined here
// in order for gtkglext to compile.
#undef GTK_DISABLE_SINGLE_INCLUDES
#include <gdk/gdk.h>
#include <gdk/gdkkeysyms.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <gtk/gtkgl.h>
#include <GL/gl.h>
#include "include/cef_runnable.h"
#include "cefclient/util.h"
namespace {
gint glarea_size_allocation(GtkWidget* widget,
GtkAllocation* allocation,
OSRWindow* window) {
CefRefPtr<CefBrowserHost> host = window->GetBrowserHost();
host->WasResized();
return TRUE;
}
int get_cef_state_modifiers(guint state) {
int modifiers = 0;
if (state & GDK_SHIFT_MASK)
modifiers |= EVENTFLAG_SHIFT_DOWN;
if (state & GDK_LOCK_MASK)
modifiers |= EVENTFLAG_CAPS_LOCK_ON;
if (state & GDK_CONTROL_MASK)
modifiers |= EVENTFLAG_CONTROL_DOWN;
if (state & GDK_MOD1_MASK)
modifiers |= EVENTFLAG_ALT_DOWN;
if (state & GDK_BUTTON1_MASK)
modifiers |= EVENTFLAG_LEFT_MOUSE_BUTTON;
if (state & GDK_BUTTON2_MASK)
modifiers |= EVENTFLAG_MIDDLE_MOUSE_BUTTON;
if (state & GDK_BUTTON3_MASK)
modifiers |= EVENTFLAG_RIGHT_MOUSE_BUTTON;
return modifiers;
}
gint glarea_click_event(GtkWidget* widget,
GdkEventButton* event,
OSRWindow* window) {
CefRefPtr<CefBrowserHost> host = window->GetBrowserHost();
CefBrowserHost::MouseButtonType button_type = MBT_LEFT;
switch (event->button) {
case 1:
break;
case 2:
button_type = MBT_MIDDLE;
break;
case 3:
button_type = MBT_RIGHT;
break;
default:
// Other mouse buttons are not handled here.
return FALSE;
}
CefMouseEvent mouse_event;
mouse_event.x = event->x;
mouse_event.y = event->y;
window->ApplyPopupOffset(mouse_event.x, mouse_event.y);
mouse_event.modifiers = get_cef_state_modifiers(event->state);
bool mouse_up = (event->type == GDK_BUTTON_RELEASE);
if (!mouse_up)
gtk_widget_grab_focus(widget);
int click_count = 1;
switch (event->type) {
case GDK_2BUTTON_PRESS:
click_count = 2;
break;
case GDK_3BUTTON_PRESS:
click_count = 3;
break;
default:
break;
}
host->SendMouseClickEvent(mouse_event, button_type, mouse_up, click_count);
return TRUE;
}
gint glarea_move_event(GtkWidget* widget,
GdkEventMotion* event,
OSRWindow* window) {
gint x, y;
GdkModifierType state;
if (event->is_hint) {
gdk_window_get_pointer(event->window, &x, &y, &state);
} else {
x = (gint)event->x;
y = (gint)event->y;
state = (GdkModifierType)event->state;
}
CefRefPtr<CefBrowserHost> host = window->GetBrowserHost();
CefMouseEvent mouse_event;
mouse_event.x = x;
mouse_event.y = y;
window->ApplyPopupOffset(mouse_event.x, mouse_event.y);
mouse_event.modifiers = get_cef_state_modifiers(state);
bool mouse_leave = (event->type == GDK_LEAVE_NOTIFY);
host->SendMouseMoveEvent(mouse_event, mouse_leave);
return TRUE;
}
gint glarea_scroll_event(GtkWidget* widget,
GdkEventScroll* event,
OSRWindow* window) {
CefRefPtr<CefBrowserHost> host = window->GetBrowserHost();
CefMouseEvent mouse_event;
mouse_event.x = event->x;
mouse_event.y = event->y;
window->ApplyPopupOffset(mouse_event.x, mouse_event.y);
mouse_event.modifiers = get_cef_state_modifiers(event->state);
static const int scrollbarPixelsPerGtkTick = 40;
int deltaX = 0;
int deltaY = 0;
switch (event->direction) {
case GDK_SCROLL_UP:
deltaY = scrollbarPixelsPerGtkTick;
break;
case GDK_SCROLL_DOWN:
deltaY = -scrollbarPixelsPerGtkTick;
break;
case GDK_SCROLL_LEFT:
deltaX = scrollbarPixelsPerGtkTick;
break;
case GDK_SCROLL_RIGHT:
deltaX = -scrollbarPixelsPerGtkTick;
break;
}
host->SendMouseWheelEvent(mouse_event, deltaX, deltaY);
return TRUE;
}
gint glarea_key_event(GtkWidget* widget,
GdkEventKey* event,
OSRWindow* window) {
CefRefPtr<CefBrowserHost> host = window->GetBrowserHost();
CefKeyEvent key_event;
key_event.native_key_code = event->keyval;
key_event.modifiers = get_cef_state_modifiers(event->state);
if (event->type == GDK_KEY_PRESS) {
key_event.type = KEYEVENT_RAWKEYDOWN;
host->SendKeyEvent(key_event);
} else {
// Need to send both KEYUP and CHAR events.
key_event.type = KEYEVENT_KEYUP;
host->SendKeyEvent(key_event);
key_event.type = KEYEVENT_CHAR;
host->SendKeyEvent(key_event);
}
return TRUE;
}
gint glarea_focus_event(GtkWidget* widget,
GdkEventFocus* event,
OSRWindow* window) {
CefRefPtr<CefBrowserHost> host = window->GetBrowserHost();
host->SendFocusEvent(event->in == TRUE);
return TRUE;
}
void widget_get_rect_in_screen(GtkWidget* widget, GdkRectangle* r) {
gint x, y, w, h;
GdkRectangle extents;
GdkWindow* window = gtk_widget_get_parent_window(widget);
// Get parent's left-top screen coordinates.
gdk_window_get_root_origin(window, &x, &y);
// Get parent's width and height.
gdk_drawable_get_size(window, &w, &h);
// Get parent's extents including decorations.
gdk_window_get_frame_extents(window, &extents);
// X and Y calculations assume that left, right and bottom border sizes are
// all the same.
const gint border = (extents.width - w) / 2;
r->x = x + border + widget->allocation.x;
r->y = y + (extents.height - h) - border + widget->allocation.y;
r->width = widget->allocation.width;
r->height = widget->allocation.height;
}
class ScopedGLContext {
public:
ScopedGLContext(GtkWidget* widget, bool swap_buffers)
: swap_buffers_(swap_buffers) {
GdkGLContext* glcontext = gtk_widget_get_gl_context(widget);
gldrawable_ = gtk_widget_get_gl_drawable(widget);
is_valid_ = gdk_gl_drawable_gl_begin(gldrawable_, glcontext);
}
virtual ~ScopedGLContext() {
if (is_valid_) {
gdk_gl_drawable_gl_end(gldrawable_);
if(swap_buffers_) {
if (gdk_gl_drawable_is_double_buffered(gldrawable_))
gdk_gl_drawable_swap_buffers(gldrawable_);
else
glFlush();
}
}
}
bool IsValid() const { return is_valid_; }
private:
bool swap_buffers_;
GdkGLContext* glcontext_;
GdkGLDrawable* gldrawable_;
bool is_valid_;
};
} // namespace
// static
CefRefPtr<OSRWindow> OSRWindow::Create(OSRBrowserProvider* browser_provider,
bool transparent,
CefWindowHandle parentView) {
ASSERT(browser_provider);
if (!browser_provider)
return NULL;
return new OSRWindow(browser_provider, transparent, parentView);
}
// static
CefRefPtr<OSRWindow> OSRWindow::From(
CefRefPtr<ClientHandler::RenderHandler> renderHandler) {
return static_cast<OSRWindow*>(renderHandler.get());
}
void OSRWindow::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
// Disconnect all signal handlers that reference |this|.
g_signal_handlers_disconnect_matched(glarea_, G_SIGNAL_MATCH_DATA, 0, 0,
NULL, NULL, this);
DisableGL();
}
bool OSRWindow::GetViewRect(CefRefPtr<CefBrowser> browser,
CefRect& rect) {
if (!glarea_)
return false;
// The simulated screen and view rectangle are the same. This is necessary
// for popup menus to be located and sized inside the view.
rect.x = rect.y = 0;
rect.width = glarea_->allocation.width;
rect.height = glarea_->allocation.height;
return true;
}
bool OSRWindow::GetScreenPoint(CefRefPtr<CefBrowser> browser,
int viewX,
int viewY,
int& screenX,
int& screenY) {
GdkRectangle screen_rect;
widget_get_rect_in_screen(glarea_, &screen_rect);
screenX = screen_rect.x + viewX;
screenY = screen_rect.y + viewY;
return true;
}
void OSRWindow::OnPopupShow(CefRefPtr<CefBrowser> browser,
bool show) {
if (!show) {
CefRect dirty_rect = renderer_.popup_rect();
renderer_.ClearPopupRects();
browser->GetHost()->Invalidate(dirty_rect, PET_VIEW);
}
renderer_.OnPopupShow(browser, show);
}
void OSRWindow::OnPopupSize(CefRefPtr<CefBrowser> browser,
const CefRect& rect) {
renderer_.OnPopupSize(browser, rect);
}
void OSRWindow::OnPaint(CefRefPtr<CefBrowser> browser,
PaintElementType type,
const RectList& dirtyRects,
const void* buffer,
int width, int height) {
if (painting_popup_) {
renderer_.OnPaint(browser, type, dirtyRects, buffer, width, height);
return;
}
if (!gl_enabled_)
EnableGL();
ScopedGLContext scoped_gl_context(glarea_, true);
if (!scoped_gl_context.IsValid())
return;
renderer_.OnPaint(browser, type, dirtyRects, buffer, width, height);
if (type == PET_VIEW && !renderer_.popup_rect().IsEmpty()) {
painting_popup_ = true;
CefRect client_popup_rect(0, 0,
renderer_.popup_rect().width,
renderer_.popup_rect().height);
browser->GetHost()->Invalidate(client_popup_rect, PET_POPUP);
painting_popup_ = false;
}
renderer_.Render();
}
void OSRWindow::OnCursorChange(CefRefPtr<CefBrowser> browser,
CefCursorHandle cursor) {
GtkWidget* window = gtk_widget_get_toplevel(glarea_);
GdkWindow* gdk_window = gtk_widget_get_window(window);
if (cursor->type == GDK_LAST_CURSOR)
cursor = NULL;
gdk_window_set_cursor(gdk_window, cursor);
}
void OSRWindow::Invalidate() {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI, NewCefRunnableMethod(this, &OSRWindow::Invalidate));
return;
}
// Don't post another task if the previous task is still pending.
if (render_task_pending_)
return;
render_task_pending_ = true;
// Render at 30fps.
static const int kRenderDelay = 1000 / 30;
CefPostDelayedTask(TID_UI, NewCefRunnableMethod(this, &OSRWindow::Render),
kRenderDelay);
}
bool OSRWindow::IsOverPopupWidget(int x, int y) const {
const CefRect& rc = renderer_.popup_rect();
int popup_right = rc.x + rc.width;
int popup_bottom = rc.y + rc.height;
return (x >= rc.x) && (x < popup_right) &&
(y >= rc.y) && (y < popup_bottom);
}
int OSRWindow::GetPopupXOffset() const {
return renderer_.original_popup_rect().x - renderer_.popup_rect().x;
}
int OSRWindow::GetPopupYOffset() const {
return renderer_.original_popup_rect().y - renderer_.popup_rect().y;
}
void OSRWindow::ApplyPopupOffset(int& x, int& y) const {
if (IsOverPopupWidget(x, y)) {
x += GetPopupXOffset();
y += GetPopupYOffset();
}
}
OSRWindow::OSRWindow(OSRBrowserProvider* browser_provider,
bool transparent,
CefWindowHandle parentView)
: renderer_(transparent),
browser_provider_(browser_provider),
gl_enabled_(false),
painting_popup_(false),
render_task_pending_(false) {
glarea_ = gtk_drawing_area_new();
ASSERT(glarea_);
GdkGLConfig* glconfig = gdk_gl_config_new_by_mode(
static_cast<GdkGLConfigMode>(GDK_GL_MODE_RGB |
GDK_GL_MODE_DEPTH |
GDK_GL_MODE_DOUBLE));
ASSERT(glconfig);
gtk_widget_set_gl_capability(glarea_, glconfig, NULL, TRUE,
GDK_GL_RGBA_TYPE);
gtk_widget_set_can_focus(glarea_, TRUE);
g_signal_connect(G_OBJECT(glarea_), "size_allocate",
G_CALLBACK(glarea_size_allocation), this);
gtk_widget_set_events(glarea_,
GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK |
GDK_KEY_PRESS_MASK |
GDK_KEY_RELEASE_MASK |
GDK_ENTER_NOTIFY_MASK |
GDK_LEAVE_NOTIFY_MASK |
GDK_POINTER_MOTION_MASK |
GDK_POINTER_MOTION_HINT_MASK |
GDK_SCROLL_MASK |
GDK_FOCUS_CHANGE_MASK);
g_signal_connect(G_OBJECT(glarea_), "button_press_event",
G_CALLBACK(glarea_click_event), this);
g_signal_connect(G_OBJECT(glarea_), "button_release_event",
G_CALLBACK(glarea_click_event), this);
g_signal_connect(G_OBJECT(glarea_), "key_press_event",
G_CALLBACK(glarea_key_event), this);
g_signal_connect(G_OBJECT(glarea_), "key_release_event",
G_CALLBACK(glarea_key_event), this);
g_signal_connect(G_OBJECT(glarea_), "enter_notify_event",
G_CALLBACK(glarea_move_event), this);
g_signal_connect(G_OBJECT(glarea_), "leave_notify_event",
G_CALLBACK(glarea_move_event), this);
g_signal_connect(G_OBJECT(glarea_), "motion_notify_event",
G_CALLBACK(glarea_move_event), this);
g_signal_connect(G_OBJECT(glarea_), "scroll_event",
G_CALLBACK(glarea_scroll_event), this);
g_signal_connect(G_OBJECT(glarea_), "focus_in_event",
G_CALLBACK(glarea_focus_event), this);
g_signal_connect(G_OBJECT(glarea_), "focus_out_event",
G_CALLBACK(glarea_focus_event), this);
gtk_container_add(GTK_CONTAINER(parentView), glarea_);
}
OSRWindow::~OSRWindow() {
}
void OSRWindow::Render() {
ASSERT(CefCurrentlyOn(TID_UI));
if (render_task_pending_)
render_task_pending_ = false;
if (!gl_enabled_)
EnableGL();
ScopedGLContext scoped_gl_context(glarea_, true);
if (!scoped_gl_context.IsValid())
return;
renderer_.Render();
}
void OSRWindow::EnableGL() {
ASSERT(CefCurrentlyOn(TID_UI));
if (gl_enabled_)
return;
ScopedGLContext scoped_gl_context(glarea_, false);
if (!scoped_gl_context.IsValid())
return;
renderer_.Initialize();
gl_enabled_ = true;
}
void OSRWindow::DisableGL() {
ASSERT(CefCurrentlyOn(TID_UI));
if (!gl_enabled_)
return;
ScopedGLContext scoped_gl_context(glarea_, false);
if (!scoped_gl_context.IsValid())
return;
renderer_.Cleanup();
gl_enabled_ = false;
}
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "cefclient/cefclient_osr_widget_gtk.h"
// This value is defined in build/common.gypi and must be undefined here
// in order for gtkglext to compile.
#undef GTK_DISABLE_SINGLE_INCLUDES
#include <gdk/gdk.h>
#include <gdk/gdkkeysyms.h>
#include <glib-object.h>
#include <gtk/gtk.h>
#include <gtk/gtkgl.h>
#include <GL/gl.h>
#include "include/cef_runnable.h"
#include "cefclient/util.h"
namespace {
gint glarea_size_allocation(GtkWidget* widget,
GtkAllocation* allocation,
OSRWindow* window) {
CefRefPtr<CefBrowserHost> host = window->GetBrowserHost();
host->WasResized();
return TRUE;
}
int get_cef_state_modifiers(guint state) {
int modifiers = 0;
if (state & GDK_SHIFT_MASK)
modifiers |= EVENTFLAG_SHIFT_DOWN;
if (state & GDK_LOCK_MASK)
modifiers |= EVENTFLAG_CAPS_LOCK_ON;
if (state & GDK_CONTROL_MASK)
modifiers |= EVENTFLAG_CONTROL_DOWN;
if (state & GDK_MOD1_MASK)
modifiers |= EVENTFLAG_ALT_DOWN;
if (state & GDK_BUTTON1_MASK)
modifiers |= EVENTFLAG_LEFT_MOUSE_BUTTON;
if (state & GDK_BUTTON2_MASK)
modifiers |= EVENTFLAG_MIDDLE_MOUSE_BUTTON;
if (state & GDK_BUTTON3_MASK)
modifiers |= EVENTFLAG_RIGHT_MOUSE_BUTTON;
return modifiers;
}
gint glarea_click_event(GtkWidget* widget,
GdkEventButton* event,
OSRWindow* window) {
CefRefPtr<CefBrowserHost> host = window->GetBrowserHost();
CefBrowserHost::MouseButtonType button_type = MBT_LEFT;
switch (event->button) {
case 1:
break;
case 2:
button_type = MBT_MIDDLE;
break;
case 3:
button_type = MBT_RIGHT;
break;
default:
// Other mouse buttons are not handled here.
return FALSE;
}
CefMouseEvent mouse_event;
mouse_event.x = event->x;
mouse_event.y = event->y;
window->ApplyPopupOffset(mouse_event.x, mouse_event.y);
mouse_event.modifiers = get_cef_state_modifiers(event->state);
bool mouse_up = (event->type == GDK_BUTTON_RELEASE);
if (!mouse_up)
gtk_widget_grab_focus(widget);
int click_count = 1;
switch (event->type) {
case GDK_2BUTTON_PRESS:
click_count = 2;
break;
case GDK_3BUTTON_PRESS:
click_count = 3;
break;
default:
break;
}
host->SendMouseClickEvent(mouse_event, button_type, mouse_up, click_count);
return TRUE;
}
gint glarea_move_event(GtkWidget* widget,
GdkEventMotion* event,
OSRWindow* window) {
gint x, y;
GdkModifierType state;
if (event->is_hint) {
gdk_window_get_pointer(event->window, &x, &y, &state);
} else {
x = (gint)event->x;
y = (gint)event->y;
state = (GdkModifierType)event->state;
}
CefRefPtr<CefBrowserHost> host = window->GetBrowserHost();
CefMouseEvent mouse_event;
mouse_event.x = x;
mouse_event.y = y;
window->ApplyPopupOffset(mouse_event.x, mouse_event.y);
mouse_event.modifiers = get_cef_state_modifiers(state);
bool mouse_leave = (event->type == GDK_LEAVE_NOTIFY);
host->SendMouseMoveEvent(mouse_event, mouse_leave);
return TRUE;
}
gint glarea_scroll_event(GtkWidget* widget,
GdkEventScroll* event,
OSRWindow* window) {
CefRefPtr<CefBrowserHost> host = window->GetBrowserHost();
CefMouseEvent mouse_event;
mouse_event.x = event->x;
mouse_event.y = event->y;
window->ApplyPopupOffset(mouse_event.x, mouse_event.y);
mouse_event.modifiers = get_cef_state_modifiers(event->state);
static const int scrollbarPixelsPerGtkTick = 40;
int deltaX = 0;
int deltaY = 0;
switch (event->direction) {
case GDK_SCROLL_UP:
deltaY = scrollbarPixelsPerGtkTick;
break;
case GDK_SCROLL_DOWN:
deltaY = -scrollbarPixelsPerGtkTick;
break;
case GDK_SCROLL_LEFT:
deltaX = scrollbarPixelsPerGtkTick;
break;
case GDK_SCROLL_RIGHT:
deltaX = -scrollbarPixelsPerGtkTick;
break;
}
host->SendMouseWheelEvent(mouse_event, deltaX, deltaY);
return TRUE;
}
gint glarea_key_event(GtkWidget* widget,
GdkEventKey* event,
OSRWindow* window) {
CefRefPtr<CefBrowserHost> host = window->GetBrowserHost();
CefKeyEvent key_event;
key_event.native_key_code = event->keyval;
key_event.modifiers = get_cef_state_modifiers(event->state);
if (event->type == GDK_KEY_PRESS) {
key_event.type = KEYEVENT_RAWKEYDOWN;
host->SendKeyEvent(key_event);
} else {
// Need to send both KEYUP and CHAR events.
key_event.type = KEYEVENT_KEYUP;
host->SendKeyEvent(key_event);
key_event.type = KEYEVENT_CHAR;
host->SendKeyEvent(key_event);
}
return TRUE;
}
gint glarea_focus_event(GtkWidget* widget,
GdkEventFocus* event,
OSRWindow* window) {
CefRefPtr<CefBrowserHost> host = window->GetBrowserHost();
host->SendFocusEvent(event->in == TRUE);
return TRUE;
}
void widget_get_rect_in_screen(GtkWidget* widget, GdkRectangle* r) {
gint x, y, w, h;
GdkRectangle extents;
GdkWindow* window = gtk_widget_get_parent_window(widget);
// Get parent's left-top screen coordinates.
gdk_window_get_root_origin(window, &x, &y);
// Get parent's width and height.
gdk_drawable_get_size(window, &w, &h);
// Get parent's extents including decorations.
gdk_window_get_frame_extents(window, &extents);
// X and Y calculations assume that left, right and bottom border sizes are
// all the same.
const gint border = (extents.width - w) / 2;
r->x = x + border + widget->allocation.x;
r->y = y + (extents.height - h) - border + widget->allocation.y;
r->width = widget->allocation.width;
r->height = widget->allocation.height;
}
class ScopedGLContext {
public:
ScopedGLContext(GtkWidget* widget, bool swap_buffers)
: swap_buffers_(swap_buffers) {
GdkGLContext* glcontext = gtk_widget_get_gl_context(widget);
gldrawable_ = gtk_widget_get_gl_drawable(widget);
is_valid_ = gdk_gl_drawable_gl_begin(gldrawable_, glcontext);
}
virtual ~ScopedGLContext() {
if (is_valid_) {
gdk_gl_drawable_gl_end(gldrawable_);
if(swap_buffers_) {
if (gdk_gl_drawable_is_double_buffered(gldrawable_))
gdk_gl_drawable_swap_buffers(gldrawable_);
else
glFlush();
}
}
}
bool IsValid() const { return is_valid_; }
private:
bool swap_buffers_;
GdkGLContext* glcontext_;
GdkGLDrawable* gldrawable_;
bool is_valid_;
};
} // namespace
// static
CefRefPtr<OSRWindow> OSRWindow::Create(OSRBrowserProvider* browser_provider,
bool transparent,
CefWindowHandle parentView) {
ASSERT(browser_provider);
if (!browser_provider)
return NULL;
return new OSRWindow(browser_provider, transparent, parentView);
}
// static
CefRefPtr<OSRWindow> OSRWindow::From(
CefRefPtr<ClientHandler::RenderHandler> renderHandler) {
return static_cast<OSRWindow*>(renderHandler.get());
}
void OSRWindow::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
// Disconnect all signal handlers that reference |this|.
g_signal_handlers_disconnect_matched(glarea_, G_SIGNAL_MATCH_DATA, 0, 0,
NULL, NULL, this);
DisableGL();
}
bool OSRWindow::GetViewRect(CefRefPtr<CefBrowser> browser,
CefRect& rect) {
if (!glarea_)
return false;
// The simulated screen and view rectangle are the same. This is necessary
// for popup menus to be located and sized inside the view.
rect.x = rect.y = 0;
rect.width = glarea_->allocation.width;
rect.height = glarea_->allocation.height;
return true;
}
bool OSRWindow::GetScreenPoint(CefRefPtr<CefBrowser> browser,
int viewX,
int viewY,
int& screenX,
int& screenY) {
GdkRectangle screen_rect;
widget_get_rect_in_screen(glarea_, &screen_rect);
screenX = screen_rect.x + viewX;
screenY = screen_rect.y + viewY;
return true;
}
void OSRWindow::OnPopupShow(CefRefPtr<CefBrowser> browser,
bool show) {
if (!show) {
CefRect dirty_rect = renderer_.popup_rect();
renderer_.ClearPopupRects();
browser->GetHost()->Invalidate(dirty_rect, PET_VIEW);
}
renderer_.OnPopupShow(browser, show);
}
void OSRWindow::OnPopupSize(CefRefPtr<CefBrowser> browser,
const CefRect& rect) {
renderer_.OnPopupSize(browser, rect);
}
void OSRWindow::OnPaint(CefRefPtr<CefBrowser> browser,
PaintElementType type,
const RectList& dirtyRects,
const void* buffer,
int width, int height) {
if (painting_popup_) {
renderer_.OnPaint(browser, type, dirtyRects, buffer, width, height);
return;
}
if (!gl_enabled_)
EnableGL();
ScopedGLContext scoped_gl_context(glarea_, true);
if (!scoped_gl_context.IsValid())
return;
renderer_.OnPaint(browser, type, dirtyRects, buffer, width, height);
if (type == PET_VIEW && !renderer_.popup_rect().IsEmpty()) {
painting_popup_ = true;
CefRect client_popup_rect(0, 0,
renderer_.popup_rect().width,
renderer_.popup_rect().height);
browser->GetHost()->Invalidate(client_popup_rect, PET_POPUP);
painting_popup_ = false;
}
renderer_.Render();
}
void OSRWindow::OnCursorChange(CefRefPtr<CefBrowser> browser,
CefCursorHandle cursor) {
GtkWidget* window = gtk_widget_get_toplevel(glarea_);
GdkWindow* gdk_window = gtk_widget_get_window(window);
if (cursor->type == GDK_LAST_CURSOR)
cursor = NULL;
gdk_window_set_cursor(gdk_window, cursor);
}
void OSRWindow::Invalidate() {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI, NewCefRunnableMethod(this, &OSRWindow::Invalidate));
return;
}
// Don't post another task if the previous task is still pending.
if (render_task_pending_)
return;
render_task_pending_ = true;
// Render at 30fps.
static const int kRenderDelay = 1000 / 30;
CefPostDelayedTask(TID_UI, NewCefRunnableMethod(this, &OSRWindow::Render),
kRenderDelay);
}
bool OSRWindow::IsOverPopupWidget(int x, int y) const {
const CefRect& rc = renderer_.popup_rect();
int popup_right = rc.x + rc.width;
int popup_bottom = rc.y + rc.height;
return (x >= rc.x) && (x < popup_right) &&
(y >= rc.y) && (y < popup_bottom);
}
int OSRWindow::GetPopupXOffset() const {
return renderer_.original_popup_rect().x - renderer_.popup_rect().x;
}
int OSRWindow::GetPopupYOffset() const {
return renderer_.original_popup_rect().y - renderer_.popup_rect().y;
}
void OSRWindow::ApplyPopupOffset(int& x, int& y) const {
if (IsOverPopupWidget(x, y)) {
x += GetPopupXOffset();
y += GetPopupYOffset();
}
}
OSRWindow::OSRWindow(OSRBrowserProvider* browser_provider,
bool transparent,
CefWindowHandle parentView)
: renderer_(transparent),
browser_provider_(browser_provider),
gl_enabled_(false),
painting_popup_(false),
render_task_pending_(false) {
glarea_ = gtk_drawing_area_new();
ASSERT(glarea_);
GdkGLConfig* glconfig = gdk_gl_config_new_by_mode(
static_cast<GdkGLConfigMode>(GDK_GL_MODE_RGB |
GDK_GL_MODE_DEPTH |
GDK_GL_MODE_DOUBLE));
ASSERT(glconfig);
gtk_widget_set_gl_capability(glarea_, glconfig, NULL, TRUE,
GDK_GL_RGBA_TYPE);
gtk_widget_set_can_focus(glarea_, TRUE);
g_signal_connect(G_OBJECT(glarea_), "size_allocate",
G_CALLBACK(glarea_size_allocation), this);
gtk_widget_set_events(glarea_,
GDK_BUTTON_PRESS_MASK |
GDK_BUTTON_RELEASE_MASK |
GDK_KEY_PRESS_MASK |
GDK_KEY_RELEASE_MASK |
GDK_ENTER_NOTIFY_MASK |
GDK_LEAVE_NOTIFY_MASK |
GDK_POINTER_MOTION_MASK |
GDK_POINTER_MOTION_HINT_MASK |
GDK_SCROLL_MASK |
GDK_FOCUS_CHANGE_MASK);
g_signal_connect(G_OBJECT(glarea_), "button_press_event",
G_CALLBACK(glarea_click_event), this);
g_signal_connect(G_OBJECT(glarea_), "button_release_event",
G_CALLBACK(glarea_click_event), this);
g_signal_connect(G_OBJECT(glarea_), "key_press_event",
G_CALLBACK(glarea_key_event), this);
g_signal_connect(G_OBJECT(glarea_), "key_release_event",
G_CALLBACK(glarea_key_event), this);
g_signal_connect(G_OBJECT(glarea_), "enter_notify_event",
G_CALLBACK(glarea_move_event), this);
g_signal_connect(G_OBJECT(glarea_), "leave_notify_event",
G_CALLBACK(glarea_move_event), this);
g_signal_connect(G_OBJECT(glarea_), "motion_notify_event",
G_CALLBACK(glarea_move_event), this);
g_signal_connect(G_OBJECT(glarea_), "scroll_event",
G_CALLBACK(glarea_scroll_event), this);
g_signal_connect(G_OBJECT(glarea_), "focus_in_event",
G_CALLBACK(glarea_focus_event), this);
g_signal_connect(G_OBJECT(glarea_), "focus_out_event",
G_CALLBACK(glarea_focus_event), this);
gtk_container_add(GTK_CONTAINER(parentView), glarea_);
}
OSRWindow::~OSRWindow() {
}
void OSRWindow::Render() {
ASSERT(CefCurrentlyOn(TID_UI));
if (render_task_pending_)
render_task_pending_ = false;
if (!gl_enabled_)
EnableGL();
ScopedGLContext scoped_gl_context(glarea_, true);
if (!scoped_gl_context.IsValid())
return;
renderer_.Render();
}
void OSRWindow::EnableGL() {
ASSERT(CefCurrentlyOn(TID_UI));
if (gl_enabled_)
return;
ScopedGLContext scoped_gl_context(glarea_, false);
if (!scoped_gl_context.IsValid())
return;
renderer_.Initialize();
gl_enabled_ = true;
}
void OSRWindow::DisableGL() {
ASSERT(CefCurrentlyOn(TID_UI));
if (!gl_enabled_)
return;
ScopedGLContext scoped_gl_context(glarea_, false);
if (!scoped_gl_context.IsValid())
return;
renderer_.Cleanup();
gl_enabled_ = false;
}

View File

@@ -1,90 +1,90 @@
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef CEF_TESTS_CEFCLIENT_CEFCLIENT_OSR_WIDGET_GTK_H_
#define CEF_TESTS_CEFCLIENT_CEFCLIENT_OSR_WIDGET_GTK_H_
#pragma once
#include "include/cef_render_handler.h"
#include "cefclient/client_handler.h"
#include "cefclient/osrenderer.h"
class OSRBrowserProvider {
public:
virtual CefRefPtr<CefBrowser> GetBrowser() =0;
protected:
virtual ~OSRBrowserProvider() {}
};
class OSRWindow : public ClientHandler::RenderHandler {
public:
// Create a new OSRWindow instance. |browser_provider| must outlive this
// object.
static CefRefPtr<OSRWindow> Create(OSRBrowserProvider* browser_provider,
bool transparent,
CefWindowHandle parentView);
static CefRefPtr<OSRWindow> From(
CefRefPtr<ClientHandler::RenderHandler> renderHandler);
CefWindowHandle GetWindowHandle() const {
return glarea_;
}
CefRefPtr<CefBrowserHost> GetBrowserHost() const {
return browser_provider_->GetBrowser()->GetHost();
}
// ClientHandler::RenderHandler methods
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
// CefRenderHandler methods
virtual bool GetViewRect(CefRefPtr<CefBrowser> browser,
CefRect& rect) OVERRIDE;
virtual bool GetScreenPoint(CefRefPtr<CefBrowser> browser,
int viewX,
int viewY,
int& screenX,
int& screenY) OVERRIDE;
virtual void OnPopupShow(CefRefPtr<CefBrowser> browser,
bool show) OVERRIDE;
virtual void OnPopupSize(CefRefPtr<CefBrowser> browser,
const CefRect& rect) OVERRIDE;
virtual void OnPaint(CefRefPtr<CefBrowser> browser,
PaintElementType type,
const RectList& dirtyRects,
const void* buffer,
int width,
int height) OVERRIDE;
virtual void OnCursorChange(CefRefPtr<CefBrowser> browser,
CefCursorHandle cursor) OVERRIDE;
void Invalidate();
bool IsOverPopupWidget(int x, int y) const;
int GetPopupXOffset() const;
int GetPopupYOffset() const;
void ApplyPopupOffset(int& x, int& y) const;
private:
OSRWindow(OSRBrowserProvider* browser_provider,
bool transparent,
CefWindowHandle parentView);
virtual ~OSRWindow();
void Render();
void EnableGL();
void DisableGL();
ClientOSRenderer renderer_;
OSRBrowserProvider* browser_provider_;
CefWindowHandle glarea_;
bool gl_enabled_;
bool painting_popup_;
bool render_task_pending_;
IMPLEMENT_REFCOUNTING(OSRWindow);
};
#endif // CEF_TESTS_CEFCLIENT_CEFCLIENT_OSR_WIDGET_GTK_H_
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#ifndef CEF_TESTS_CEFCLIENT_CEFCLIENT_OSR_WIDGET_GTK_H_
#define CEF_TESTS_CEFCLIENT_CEFCLIENT_OSR_WIDGET_GTK_H_
#pragma once
#include "include/cef_render_handler.h"
#include "cefclient/client_handler.h"
#include "cefclient/osrenderer.h"
class OSRBrowserProvider {
public:
virtual CefRefPtr<CefBrowser> GetBrowser() =0;
protected:
virtual ~OSRBrowserProvider() {}
};
class OSRWindow : public ClientHandler::RenderHandler {
public:
// Create a new OSRWindow instance. |browser_provider| must outlive this
// object.
static CefRefPtr<OSRWindow> Create(OSRBrowserProvider* browser_provider,
bool transparent,
CefWindowHandle parentView);
static CefRefPtr<OSRWindow> From(
CefRefPtr<ClientHandler::RenderHandler> renderHandler);
CefWindowHandle GetWindowHandle() const {
return glarea_;
}
CefRefPtr<CefBrowserHost> GetBrowserHost() const {
return browser_provider_->GetBrowser()->GetHost();
}
// ClientHandler::RenderHandler methods
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
// CefRenderHandler methods
virtual bool GetViewRect(CefRefPtr<CefBrowser> browser,
CefRect& rect) OVERRIDE;
virtual bool GetScreenPoint(CefRefPtr<CefBrowser> browser,
int viewX,
int viewY,
int& screenX,
int& screenY) OVERRIDE;
virtual void OnPopupShow(CefRefPtr<CefBrowser> browser,
bool show) OVERRIDE;
virtual void OnPopupSize(CefRefPtr<CefBrowser> browser,
const CefRect& rect) OVERRIDE;
virtual void OnPaint(CefRefPtr<CefBrowser> browser,
PaintElementType type,
const RectList& dirtyRects,
const void* buffer,
int width,
int height) OVERRIDE;
virtual void OnCursorChange(CefRefPtr<CefBrowser> browser,
CefCursorHandle cursor) OVERRIDE;
void Invalidate();
bool IsOverPopupWidget(int x, int y) const;
int GetPopupXOffset() const;
int GetPopupYOffset() const;
void ApplyPopupOffset(int& x, int& y) const;
private:
OSRWindow(OSRBrowserProvider* browser_provider,
bool transparent,
CefWindowHandle parentView);
virtual ~OSRWindow();
void Render();
void EnableGL();
void DisableGL();
ClientOSRenderer renderer_;
OSRBrowserProvider* browser_provider_;
CefWindowHandle glarea_;
bool gl_enabled_;
bool painting_popup_;
bool render_task_pending_;
IMPLEMENT_REFCOUNTING(OSRWindow);
};
#endif // CEF_TESTS_CEFCLIENT_CEFCLIENT_OSR_WIDGET_GTK_H_

View File

@@ -1,128 +1,128 @@
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file.
#ifndef CEF_TESTS_CEFCLIENT_CEFCLIENT_OSR_WIDGET_MAC_H_
#define CEF_TESTS_CEFCLIENT_CEFCLIENT_OSR_WIDGET_MAC_H_
#include "include/cef_client.h"
#include "cefclient/client_handler.h"
class ClientOSRenderer;
class OSRBrowserProvider {
public:
virtual CefRefPtr<CefBrowser> GetBrowser() =0;
protected:
virtual ~OSRBrowserProvider() {}
};
// The client OpenGL view.
@interface ClientOpenGLView : NSOpenGLView {
@public
NSTrackingArea* tracking_area_;
OSRBrowserProvider* browser_provider_;
ClientOSRenderer* renderer_;
NSPoint last_mouse_pos_;
NSPoint cur_mouse_pos_;
bool rotating_;
bool was_last_mouse_down_on_view_;
// Event monitor for scroll wheel end event.
id endWheelMonitor_;
}
- (id)initWithFrame:(NSRect)frame andTransparency:(bool)transparency;
- (NSPoint)getClickPointForEvent:(NSEvent*)event;
- (void)getKeyEvent:(CefKeyEvent&)keyEvent forEvent:(NSEvent*)event;
- (void)getMouseEvent:(CefMouseEvent&)mouseEvent forEvent:(NSEvent*)event;
- (int)getModifiersForEvent:(NSEvent*)event;
- (BOOL)isKeyUpEvent:(NSEvent*)event;
- (BOOL)isKeyPadEvent:(NSEvent*)event;
- (CefRefPtr<CefBrowser>)getBrowser;
@end
// Handler for off-screen rendering windows.
class ClientOSRHandler : public ClientHandler::RenderHandler {
public:
explicit ClientOSRHandler(ClientOpenGLView* view,
OSRBrowserProvider* browser_provider);
virtual ~ClientOSRHandler();
void Disconnect();
// ClientHandler::RenderHandler
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
// CefRenderHandler methods
virtual bool GetViewRect(CefRefPtr<CefBrowser> browser,
CefRect& rect) OVERRIDE;
virtual bool GetScreenPoint(CefRefPtr<CefBrowser> browser,
int viewX,
int viewY,
int& screenX,
int& screenY) OVERRIDE;
virtual bool GetScreenInfo(CefRefPtr<CefBrowser> browser,
CefScreenInfo& screen_info) OVERRIDE;
virtual void OnPopupShow(CefRefPtr<CefBrowser> browser,
bool show) OVERRIDE;
virtual void OnPopupSize(CefRefPtr<CefBrowser> browser,
const CefRect& rect) OVERRIDE;
virtual void OnPaint(CefRefPtr<CefBrowser> browser,
PaintElementType type,
const RectList& dirtyRects,
const void* buffer,
int width, int height) OVERRIDE;
virtual void OnCursorChange(CefRefPtr<CefBrowser> browser,
CefCursorHandle cursor) OVERRIDE;
CefWindowHandle view() { return view_; }
private:
void SetLoading(bool isLoading);
ClientOpenGLView* view_;
bool painting_popup_;
// Include the default reference counting implementation.
IMPLEMENT_REFCOUNTING(ClientOSRHandler);
};
class OSRWindow {
public:
static CefRefPtr<OSRWindow> Create(OSRBrowserProvider* browser_provider,
bool transparent,
CefWindowHandle parentView,
const CefRect& frame);
CefRefPtr<ClientHandler::RenderHandler> GetRenderHandler() {
return render_client.get();
}
CefWindowHandle GetWindowHandle() { return view_; }
private:
OSRWindow(OSRBrowserProvider* browser_provider,
bool transparent,
CefWindowHandle parentView,
const CefRect& frame);
~OSRWindow();
CefRefPtr<ClientOSRHandler> render_client;
CefWindowHandle view_;
IMPLEMENT_REFCOUNTING(OSRWindow);
};
#endif // CEF_TESTS_CEFCLIENT_CEFCLIENT_OSR_WIDGET_MAC_H_
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file.
#ifndef CEF_TESTS_CEFCLIENT_CEFCLIENT_OSR_WIDGET_MAC_H_
#define CEF_TESTS_CEFCLIENT_CEFCLIENT_OSR_WIDGET_MAC_H_
#include "include/cef_client.h"
#include "cefclient/client_handler.h"
class ClientOSRenderer;
class OSRBrowserProvider {
public:
virtual CefRefPtr<CefBrowser> GetBrowser() =0;
protected:
virtual ~OSRBrowserProvider() {}
};
// The client OpenGL view.
@interface ClientOpenGLView : NSOpenGLView {
@public
NSTrackingArea* tracking_area_;
OSRBrowserProvider* browser_provider_;
ClientOSRenderer* renderer_;
NSPoint last_mouse_pos_;
NSPoint cur_mouse_pos_;
bool rotating_;
bool was_last_mouse_down_on_view_;
// Event monitor for scroll wheel end event.
id endWheelMonitor_;
}
- (id)initWithFrame:(NSRect)frame andTransparency:(bool)transparency;
- (NSPoint)getClickPointForEvent:(NSEvent*)event;
- (void)getKeyEvent:(CefKeyEvent&)keyEvent forEvent:(NSEvent*)event;
- (void)getMouseEvent:(CefMouseEvent&)mouseEvent forEvent:(NSEvent*)event;
- (int)getModifiersForEvent:(NSEvent*)event;
- (BOOL)isKeyUpEvent:(NSEvent*)event;
- (BOOL)isKeyPadEvent:(NSEvent*)event;
- (CefRefPtr<CefBrowser>)getBrowser;
@end
// Handler for off-screen rendering windows.
class ClientOSRHandler : public ClientHandler::RenderHandler {
public:
explicit ClientOSRHandler(ClientOpenGLView* view,
OSRBrowserProvider* browser_provider);
virtual ~ClientOSRHandler();
void Disconnect();
// ClientHandler::RenderHandler
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
// CefRenderHandler methods
virtual bool GetViewRect(CefRefPtr<CefBrowser> browser,
CefRect& rect) OVERRIDE;
virtual bool GetScreenPoint(CefRefPtr<CefBrowser> browser,
int viewX,
int viewY,
int& screenX,
int& screenY) OVERRIDE;
virtual bool GetScreenInfo(CefRefPtr<CefBrowser> browser,
CefScreenInfo& screen_info) OVERRIDE;
virtual void OnPopupShow(CefRefPtr<CefBrowser> browser,
bool show) OVERRIDE;
virtual void OnPopupSize(CefRefPtr<CefBrowser> browser,
const CefRect& rect) OVERRIDE;
virtual void OnPaint(CefRefPtr<CefBrowser> browser,
PaintElementType type,
const RectList& dirtyRects,
const void* buffer,
int width, int height) OVERRIDE;
virtual void OnCursorChange(CefRefPtr<CefBrowser> browser,
CefCursorHandle cursor) OVERRIDE;
CefWindowHandle view() { return view_; }
private:
void SetLoading(bool isLoading);
ClientOpenGLView* view_;
bool painting_popup_;
// Include the default reference counting implementation.
IMPLEMENT_REFCOUNTING(ClientOSRHandler);
};
class OSRWindow {
public:
static CefRefPtr<OSRWindow> Create(OSRBrowserProvider* browser_provider,
bool transparent,
CefWindowHandle parentView,
const CefRect& frame);
CefRefPtr<ClientHandler::RenderHandler> GetRenderHandler() {
return render_client.get();
}
CefWindowHandle GetWindowHandle() { return view_; }
private:
OSRWindow(OSRBrowserProvider* browser_provider,
bool transparent,
CefWindowHandle parentView,
const CefRect& frame);
~OSRWindow();
CefRefPtr<ClientOSRHandler> render_client;
CefWindowHandle view_;
IMPLEMENT_REFCOUNTING(OSRWindow);
};
#endif // CEF_TESTS_CEFCLIENT_CEFCLIENT_OSR_WIDGET_MAC_H_

File diff suppressed because it is too large Load Diff

View File

@@ -1,69 +1,69 @@
<html>
<head><title>OSR Test</title></head>
<style>
.red_hover:hover {color:red;}
#li { width: 530px; }
body {background:rgba(255, 0, 0, 0.5); }
input {-webkit-appearance: none; }
#LI11select {width: 75px;}
</style>
<script>
function sendBrowserMessage(paramString) {
app.sendMessage("osrtest", [paramString]);
}
function getElement(id) { return document.getElementById(id); }
function makeH1Red() { getElement('LI00').style.color='red'; }
function makeH1Black() { getElement('LI00').style.color='black'; }
function navigate() { location.href='?k='+getElement('editbox').value; }
function load() { var select = document.getElementById('LI11select');
for (var i = 1; i < 21; i++)
select.options.add(new Option('Option ' + i, i));
}
function onEventTest(event) {
var param = event.type;
if (event.type == "click")
param += event.button;
sendBrowserMessage(param);
}
</script>
<body onfocus='onEventTest(event)' onblur='onEventTest(event)' onload='load();'>
<h1 id='LI00' onclick="onEventTest(event)">
OSR Testing h1 - Focus and blur
<select id='LI11select'>
<option value='0'>Default</option>
</select>
this page and will get this red black
</h1>
<ol>
<li id='LI01'>OnPaint should be called each time a page loads</li>
<li id='LI02' style='cursor:pointer;'><span>Move mouse
to require an OnCursorChange call</span></li>
<li id='LI03' onmousemove="onEventTest(event)"><span>Hover will color this with
red. Will trigger OnPaint once on enter and once on leave</span></li>
<li id='LI04'>Right clicking will show contextual menu and will request
GetScreenPoint</li>
<li id='LI05'>IsWindowRenderingDisabled should be true</li>
<li id='LI06'>WasResized should trigger full repaint if size changes.
</li>
<li id='LI07'>Invalidate should trigger OnPaint once</li>
<li id='LI08'>Click and write here with SendKeyEvent to trigger repaints:
<input id='editbox' type='text' value='' size="5"></li>
<li id='LI09'>Click here with SendMouseClickEvent to navigate:
<input id='btnnavigate' type='button' onclick='navigate()'
value='Click here to navigate' id='editbox' /></li>
<li id='LI10' title='EXPECTED_TOOLTIP'>Mouse over this element will
trigger show a tooltip</li>
</ol>
<br />
<br />
<br />
<br />
<br />
<br />
</body>
</html>
<html>
<head><title>OSR Test</title></head>
<style>
.red_hover:hover {color:red;}
#li { width: 530px; }
body {background:rgba(255, 0, 0, 0.5); }
input {-webkit-appearance: none; }
#LI11select {width: 75px;}
</style>
<script>
function sendBrowserMessage(paramString) {
app.sendMessage("osrtest", [paramString]);
}
function getElement(id) { return document.getElementById(id); }
function makeH1Red() { getElement('LI00').style.color='red'; }
function makeH1Black() { getElement('LI00').style.color='black'; }
function navigate() { location.href='?k='+getElement('editbox').value; }
function load() { var select = document.getElementById('LI11select');
for (var i = 1; i < 21; i++)
select.options.add(new Option('Option ' + i, i));
}
function onEventTest(event) {
var param = event.type;
if (event.type == "click")
param += event.button;
sendBrowserMessage(param);
}
</script>
<body onfocus='onEventTest(event)' onblur='onEventTest(event)' onload='load();'>
<h1 id='LI00' onclick="onEventTest(event)">
OSR Testing h1 - Focus and blur
<select id='LI11select'>
<option value='0'>Default</option>
</select>
this page and will get this red black
</h1>
<ol>
<li id='LI01'>OnPaint should be called each time a page loads</li>
<li id='LI02' style='cursor:pointer;'><span>Move mouse
to require an OnCursorChange call</span></li>
<li id='LI03' onmousemove="onEventTest(event)"><span>Hover will color this with
red. Will trigger OnPaint once on enter and once on leave</span></li>
<li id='LI04'>Right clicking will show contextual menu and will request
GetScreenPoint</li>
<li id='LI05'>IsWindowRenderingDisabled should be true</li>
<li id='LI06'>WasResized should trigger full repaint if size changes.
</li>
<li id='LI07'>Invalidate should trigger OnPaint once</li>
<li id='LI08'>Click and write here with SendKeyEvent to trigger repaints:
<input id='editbox' type='text' value='' size="5"></li>
<li id='LI09'>Click here with SendMouseClickEvent to navigate:
<input id='btnnavigate' type='button' onclick='navigate()'
value='Click here to navigate' id='editbox' /></li>
<li id='LI10' title='EXPECTED_TOOLTIP'>Mouse over this element will
trigger show a tooltip</li>
</ol>
<br />
<br />
<br />
<br />
<br />
<br />
</body>
</html>

View File

@@ -1,32 +1,32 @@
<html>
<head>
<title>Other Tests</title>
</head>
<body bgcolor="white">
<h3>Various other internal and external tests.</h3>
<ul>
<li><a href="http://mudcu.be/labs/JS1k/BreathingGalaxies.html">Accelerated 2D Canvas</a></li>
<li><a href="http://webkit.org/blog-files/3d-transforms/poster-circle.html">Accelerated Layers</a></li>
<li><a href="http://html5advent2011.digitpaint.nl/3/index.html">Cursors</a></li>
<li><a href="http://tests/dialogs">Dialogs</a></li>
<li><a href="http://tests/domaccess">DOM Access</a></li>
<li><a href="http://html5demos.com/drag">Drag & Drop</a></li>
<li><a href="http://www.adobe.com/software/flash/about/">Flash Plugin</a></li>
<li><a href="http://html5demos.com/geo">Geolocation</a></li>
<li><a href="http://www.html5test.com">HTML5 Feature Test</a></li>
<li><a href="http://www.youtube.com/watch?v=siOHh0uzcuY&html5=True">HTML5 Video</a></li>
<li><a href="http://tests/binding">JavaScript Binding</a></li>
<li><a href="http://tests/performance">JavaScript Performance Tests</a></li>
<li><a href="http://tests/performance2">JavaScript Performance (2) Tests</a></li>
<li><a href="http://tests/window">JavaScript Window Manipulation</a></li>
<li><a href="http://tests/localstorage">Local Storage</a></li>
<li><a href="http://mrdoob.com/lab/javascript/requestanimationframe/">requestAnimationFrame</a></li>
<li><a href="client://tests/handler.html">Scheme Handler</a></li>
<li><a href="http://slides.html5rocks.com/#speech-input">Speech Input</a> - requires "enable-speech-input" flag</li>
<li><a href="http://tests/transparency">Transparency</a></li>
<li><a href="http://webglsamples.googlecode.com/hg/field/field.html">WebGL</a></li>
<li><a href="http://apprtc.appspot.com/">WebRTC</a> - requires "enable-media-stream" flag</li>
<li><a href="http://tests/xmlhttprequest">XMLHttpRequest</a></li>
</ul>
</body>
</html>
<html>
<head>
<title>Other Tests</title>
</head>
<body bgcolor="white">
<h3>Various other internal and external tests.</h3>
<ul>
<li><a href="http://mudcu.be/labs/JS1k/BreathingGalaxies.html">Accelerated 2D Canvas</a></li>
<li><a href="http://webkit.org/blog-files/3d-transforms/poster-circle.html">Accelerated Layers</a></li>
<li><a href="http://html5advent2011.digitpaint.nl/3/index.html">Cursors</a></li>
<li><a href="http://tests/dialogs">Dialogs</a></li>
<li><a href="http://tests/domaccess">DOM Access</a></li>
<li><a href="http://html5demos.com/drag">Drag & Drop</a></li>
<li><a href="http://www.adobe.com/software/flash/about/">Flash Plugin</a></li>
<li><a href="http://html5demos.com/geo">Geolocation</a></li>
<li><a href="http://www.html5test.com">HTML5 Feature Test</a></li>
<li><a href="http://www.youtube.com/watch?v=siOHh0uzcuY&html5=True">HTML5 Video</a></li>
<li><a href="http://tests/binding">JavaScript Binding</a></li>
<li><a href="http://tests/performance">JavaScript Performance Tests</a></li>
<li><a href="http://tests/performance2">JavaScript Performance (2) Tests</a></li>
<li><a href="http://tests/window">JavaScript Window Manipulation</a></li>
<li><a href="http://tests/localstorage">Local Storage</a></li>
<li><a href="http://mrdoob.com/lab/javascript/requestanimationframe/">requestAnimationFrame</a></li>
<li><a href="client://tests/handler.html">Scheme Handler</a></li>
<li><a href="http://slides.html5rocks.com/#speech-input">Speech Input</a> - requires "enable-speech-input" flag</li>
<li><a href="http://tests/transparency">Transparency</a></li>
<li><a href="http://webglsamples.googlecode.com/hg/field/field.html">WebGL</a></li>
<li><a href="http://apprtc.appspot.com/">WebRTC</a> - requires "enable-media-stream" flag</li>
<li><a href="http://tests/xmlhttprequest">XMLHttpRequest</a></li>
</ul>
</body>
</html>

View File

@@ -1,442 +1,442 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Performance Tests (2)</title>
<style>
body { font-family: Tahoma, Serif; font-size: 9pt; }
.left { text-align: left; }
.right { text-align: right; }
.center { text-align: center; }
table.resultTable
{
border: 1px solid black;
border-collapse: collapse;
empty-cells: show;
width: 100%;
}
table.resultTable td
{
padding: 2px 4px;
border: 1px solid black;
}
table.resultTable > thead > tr
{
font-weight: bold;
background: lightblue;
}
table.resultTable > tbody > tr:nth-child(odd)
{
background: white;
}
table.resultTable > tbody > tr:nth-child(even)
{
background: lightgray;
}
.hide { display: none; }
</style>
</head>
<body bgcolor="white">
<h1>Performance Tests (2)</h1>
<form id="sForm" onsubmit="runTestSuite();return false">
<table>
<tr>
<td colspan="2">Settings:</td>
</tr>
<tr>
<td class="right">Iterations:</td>
<td><input id="sIterations" type="text" value="1000" required pattern="[0-9]+" /></td>
</tr>
<tr>
<td class="right">Samples:</td>
<td><input id="sSamples" type="text" value="100" required pattern="[0-9]+" /></td>
</tr>
<tr>
<td class="right">Mode:</td>
<td><input id="sAsync" name="sMode" type="radio" value="async" checked>Asynchronous</input>
<input id="sSync" name="sMode" type="radio" value="sync">Synchronous</input>
</td>
</tr>
<tr>
<td colspan="2"><button type="submit" id="sRun" autofocus>Run!</button></td>
</tr>
</table>
</form>
<div><span id="statusBox"></span> <progress id="progressBox" value="0" style="display:none"></progress></div>
<div style="padding-top:10px; padding-bottom:10px">
<table id="resultTable" class="resultTable">
<thead>
<tr>
<td class="center" style="width:1%">Enabled</td>
<td class="center" style="width:10%">Name</td>
<td class="center" style="width:5%">Samples x Iterations</td>
<td class="center" style="width:5%">Min,&nbsp;ms</td>
<td class="center" style="width:5%">Avg,&nbsp;ms</td>
<td class="center" style="width:5%">Max,&nbsp;ms</td>
<td class="center" style="width:5%">Average calls/sec</td>
<td class="center" style="width:5%">Measuring Inacurracy</td>
<td class="center hide" style="width:5%">Memory, MB</td>
<td class="center hide" style="width:5%">Memory delta, MB</td>
<td class="center" style="width:55%">Description</td>
</tr>
</thead>
<tbody>
<!-- result rows here -->
</tbody>
</table>
</div>
<script type="text/javascript">
(function () {
function getPrivateWorkingSet() {
return 0; // TODO: window.PerfTestGetPrivateWorkingSet();
}
var disableWarmUp = true;
var asyncExecution = true;
var testIterations = 1000;
var totalSamples = 100;
var sampleDelay = 0;
var collectSamples = false;
var tests = [];
var testIndex = -1;
function execTestFunc(test) {
try {
var begin = new Date();
test.func(test.totalIterations);
var end = new Date();
return (end - begin);
} catch (e) {
test.error = e.toString();
return 0;
}
}
function execTest(test) {
if (disableWarmUp) { test.warmedUp = true; }
function nextStep() {
if (asyncExecution) {
setTimeout(function () { execTest(test); }, sampleDelay);
} else {
execTest(test);
}
}
function nextTest() {
updateStatus(test);
appendResult(test);
return execNextTest();
}
updateStatus(test);
if (!test.warmedUp) {
execTestFunc(test);
if (!test.error) {
test.warmedUp = true;
test.beginMemory = getPrivateWorkingSet();
return nextStep();
} else {
return nextTest();
}
}
if (test.sample >= test.totalSamples) {
test.avg = test.total / test.totalSamples;
test.endMemory = getPrivateWorkingSet();
return nextTest();
}
if (test.skipped) return nextTest();
var elapsed = execTestFunc(test);
if (!test.error) {
test.total += elapsed;
if (!test.min) test.min = elapsed;
else if (test.min > elapsed) test.min = elapsed;
if (!test.max) test.max = elapsed;
else if (test.max < elapsed) test.max = elapsed;
if (collectSamples) {
test.results.push(elapsed);
}
test.sample++;
return nextStep();
} else {
return nextTest();
}
}
function updateStatus(test) {
var statusBox = document.getElementById("statusBox");
var progressBox = document.getElementById("progressBox");
if (test.skipped || test.error || test.sample >= test.totalSamples) {
statusBox.innerText = "";
progressBox.style.display = "none";
} else {
statusBox.innerText = (testIndex + 1) + "/" + tests.length + ": " + test.name + " (" + test.sample + "/" + test.totalSamples + ")";
progressBox.value = (test.sample / test.totalSamples);
progressBox.style.display = "inline";
}
}
function appendResult(test) {
if (test.name == "warmup") return;
var id = "testResultRow_" + test.index;
var nearBound = (test.max - test.avg) < (test.avg - test.min) ? test.max : test.min;
var memoryDelta = test.endMemory - test.beginMemory;
if (memoryDelta < 0) memoryDelta = "-" + Math.abs(memoryDelta).toFixed(2);
else memoryDelta = "+" + Math.abs(memoryDelta).toFixed(2);
var markup = ["<tr id='" + id + "'>",
"<td class='left'><input type='checkbox' id='test_enabled_", test.index ,"' ", (!test.skipped ? "checked" : "") ," /></td>",
"<td class='left'>", test.name, "</td>",
"<td class='right'>", test.totalSamples, "x", test.totalIterations, "</td>",
"<td class='right'>", test.skipped || test.error || !test.prepared ? "-" : test.min.toFixed(2), "</td>",
"<td class='right'>", test.skipped || test.error || !test.prepared ? "-" : test.avg.toFixed(2), "</td>",
"<td class='right'>", test.skipped || test.error || !test.prepared ? "-" : test.max.toFixed(2), "</td>",
"<td class='right'>", test.skipped || test.error || !test.prepared ? "-" : (test.totalIterations * 1000 / test.avg).toFixed(2), "</td>",
"<td class='right'>", test.skipped || test.error || !test.prepared ? "-" : ("&#x00B1; " + (Math.abs(test.avg - nearBound) / (test.avg) * (100)).toFixed(2) + "%"), "</td>",
"<td class='right hide'>", test.skipped || test.error || !test.prepared ? "-" : test.endMemory.toFixed(2), "</td>",
"<td class='right hide'>", test.skipped || test.error || !test.prepared ? "-" : memoryDelta, "</td>",
"<td class='left'>", test.description, test.error ? (test.description ? "<br/>" : "") + "<span style='color:red'>" + test.error + "</span>" : "", "</td>",
"</tr>"
].join("");
// test.results.join(", "), "<br/>",
var row = document.getElementById(id);
if (row) {
row.outerHTML = markup;
} else {
var tbody = document.getElementById("resultTable").tBodies[0];
tbody.insertAdjacentHTML("beforeEnd", markup);
}
}
function prepareQueuedTests() {
testIndex = -1;
for (var i = 0; i < tests.length; i++) {
var test = tests[i];
test.index = i;
test.prepared = false;
test.warmedUp = false;
test.sample = 0;
test.total = 0;
test.results = [];
test.error = false;
test.min = null;
test.avg = null;
test.max = null;
test.beginMemory = null;
test.endMemory = null;
test.totalIterations = parseInt(testIterations / test.complex);
test.totalSamples = parseInt(totalSamples / test.complex);
var skipElement = document.getElementById('test_enabled_' + test.index);
test.skipped = skipElement ? !skipElement.checked : (test.skipped || false);
if (test.totalIterations <= 0) test.totalIterations = 1;
if (test.totalSamples <= 0) test.totalSamples = 1;
appendResult(test);
test.prepared = true;
}
}
function queueTest(func, name, description) {
var test;
if (typeof func === "function") {
test = {
name: name,
func: func,
description: description
};
} else {
test = func;
}
test.warmedUp = false;
test.complex = test.complex || 1;
tests.push(test);
}
function execNextTest() {
testIndex++;
if (tests.length <= testIndex) {
return testSuiteFinished();
} else {
return execTest(tests[testIndex]);
}
}
function execQueuedTests() {
prepareQueuedTests();
execNextTest();
}
function setSettingsState(disabled) {
document.getElementById('sIterations').disabled = disabled;
document.getElementById('sSamples').disabled = disabled;
document.getElementById('sAsync').disabled = disabled;
document.getElementById('sSync').disabled = disabled;
document.getElementById('sRun').disabled = disabled;
}
function testSuiteFinished() {
setSettingsState(false);
}
window.runTestSuite = function () {
setSettingsState(true);
testIterations = parseInt(document.getElementById('sIterations').value);
totalSamples = parseInt(document.getElementById('sSamples').value);
asyncExecution = document.getElementById('sAsync').checked;
setTimeout(execQueuedTests, 0);
}
setTimeout(prepareQueuedTests, 0);
// Test queue.
queueTest({
name: "PerfTestReturnValue Default",
func: function (count) {
for (var i = 0; i < count; i++) {
window.PerfTestReturnValue();
}
},
description: "No arguments, returns int32 value.",
skipped: true,
});
queueTest({
name: "PerfTestReturnValue (0, Undefined)",
func: function (count) {
for (var i = 0; i < count; i++) {
window.PerfTestReturnValue(0);
}
},
description: "Int argument, returns undefined value."
});
queueTest({
name: "PerfTestReturnValue (1, Null)",
func: function (count) {
for (var i = 0; i < count; i++) {
window.PerfTestReturnValue(1);
}
},
description: "Int argument, returns null value."
});
queueTest({
name: "PerfTestReturnValue (2, Bool)",
func: function (count) {
for (var i = 0; i < count; i++) {
window.PerfTestReturnValue(2);
}
},
description: "Int argument, returns bool value."
});
queueTest({
name: "PerfTestReturnValue (3, Int)",
func: function (count) {
for (var i = 0; i < count; i++) {
window.PerfTestReturnValue(3);
}
},
description: "Int argument, returns int value."
});
queueTest({
name: "PerfTestReturnValue (4, UInt)",
func: function (count) {
for (var i = 0; i < count; i++) {
window.PerfTestReturnValue(4);
}
},
description: "Int argument, returns uint value."
});
queueTest({
name: "PerfTestReturnValue (5, Double)",
func: function (count) {
for (var i = 0; i < count; i++) {
window.PerfTestReturnValue(5);
}
},
description: "Int argument, returns double value."
});
queueTest({
name: "PerfTestReturnValue (6, Date)",
func: function (count) {
for (var i = 0; i < count; i++) {
window.PerfTestReturnValue(6);
}
},
description: "Int argument, returns date value.",
skipped: true,
});
queueTest({
name: "PerfTestReturnValue (7, String)",
func: function (count) {
for (var i = 0; i < count; i++) {
window.PerfTestReturnValue(7);
}
},
description: "Int argument, returns string value."
});
queueTest({
name: "PerfTestReturnValue (8, Object)",
func: function (count) {
for (var i = 0; i < count; i++) {
window.PerfTestReturnValue(8);
}
},
description: "Int argument, returns object value."
});
queueTest({
name: "PerfTestReturnValue (9, Array)",
func: function (count) {
for (var i = 0; i < count; i++) {
window.PerfTestReturnValue(9);
}
},
description: "Int argument, returns array value."
});
queueTest({
name: "PerfTestReturnValue (10, Function)",
func: function (count) {
for (var i = 0; i < count; i++) {
window.PerfTestReturnValue(10);
}
},
description: "Int argument, returns function value.",
skipped: true,
});
// add more tests to queueTest
})();
</script>
</body>
</html>
<!DOCTYPE HTML>
<html>
<head>
<title>Performance Tests (2)</title>
<style>
body { font-family: Tahoma, Serif; font-size: 9pt; }
.left { text-align: left; }
.right { text-align: right; }
.center { text-align: center; }
table.resultTable
{
border: 1px solid black;
border-collapse: collapse;
empty-cells: show;
width: 100%;
}
table.resultTable td
{
padding: 2px 4px;
border: 1px solid black;
}
table.resultTable > thead > tr
{
font-weight: bold;
background: lightblue;
}
table.resultTable > tbody > tr:nth-child(odd)
{
background: white;
}
table.resultTable > tbody > tr:nth-child(even)
{
background: lightgray;
}
.hide { display: none; }
</style>
</head>
<body bgcolor="white">
<h1>Performance Tests (2)</h1>
<form id="sForm" onsubmit="runTestSuite();return false">
<table>
<tr>
<td colspan="2">Settings:</td>
</tr>
<tr>
<td class="right">Iterations:</td>
<td><input id="sIterations" type="text" value="1000" required pattern="[0-9]+" /></td>
</tr>
<tr>
<td class="right">Samples:</td>
<td><input id="sSamples" type="text" value="100" required pattern="[0-9]+" /></td>
</tr>
<tr>
<td class="right">Mode:</td>
<td><input id="sAsync" name="sMode" type="radio" value="async" checked>Asynchronous</input>
<input id="sSync" name="sMode" type="radio" value="sync">Synchronous</input>
</td>
</tr>
<tr>
<td colspan="2"><button type="submit" id="sRun" autofocus>Run!</button></td>
</tr>
</table>
</form>
<div><span id="statusBox"></span> <progress id="progressBox" value="0" style="display:none"></progress></div>
<div style="padding-top:10px; padding-bottom:10px">
<table id="resultTable" class="resultTable">
<thead>
<tr>
<td class="center" style="width:1%">Enabled</td>
<td class="center" style="width:10%">Name</td>
<td class="center" style="width:5%">Samples x Iterations</td>
<td class="center" style="width:5%">Min,&nbsp;ms</td>
<td class="center" style="width:5%">Avg,&nbsp;ms</td>
<td class="center" style="width:5%">Max,&nbsp;ms</td>
<td class="center" style="width:5%">Average calls/sec</td>
<td class="center" style="width:5%">Measuring Inacurracy</td>
<td class="center hide" style="width:5%">Memory, MB</td>
<td class="center hide" style="width:5%">Memory delta, MB</td>
<td class="center" style="width:55%">Description</td>
</tr>
</thead>
<tbody>
<!-- result rows here -->
</tbody>
</table>
</div>
<script type="text/javascript">
(function () {
function getPrivateWorkingSet() {
return 0; // TODO: window.PerfTestGetPrivateWorkingSet();
}
var disableWarmUp = true;
var asyncExecution = true;
var testIterations = 1000;
var totalSamples = 100;
var sampleDelay = 0;
var collectSamples = false;
var tests = [];
var testIndex = -1;
function execTestFunc(test) {
try {
var begin = new Date();
test.func(test.totalIterations);
var end = new Date();
return (end - begin);
} catch (e) {
test.error = e.toString();
return 0;
}
}
function execTest(test) {
if (disableWarmUp) { test.warmedUp = true; }
function nextStep() {
if (asyncExecution) {
setTimeout(function () { execTest(test); }, sampleDelay);
} else {
execTest(test);
}
}
function nextTest() {
updateStatus(test);
appendResult(test);
return execNextTest();
}
updateStatus(test);
if (!test.warmedUp) {
execTestFunc(test);
if (!test.error) {
test.warmedUp = true;
test.beginMemory = getPrivateWorkingSet();
return nextStep();
} else {
return nextTest();
}
}
if (test.sample >= test.totalSamples) {
test.avg = test.total / test.totalSamples;
test.endMemory = getPrivateWorkingSet();
return nextTest();
}
if (test.skipped) return nextTest();
var elapsed = execTestFunc(test);
if (!test.error) {
test.total += elapsed;
if (!test.min) test.min = elapsed;
else if (test.min > elapsed) test.min = elapsed;
if (!test.max) test.max = elapsed;
else if (test.max < elapsed) test.max = elapsed;
if (collectSamples) {
test.results.push(elapsed);
}
test.sample++;
return nextStep();
} else {
return nextTest();
}
}
function updateStatus(test) {
var statusBox = document.getElementById("statusBox");
var progressBox = document.getElementById("progressBox");
if (test.skipped || test.error || test.sample >= test.totalSamples) {
statusBox.innerText = "";
progressBox.style.display = "none";
} else {
statusBox.innerText = (testIndex + 1) + "/" + tests.length + ": " + test.name + " (" + test.sample + "/" + test.totalSamples + ")";
progressBox.value = (test.sample / test.totalSamples);
progressBox.style.display = "inline";
}
}
function appendResult(test) {
if (test.name == "warmup") return;
var id = "testResultRow_" + test.index;
var nearBound = (test.max - test.avg) < (test.avg - test.min) ? test.max : test.min;
var memoryDelta = test.endMemory - test.beginMemory;
if (memoryDelta < 0) memoryDelta = "-" + Math.abs(memoryDelta).toFixed(2);
else memoryDelta = "+" + Math.abs(memoryDelta).toFixed(2);
var markup = ["<tr id='" + id + "'>",
"<td class='left'><input type='checkbox' id='test_enabled_", test.index ,"' ", (!test.skipped ? "checked" : "") ," /></td>",
"<td class='left'>", test.name, "</td>",
"<td class='right'>", test.totalSamples, "x", test.totalIterations, "</td>",
"<td class='right'>", test.skipped || test.error || !test.prepared ? "-" : test.min.toFixed(2), "</td>",
"<td class='right'>", test.skipped || test.error || !test.prepared ? "-" : test.avg.toFixed(2), "</td>",
"<td class='right'>", test.skipped || test.error || !test.prepared ? "-" : test.max.toFixed(2), "</td>",
"<td class='right'>", test.skipped || test.error || !test.prepared ? "-" : (test.totalIterations * 1000 / test.avg).toFixed(2), "</td>",
"<td class='right'>", test.skipped || test.error || !test.prepared ? "-" : ("&#x00B1; " + (Math.abs(test.avg - nearBound) / (test.avg) * (100)).toFixed(2) + "%"), "</td>",
"<td class='right hide'>", test.skipped || test.error || !test.prepared ? "-" : test.endMemory.toFixed(2), "</td>",
"<td class='right hide'>", test.skipped || test.error || !test.prepared ? "-" : memoryDelta, "</td>",
"<td class='left'>", test.description, test.error ? (test.description ? "<br/>" : "") + "<span style='color:red'>" + test.error + "</span>" : "", "</td>",
"</tr>"
].join("");
// test.results.join(", "), "<br/>",
var row = document.getElementById(id);
if (row) {
row.outerHTML = markup;
} else {
var tbody = document.getElementById("resultTable").tBodies[0];
tbody.insertAdjacentHTML("beforeEnd", markup);
}
}
function prepareQueuedTests() {
testIndex = -1;
for (var i = 0; i < tests.length; i++) {
var test = tests[i];
test.index = i;
test.prepared = false;
test.warmedUp = false;
test.sample = 0;
test.total = 0;
test.results = [];
test.error = false;
test.min = null;
test.avg = null;
test.max = null;
test.beginMemory = null;
test.endMemory = null;
test.totalIterations = parseInt(testIterations / test.complex);
test.totalSamples = parseInt(totalSamples / test.complex);
var skipElement = document.getElementById('test_enabled_' + test.index);
test.skipped = skipElement ? !skipElement.checked : (test.skipped || false);
if (test.totalIterations <= 0) test.totalIterations = 1;
if (test.totalSamples <= 0) test.totalSamples = 1;
appendResult(test);
test.prepared = true;
}
}
function queueTest(func, name, description) {
var test;
if (typeof func === "function") {
test = {
name: name,
func: func,
description: description
};
} else {
test = func;
}
test.warmedUp = false;
test.complex = test.complex || 1;
tests.push(test);
}
function execNextTest() {
testIndex++;
if (tests.length <= testIndex) {
return testSuiteFinished();
} else {
return execTest(tests[testIndex]);
}
}
function execQueuedTests() {
prepareQueuedTests();
execNextTest();
}
function setSettingsState(disabled) {
document.getElementById('sIterations').disabled = disabled;
document.getElementById('sSamples').disabled = disabled;
document.getElementById('sAsync').disabled = disabled;
document.getElementById('sSync').disabled = disabled;
document.getElementById('sRun').disabled = disabled;
}
function testSuiteFinished() {
setSettingsState(false);
}
window.runTestSuite = function () {
setSettingsState(true);
testIterations = parseInt(document.getElementById('sIterations').value);
totalSamples = parseInt(document.getElementById('sSamples').value);
asyncExecution = document.getElementById('sAsync').checked;
setTimeout(execQueuedTests, 0);
}
setTimeout(prepareQueuedTests, 0);
// Test queue.
queueTest({
name: "PerfTestReturnValue Default",
func: function (count) {
for (var i = 0; i < count; i++) {
window.PerfTestReturnValue();
}
},
description: "No arguments, returns int32 value.",
skipped: true,
});
queueTest({
name: "PerfTestReturnValue (0, Undefined)",
func: function (count) {
for (var i = 0; i < count; i++) {
window.PerfTestReturnValue(0);
}
},
description: "Int argument, returns undefined value."
});
queueTest({
name: "PerfTestReturnValue (1, Null)",
func: function (count) {
for (var i = 0; i < count; i++) {
window.PerfTestReturnValue(1);
}
},
description: "Int argument, returns null value."
});
queueTest({
name: "PerfTestReturnValue (2, Bool)",
func: function (count) {
for (var i = 0; i < count; i++) {
window.PerfTestReturnValue(2);
}
},
description: "Int argument, returns bool value."
});
queueTest({
name: "PerfTestReturnValue (3, Int)",
func: function (count) {
for (var i = 0; i < count; i++) {
window.PerfTestReturnValue(3);
}
},
description: "Int argument, returns int value."
});
queueTest({
name: "PerfTestReturnValue (4, UInt)",
func: function (count) {
for (var i = 0; i < count; i++) {
window.PerfTestReturnValue(4);
}
},
description: "Int argument, returns uint value."
});
queueTest({
name: "PerfTestReturnValue (5, Double)",
func: function (count) {
for (var i = 0; i < count; i++) {
window.PerfTestReturnValue(5);
}
},
description: "Int argument, returns double value."
});
queueTest({
name: "PerfTestReturnValue (6, Date)",
func: function (count) {
for (var i = 0; i < count; i++) {
window.PerfTestReturnValue(6);
}
},
description: "Int argument, returns date value.",
skipped: true,
});
queueTest({
name: "PerfTestReturnValue (7, String)",
func: function (count) {
for (var i = 0; i < count; i++) {
window.PerfTestReturnValue(7);
}
},
description: "Int argument, returns string value."
});
queueTest({
name: "PerfTestReturnValue (8, Object)",
func: function (count) {
for (var i = 0; i < count; i++) {
window.PerfTestReturnValue(8);
}
},
description: "Int argument, returns object value."
});
queueTest({
name: "PerfTestReturnValue (9, Array)",
func: function (count) {
for (var i = 0; i < count; i++) {
window.PerfTestReturnValue(9);
}
},
description: "Int argument, returns array value."
});
queueTest({
name: "PerfTestReturnValue (10, Function)",
func: function (count) {
for (var i = 0; i < count; i++) {
window.PerfTestReturnValue(10);
}
},
description: "Int argument, returns function value.",
skipped: true,
});
// add more tests to queueTest
})();
</script>
</body>
</html>

View File

@@ -1,78 +1,78 @@
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "cefclient/window_test.h"
namespace window_test {
namespace {
// Toggles the current display state.
void Toggle(CefWindowHandle handle, UINT nCmdShow) {
HWND root_wnd = ::GetAncestor(handle, GA_ROOT);
// Retrieve current window placement information.
WINDOWPLACEMENT placement;
::GetWindowPlacement(root_wnd, &placement);
if (placement.showCmd == nCmdShow)
::ShowWindow(root_wnd, SW_RESTORE);
else
::ShowWindow(root_wnd, nCmdShow);
}
} // namespace
void SetPos(CefWindowHandle handle, int x, int y, int width, int height) {
HWND root_wnd = ::GetAncestor(handle, GA_ROOT);
// Retrieve current window placement information.
WINDOWPLACEMENT placement;
::GetWindowPlacement(root_wnd, &placement);
// Retrieve information about the display that contains the window.
HMONITOR monitor = MonitorFromRect(&placement.rcNormalPosition,
MONITOR_DEFAULTTONEAREST);
MONITORINFO info;
info.cbSize = sizeof(info);
GetMonitorInfo(monitor, &info);
// Make sure the window is inside the display.
CefRect display_rect(
info.rcWork.left,
info.rcWork.top,
info.rcWork.right - info.rcWork.left,
info.rcWork.bottom - info.rcWork.top);
CefRect window_rect(x, y, width, height);
ModifyBounds(display_rect, window_rect);
if (placement.showCmd == SW_MINIMIZE || placement.showCmd == SW_MAXIMIZE) {
// The window is currently minimized or maximized. Restore it to the desired
// position.
placement.rcNormalPosition.left = window_rect.x;
placement.rcNormalPosition.right = window_rect.x + window_rect.width;
placement.rcNormalPosition.top = window_rect.y;
placement.rcNormalPosition.bottom = window_rect.y + window_rect.height;
::SetWindowPlacement(root_wnd, &placement);
::ShowWindow(root_wnd, SW_RESTORE);
} else {
// Set the window position.
::SetWindowPos(root_wnd, NULL, window_rect.x, window_rect.y,
window_rect.width, window_rect.height, SWP_NOZORDER);
}
}
void Minimize(CefWindowHandle handle) {
Toggle(handle, SW_MINIMIZE);
}
void Maximize(CefWindowHandle handle) {
Toggle(handle, SW_MAXIMIZE);
}
void Restore(CefWindowHandle handle) {
::ShowWindow(::GetAncestor(handle, GA_ROOT), SW_RESTORE);
}
} // namespace window_test
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "cefclient/window_test.h"
namespace window_test {
namespace {
// Toggles the current display state.
void Toggle(CefWindowHandle handle, UINT nCmdShow) {
HWND root_wnd = ::GetAncestor(handle, GA_ROOT);
// Retrieve current window placement information.
WINDOWPLACEMENT placement;
::GetWindowPlacement(root_wnd, &placement);
if (placement.showCmd == nCmdShow)
::ShowWindow(root_wnd, SW_RESTORE);
else
::ShowWindow(root_wnd, nCmdShow);
}
} // namespace
void SetPos(CefWindowHandle handle, int x, int y, int width, int height) {
HWND root_wnd = ::GetAncestor(handle, GA_ROOT);
// Retrieve current window placement information.
WINDOWPLACEMENT placement;
::GetWindowPlacement(root_wnd, &placement);
// Retrieve information about the display that contains the window.
HMONITOR monitor = MonitorFromRect(&placement.rcNormalPosition,
MONITOR_DEFAULTTONEAREST);
MONITORINFO info;
info.cbSize = sizeof(info);
GetMonitorInfo(monitor, &info);
// Make sure the window is inside the display.
CefRect display_rect(
info.rcWork.left,
info.rcWork.top,
info.rcWork.right - info.rcWork.left,
info.rcWork.bottom - info.rcWork.top);
CefRect window_rect(x, y, width, height);
ModifyBounds(display_rect, window_rect);
if (placement.showCmd == SW_MINIMIZE || placement.showCmd == SW_MAXIMIZE) {
// The window is currently minimized or maximized. Restore it to the desired
// position.
placement.rcNormalPosition.left = window_rect.x;
placement.rcNormalPosition.right = window_rect.x + window_rect.width;
placement.rcNormalPosition.top = window_rect.y;
placement.rcNormalPosition.bottom = window_rect.y + window_rect.height;
::SetWindowPlacement(root_wnd, &placement);
::ShowWindow(root_wnd, SW_RESTORE);
} else {
// Set the window position.
::SetWindowPos(root_wnd, NULL, window_rect.x, window_rect.y,
window_rect.width, window_rect.height, SWP_NOZORDER);
}
}
void Minimize(CefWindowHandle handle) {
Toggle(handle, SW_MINIMIZE);
}
void Maximize(CefWindowHandle handle) {
Toggle(handle, SW_MAXIMIZE);
}
void Restore(CefWindowHandle handle) {
::ShowWindow(::GetAncestor(handle, GA_ROOT), SW_RESTORE);
}
} // namespace window_test

View File

@@ -1,262 +1,262 @@
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "include/cef_scheme.h"
#include "base/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "tests/unittests/test_handler.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
const char kTestDomain[] = "test-download";
const char kTestEntryUrl[] = "http://test-download/test.html";
const char kTestDownloadUrl[] = "http://test-download/download.txt";
const char kTestFileName[] = "download_test.txt";
const char kTestContentDisposition[] =
"attachment; filename=\"download_test.txt\"";
const char kTestMimeType[] = "text/plain";
const char kTestContent[] = "Download test text";
class DownloadSchemeHandler : public CefResourceHandler {
public:
explicit DownloadSchemeHandler(TrackCallback* got_download_request)
: got_download_request_(got_download_request),
offset_(0) {}
virtual bool ProcessRequest(CefRefPtr<CefRequest> request,
CefRefPtr<CefCallback> callback)
OVERRIDE {
std::string url = request->GetURL();
if (url == kTestEntryUrl) {
content_ = "<html><body>Download Test</body></html>";
mime_type_ = "text/html";
} else if (url == kTestDownloadUrl) {
got_download_request_->yes();
content_ = kTestContent;
mime_type_ = kTestMimeType;
content_disposition_ = kTestContentDisposition;
} else {
EXPECT_TRUE(false); // Not reached.
return false;
}
callback->Continue();
return true;
}
virtual void GetResponseHeaders(CefRefPtr<CefResponse> response,
int64& response_length,
CefString& redirectUrl) OVERRIDE {
response_length = content_.size();
response->SetStatus(200);
response->SetMimeType(mime_type_);
if (!content_disposition_.empty()) {
CefResponse::HeaderMap headerMap;
response->GetHeaderMap(headerMap);
headerMap.insert(
std::make_pair("Content-Disposition", content_disposition_));
response->SetHeaderMap(headerMap);
}
}
virtual bool ReadResponse(void* data_out,
int bytes_to_read,
int& bytes_read,
CefRefPtr<CefCallback> callback)
OVERRIDE {
bool has_data = false;
bytes_read = 0;
size_t size = content_.size();
if (offset_ < size) {
int transfer_size =
std::min(bytes_to_read, static_cast<int>(size - offset_));
memcpy(data_out, content_.c_str() + offset_, transfer_size);
offset_ += transfer_size;
bytes_read = transfer_size;
has_data = true;
}
return has_data;
}
virtual void Cancel() OVERRIDE {
}
private:
TrackCallback* got_download_request_;
std::string content_;
std::string mime_type_;
std::string content_disposition_;
size_t offset_;
IMPLEMENT_REFCOUNTING(SchemeHandler);
};
class DownloadSchemeHandlerFactory : public CefSchemeHandlerFactory {
public:
explicit DownloadSchemeHandlerFactory(TrackCallback* got_download_request)
: got_download_request_(got_download_request) {}
virtual CefRefPtr<CefResourceHandler> Create(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& scheme_name,
CefRefPtr<CefRequest> request) OVERRIDE {
return new DownloadSchemeHandler(got_download_request_);
}
private:
TrackCallback* got_download_request_;
IMPLEMENT_REFCOUNTING(SchemeHandlerFactory);
};
class DownloadTestHandler : public TestHandler {
public:
DownloadTestHandler() {}
virtual void RunTest() OVERRIDE {
CefRegisterSchemeHandlerFactory("http", kTestDomain,
new DownloadSchemeHandlerFactory(&got_download_request_));
// Create a new temporary directory.
EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
test_path_ = temp_dir_.path().AppendASCII(kTestFileName);
// Create the browser
CreateBrowser(kTestEntryUrl);
}
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode) OVERRIDE {
EXPECT_STREQ(kTestEntryUrl, frame->GetURL().ToString().c_str());
// Begin the download.
browser->GetHost()->StartDownload(kTestDownloadUrl);
}
virtual void OnBeforeDownload(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDownloadItem> download_item,
const CefString& suggested_name,
CefRefPtr<CefBeforeDownloadCallback> callback) OVERRIDE {
EXPECT_TRUE(CefCurrentlyOn(TID_UI));
EXPECT_FALSE(got_on_before_download_);
got_on_before_download_.yes();
EXPECT_TRUE(browser->IsSame(GetBrowser()));
EXPECT_STREQ(kTestFileName, suggested_name.ToString().c_str());
EXPECT_TRUE(download_item.get());
EXPECT_TRUE(callback.get());
download_id_ = download_item->GetId();
EXPECT_LT(0U, download_id_);
EXPECT_TRUE(download_item->IsValid());
EXPECT_TRUE(download_item->IsInProgress());
EXPECT_FALSE(download_item->IsComplete());
EXPECT_FALSE(download_item->IsCanceled());
EXPECT_EQ(static_cast<int64>(sizeof(kTestContent)-1),
download_item->GetTotalBytes());
EXPECT_EQ(0UL, download_item->GetFullPath().length());
EXPECT_STREQ(kTestDownloadUrl, download_item->GetURL().ToString().c_str());
EXPECT_EQ(0UL, download_item->GetSuggestedFileName().length());
EXPECT_STREQ(kTestContentDisposition,
download_item->GetContentDisposition().ToString().c_str());
EXPECT_STREQ(kTestMimeType, download_item->GetMimeType().ToString().c_str());
callback->Continue(test_path_.value(), false);
}
virtual void OnDownloadUpdated(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDownloadItem> download_item,
CefRefPtr<CefDownloadItemCallback> callback) OVERRIDE {
EXPECT_TRUE(CefCurrentlyOn(TID_UI));
got_on_download_updated_.yes();
EXPECT_TRUE(browser->IsSame(GetBrowser()));
EXPECT_TRUE(download_item.get());
EXPECT_TRUE(callback.get());
if (got_on_before_download_)
EXPECT_EQ(download_id_, download_item->GetId());
EXPECT_LE(0LL, download_item->GetCurrentSpeed());
EXPECT_LE(0, download_item->GetPercentComplete());
EXPECT_TRUE(download_item->IsValid());
EXPECT_FALSE(download_item->IsCanceled());
EXPECT_STREQ(kTestDownloadUrl, download_item->GetURL().ToString().c_str());
EXPECT_STREQ(kTestContentDisposition,
download_item->GetContentDisposition().ToString().c_str());
EXPECT_STREQ(kTestMimeType,
download_item->GetMimeType().ToString().c_str());
std::string full_path = download_item->GetFullPath();
if (!full_path.empty()) {
got_full_path_.yes();
EXPECT_STREQ(CefString(test_path_.value()).ToString().c_str(),
full_path.c_str());
}
if (download_item->IsComplete()) {
EXPECT_FALSE(download_item->IsInProgress());
EXPECT_EQ(100, download_item->GetPercentComplete());
EXPECT_EQ(static_cast<int64>(sizeof(kTestContent)-1),
download_item->GetReceivedBytes());
EXPECT_EQ(static_cast<int64>(sizeof(kTestContent)-1),
download_item->GetTotalBytes());
DestroyTest();
} else {
EXPECT_TRUE(download_item->IsInProgress());
EXPECT_LE(0LL, download_item->GetReceivedBytes());
}
}
virtual void DestroyTest() OVERRIDE {
CefRegisterSchemeHandlerFactory("http", kTestDomain, NULL);
EXPECT_TRUE(got_download_request_);
EXPECT_TRUE(got_on_before_download_);
EXPECT_TRUE(got_on_download_updated_);
EXPECT_TRUE(got_full_path_);
// Verify the file contents.
std::string contents;
EXPECT_TRUE(base::ReadFileToString(test_path_, &contents));
EXPECT_STREQ(kTestContent, contents.c_str());
EXPECT_TRUE(temp_dir_.Delete());
TestHandler::DestroyTest();
}
private:
base::ScopedTempDir temp_dir_;
base::FilePath test_path_;
uint32 download_id_;
TrackCallback got_download_request_;
TrackCallback got_on_before_download_;
TrackCallback got_on_download_updated_;
TrackCallback got_full_path_;
};
} // namespace
// Verify that downloads work.
TEST(DownloadTest, Download) {
CefRefPtr<DownloadTestHandler> handler = new DownloadTestHandler();
handler->ExecuteTest();
}
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "include/cef_scheme.h"
#include "base/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "tests/unittests/test_handler.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
const char kTestDomain[] = "test-download";
const char kTestEntryUrl[] = "http://test-download/test.html";
const char kTestDownloadUrl[] = "http://test-download/download.txt";
const char kTestFileName[] = "download_test.txt";
const char kTestContentDisposition[] =
"attachment; filename=\"download_test.txt\"";
const char kTestMimeType[] = "text/plain";
const char kTestContent[] = "Download test text";
class DownloadSchemeHandler : public CefResourceHandler {
public:
explicit DownloadSchemeHandler(TrackCallback* got_download_request)
: got_download_request_(got_download_request),
offset_(0) {}
virtual bool ProcessRequest(CefRefPtr<CefRequest> request,
CefRefPtr<CefCallback> callback)
OVERRIDE {
std::string url = request->GetURL();
if (url == kTestEntryUrl) {
content_ = "<html><body>Download Test</body></html>";
mime_type_ = "text/html";
} else if (url == kTestDownloadUrl) {
got_download_request_->yes();
content_ = kTestContent;
mime_type_ = kTestMimeType;
content_disposition_ = kTestContentDisposition;
} else {
EXPECT_TRUE(false); // Not reached.
return false;
}
callback->Continue();
return true;
}
virtual void GetResponseHeaders(CefRefPtr<CefResponse> response,
int64& response_length,
CefString& redirectUrl) OVERRIDE {
response_length = content_.size();
response->SetStatus(200);
response->SetMimeType(mime_type_);
if (!content_disposition_.empty()) {
CefResponse::HeaderMap headerMap;
response->GetHeaderMap(headerMap);
headerMap.insert(
std::make_pair("Content-Disposition", content_disposition_));
response->SetHeaderMap(headerMap);
}
}
virtual bool ReadResponse(void* data_out,
int bytes_to_read,
int& bytes_read,
CefRefPtr<CefCallback> callback)
OVERRIDE {
bool has_data = false;
bytes_read = 0;
size_t size = content_.size();
if (offset_ < size) {
int transfer_size =
std::min(bytes_to_read, static_cast<int>(size - offset_));
memcpy(data_out, content_.c_str() + offset_, transfer_size);
offset_ += transfer_size;
bytes_read = transfer_size;
has_data = true;
}
return has_data;
}
virtual void Cancel() OVERRIDE {
}
private:
TrackCallback* got_download_request_;
std::string content_;
std::string mime_type_;
std::string content_disposition_;
size_t offset_;
IMPLEMENT_REFCOUNTING(SchemeHandler);
};
class DownloadSchemeHandlerFactory : public CefSchemeHandlerFactory {
public:
explicit DownloadSchemeHandlerFactory(TrackCallback* got_download_request)
: got_download_request_(got_download_request) {}
virtual CefRefPtr<CefResourceHandler> Create(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& scheme_name,
CefRefPtr<CefRequest> request) OVERRIDE {
return new DownloadSchemeHandler(got_download_request_);
}
private:
TrackCallback* got_download_request_;
IMPLEMENT_REFCOUNTING(SchemeHandlerFactory);
};
class DownloadTestHandler : public TestHandler {
public:
DownloadTestHandler() {}
virtual void RunTest() OVERRIDE {
CefRegisterSchemeHandlerFactory("http", kTestDomain,
new DownloadSchemeHandlerFactory(&got_download_request_));
// Create a new temporary directory.
EXPECT_TRUE(temp_dir_.CreateUniqueTempDir());
test_path_ = temp_dir_.path().AppendASCII(kTestFileName);
// Create the browser
CreateBrowser(kTestEntryUrl);
}
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode) OVERRIDE {
EXPECT_STREQ(kTestEntryUrl, frame->GetURL().ToString().c_str());
// Begin the download.
browser->GetHost()->StartDownload(kTestDownloadUrl);
}
virtual void OnBeforeDownload(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDownloadItem> download_item,
const CefString& suggested_name,
CefRefPtr<CefBeforeDownloadCallback> callback) OVERRIDE {
EXPECT_TRUE(CefCurrentlyOn(TID_UI));
EXPECT_FALSE(got_on_before_download_);
got_on_before_download_.yes();
EXPECT_TRUE(browser->IsSame(GetBrowser()));
EXPECT_STREQ(kTestFileName, suggested_name.ToString().c_str());
EXPECT_TRUE(download_item.get());
EXPECT_TRUE(callback.get());
download_id_ = download_item->GetId();
EXPECT_LT(0U, download_id_);
EXPECT_TRUE(download_item->IsValid());
EXPECT_TRUE(download_item->IsInProgress());
EXPECT_FALSE(download_item->IsComplete());
EXPECT_FALSE(download_item->IsCanceled());
EXPECT_EQ(static_cast<int64>(sizeof(kTestContent)-1),
download_item->GetTotalBytes());
EXPECT_EQ(0UL, download_item->GetFullPath().length());
EXPECT_STREQ(kTestDownloadUrl, download_item->GetURL().ToString().c_str());
EXPECT_EQ(0UL, download_item->GetSuggestedFileName().length());
EXPECT_STREQ(kTestContentDisposition,
download_item->GetContentDisposition().ToString().c_str());
EXPECT_STREQ(kTestMimeType, download_item->GetMimeType().ToString().c_str());
callback->Continue(test_path_.value(), false);
}
virtual void OnDownloadUpdated(
CefRefPtr<CefBrowser> browser,
CefRefPtr<CefDownloadItem> download_item,
CefRefPtr<CefDownloadItemCallback> callback) OVERRIDE {
EXPECT_TRUE(CefCurrentlyOn(TID_UI));
got_on_download_updated_.yes();
EXPECT_TRUE(browser->IsSame(GetBrowser()));
EXPECT_TRUE(download_item.get());
EXPECT_TRUE(callback.get());
if (got_on_before_download_)
EXPECT_EQ(download_id_, download_item->GetId());
EXPECT_LE(0LL, download_item->GetCurrentSpeed());
EXPECT_LE(0, download_item->GetPercentComplete());
EXPECT_TRUE(download_item->IsValid());
EXPECT_FALSE(download_item->IsCanceled());
EXPECT_STREQ(kTestDownloadUrl, download_item->GetURL().ToString().c_str());
EXPECT_STREQ(kTestContentDisposition,
download_item->GetContentDisposition().ToString().c_str());
EXPECT_STREQ(kTestMimeType,
download_item->GetMimeType().ToString().c_str());
std::string full_path = download_item->GetFullPath();
if (!full_path.empty()) {
got_full_path_.yes();
EXPECT_STREQ(CefString(test_path_.value()).ToString().c_str(),
full_path.c_str());
}
if (download_item->IsComplete()) {
EXPECT_FALSE(download_item->IsInProgress());
EXPECT_EQ(100, download_item->GetPercentComplete());
EXPECT_EQ(static_cast<int64>(sizeof(kTestContent)-1),
download_item->GetReceivedBytes());
EXPECT_EQ(static_cast<int64>(sizeof(kTestContent)-1),
download_item->GetTotalBytes());
DestroyTest();
} else {
EXPECT_TRUE(download_item->IsInProgress());
EXPECT_LE(0LL, download_item->GetReceivedBytes());
}
}
virtual void DestroyTest() OVERRIDE {
CefRegisterSchemeHandlerFactory("http", kTestDomain, NULL);
EXPECT_TRUE(got_download_request_);
EXPECT_TRUE(got_on_before_download_);
EXPECT_TRUE(got_on_download_updated_);
EXPECT_TRUE(got_full_path_);
// Verify the file contents.
std::string contents;
EXPECT_TRUE(base::ReadFileToString(test_path_, &contents));
EXPECT_STREQ(kTestContent, contents.c_str());
EXPECT_TRUE(temp_dir_.Delete());
TestHandler::DestroyTest();
}
private:
base::ScopedTempDir temp_dir_;
base::FilePath test_path_;
uint32 download_id_;
TrackCallback got_download_request_;
TrackCallback got_on_before_download_;
TrackCallback got_on_download_updated_;
TrackCallback got_full_path_;
};
} // namespace
// Verify that downloads work.
TEST(DownloadTest, Download) {
CefRefPtr<DownloadTestHandler> handler = new DownloadTestHandler();
handler->ExecuteTest();
}

View File

@@ -1,306 +1,306 @@
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "include/cef_runnable.h"
#include "tests/unittests/test_handler.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
const char kLifeSpanUrl[] = "http://tests-life-span/test.html";
const char kUnloadDialogText[] = "Are you sure?";
const char kUnloadMsg[] = "LifeSpanTestHandler.Unload";
// Browser side.
class LifeSpanTestHandler : public TestHandler {
public:
struct Settings {
Settings()
: force_close(false),
add_onunload_handler(false),
allow_do_close(true),
accept_before_unload_dialog(true) {}
bool force_close;
bool add_onunload_handler;
bool allow_do_close;
bool accept_before_unload_dialog;
};
explicit LifeSpanTestHandler(const Settings& settings)
: settings_(settings),
executing_delay_close_(false) {}
virtual void RunTest() OVERRIDE {
// Add the resources that we will navigate to/from.
std::string page = "<html><script>";
page += "window.onunload = function() { app.sendMessage('" +
std::string(kUnloadMsg) + "'); };";
if (settings_.add_onunload_handler) {
page += "window.onbeforeunload = function() { return '" +
std::string(kUnloadDialogText) + "'; };";
}
page += "</script><body>Page</body></html>";
AddResource(kLifeSpanUrl, page, "text/html");
// Create the browser.
CreateBrowser(kLifeSpanUrl);
}
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE {
got_after_created_.yes();
TestHandler::OnAfterCreated(browser);
}
virtual bool DoClose(CefRefPtr<CefBrowser> browser) OVERRIDE {
if (executing_delay_close_)
return false;
EXPECT_TRUE(browser->IsSame(GetBrowser()));
got_do_close_.yes();
if (!settings_.allow_do_close) {
// The close will be canceled.
ScheduleDelayClose();
}
return !settings_.allow_do_close;
}
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE {
if (!executing_delay_close_) {
got_before_close_.yes();
EXPECT_TRUE(browser->IsSame(GetBrowser()));
}
TestHandler::OnBeforeClose(browser);
}
virtual bool OnBeforeUnloadDialog(
CefRefPtr<CefBrowser> browser,
const CefString& message_text,
bool is_reload,
CefRefPtr<CefJSDialogCallback> callback) OVERRIDE {
if (executing_delay_close_) {
callback->Continue(true, CefString());
return true;
}
EXPECT_TRUE(browser->IsSame(GetBrowser()));
EXPECT_STREQ(kUnloadDialogText, message_text.ToString().c_str());
EXPECT_FALSE(is_reload);
EXPECT_TRUE(callback.get());
if (!settings_.accept_before_unload_dialog) {
// The close will be canceled.
ScheduleDelayClose();
}
got_before_unload_dialog_.yes();
callback->Continue(settings_.accept_before_unload_dialog, CefString());
return true;
}
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode) OVERRIDE {
got_load_end_.yes();
EXPECT_TRUE(browser->IsSame(GetBrowser()));
// Attempt to close the browser.
browser->GetHost()->CloseBrowser(settings_.force_close);
}
virtual bool OnProcessMessageReceived(
CefRefPtr<CefBrowser> browser,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message) OVERRIDE {
const std::string& message_name = message->GetName();
if (message_name == kUnloadMsg) {
if (!executing_delay_close_)
got_unload_message_.yes();
return true;
}
return false;
}
TrackCallback got_after_created_;
TrackCallback got_do_close_;
TrackCallback got_before_close_;
TrackCallback got_before_unload_dialog_;
TrackCallback got_unload_message_;
TrackCallback got_load_end_;
TrackCallback got_delay_close_;
private:
// Wait a bit to make sure no additional events are received and then close
// the window.
void ScheduleDelayClose() {
CefPostDelayedTask(TID_UI,
NewCefRunnableMethod(this, &LifeSpanTestHandler::DelayClose), 100);
}
void DelayClose() {
got_delay_close_.yes();
executing_delay_close_ = true;
DestroyTest();
}
Settings settings_;
// Forces the window to close (bypasses test conditions).
bool executing_delay_close_;
};
} // namespace
TEST(LifeSpanTest, DoCloseAllow) {
LifeSpanTestHandler::Settings settings;
settings.allow_do_close = true;
CefRefPtr<LifeSpanTestHandler> handler = new LifeSpanTestHandler(settings);
handler->ExecuteTest();
EXPECT_TRUE(handler->got_after_created_);
EXPECT_TRUE(handler->got_do_close_);
EXPECT_TRUE(handler->got_before_close_);
EXPECT_FALSE(handler->got_before_unload_dialog_);
EXPECT_TRUE(handler->got_unload_message_);
EXPECT_TRUE(handler->got_load_end_);
EXPECT_FALSE(handler->got_delay_close_);
}
TEST(LifeSpanTest, DoCloseAllowForce) {
LifeSpanTestHandler::Settings settings;
settings.allow_do_close = true;
settings.force_close = true;
CefRefPtr<LifeSpanTestHandler> handler = new LifeSpanTestHandler(settings);
handler->ExecuteTest();
EXPECT_TRUE(handler->got_after_created_);
EXPECT_TRUE(handler->got_do_close_);
EXPECT_TRUE(handler->got_before_close_);
EXPECT_FALSE(handler->got_before_unload_dialog_);
EXPECT_TRUE(handler->got_unload_message_);
EXPECT_TRUE(handler->got_load_end_);
EXPECT_FALSE(handler->got_delay_close_);
}
TEST(LifeSpanTest, DoCloseDisallow) {
LifeSpanTestHandler::Settings settings;
settings.allow_do_close = false;
CefRefPtr<LifeSpanTestHandler> handler = new LifeSpanTestHandler(settings);
handler->ExecuteTest();
EXPECT_TRUE(handler->got_after_created_);
EXPECT_TRUE(handler->got_do_close_);
EXPECT_FALSE(handler->got_before_close_);
EXPECT_FALSE(handler->got_before_unload_dialog_);
EXPECT_TRUE(handler->got_unload_message_);
EXPECT_TRUE(handler->got_load_end_);
EXPECT_TRUE(handler->got_delay_close_);
}
TEST(LifeSpanTest, DoCloseDisallowForce) {
LifeSpanTestHandler::Settings settings;
settings.allow_do_close = false;
settings.force_close = true;
CefRefPtr<LifeSpanTestHandler> handler = new LifeSpanTestHandler(settings);
handler->ExecuteTest();
EXPECT_TRUE(handler->got_after_created_);
EXPECT_TRUE(handler->got_do_close_);
EXPECT_FALSE(handler->got_before_close_);
EXPECT_FALSE(handler->got_before_unload_dialog_);
EXPECT_TRUE(handler->got_unload_message_);
EXPECT_TRUE(handler->got_load_end_);
EXPECT_TRUE(handler->got_delay_close_);
}
TEST(LifeSpanTest, DoCloseDisallowWithOnUnloadAllow) {
LifeSpanTestHandler::Settings settings;
settings.allow_do_close = false;
settings.add_onunload_handler = true;
settings.accept_before_unload_dialog = true;
CefRefPtr<LifeSpanTestHandler> handler = new LifeSpanTestHandler(settings);
handler->ExecuteTest();
EXPECT_TRUE(handler->got_after_created_);
EXPECT_TRUE(handler->got_do_close_);
EXPECT_FALSE(handler->got_before_close_);
EXPECT_TRUE(handler->got_before_unload_dialog_);
EXPECT_TRUE(handler->got_unload_message_);
EXPECT_TRUE(handler->got_load_end_);
EXPECT_TRUE(handler->got_delay_close_);
}
TEST(LifeSpanTest, DoCloseAllowWithOnUnloadForce) {
LifeSpanTestHandler::Settings settings;
settings.allow_do_close = true;
settings.add_onunload_handler = true;
settings.force_close = true;
CefRefPtr<LifeSpanTestHandler> handler = new LifeSpanTestHandler(settings);
handler->ExecuteTest();
EXPECT_TRUE(handler->got_after_created_);
EXPECT_TRUE(handler->got_do_close_);
EXPECT_TRUE(handler->got_before_close_);
EXPECT_FALSE(handler->got_before_unload_dialog_);
EXPECT_TRUE(handler->got_unload_message_);
EXPECT_TRUE(handler->got_load_end_);
EXPECT_FALSE(handler->got_delay_close_);
}
TEST(LifeSpanTest, DoCloseDisallowWithOnUnloadForce) {
LifeSpanTestHandler::Settings settings;
settings.allow_do_close = false;
settings.add_onunload_handler = true;
settings.force_close = true;
CefRefPtr<LifeSpanTestHandler> handler = new LifeSpanTestHandler(settings);
handler->ExecuteTest();
EXPECT_TRUE(handler->got_after_created_);
EXPECT_TRUE(handler->got_do_close_);
EXPECT_FALSE(handler->got_before_close_);
EXPECT_FALSE(handler->got_before_unload_dialog_);
EXPECT_TRUE(handler->got_unload_message_);
EXPECT_TRUE(handler->got_load_end_);
EXPECT_TRUE(handler->got_delay_close_);
}
TEST(LifeSpanTest, OnUnloadAllow) {
LifeSpanTestHandler::Settings settings;
settings.add_onunload_handler = true;
settings.accept_before_unload_dialog = true;
CefRefPtr<LifeSpanTestHandler> handler = new LifeSpanTestHandler(settings);
handler->ExecuteTest();
EXPECT_TRUE(handler->got_after_created_);
EXPECT_TRUE(handler->got_do_close_);
EXPECT_TRUE(handler->got_before_close_);
EXPECT_TRUE(handler->got_before_unload_dialog_);
EXPECT_TRUE(handler->got_unload_message_);
EXPECT_TRUE(handler->got_load_end_);
EXPECT_FALSE(handler->got_delay_close_);
}
TEST(LifeSpanTest, OnUnloadDisallow) {
LifeSpanTestHandler::Settings settings;
settings.add_onunload_handler = true;
settings.accept_before_unload_dialog = false;
CefRefPtr<LifeSpanTestHandler> handler = new LifeSpanTestHandler(settings);
handler->ExecuteTest();
EXPECT_TRUE(handler->got_after_created_);
EXPECT_FALSE(handler->got_do_close_);
EXPECT_FALSE(handler->got_before_close_);
EXPECT_TRUE(handler->got_before_unload_dialog_);
EXPECT_FALSE(handler->got_unload_message_);
EXPECT_TRUE(handler->got_load_end_);
EXPECT_TRUE(handler->got_delay_close_);
}
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "include/cef_runnable.h"
#include "tests/unittests/test_handler.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace {
const char kLifeSpanUrl[] = "http://tests-life-span/test.html";
const char kUnloadDialogText[] = "Are you sure?";
const char kUnloadMsg[] = "LifeSpanTestHandler.Unload";
// Browser side.
class LifeSpanTestHandler : public TestHandler {
public:
struct Settings {
Settings()
: force_close(false),
add_onunload_handler(false),
allow_do_close(true),
accept_before_unload_dialog(true) {}
bool force_close;
bool add_onunload_handler;
bool allow_do_close;
bool accept_before_unload_dialog;
};
explicit LifeSpanTestHandler(const Settings& settings)
: settings_(settings),
executing_delay_close_(false) {}
virtual void RunTest() OVERRIDE {
// Add the resources that we will navigate to/from.
std::string page = "<html><script>";
page += "window.onunload = function() { app.sendMessage('" +
std::string(kUnloadMsg) + "'); };";
if (settings_.add_onunload_handler) {
page += "window.onbeforeunload = function() { return '" +
std::string(kUnloadDialogText) + "'; };";
}
page += "</script><body>Page</body></html>";
AddResource(kLifeSpanUrl, page, "text/html");
// Create the browser.
CreateBrowser(kLifeSpanUrl);
}
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE {
got_after_created_.yes();
TestHandler::OnAfterCreated(browser);
}
virtual bool DoClose(CefRefPtr<CefBrowser> browser) OVERRIDE {
if (executing_delay_close_)
return false;
EXPECT_TRUE(browser->IsSame(GetBrowser()));
got_do_close_.yes();
if (!settings_.allow_do_close) {
// The close will be canceled.
ScheduleDelayClose();
}
return !settings_.allow_do_close;
}
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE {
if (!executing_delay_close_) {
got_before_close_.yes();
EXPECT_TRUE(browser->IsSame(GetBrowser()));
}
TestHandler::OnBeforeClose(browser);
}
virtual bool OnBeforeUnloadDialog(
CefRefPtr<CefBrowser> browser,
const CefString& message_text,
bool is_reload,
CefRefPtr<CefJSDialogCallback> callback) OVERRIDE {
if (executing_delay_close_) {
callback->Continue(true, CefString());
return true;
}
EXPECT_TRUE(browser->IsSame(GetBrowser()));
EXPECT_STREQ(kUnloadDialogText, message_text.ToString().c_str());
EXPECT_FALSE(is_reload);
EXPECT_TRUE(callback.get());
if (!settings_.accept_before_unload_dialog) {
// The close will be canceled.
ScheduleDelayClose();
}
got_before_unload_dialog_.yes();
callback->Continue(settings_.accept_before_unload_dialog, CefString());
return true;
}
virtual void OnLoadEnd(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
int httpStatusCode) OVERRIDE {
got_load_end_.yes();
EXPECT_TRUE(browser->IsSame(GetBrowser()));
// Attempt to close the browser.
browser->GetHost()->CloseBrowser(settings_.force_close);
}
virtual bool OnProcessMessageReceived(
CefRefPtr<CefBrowser> browser,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message) OVERRIDE {
const std::string& message_name = message->GetName();
if (message_name == kUnloadMsg) {
if (!executing_delay_close_)
got_unload_message_.yes();
return true;
}
return false;
}
TrackCallback got_after_created_;
TrackCallback got_do_close_;
TrackCallback got_before_close_;
TrackCallback got_before_unload_dialog_;
TrackCallback got_unload_message_;
TrackCallback got_load_end_;
TrackCallback got_delay_close_;
private:
// Wait a bit to make sure no additional events are received and then close
// the window.
void ScheduleDelayClose() {
CefPostDelayedTask(TID_UI,
NewCefRunnableMethod(this, &LifeSpanTestHandler::DelayClose), 100);
}
void DelayClose() {
got_delay_close_.yes();
executing_delay_close_ = true;
DestroyTest();
}
Settings settings_;
// Forces the window to close (bypasses test conditions).
bool executing_delay_close_;
};
} // namespace
TEST(LifeSpanTest, DoCloseAllow) {
LifeSpanTestHandler::Settings settings;
settings.allow_do_close = true;
CefRefPtr<LifeSpanTestHandler> handler = new LifeSpanTestHandler(settings);
handler->ExecuteTest();
EXPECT_TRUE(handler->got_after_created_);
EXPECT_TRUE(handler->got_do_close_);
EXPECT_TRUE(handler->got_before_close_);
EXPECT_FALSE(handler->got_before_unload_dialog_);
EXPECT_TRUE(handler->got_unload_message_);
EXPECT_TRUE(handler->got_load_end_);
EXPECT_FALSE(handler->got_delay_close_);
}
TEST(LifeSpanTest, DoCloseAllowForce) {
LifeSpanTestHandler::Settings settings;
settings.allow_do_close = true;
settings.force_close = true;
CefRefPtr<LifeSpanTestHandler> handler = new LifeSpanTestHandler(settings);
handler->ExecuteTest();
EXPECT_TRUE(handler->got_after_created_);
EXPECT_TRUE(handler->got_do_close_);
EXPECT_TRUE(handler->got_before_close_);
EXPECT_FALSE(handler->got_before_unload_dialog_);
EXPECT_TRUE(handler->got_unload_message_);
EXPECT_TRUE(handler->got_load_end_);
EXPECT_FALSE(handler->got_delay_close_);
}
TEST(LifeSpanTest, DoCloseDisallow) {
LifeSpanTestHandler::Settings settings;
settings.allow_do_close = false;
CefRefPtr<LifeSpanTestHandler> handler = new LifeSpanTestHandler(settings);
handler->ExecuteTest();
EXPECT_TRUE(handler->got_after_created_);
EXPECT_TRUE(handler->got_do_close_);
EXPECT_FALSE(handler->got_before_close_);
EXPECT_FALSE(handler->got_before_unload_dialog_);
EXPECT_TRUE(handler->got_unload_message_);
EXPECT_TRUE(handler->got_load_end_);
EXPECT_TRUE(handler->got_delay_close_);
}
TEST(LifeSpanTest, DoCloseDisallowForce) {
LifeSpanTestHandler::Settings settings;
settings.allow_do_close = false;
settings.force_close = true;
CefRefPtr<LifeSpanTestHandler> handler = new LifeSpanTestHandler(settings);
handler->ExecuteTest();
EXPECT_TRUE(handler->got_after_created_);
EXPECT_TRUE(handler->got_do_close_);
EXPECT_FALSE(handler->got_before_close_);
EXPECT_FALSE(handler->got_before_unload_dialog_);
EXPECT_TRUE(handler->got_unload_message_);
EXPECT_TRUE(handler->got_load_end_);
EXPECT_TRUE(handler->got_delay_close_);
}
TEST(LifeSpanTest, DoCloseDisallowWithOnUnloadAllow) {
LifeSpanTestHandler::Settings settings;
settings.allow_do_close = false;
settings.add_onunload_handler = true;
settings.accept_before_unload_dialog = true;
CefRefPtr<LifeSpanTestHandler> handler = new LifeSpanTestHandler(settings);
handler->ExecuteTest();
EXPECT_TRUE(handler->got_after_created_);
EXPECT_TRUE(handler->got_do_close_);
EXPECT_FALSE(handler->got_before_close_);
EXPECT_TRUE(handler->got_before_unload_dialog_);
EXPECT_TRUE(handler->got_unload_message_);
EXPECT_TRUE(handler->got_load_end_);
EXPECT_TRUE(handler->got_delay_close_);
}
TEST(LifeSpanTest, DoCloseAllowWithOnUnloadForce) {
LifeSpanTestHandler::Settings settings;
settings.allow_do_close = true;
settings.add_onunload_handler = true;
settings.force_close = true;
CefRefPtr<LifeSpanTestHandler> handler = new LifeSpanTestHandler(settings);
handler->ExecuteTest();
EXPECT_TRUE(handler->got_after_created_);
EXPECT_TRUE(handler->got_do_close_);
EXPECT_TRUE(handler->got_before_close_);
EXPECT_FALSE(handler->got_before_unload_dialog_);
EXPECT_TRUE(handler->got_unload_message_);
EXPECT_TRUE(handler->got_load_end_);
EXPECT_FALSE(handler->got_delay_close_);
}
TEST(LifeSpanTest, DoCloseDisallowWithOnUnloadForce) {
LifeSpanTestHandler::Settings settings;
settings.allow_do_close = false;
settings.add_onunload_handler = true;
settings.force_close = true;
CefRefPtr<LifeSpanTestHandler> handler = new LifeSpanTestHandler(settings);
handler->ExecuteTest();
EXPECT_TRUE(handler->got_after_created_);
EXPECT_TRUE(handler->got_do_close_);
EXPECT_FALSE(handler->got_before_close_);
EXPECT_FALSE(handler->got_before_unload_dialog_);
EXPECT_TRUE(handler->got_unload_message_);
EXPECT_TRUE(handler->got_load_end_);
EXPECT_TRUE(handler->got_delay_close_);
}
TEST(LifeSpanTest, OnUnloadAllow) {
LifeSpanTestHandler::Settings settings;
settings.add_onunload_handler = true;
settings.accept_before_unload_dialog = true;
CefRefPtr<LifeSpanTestHandler> handler = new LifeSpanTestHandler(settings);
handler->ExecuteTest();
EXPECT_TRUE(handler->got_after_created_);
EXPECT_TRUE(handler->got_do_close_);
EXPECT_TRUE(handler->got_before_close_);
EXPECT_TRUE(handler->got_before_unload_dialog_);
EXPECT_TRUE(handler->got_unload_message_);
EXPECT_TRUE(handler->got_load_end_);
EXPECT_FALSE(handler->got_delay_close_);
}
TEST(LifeSpanTest, OnUnloadDisallow) {
LifeSpanTestHandler::Settings settings;
settings.add_onunload_handler = true;
settings.accept_before_unload_dialog = false;
CefRefPtr<LifeSpanTestHandler> handler = new LifeSpanTestHandler(settings);
handler->ExecuteTest();
EXPECT_TRUE(handler->got_after_created_);
EXPECT_FALSE(handler->got_do_close_);
EXPECT_FALSE(handler->got_before_close_);
EXPECT_TRUE(handler->got_before_unload_dialog_);
EXPECT_FALSE(handler->got_unload_message_);
EXPECT_TRUE(handler->got_load_end_);
EXPECT_TRUE(handler->got_delay_close_);
}

View File

@@ -1,18 +1,18 @@
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file.
#ifndef CEF_TESTS_UNITTESTS_OS_RENDERING_UNITTEST_MAC_H_
#define CEF_TESTS_UNITTESTS_OS_RENDERING_UNITTEST_MAC_H_
#include "include/cef_base.h"
#include "ui/events/keycodes/keyboard_codes.h"
namespace osr_unittests {
CefWindowHandle GetFakeView();
void GetKeyEvent(CefKeyEvent& event, ui::KeyboardCode keyCode, int modifiers);
} // namespace osr_unittests
#endif
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file.
#ifndef CEF_TESTS_UNITTESTS_OS_RENDERING_UNITTEST_MAC_H_
#define CEF_TESTS_UNITTESTS_OS_RENDERING_UNITTEST_MAC_H_
#include "include/cef_base.h"
#include "ui/events/keycodes/keyboard_codes.h"
namespace osr_unittests {
CefWindowHandle GetFakeView();
void GetKeyEvent(CefKeyEvent& event, ui::KeyboardCode keyCode, int modifiers);
} // namespace osr_unittests
#endif

View File

@@ -1,39 +1,39 @@
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file.
#import <AppKit/AppKit.h>
#import <Cocoa/Cocoa.h>
#include "os_rendering_unittest_mac.h"
#include "ui/events/keycodes/keyboard_code_conversion_mac.h"
#include "include/cef_base.h"
namespace osr_unittests {
CefWindowHandle GetFakeView() {
NSScreen *mainScreen = [NSScreen mainScreen];
NSRect screenRect = [mainScreen visibleFrame];
NSView* fakeView = [[NSView alloc] initWithFrame: screenRect];
return fakeView;
}
void GetKeyEvent(CefKeyEvent& event, ui::KeyboardCode keyCode, int modifiers) {
unichar character;
unichar unmodified_character;
// TODO(port): translate modifiers from the input format to NSFlags
// MacKeyCodeForWindowsKeyCode takes a NSUinteger as flags.
int macKeyCode = ui::MacKeyCodeForWindowsKeyCode(keyCode,
modifiers,
&character,
&unmodified_character);
event.native_key_code = macKeyCode;
event.character = character;
event.unmodified_character = unmodified_character;
}
} // namespace osr_unittests
// Copyright (c) 2013 The Chromium Embedded Framework Authors. All rights
// reserved. Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file.
#import <AppKit/AppKit.h>
#import <Cocoa/Cocoa.h>
#include "os_rendering_unittest_mac.h"
#include "ui/events/keycodes/keyboard_code_conversion_mac.h"
#include "include/cef_base.h"
namespace osr_unittests {
CefWindowHandle GetFakeView() {
NSScreen *mainScreen = [NSScreen mainScreen];
NSRect screenRect = [mainScreen visibleFrame];
NSView* fakeView = [[NSView alloc] initWithFrame: screenRect];
return fakeView;
}
void GetKeyEvent(CefKeyEvent& event, ui::KeyboardCode keyCode, int modifiers) {
unichar character;
unichar unmodified_character;
// TODO(port): translate modifiers from the input format to NSFlags
// MacKeyCodeForWindowsKeyCode takes a NSUinteger as flags.
int macKeyCode = ui::MacKeyCodeForWindowsKeyCode(keyCode,
modifiers,
&character,
&unmodified_character);
event.native_key_code = macKeyCode;
event.character = character;
event.unmodified_character = unmodified_character;
}
} // namespace osr_unittests