DOMWindowExtensionBasic.cpp 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 <WebKit2/WKRetainPtr.h>
  30. #include <wtf/Vector.h>
  31. namespace TestWebKitAPI {
  32. static bool finished;
  33. static const char* expectedMessages[] = {
  34. "GlobalObjectIsAvailableForFrame called",
  35. "GlobalObjectIsAvailableForFrame called",
  36. "GlobalObjectIsAvailableForFrame called",
  37. "GlobalObjectIsAvailableForFrame called",
  38. "Subframe finished loading",
  39. "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",
  40. "Main frame finished loading",
  41. "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",
  42. "WillDisconnectDOMWindowExtensionFromGlobalObject called",
  43. "WillDisconnectDOMWindowExtensionFromGlobalObject called",
  44. "WillDisconnectDOMWindowExtensionFromGlobalObject called",
  45. "WillDisconnectDOMWindowExtensionFromGlobalObject called",
  46. "GlobalObjectIsAvailableForFrame called",
  47. "GlobalObjectIsAvailableForFrame called",
  48. "Main frame finished loading",
  49. "Extension states:\nFirst page, main frame, standard world - Disconnected\nFirst page, main frame, non-standard world - Disconnected\nFirst page, subframe, standard world - Disconnected\nFirst page, subframe, non-standard world - Disconnected\nSecond page, main frame, standard world - Connected\nSecond page, main frame, non-standard world - Connected",
  50. "WillDisconnectDOMWindowExtensionFromGlobalObject called",
  51. "WillDisconnectDOMWindowExtensionFromGlobalObject called",
  52. "DidReconnectDOMWindowExtensionToGlobalObject called",
  53. "DidReconnectDOMWindowExtensionToGlobalObject called",
  54. "DidReconnectDOMWindowExtensionToGlobalObject called",
  55. "DidReconnectDOMWindowExtensionToGlobalObject called",
  56. "Main frame finished loading",
  57. "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 - Disconnected\nSecond page, main frame, non-standard world - Disconnected",
  58. "Extension states:\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\nSecond page, main frame, standard world - Removed\nSecond page, main frame, non-standard world - Removed",
  59. "TestComplete"
  60. };
  61. static Vector<WKRetainPtr<WKStringRef> > messages;
  62. static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, const void*)
  63. {
  64. ASSERT_NOT_NULL(messageBody);
  65. EXPECT_EQ(WKStringGetTypeID(), WKGetTypeID(messageBody));
  66. WKStringRef bodyString = (WKStringRef)messageBody;
  67. messages.append(bodyString);
  68. if (WKStringIsEqualToUTF8CString(messageName, "DidFinishLoadForMainFrame") || WKStringIsEqualToUTF8CString(messageName, "TestComplete"))
  69. finished = true;
  70. }
  71. TEST(WebKit2, DISABLED_DOMWindowExtensionBasic)
  72. {
  73. WKRetainPtr<WKPageGroupRef> pageGroup(AdoptWK, WKPageGroupCreateWithIdentifier(WKStringCreateWithUTF8CString("DOMWindowExtensionBasicPageGroup")));
  74. WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextForInjectedBundleTest("DOMWindowExtensionBasic", pageGroup.get()));
  75. WKContextInjectedBundleClient injectedBundleClient;
  76. memset(&injectedBundleClient, 0, sizeof(injectedBundleClient));
  77. injectedBundleClient.version = 0;
  78. injectedBundleClient.clientInfo = 0;
  79. injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle;
  80. WKContextSetInjectedBundleClient(context.get(), &injectedBundleClient);
  81. // The default cache model has a capacity of 0, so it is necessary to switch to a cache
  82. // model that actually allows for a page cache.
  83. WKContextSetCacheModel(context.get(), kWKCacheModelDocumentBrowser);
  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 disconnected, 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 two are disconnected, and the first four are reconnected.
  96. WKPageGoBack(webView.page());
  97. Util::run(&finished);
  98. finished = false;
  99. // Make sure the 2 disconnected extensions in the page cache and the 4 active extensions are all removed.
  100. WKPageClose(webView.page());
  101. Util::run(&finished);
  102. const size_t expectedSize = sizeof(expectedMessages) / sizeof(const char*);
  103. EXPECT_EQ(expectedSize, messages.size());
  104. if (messages.size() != expectedSize)
  105. return;
  106. for (size_t i = 0; i < messages.size(); ++i)
  107. EXPECT_WK_STREQ(expectedMessages[i], messages[i].get());
  108. }
  109. } // namespace TestWebKitAPI