summaryrefslogtreecommitdiffstats
path: root/webkit/glue/plugins/test/plugin_windowless_test.cc
diff options
context:
space:
mode:
authorstuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-09 00:32:43 +0000
committerstuartmorgan@chromium.org <stuartmorgan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-09 00:32:43 +0000
commit06e7d7fd35cbd00b8c0bc771a654d0d56d859ac4 (patch)
tree083138dd9ef4b706d4087db197fc97b3e44a95a6 /webkit/glue/plugins/test/plugin_windowless_test.cc
parentf0e11278e195088d92ae5acfdbc975ba73868dbe (diff)
downloadchromium_src-06e7d7fd35cbd00b8c0bc771a654d0d56d859ac4.zip
chromium_src-06e7d7fd35cbd00b8c0bc771a654d0d56d859ac4.tar.gz
chromium_src-06e7d7fd35cbd00b8c0bc771a654d0d56d859ac4.tar.bz2
Finish implementing NPN_ConvertPoint, and add a unit test for it
BUG=29457,31767 TEST=self-testing Review URL: http://codereview.chromium.org/580019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38417 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/plugins/test/plugin_windowless_test.cc')
-rw-r--r--webkit/glue/plugins/test/plugin_windowless_test.cc93
1 files changed, 91 insertions, 2 deletions
diff --git a/webkit/glue/plugins/test/plugin_windowless_test.cc b/webkit/glue/plugins/test/plugin_windowless_test.cc
index 2ab9ca1..665072e 100644
--- a/webkit/glue/plugins/test/plugin_windowless_test.cc
+++ b/webkit/glue/plugins/test/plugin_windowless_test.cc
@@ -7,6 +7,7 @@
#include "webkit/glue/plugins/test/plugin_client.h"
#if defined(OS_MACOSX)
+#include <ApplicationServices/ApplicationServices.h>
#include <Carbon/Carbon.h>
#endif
@@ -47,6 +48,15 @@ static bool IsMouseUpEvent(NPEvent* np_event) {
#endif
}
+static bool IsWindowActivationEvent(NPEvent* np_event) {
+#if defined(OS_WIN)
+ NOTIMPLEMENTED();
+ return false;
+#elif defined(OS_MACOSX)
+ return np_event->what == activateEvt;
+#endif
+}
+
int16 WindowlessPluginTest::HandleEvent(void* event) {
NPNetscapeFuncs* browser = NPAPIClient::PluginClient::HostFunctions();
@@ -86,13 +96,17 @@ int16 WindowlessPluginTest::HandleEvent(void* event) {
} else if (test_name_ == "multiple_instances_sync_calls") {
MultipleInstanceSyncCalls(browser);
}
-
+#if OS_MACOSX
+ } else if (IsWindowActivationEvent(np_event) &&
+ test_name_ == "convert_point") {
+ ConvertPoint(browser);
+#endif
} else if (IsMouseMoveEvent(np_event) &&
test_name_ == "execute_script_delete_in_mouse_move") {
ExecuteScript(browser, id(), "DeletePluginWithinScript();", NULL);
SignalTestCompleted();
} else if (IsMouseUpEvent(np_event) &&
- test_name_ == "delete_frame_test") {
+ test_name_ == "delete_frame_test") {
ExecuteScript(
browser, id(),
"parent.document.getElementById('frame').outerHTML = ''", NULL);
@@ -134,4 +148,79 @@ void WindowlessPluginTest::MultipleInstanceSyncCalls(NPNetscapeFuncs* browser) {
SignalTestCompleted();
}
+void WindowlessPluginTest::ConvertPoint(NPNetscapeFuncs* browser) {
+#if defined(OS_MACOSX)
+ // First, just sanity-test that round trips work.
+ NPCoordinateSpace spaces[] = { NPCoordinateSpacePlugin,
+ NPCoordinateSpaceWindow,
+ NPCoordinateSpaceFlippedWindow,
+ NPCoordinateSpaceScreen,
+ NPCoordinateSpaceFlippedScreen };
+ for (unsigned int i = 0; i < arraysize(spaces); ++i) {
+ for (unsigned int j = 0; j < arraysize(spaces); ++j) {
+ double x, y, round_trip_x, round_trip_y;
+ if (!(browser->convertpoint(id(), 0, 0, spaces[i], &x, &y, spaces[j])) ||
+ !(browser->convertpoint(id(), x, y, spaces[j], &round_trip_x,
+ &round_trip_y, spaces[i]))) {
+ SetError("Conversion failed");
+ SignalTestCompleted();
+ return;
+ }
+ if (i != j && x == 0 && y == 0) {
+ SetError("Converting a coordinate should change it");
+ SignalTestCompleted();
+ return;
+ }
+ if (round_trip_x != 0 || round_trip_y != 0) {
+ SetError("Round-trip conversion should give return the original point");
+ SignalTestCompleted();
+ return;
+ }
+ }
+ }
+
+ // Now, more extensive testing on a single point.
+ double screen_x, screen_y;
+ browser->convertpoint(id(), 0, 0, NPCoordinateSpacePlugin,
+ &screen_x, &screen_y, NPCoordinateSpaceScreen);
+ double flipped_screen_x, flipped_screen_y;
+ browser->convertpoint(id(), 0, 0, NPCoordinateSpacePlugin,
+ &flipped_screen_x, &flipped_screen_y,
+ NPCoordinateSpaceFlippedScreen);
+ double window_x, window_y;
+ browser->convertpoint(id(), 0, 0, NPCoordinateSpacePlugin,
+ &window_x, &window_y, NPCoordinateSpaceWindow);
+ double flipped_window_x, flipped_window_y;
+ browser->convertpoint(id(), 0, 0, NPCoordinateSpacePlugin,
+ &flipped_window_x, &flipped_window_y,
+ NPCoordinateSpaceFlippedWindow);
+
+ CGRect main_display_bounds = CGDisplayBounds(CGMainDisplayID());
+
+ // Check that all the coordinates are right. The plugin is in a 600x600 window
+ // at (100, 100), with a content area origin of (100, 100).
+ // Y-coordinates are not checked exactly so that the test is robust against
+ // toolbar changes, info bar visibility, etc.
+ if (screen_x != flipped_screen_x)
+ SetError("Flipping screen coordinates shouldn't change x");
+ else if (flipped_screen_y != main_display_bounds.size.height - screen_y)
+ SetError("Flipped screen coordinates should be flipped vertically!");
+ else if (screen_x != 200)
+ SetError("Screen x location is wrong");
+ else if (flipped_screen_y < 200 || flipped_screen_y > 400)
+ SetError("Screen y location is wrong");
+ if (window_x != flipped_window_x)
+ SetError("Flipping window coordinates shouldn't change x");
+ else if (flipped_window_y != 600 - window_y)
+ SetError("Flipped window coordinates should be flipped vertically!");
+ else if (window_x != 100)
+ SetError("Window x location is wrong");
+ else if (flipped_screen_y < 100 || flipped_screen_y > 300)
+ SetError("Window y location is wrong");
+#else
+ SetError("Unimplemented");
+#endif
+ SignalTestCompleted();
+}
+
} // namespace NPAPIClient