DOMWindowExtensionNoCache.cpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright (C) 2012 Apple Inc. All rights reserved.
  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 <wtf/Vector.h>
  30. namespace TestWebKitAPI {
  31. static bool finished;
  32. static const char* expectedMessages[] = {
  33. "GlobalObjectIsAvailableForFrame called",
  34. "GlobalObjectIsAvailableForFrame called",
  35. "GlobalObjectIsAvailableForFrame called",
  36. "GlobalObjectIsAvailableForFrame called",
  37. "Subframe finished loading",
  38. "Extension states:\nFirst page, main frame, standard world - Connected\nFirst page, main frame, non-standard world - Connected\nFirst page, subframe, standard world - Connected\nFirst page, subframe, non-standard world - Connected\nSecond page, main frame, standard world - Uncreated\nSecond page, main frame, non-standard world - Uncreated\nFirst page, main frame, standard world - Uncreated\nFirst page, main frame, non-standard world - Uncreated\nFirst page, subframe, standard world - Uncreated\nFirst page, subframe, non-standard world - Uncreated",
  39. "Main frame finished loading",
  40. "Extension states:\nFirst page, main frame, standard world - Connected\nFirst page, main frame, non-standard world - Connected\nFirst page, subframe, standard world - Connected\nFirst page, subframe, non-standard world - Connected\nSecond page, main frame, standard world - Uncreated\nSecond page, main frame, non-standard world - Uncreated\nFirst page, main frame, standard world - Uncreated\nFirst page, main frame, non-standard world - Uncreated\nFirst page, subframe, standard world - Uncreated\nFirst page, subframe, non-standard world - Uncreated",
  41. "WillDestroyDOMWindowExtensionToGlobalObject called",
  42. "WillDestroyDOMWindowExtensionToGlobalObject called",
  43. "WillDestroyDOMWindowExtensionToGlobalObject called",
  44. "WillDestroyDOMWindowExtensionToGlobalObject called",
  45. "GlobalObjectIsAvailableForFrame called",
  46. "GlobalObjectIsAvailableForFrame called",
  47. "Main frame finished loading",
  48. "Extension states:\nFirst page, main frame, standard world - Destroyed\nFirst page, main frame, non-standard world - Destroyed\nFirst page, subframe, standard world - Destroyed\nFirst page, subframe, non-standard world - Destroyed\nSecond page, main frame, standard world - Connected\nSecond page, main frame, non-standard world - Connected\nFirst page, main frame, standard world - Uncreated\nFirst page, main frame, non-standard world - Uncreated\nFirst page, subframe, standard world - Uncreated\nFirst page, subframe, non-standard world - Uncreated",
  49. "WillDestroyDOMWindowExtensionToGlobalObject called",
  50. "WillDestroyDOMWindowExtensionToGlobalObject called",
  51. "GlobalObjectIsAvailableForFrame called",
  52. "GlobalObjectIsAvailableForFrame called",
  53. "GlobalObjectIsAvailableForFrame called",
  54. "GlobalObjectIsAvailableForFrame called",
  55. "Subframe finished loading",
  56. "Extension states:\nFirst page, main frame, standard world - Destroyed\nFirst page, main frame, non-standard world - Destroyed\nFirst page, subframe, standard world - Destroyed\nFirst page, subframe, non-standard world - Destroyed\nSecond page, main frame, standard world - Destroyed\nSecond page, main frame, non-standard world - Destroyed\nFirst page, main frame, standard world - Connected\nFirst page, main frame, non-standard world - Connected\nFirst page, subframe, standard world - Connected\nFirst page, subframe, non-standard world - Connected",
  57. "Main frame finished loading",
  58. "Extension states:\nFirst page, main frame, standard world - Destroyed\nFirst page, main frame, non-standard world - Destroyed\nFirst page, subframe, standard world - Destroyed\nFirst page, subframe, non-standard world - Destroyed\nSecond page, main frame, standard world - Destroyed\nSecond page, main frame, non-standard world - Destroyed\nFirst page, main frame, standard world - Connected\nFirst page, main frame, non-standard world - Connected\nFirst page, subframe, standard world - Connected\nFirst page, subframe, non-standard world - Connected",
  59. "Extension states:\nFirst page, main frame, standard world - Destroyed\nFirst page, main frame, non-standard world - Destroyed\nFirst page, subframe, standard world - Destroyed\nFirst page, subframe, non-standard world - Destroyed\nSecond page, main frame, standard world - Destroyed\nSecond page, main frame, non-standard world - Destroyed\nFirst page, main frame, standard world - Removed\nFirst page, main frame, non-standard world - Removed\nFirst page, subframe, standard world - Removed\nFirst page, subframe, non-standard world - Removed",
  60. "TestComplete"
  61. };
  62. static Vector<WKRetainPtr<WKStringRef> > messages;
  63. static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, const void*)
  64. {
  65. ASSERT_NOT_NULL(messageBody);
  66. EXPECT_EQ(WKStringGetTypeID(), WKGetTypeID(messageBody));
  67. WKStringRef bodyString = (WKStringRef)messageBody;
  68. messages.append(bodyString);
  69. if (WKStringIsEqualToUTF8CString(messageName, "DidFinishLoadForMainFrame") || WKStringIsEqualToUTF8CString(messageName, "TestComplete"))
  70. finished = true;
  71. }
  72. TEST(WebKit2, DISABLED_DOMWindowExtensionNoCache)
  73. {
  74. WKRetainPtr<WKPageGroupRef> pageGroup(AdoptWK, WKPageGroupCreateWithIdentifier(WKStringCreateWithUTF8CString("DOMWindowExtensionNoCachePageGroup")));
  75. WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextForInjectedBundleTest("DOMWindowExtensionNoCache", pageGroup.get()));
  76. WKContextInjectedBundleClient injectedBundleClient;
  77. memset(&injectedBundleClient, 0, sizeof(injectedBundleClient));
  78. injectedBundleClient.version = kWKContextInjectedBundleClientCurrentVersion;
  79. injectedBundleClient.clientInfo = 0;
  80. injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle;
  81. WKContextSetInjectedBundleClient(context.get(), &injectedBundleClient);
  82. // Disable the page cache.
  83. WKContextSetCacheModel(context.get(), kWKCacheModelDocumentViewer);
  84. PlatformWebView webView(context.get(), pageGroup.get());
  85. // Make sure the extensions for each frame are installed in each world.
  86. WKRetainPtr<WKURLRef> url1(AdoptWK, Util::createURLForResource("simple-iframe", "html"));
  87. WKPageLoadURL(webView.page(), url1.get());
  88. Util::run(&finished);
  89. finished = false;
  90. // Make sure those first 4 extensions are destroyed, and 2 new ones are installed.
  91. WKRetainPtr<WKURLRef> url2(AdoptWK, Util::createURLForResource("simple", "html"));
  92. WKPageLoadURL(webView.page(), url2.get());
  93. Util::run(&finished);
  94. finished = false;
  95. // Make sure those 2 are destroyed, and the first 4 are recreated.
  96. WKPageGoBack(webView.page());
  97. Util::run(&finished);
  98. finished = false;
  99. WKPageClose(webView.page());
  100. Util::run(&finished);
  101. const size_t expectedSize = sizeof(expectedMessages) / sizeof(const char*);
  102. EXPECT_EQ(expectedSize, messages.size());
  103. if (messages.size() != expectedSize)
  104. return;
  105. for (size_t i = 0; i < messages.size(); ++i)
  106. EXPECT_WK_STREQ(expectedMessages[i], messages[i].get());
  107. }
  108. } // namespace TestWebKitAPI