Commit 6d09c98a authored by aroben@apple.com's avatar aroben@apple.com

Move code required for most tests of plugin window geometry into a base class

WebKit2's asynchronous plugin window positioning makes testing window geometry tricky. By
having all the trickiness in a shared base class, writing new window geometry tests will be
much easier.

Fixes <http://webkit.org/b/60776> It's hard to write tests that check plugin window geometry

Reviewed by Anders Carlsson.

* DumpRenderTree/TestNetscapePlugIn/Tests/win/WindowRegionIsSetToClipRect.cpp:
(WindowRegionIsSetToClipRect::WindowRegionIsSetToClipRect): Changed to inherit from the new
WindowGeometryTest base class. Most of the code from this class was moved to the new base
class.
(WindowRegionIsSetToClipRect::performWindowGeometryTest): Renamed from checkWindowRegion.
This is called by the base class when it is safe to check the window's geometry. Note that
the m_didCheckWindowRegion logic was removed completely; it has never been needed and was
just vestigial code from an earlier version of this test.

* DumpRenderTree/TestNetscapePlugIn/win/TestNetscapePlugin.vcproj: Added new
WindowGeometryTest class.

* DumpRenderTree/TestNetscapePlugIn/win/WindowGeometryTest.cpp: Added. Code came from
WindowRegionIsSetToClipRect.
(WindowGeometryTest::finishTest): This is the only change from WindowRegionIsSetToClipRect.
We now call the new virtual performWindowGeometryTest function instead of checkWindowRegion.
Subclasses can implement that function to perform their own tests.

