Changeset 95955 in webkit
- Timestamp:
- Sep 26, 2011 8:55:05 AM (13 years ago)
- Location:
- trunk/Tools
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r95944 r95955 1 2011-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 1 26 2011-09-23 Adam Roben <aroben@apple.com> 2 27 -
trunk/Tools/TestWebKitAPI/Tests/WebKit/win/WebViewDestruction.cpp
r95944 r95955 32 32 #include <wtf/PassOwnPtr.h> 33 33 34 #define TEST_ASSERT(x) ASSERT_TRUE(x) 35 36 namespace WebKitAPITest { 34 namespace TestWebKitAPI { 37 35 38 36 template <typename T> … … 42 40 } 43 41 44 static int webViewCount() 42 class WebViewDestruction : public ::testing::Test { 43 protected: 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 53 class WebViewDestructionWithHostWindow : public WebViewDestruction { 54 protected: 55 virtual void SetUp(); 56 virtual void TearDown(); 57 58 HostWindow m_window; 59 HWND m_viewWindow; 60 }; 61 62 void WebViewDestruction::SetUp() 63 { 64 EXPECT_HRESULT_SUCCEEDED(WebKitCreateInstance(__uuidof(WebView), &m_webView)); 65 } 66 67 int WebViewDestruction::webViewCount() 45 68 { 46 69 COMPtr<IWebKitStatistics> statistics; … … 53 76 } 54 77 55 static void createAndInitializeWebView(COMPtr<IWebView>& outWebView, HostWindow& window, HWND& viewWindow)78 void WebViewDestructionWithHostWindow::SetUp() 56 79 { 57 COMPtr<IWebView> webView; 58 TEST_ASSERT(SUCCEEDED(WebKitCreateInstance(__uuidof(WebView), &webView))); 80 WebViewDestruction::SetUp(); 59 81 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)); 63 85 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)); 70 90 } 71 91 72 static voidrunMessagePump(DWORD timeoutMilliseconds)92 void WebViewDestruction::runMessagePump(DWORD timeoutMilliseconds) 73 93 { 74 DWORD startTickCount = GetTickCount(); 94 // FIXME: We should move this functionality to PlatformUtilities at some point. 95 96 DWORD startTickCount = ::GetTickCount(); 75 97 MSG msg; 76 98 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) { 78 100 if (result == -1) 79 101 break; 80 TranslateMessage(&msg);81 DispatchMessage(&msg);102 ::TranslateMessage(&msg); 103 ::DispatchMessage(&msg); 82 104 } 83 105 } 84 106 85 static void finishWebViewDestructionTest(COMPtr<IWebView>& webView, HWND viewWindow)107 void WebViewDestruction::TearDown() 86 108 { 87 109 // Allow window messages to be processed, because in some cases that would trigger a crash (e.g., <http://webkit.org/b/32827>). … … 90 112 // We haven't crashed. Release the WebView and ensure that its view window has been destroyed and the WebView doesn't leak. 91 113 int currentWebViewCount = webViewCount(); 92 TEST_ASSERT(currentWebViewCount >0);114 EXPECT_GT(currentWebViewCount, 0); 93 115 94 webView = 0;116 m_webView = 0; 95 117 96 TEST_ASSERT(webViewCount() == currentWebViewCount - 1); 97 TEST_ASSERT(!IsWindow(viewWindow)); 118 EXPECT_EQ(webViewCount(), currentWebViewCount - 1); 119 } 120 121 void WebViewDestructionWithHostWindow::TearDown() 122 { 123 WebViewDestruction::TearDown(); 124 125 EXPECT_FALSE(::IsWindow(m_viewWindow)); 98 126 } 99 127 100 128 // Tests that releasing a WebView without calling IWebView::initWithFrame works. 101 TEST (WebViewDestruction, NoInitWithFrame)129 TEST_F(WebViewDestruction, NoInitWithFrame) 102 130 { 103 COMPtr<IWebView> webView;104 TEST_ASSERT(SUCCEEDED(WebKitCreateInstance(__uuidof(WebView), &webView)));105 106 finishWebViewDestructionTest(webView, 0);107 131 } 108 132 109 TEST (WebViewDestruction, CloseWithoutInitWithFrame)133 TEST_F(WebViewDestruction, CloseWithoutInitWithFrame) 110 134 { 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()); 117 136 } 118 137 119 138 // Tests that calling IWebView::close without calling DestroyWindow, then releasing a WebView doesn't crash. <http://webkit.org/b/32827> 120 TEST (WebViewDestruction, CloseWithoutDestroyViewWindow)139 TEST_F(WebViewDestructionWithHostWindow, CloseWithoutDestroyViewWindow) 121 140 { 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()); 130 142 } 131 143 132 TEST (WebViewDestruction, DestroyViewWindowWithoutClose)144 TEST_F(WebViewDestructionWithHostWindow, DestroyViewWindowWithoutClose) 133 145 { 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); 142 147 } 143 148 144 TEST (WebViewDestruction, CloseThenDestroyViewWindow)149 TEST_F(WebViewDestructionWithHostWindow, CloseThenDestroyViewWindow) 145 150 { 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); 155 153 } 156 154 157 TEST (WebViewDestruction, DestroyViewWindowThenClose)155 TEST_F(WebViewDestructionWithHostWindow, DestroyViewWindowThenClose) 158 156 { 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()); 168 159 } 169 160 170 TEST (WebViewDestruction, DestroyHostWindow)161 TEST_F(WebViewDestructionWithHostWindow, DestroyHostWindow) 171 162 { 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()); 180 164 } 181 165 182 TEST (WebViewDestruction, DestroyHostWindowThenClose)166 TEST_F(WebViewDestructionWithHostWindow, DestroyHostWindowThenClose) 183 167 { 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()); 193 170 } 194 171 195 TEST (WebViewDestruction, CloseThenDestroyHostWindow)172 TEST_F(WebViewDestructionWithHostWindow, CloseThenDestroyHostWindow) 196 173 { 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()); 206 176 } 207 177 -
trunk/Tools/TestWebKitAPI/win/HostWindow.cpp
r95944 r95955 26 26 #include "HostWindow.h" 27 27 28 namespace WebKitAPITest{28 namespace TestWebKitAPI { 29 29 30 30 static LPCWSTR hostWindowClassName = L"HostWindow"; … … 38 38 { 39 39 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); 41 41 return m_window; 42 42 } … … 44 44 HostWindow::~HostWindow() 45 45 { 46 if (! IsWindow(m_window))46 if (!::IsWindow(m_window)) 47 47 return; 48 DestroyWindow(m_window);48 ::DestroyWindow(m_window); 49 49 } 50 50 … … 52 52 { 53 53 RECT rect = {0}; 54 if (! GetClientRect(m_window, &rect)) {54 if (!::GetClientRect(m_window, &rect)) { 55 55 RECT emptyRect = {0}; 56 56 return emptyRect; … … 74 74 wndClass.lpszClassName = hostWindowClassName; 75 75 76 RegisterClassExW(&wndClass);76 ::RegisterClassExW(&wndClass); 77 77 } 78 78 79 79 LRESULT HostWindow::wndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) 80 80 { 81 return DefWindowProcW(hWnd, uMsg, wParam, lParam);81 return ::DefWindowProcW(hWnd, uMsg, wParam, lParam); 82 82 } 83 83 -
trunk/Tools/TestWebKitAPI/win/HostWindow.h
r95944 r95955 29 29 #include <wtf/Noncopyable.h> 30 30 31 namespace WebKitAPITest{31 namespace TestWebKitAPI { 32 32 33 33 class HostWindow {
Note: See TracChangeset
for help on using the changeset viewer.