Changeset 95955 in webkit


Ignore:
Timestamp:
Sep 26, 2011 8:55:05 AM (13 years ago)
Author:
Adam Roben
Message:

Clean up code imported from WebKitAPITest

Fixes <http://webkit.org/b/68799> WebViewDestruction tests and related code don't match
TestWebKitAPI conventions

Reviewed by David Levin.

  • TestWebKitAPI/Tests/WebKit/win/WebViewDestruction.cpp: Changed tests to use gtest macros

and to share functionality via test fixtures. Prefixed Win32 API calls with ::. Updated
namespace name.

(TestWebKitAPI::WebViewDestruction::SetUp):
(TestWebKitAPI::WebViewDestruction::webViewCount):
(TestWebKitAPI::WebViewDestructionWithHostWindow::SetUp):
(TestWebKitAPI::WebViewDestruction::runMessagePump):
(TestWebKitAPI::WebViewDestruction::TearDown):
(TestWebKitAPI::WebViewDestructionWithHostWindow::TearDown):
Moved functionality from free functions into these new test fixtures.

  • TestWebKitAPI/win/HostWindow.cpp:
  • TestWebKitAPI/win/HostWindow.h:

Prefixed Win32 API calls with ::. Updated namespace name.

Location:
trunk/Tools
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r95944 r95955  
     12011-09-26  Adam Roben  <aroben@apple.com>
     2
     3        Clean up code imported from WebKitAPITest
     4
     5        Fixes <http://webkit.org/b/68799> WebViewDestruction tests and related code don't match
     6        TestWebKitAPI conventions
     7
     8        Reviewed by David Levin.
     9
     10        * TestWebKitAPI/Tests/WebKit/win/WebViewDestruction.cpp: Changed tests to use gtest macros
     11        and to share functionality via test fixtures. Prefixed Win32 API calls with ::. Updated
     12        namespace name.
     13
     14        (TestWebKitAPI::WebViewDestruction::SetUp):
     15        (TestWebKitAPI::WebViewDestruction::webViewCount):
     16        (TestWebKitAPI::WebViewDestructionWithHostWindow::SetUp):
     17        (TestWebKitAPI::WebViewDestruction::runMessagePump):
     18        (TestWebKitAPI::WebViewDestruction::TearDown):
     19        (TestWebKitAPI::WebViewDestructionWithHostWindow::TearDown):
     20        Moved functionality from free functions into these new test fixtures.
     21
     22        * TestWebKitAPI/win/HostWindow.cpp:
     23        * TestWebKitAPI/win/HostWindow.h:
     24        Prefixed Win32 API calls with ::. Updated namespace name.
     25
    1262011-09-23  Adam Roben  <aroben@apple.com>
    227
  • trunk/Tools/TestWebKitAPI/Tests/WebKit/win/WebViewDestruction.cpp

    r95944 r95955  
    3232#include <wtf/PassOwnPtr.h>
    3333
    34 #define TEST_ASSERT(x) ASSERT_TRUE(x)
    35 
    36 namespace WebKitAPITest {
     34namespace TestWebKitAPI {
    3735
    3836template <typename T>
     
    4240}
    4341
    44 static int webViewCount()
     42class WebViewDestruction : public ::testing::Test {
     43protected:
     44    virtual void SetUp();
     45    virtual void TearDown();
     46
     47    static int webViewCount();
     48    static void runMessagePump(DWORD timeoutMilliseconds);
     49
     50    COMPtr<IWebView> m_webView;
     51};
     52
     53class WebViewDestructionWithHostWindow : public WebViewDestruction {
     54protected:
     55    virtual void SetUp();
     56    virtual void TearDown();
     57
     58    HostWindow m_window;
     59    HWND m_viewWindow;
     60};
     61
     62void WebViewDestruction::SetUp()
     63{
     64    EXPECT_HRESULT_SUCCEEDED(WebKitCreateInstance(__uuidof(WebView), &m_webView));
     65}
     66
     67int WebViewDestruction::webViewCount()
    4568{
    4669    COMPtr<IWebKitStatistics> statistics;
     
    5376}
    5477
    55 static void createAndInitializeWebView(COMPtr<IWebView>& outWebView, HostWindow& window, HWND& viewWindow)
     78void WebViewDestructionWithHostWindow::SetUp()
    5679{
    57     COMPtr<IWebView> webView;
    58     TEST_ASSERT(SUCCEEDED(WebKitCreateInstance(__uuidof(WebView), &webView)));
     80    WebViewDestruction::SetUp();
    5981
    60     TEST_ASSERT(window.initialize());
    61     TEST_ASSERT(SUCCEEDED(webView->setHostWindow(reinterpret_cast<OLE_HANDLE>(window.window()))));
    62     TEST_ASSERT(SUCCEEDED(webView->initWithFrame(window.clientRect(), 0, 0)));
     82    EXPECT_TRUE(m_window.initialize());
     83    EXPECT_HRESULT_SUCCEEDED(m_webView->setHostWindow(reinterpret_cast<OLE_HANDLE>(m_window.window())));
     84    EXPECT_HRESULT_SUCCEEDED(m_webView->initWithFrame(m_window.clientRect(), 0, 0));
    6385
    64     COMPtr<IWebViewPrivate> viewPrivate(Query, webView);
    65     TEST_ASSERT(viewPrivate);
    66     TEST_ASSERT(SUCCEEDED(viewPrivate->viewWindow(reinterpret_cast<OLE_HANDLE*>(&viewWindow))));
    67     TEST_ASSERT(IsWindow(viewWindow));
    68 
    69     outWebView.adoptRef(webView.releaseRef());
     86    COMPtr<IWebViewPrivate> viewPrivate(Query, m_webView);
     87    ASSERT_NOT_NULL(viewPrivate);
     88    EXPECT_HRESULT_SUCCEEDED(viewPrivate->viewWindow(reinterpret_cast<OLE_HANDLE*>(&m_viewWindow)));
     89    EXPECT_TRUE(::IsWindow(m_viewWindow));
    7090}
    7191
    72 static void runMessagePump(DWORD timeoutMilliseconds)
     92void WebViewDestruction::runMessagePump(DWORD timeoutMilliseconds)
    7393{
    74     DWORD startTickCount = GetTickCount();
     94    // FIXME: We should move this functionality to PlatformUtilities at some point.
     95
     96    DWORD startTickCount = ::GetTickCount();
    7597    MSG msg;
    7698    BOOL result;
    77     while ((result = PeekMessageW(&msg, 0, 0, 0, PM_REMOVE)) && GetTickCount() - startTickCount <= timeoutMilliseconds) {
     99    while ((result = ::PeekMessageW(&msg, 0, 0, 0, PM_REMOVE)) && ::GetTickCount() - startTickCount <= timeoutMilliseconds) {
    78100        if (result == -1)
    79101            break;
    80         TranslateMessage(&msg);
    81         DispatchMessage(&msg);
     102        ::TranslateMessage(&msg);
     103        ::DispatchMessage(&msg);
    82104    }
    83105}
    84106
    85 static void finishWebViewDestructionTest(COMPtr<IWebView>& webView, HWND viewWindow)
     107void WebViewDestruction::TearDown()
    86108{
    87109    // Allow window messages to be processed, because in some cases that would trigger a crash (e.g., <http://webkit.org/b/32827>).
     
    90112    // We haven't crashed. Release the WebView and ensure that its view window has been destroyed and the WebView doesn't leak.
    91113    int currentWebViewCount = webViewCount();
    92     TEST_ASSERT(currentWebViewCount > 0);
     114    EXPECT_GT(currentWebViewCount, 0);
    93115
    94     webView = 0;
     116    m_webView = 0;
    95117
    96     TEST_ASSERT(webViewCount() == currentWebViewCount - 1);
    97     TEST_ASSERT(!IsWindow(viewWindow));
     118    EXPECT_EQ(webViewCount(), currentWebViewCount - 1);
     119}
     120
     121void WebViewDestructionWithHostWindow::TearDown()
     122{
     123    WebViewDestruction::TearDown();
     124
     125    EXPECT_FALSE(::IsWindow(m_viewWindow));
    98126}
    99127
    100128// Tests that releasing a WebView without calling IWebView::initWithFrame works.
    101 TEST(WebViewDestruction, NoInitWithFrame)
     129TEST_F(WebViewDestruction, NoInitWithFrame)
    102130{
    103     COMPtr<IWebView> webView;
    104     TEST_ASSERT(SUCCEEDED(WebKitCreateInstance(__uuidof(WebView), &webView)));
    105 
    106     finishWebViewDestructionTest(webView, 0);
    107131}
    108132
    109 TEST(WebViewDestruction, CloseWithoutInitWithFrame)
     133TEST_F(WebViewDestruction, CloseWithoutInitWithFrame)
    110134{
    111     COMPtr<IWebView> webView;
    112     TEST_ASSERT(SUCCEEDED(WebKitCreateInstance(__uuidof(WebView), &webView)));
    113 
    114     TEST_ASSERT(SUCCEEDED(webView->close()));
    115 
    116     finishWebViewDestructionTest(webView, 0);
     135    EXPECT_HRESULT_SUCCEEDED(m_webView->close());
    117136}
    118137
    119138// Tests that calling IWebView::close without calling DestroyWindow, then releasing a WebView doesn't crash. <http://webkit.org/b/32827>
    120 TEST(WebViewDestruction, CloseWithoutDestroyViewWindow)
     139TEST_F(WebViewDestructionWithHostWindow, CloseWithoutDestroyViewWindow)
    121140{
    122     COMPtr<IWebView> webView;
    123     HostWindow window;
    124     HWND viewWindow;
    125     createAndInitializeWebView(webView, window, viewWindow);
    126 
    127     TEST_ASSERT(SUCCEEDED(webView->close()));
    128 
    129     finishWebViewDestructionTest(webView, viewWindow);
     141    EXPECT_HRESULT_SUCCEEDED(m_webView->close());
    130142}
    131143
    132 TEST(WebViewDestruction, DestroyViewWindowWithoutClose)
     144TEST_F(WebViewDestructionWithHostWindow, DestroyViewWindowWithoutClose)
    133145{
    134     COMPtr<IWebView> webView;
    135     HostWindow window;
    136     HWND viewWindow;
    137     createAndInitializeWebView(webView, window, viewWindow);
    138 
    139     DestroyWindow(viewWindow);
    140 
    141     finishWebViewDestructionTest(webView, viewWindow);
     146    ::DestroyWindow(m_viewWindow);
    142147}
    143148
    144 TEST(WebViewDestruction, CloseThenDestroyViewWindow)
     149TEST_F(WebViewDestructionWithHostWindow, CloseThenDestroyViewWindow)
    145150{
    146     COMPtr<IWebView> webView;
    147     HostWindow window;
    148     HWND viewWindow;
    149     createAndInitializeWebView(webView, window, viewWindow);
    150 
    151     TEST_ASSERT(SUCCEEDED(webView->close()));
    152     DestroyWindow(viewWindow);
    153 
    154     finishWebViewDestructionTest(webView, viewWindow);
     151    EXPECT_HRESULT_SUCCEEDED(m_webView->close());
     152    ::DestroyWindow(m_viewWindow);
    155153}
    156154
    157 TEST(WebViewDestruction, DestroyViewWindowThenClose)
     155TEST_F(WebViewDestructionWithHostWindow, DestroyViewWindowThenClose)
    158156{
    159     COMPtr<IWebView> webView;
    160     HostWindow window;
    161     HWND viewWindow;
    162     createAndInitializeWebView(webView, window, viewWindow);
    163 
    164     DestroyWindow(viewWindow);
    165     TEST_ASSERT(SUCCEEDED(webView->close()));
    166 
    167     finishWebViewDestructionTest(webView, viewWindow);
     157    ::DestroyWindow(m_viewWindow);
     158    EXPECT_HRESULT_SUCCEEDED(m_webView->close());
    168159}
    169160
    170 TEST(WebViewDestruction, DestroyHostWindow)
     161TEST_F(WebViewDestructionWithHostWindow, DestroyHostWindow)
    171162{
    172     COMPtr<IWebView> webView;
    173     HostWindow window;
    174     HWND viewWindow;
    175     createAndInitializeWebView(webView, window, viewWindow);
    176 
    177     DestroyWindow(window.window());
    178 
    179     finishWebViewDestructionTest(webView, viewWindow);
     163    ::DestroyWindow(m_window.window());
    180164}
    181165
    182 TEST(WebViewDestruction, DestroyHostWindowThenClose)
     166TEST_F(WebViewDestructionWithHostWindow, DestroyHostWindowThenClose)
    183167{
    184     COMPtr<IWebView> webView;
    185     HostWindow window;
    186     HWND viewWindow;
    187     createAndInitializeWebView(webView, window, viewWindow);
    188 
    189     DestroyWindow(window.window());
    190     TEST_ASSERT(SUCCEEDED(webView->close()));
    191 
    192     finishWebViewDestructionTest(webView, viewWindow);
     168    ::DestroyWindow(m_window.window());
     169    EXPECT_HRESULT_SUCCEEDED(m_webView->close());
    193170}
    194171
    195 TEST(WebViewDestruction, CloseThenDestroyHostWindow)
     172TEST_F(WebViewDestructionWithHostWindow, CloseThenDestroyHostWindow)
    196173{
    197     COMPtr<IWebView> webView;
    198     HostWindow window;
    199     HWND viewWindow;
    200     createAndInitializeWebView(webView, window, viewWindow);
    201 
    202     TEST_ASSERT(SUCCEEDED(webView->close()));
    203     DestroyWindow(window.window());
    204 
    205     finishWebViewDestructionTest(webView, viewWindow);
     174    EXPECT_HRESULT_SUCCEEDED(m_webView->close());
     175    ::DestroyWindow(m_window.window());
    206176}
    207177
  • trunk/Tools/TestWebKitAPI/win/HostWindow.cpp

    r95944 r95955  
    2626#include "HostWindow.h"
    2727
    28 namespace WebKitAPITest {
     28namespace TestWebKitAPI {
    2929
    3030static LPCWSTR hostWindowClassName = L"HostWindow";
     
    3838{
    3939    registerWindowClass();
    40     m_window = CreateWindowExW(0, hostWindowClassName, L"WebKitAPITest", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, GetModuleHandle(0), 0);
     40    m_window = ::CreateWindowExW(0, hostWindowClassName, L"TestWebKitAPI", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, ::GetModuleHandle(0), 0);
    4141    return m_window;
    4242}
     
    4444HostWindow::~HostWindow()
    4545{
    46     if (!IsWindow(m_window))
     46    if (!::IsWindow(m_window))
    4747        return;
    48     DestroyWindow(m_window);
     48    ::DestroyWindow(m_window);
    4949}
    5050
     
    5252{
    5353    RECT rect = {0};
    54     if (!GetClientRect(m_window, &rect)) {
     54    if (!::GetClientRect(m_window, &rect)) {
    5555        RECT emptyRect = {0};
    5656        return emptyRect;
     
    7474    wndClass.lpszClassName = hostWindowClassName;
    7575
    76     RegisterClassExW(&wndClass);
     76    ::RegisterClassExW(&wndClass);
    7777}
    7878
    7979LRESULT HostWindow::wndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    8080{
    81     return DefWindowProcW(hWnd, uMsg, wParam, lParam);
     81    return ::DefWindowProcW(hWnd, uMsg, wParam, lParam);
    8282}
    8383
  • trunk/Tools/TestWebKitAPI/win/HostWindow.h

    r95944 r95955  
    2929#include <wtf/Noncopyable.h>
    3030
    31 namespace WebKitAPITest {
     31namespace TestWebKitAPI {
    3232
    3333class HostWindow {
Note: See TracChangeset for help on using the changeset viewer.