1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/test/plugin/plugin_javascript_open_popup.h"
7 #include "build/build_config.h"
8 #include "base/logging.h"
11 #include "third_party/npapi/bindings/npapi_x11.h"
13 #include "content/test/plugin/plugin_client.h"
15 namespace NPAPIClient {
17 ExecuteJavascriptOpenPopupWithPluginTest::
18 ExecuteJavascriptOpenPopupWithPluginTest(NPP id,
19 NPNetscapeFuncs *host_functions)
20 : PluginTest(id, host_functions),
21 popup_window_test_started_(false) {
24 int16 ExecuteJavascriptOpenPopupWithPluginTest::SetWindow(
26 #if !defined(OS_MACOSX)
27 if (window->window == NULL)
28 return NPERR_NO_ERROR;
31 if (!popup_window_test_started_) {
32 popup_window_test_started_ = true;
33 HostFunctions()->geturl(
34 id(), "popup_window_with_target_plugin.html", "_blank");
36 return NPERR_NO_ERROR;
39 // ExecuteJavascriptPopupWindowTargetPluginTest member defines.
40 ExecuteJavascriptPopupWindowTargetPluginTest::
41 ExecuteJavascriptPopupWindowTargetPluginTest(
42 NPP id, NPNetscapeFuncs* host_functions)
43 : PluginTest(id, host_functions),
44 test_completed_(false) {
47 int16 ExecuteJavascriptPopupWindowTargetPluginTest::SetWindow(
49 #if !defined(OS_MACOSX)
50 if (window->window == NULL)
51 return NPERR_NO_ERROR;
54 if (!test_completed_) {
55 if (CheckWindow(window)) {
56 SignalTestCompleted();
57 test_completed_ = true;
60 return PluginTest::SetWindow(window);
64 bool ExecuteJavascriptPopupWindowTargetPluginTest::CheckWindow(
66 HWND window_handle = reinterpret_cast<HWND>(window->window);
68 if (IsWindow(window_handle)) {
69 HWND parent_window = GetParent(window_handle);
70 if (!IsWindow(parent_window))
71 SetError("Windowed plugin instantiated with NULL parent");
78 #elif defined(USE_X11)
79 // This code blindly follows the same sorts of verifications done on
80 // the Windows side. Does it make sense on X? Maybe not really, but
81 // it can't hurt to do extra validations.
82 bool ExecuteJavascriptPopupWindowTargetPluginTest::CheckWindow(
84 Window xwindow = reinterpret_cast<Window>(window->window);
85 // Grab a pointer to the extra SetWindow data so we can grab the display out.
86 NPSetWindowCallbackStruct* extra =
87 static_cast<NPSetWindowCallbackStruct*>(window->ws_info);
92 unsigned int num_child;
93 Status status = XQueryTree(extra->display, xwindow, &root, &parent,
98 if (!parent || parent == root)
99 SetError("Windowed plugin instantiated with NULL parent");
105 #elif defined(OS_MACOSX)
106 bool ExecuteJavascriptPopupWindowTargetPluginTest::CheckWindow(
108 // TODO(port) scaffolding--replace with a real test once NPWindow is done.
113 } // namespace NPAPIClient