ResizeWindowAfterCrash.cpp 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (C) 2013 Adenilson Cavalcanti <cavalcantii@gmail.com>
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
  14. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  15. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
  17. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  18. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  19. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  21. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  23. * THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include "config.h"
  26. #include "PlatformUtilities.h"
  27. #include "PlatformWebView.h"
  28. #include "Test.h"
  29. #include <WebKit2/WKRetainPtr.h>
  30. namespace TestWebKitAPI {
  31. struct TestStatesData {
  32. TestStatesData(WKContextRef context)
  33. : webView(context)
  34. , firstLoad(false)
  35. , resizeAfterCrash(false)
  36. {
  37. }
  38. PlatformWebView webView;
  39. bool firstLoad;
  40. bool resizeAfterCrash;
  41. };
  42. static void didFinishLoad(WKPageRef page, WKFrameRef frame, WKTypeRef userData, const void* clientInfo)
  43. {
  44. TestStatesData* states = const_cast<TestStatesData*>(static_cast<const TestStatesData*>(clientInfo));
  45. if (!states->firstLoad) {
  46. // Loading a blank page worked, next we will kill WebProcess.
  47. states->firstLoad = true;
  48. return;
  49. }
  50. EXPECT_FALSE(states->resizeAfterCrash);
  51. states->resizeAfterCrash = true;
  52. }
  53. static void didCrash(WKPageRef page, const void* clientInfo)
  54. {
  55. TestStatesData* states = const_cast<TestStatesData*>(static_cast<const TestStatesData*>(clientInfo));
  56. EXPECT_TRUE(states->firstLoad);
  57. // Resize should work after WebProcess was terminated, unless
  58. // the port's View is accessing nulled WebProcess related data,
  59. // which would cause a crash.
  60. states->webView.resizeTo(100, 200);
  61. states->webView.resizeTo(300, 400);
  62. WKPageReload(page);
  63. }
  64. TEST(WebKit2, ResizeWindowAfterCrash)
  65. {
  66. WKRetainPtr<WKContextRef> context(AdoptWK, WKContextCreate());
  67. TestStatesData states(context.get());
  68. WKPageLoaderClient loaderClient;
  69. memset(&loaderClient, 0, sizeof(loaderClient));
  70. loaderClient.clientInfo = &states;
  71. loaderClient.didFinishLoadForFrame = didFinishLoad;
  72. loaderClient.processDidCrash = didCrash;
  73. WKPageSetPageLoaderClient(states.webView.page(), &loaderClient);
  74. WKRetainPtr<WKURLRef> url = adoptWK(WKURLCreateWithUTF8CString("about:blank"));
  75. // Load a blank page and next kills WebProcess.
  76. WKPageLoadURL(states.webView.page(), url.get());
  77. Util::run(&states.firstLoad);
  78. WKPageTerminate(states.webView.page());
  79. // Let's try load a page and see what happens.
  80. WKPageLoadURL(states.webView.page(), url.get());
  81. Util::run(&states.resizeAfterCrash);
  82. }
  83. } // namespace TestWebKitAPI