1// Copyright (c) 2010 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. 4 5#include "content/test/plugin/plugin_window_size_test.h" 6#include "content/test/plugin/plugin_client.h" 7 8namespace NPAPIClient { 9 10PluginWindowSizeTest::PluginWindowSizeTest(NPP id, 11 NPNetscapeFuncs *host_functions) 12 : PluginTest(id, host_functions) { 13} 14 15NPError PluginWindowSizeTest::SetWindow(NPWindow* pNPWindow) { 16 if (pNPWindow->window == NULL) 17 return NPERR_NO_ERROR; 18 19 HWND window = reinterpret_cast<HWND>(pNPWindow->window); 20 if (!::IsWindow(window)) { 21 SetError("Invalid arguments passed in"); 22 return NPERR_INVALID_PARAM; 23 } 24 25 RECT window_rect = {0}; 26 window_rect.left = pNPWindow->x; 27 window_rect.top = pNPWindow->y; 28 window_rect.right = pNPWindow->width; 29 window_rect.bottom = pNPWindow->height; 30 31 if (!::IsRectEmpty(&window_rect)) { 32 RECT client_rect = {0}; 33 ::GetClientRect(window, &client_rect); 34 if (::IsRectEmpty(&client_rect)) { 35 SetError("The client rect of the plugin window is empty. Test failed"); 36 } 37 38 // Bug 6742: ensure that the coordinates passed in are relative to the 39 // parent HWND. 40 POINT origin_from_os; 41 RECT window_rect_from_os; 42 ::GetWindowRect(window, &window_rect_from_os); 43 origin_from_os.x = window_rect_from_os.left; 44 origin_from_os.y = window_rect_from_os.top; 45 ::ScreenToClient(GetParent(window), &origin_from_os); 46 if (origin_from_os.x != pNPWindow->x || origin_from_os.y != pNPWindow->y) 47 SetError("Wrong position passed in to SetWindow! Test failed"); 48 49 SignalTestCompleted(); 50 } 51 52 return NPERR_NO_ERROR; 53} 54 55} // namespace NPAPIClient 56