* DumpRenderTree/TestNetscapePlugIn/win/WindowGeometryTest.h: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@86441 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 7e68d0bd
2011-05-13 Adam Roben <aroben@apple.com>
Move code required for most tests of plugin window geometry into a base class
WebKit2's asynchronous plugin window positioning makes testing window geometry tricky. By
having all the trickiness in a shared base class, writing new window geometry tests will be
much easier.
Fixes <http://webkit.org/b/60776> It's hard to write tests that check plugin window geometry
Reviewed by Anders Carlsson.
* DumpRenderTree/TestNetscapePlugIn/Tests/win/WindowRegionIsSetToClipRect.cpp:
(WindowRegionIsSetToClipRect::WindowRegionIsSetToClipRect): Changed to inherit from the new
WindowGeometryTest base class. Most of the code from this class was moved to the new base
class.
(WindowRegionIsSetToClipRect::performWindowGeometryTest): Renamed from checkWindowRegion.
This is called by the base class when it is safe to check the window's geometry. Note that
the m_didCheckWindowRegion logic was removed completely; it has never been needed and was
just vestigial code from an earlier version of this test.
* DumpRenderTree/TestNetscapePlugIn/win/TestNetscapePlugin.vcproj: Added new
WindowGeometryTest class.
* DumpRenderTree/TestNetscapePlugIn/win/WindowGeometryTest.cpp: Added. Code came from
WindowRegionIsSetToClipRect.
(WindowGeometryTest::finishTest): This is the only change from WindowRegionIsSetToClipRect.
We now call the new virtual performWindowGeometryTest function instead of checkWindowRegion.
Subclasses can implement that function to perform their own tests.
* DumpRenderTree/TestNetscapePlugIn/win/WindowGeometryTest.h: Added.
2011-05-13 Zoltan Herczeg <zherczeg@webkit.org> 2011-05-13 Zoltan Herczeg <zherczeg@webkit.org>
Reviewed by Csaba Osztrogonác. Reviewed by Csaba Osztrogonác.
......
/* /*
* Copyright (C) 2010 Apple Inc. All rights reserved. * Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
* THE POSSIBILITY OF SUCH DAMAGE. * THE POSSIBILITY OF SUCH DAMAGE.
*/ */
#include "WindowedPluginTest.h" #include "WindowGeometryTest.h"
#include "PluginObject.h" #include "PluginObject.h"
...@@ -31,82 +31,23 @@ using namespace std; ...@@ -31,82 +31,23 @@ using namespace std;
// The plugin's window's window region should be set to the plugin's clip rect. // The plugin's window's window region should be set to the plugin's clip rect.
class WindowRegionIsSetToClipRect : public WindowedPluginTest { class WindowRegionIsSetToClipRect : public WindowGeometryTest {
public: public:
WindowRegionIsSetToClipRect(NPP, const string& identifier); WindowRegionIsSetToClipRect(NPP, const string& identifier);
private: private:
struct ScriptObject : Object<ScriptObject> { virtual void performWindowGeometryTest();
bool hasMethod(NPIdentifier);
bool invoke(NPIdentifier, const NPVariant*, uint32_t, NPVariant*);
};
static const UINT_PTR triggerPaintTimerID = 1;
void startTest();
void finishTest();
void checkWindowRegion();
void showTestHarnessWindowIfNeeded();
void hideTestHarnessWindowIfNeeded();
// WindowedPluginTest
virtual LRESULT wndProc(UINT message, WPARAM, LPARAM, bool& handled);
// PluginTest
virtual NPError NPP_GetValue(NPPVariable, void*);
bool m_didCheckWindowRegion;
bool m_testHarnessWindowWasVisible;
}; };
static PluginTest::Register<WindowRegionIsSetToClipRect> registrar("window-region-is-set-to-clip-rect"); static PluginTest::Register<WindowRegionIsSetToClipRect> registrar("window-region-is-set-to-clip-rect");
WindowRegionIsSetToClipRect::WindowRegionIsSetToClipRect(NPP npp, const string& identifier) WindowRegionIsSetToClipRect::WindowRegionIsSetToClipRect(NPP npp, const string& identifier)
: WindowedPluginTest(npp, identifier) : WindowGeometryTest(npp, identifier)
, m_didCheckWindowRegion(false)
, m_testHarnessWindowWasVisible(false)
{
}
void WindowRegionIsSetToClipRect::startTest()
{
// In WebKit1, our window's window region will be set immediately. In WebKit2, it won't be set
// until the UI process paints. Since the UI process will also show our window when it paints,
// we can detect when the paint occurs (and thus when our window region should be set) by
// starting with our plugin element hidden, then making it visible and waiting for a
// WM_WINDOWPOSCHANGED event to tell us our window has been shown.
waitUntilDone();
// If the test harness window isn't visible, we might not receive a WM_WINDOWPOSCHANGED message
// when our window is made visible. So we temporarily show the test harness window during this test.
showTestHarnessWindowIfNeeded();
// Make our window visible. (In WebKit2, this won't take effect immediately.)
executeScript("document.getElementsByTagName('embed')[0].style.visibility = 'visible';");
// We trigger a UI process paint after a slight delay to ensure that the UI process has
// received the "make the plugin window visible" message before it paints.
// FIXME: It would be nice to have a way to guarantee that the UI process had received that
// message before we triggered a paint. Hopefully that would let us get rid of this semi-
// arbitrary timeout.
::SetTimer(window(), triggerPaintTimerID, 250, 0);
}
void WindowRegionIsSetToClipRect::finishTest()
{ {
checkWindowRegion();
hideTestHarnessWindowIfNeeded();
notifyDone();
} }
void WindowRegionIsSetToClipRect::checkWindowRegion() void WindowRegionIsSetToClipRect::performWindowGeometryTest()
{ {
if (m_didCheckWindowRegion)
return;
m_didCheckWindowRegion = true;
RECT regionRect; RECT regionRect;
if (::GetWindowRgnBox(window(), &regionRect) == ERROR) { if (::GetWindowRgnBox(window(), &regionRect) == ERROR) {
log("::GetWindowRgnBox failed, or window has no window region"); log("::GetWindowRgnBox failed, or window has no window region");
...@@ -155,65 +96,3 @@ void WindowRegionIsSetToClipRect::checkWindowRegion() ...@@ -155,65 +96,3 @@ void WindowRegionIsSetToClipRect::checkWindowRegion()
else else
log("PASS: Plugin's window's class does not have the CS_PARENTDC style"); log("PASS: Plugin's window's class does not have the CS_PARENTDC style");
} }
void WindowRegionIsSetToClipRect::showTestHarnessWindowIfNeeded()
{
HWND testHarnessWindow = this->testHarnessWindow();
m_testHarnessWindowWasVisible = ::IsWindowVisible(testHarnessWindow);
if (m_testHarnessWindowWasVisible)
return;
::ShowWindow(testHarnessWindow, SW_SHOWNA);
}
void WindowRegionIsSetToClipRect::hideTestHarnessWindowIfNeeded()
{
if (m_testHarnessWindowWasVisible)
return;
::ShowWindow(testHarnessWindow(), SW_HIDE);
}
LRESULT WindowRegionIsSetToClipRect::wndProc(UINT message, WPARAM wParam, LPARAM lParam, bool& handled)
{
switch (message) {
case WM_TIMER:
if (wParam != triggerPaintTimerID)
break;
handled = true;
::KillTimer(window(), wParam);
// Tell the UI process to paint.
::PostMessageW(::GetParent(window()), WM_PAINT, 0, 0);
break;
case WM_WINDOWPOSCHANGED: {
WINDOWPOS* windowPos = reinterpret_cast<WINDOWPOS*>(lParam);
if (!(windowPos->flags & SWP_SHOWWINDOW))
break;
finishTest();
break;
}
}
return 0;
}
NPError WindowRegionIsSetToClipRect::NPP_GetValue(NPPVariable variable, void* value)
{
if (variable != NPPVpluginScriptableNPObject)
return NPERR_GENERIC_ERROR;
*static_cast<NPObject**>(value) = ScriptObject::create(this);
return NPERR_NO_ERROR;
}
bool WindowRegionIsSetToClipRect::ScriptObject::hasMethod(NPIdentifier methodName)
{
return methodName == pluginTest()->NPN_GetStringIdentifier("startTest");
}
bool WindowRegionIsSetToClipRect::ScriptObject::invoke(NPIdentifier identifier, const NPVariant*, uint32_t, NPVariant*)
{
assert(identifier == pluginTest()->NPN_GetStringIdentifier("startTest"));
static_cast<WindowRegionIsSetToClipRect*>(pluginTest())->startTest();
return true;
}
...@@ -473,6 +473,14 @@ ...@@ -473,6 +473,14 @@
RelativePath=".\WindowedPluginTest.h" RelativePath=".\WindowedPluginTest.h"
> >
</File> </File>
<File
RelativePath=".\WindowGeometryTest.cpp"
>
</File>
<File
RelativePath=".\WindowGeometryTest.h"
>
</File>
</Filter> </Filter>
<File <File
RelativePath="..\main.cpp" RelativePath="..\main.cpp"
......
/*
* Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "WindowGeometryTest.h"
#include "PluginObject.h"
using namespace std;
WindowGeometryTest::WindowGeometryTest(NPP npp, const string& identifier)
: WindowedPluginTest(npp, identifier)
, m_testHarnessWindowWasVisible(false)
{
}
void WindowGeometryTest::startTest()
{
// In WebKit1, our window's window region will be set immediately. In WebKit2, it won't be set
// until the UI process paints. Since the UI process will also show our window when it paints,
// we can detect when the paint occurs (and thus when our window region should be set) by
// starting with our plugin element hidden, then making it visible and waiting for a
// WM_WINDOWPOSCHANGED event to tell us our window has been shown.
waitUntilDone();
// If the test harness window isn't visible, we might not receive a WM_WINDOWPOSCHANGED message
// when our window is made visible. So we temporarily show the test harness window during this test.
showTestHarnessWindowIfNeeded();
// Make our window visible. (In WebKit2, this won't take effect immediately.)
executeScript("document.getElementsByTagName('embed')[0].style.visibility = 'visible';");
// We trigger a UI process paint after a slight delay to ensure that the UI process has
// received the "make the plugin window visible" message before it paints.
// FIXME: It would be nice to have a way to guarantee that the UI process had received that
// message before we triggered a paint. Hopefully that would let us get rid of this semi-
// arbitrary timeout.
::SetTimer(window(), triggerPaintTimerID, 250, 0);
}
void WindowGeometryTest::finishTest()
{
performWindowGeometryTest();
hideTestHarnessWindowIfNeeded();
notifyDone();
}
void WindowGeometryTest::showTestHarnessWindowIfNeeded()
{
HWND testHarnessWindow = this->testHarnessWindow();
m_testHarnessWindowWasVisible = ::IsWindowVisible(testHarnessWindow);
if (m_testHarnessWindowWasVisible)
return;
::ShowWindow(testHarnessWindow, SW_SHOWNA);
}
void WindowGeometryTest::hideTestHarnessWindowIfNeeded()
{
if (m_testHarnessWindowWasVisible)
return;
::ShowWindow(testHarnessWindow(), SW_HIDE);
}
LRESULT WindowGeometryTest::wndProc(UINT message, WPARAM wParam, LPARAM lParam, bool& handled)
{
switch (message) {
case WM_TIMER:
if (wParam != triggerPaintTimerID)
break;
handled = true;
::KillTimer(window(), wParam);
// Tell the UI process to paint.
::PostMessageW(::GetParent(window()), WM_PAINT, 0, 0);
break;
case WM_WINDOWPOSCHANGED: {
WINDOWPOS* windowPos = reinterpret_cast<WINDOWPOS*>(lParam);
if (!(windowPos->flags & SWP_SHOWWINDOW))
break;
finishTest();
break;
}
}
return 0;
}
NPError WindowGeometryTest::NPP_GetValue(NPPVariable variable, void* value)
{
if (variable != NPPVpluginScriptableNPObject)
return NPERR_GENERIC_ERROR;
*static_cast<NPObject**>(value) = ScriptObject::create(this);
return NPERR_NO_ERROR;
}
bool WindowGeometryTest::ScriptObject::hasMethod(NPIdentifier methodName)
{
return methodName == pluginTest()->NPN_GetStringIdentifier("startTest");
}
bool WindowGeometryTest::ScriptObject::invoke(NPIdentifier identifier, const NPVariant*, uint32_t, NPVariant*)
{
assert(identifier == pluginTest()->NPN_GetStringIdentifier("startTest"));
static_cast<WindowGeometryTest*>(pluginTest())->startTest();
return true;
}
/*
* Copyright (C) 2010, 2011 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef WindowGeometryTest_h
#define WindowGeometryTest_h
#include "WindowedPluginTest.h"
class WindowGeometryTest : public WindowedPluginTest {
public:
WindowGeometryTest(NPP, const std::string& identifier);
private:
struct ScriptObject : Object<ScriptObject> {
bool hasMethod(NPIdentifier);
bool invoke(NPIdentifier, const NPVariant*, uint32_t, NPVariant*);
};
static const UINT_PTR triggerPaintTimerID = 1;
void startTest();
void finishTest();
void showTestHarnessWindowIfNeeded();
void hideTestHarnessWindowIfNeeded();
// For subclasses to implement
virtual void performWindowGeometryTest() = 0;
// WindowedPluginTest
virtual LRESULT wndProc(UINT message, WPARAM, LPARAM, bool& handled);
// PluginTest
virtual NPError NPP_GetValue(NPPVariable, void*);
bool m_testHarnessWindowWasVisible;
};
#endif // WindowGeometryTest_h
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment