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
26#include "config.h"
27
28#if WK_HAVE_C_SPI
29
30#include "PlatformUtilities.h"
31#include "PlatformWebView.h"
32#include "Test.h"
33#include <wtf/Vector.h>
34
35namespace TestWebKitAPI {
36
37static bool finished;
38
39static const char* expectedMessages[] = {
40"GlobalObjectIsAvailableForFrame called",
41"GlobalObjectIsAvailableForFrame called",
42"GlobalObjectIsAvailableForFrame called",
43"GlobalObjectIsAvailableForFrame called",
44"Subframe finished loading",
45"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",
46"Main frame finished loading",
47"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",
48"WillDestroyDOMWindowExtensionToGlobalObject called",
49"WillDestroyDOMWindowExtensionToGlobalObject called",
50"WillDestroyDOMWindowExtensionToGlobalObject called",
51"WillDestroyDOMWindowExtensionToGlobalObject called",
52"GlobalObjectIsAvailableForFrame called",
53"GlobalObjectIsAvailableForFrame called",
54"Main frame finished loading",
55"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",
56"WillDestroyDOMWindowExtensionToGlobalObject called",
57"WillDestroyDOMWindowExtensionToGlobalObject called",
58"GlobalObjectIsAvailableForFrame called",
59"GlobalObjectIsAvailableForFrame called",
60"GlobalObjectIsAvailableForFrame called",
61"GlobalObjectIsAvailableForFrame called",
62"Subframe finished loading",
63"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",
64"Main frame finished loading",
65"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",
66"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",
67"TestComplete"
68};
69
70static Vector<WKRetainPtr<WKStringRef> > messages;
71
72static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef messageBody, const void*)
73{
74 ASSERT_NOT_NULL(messageBody);
75 EXPECT_EQ(WKStringGetTypeID(), WKGetTypeID(messageBody));
76
77 WKStringRef bodyString = (WKStringRef)messageBody;
78 messages.append(bodyString);
79
80 if (WKStringIsEqualToUTF8CString(messageName, "DidFinishLoadForMainFrame") || WKStringIsEqualToUTF8CString(messageName, "TestComplete"))
81 finished = true;
82}
83
84TEST(WebKit, DISABLED_DOMWindowExtensionNoCache)
85{
86 WKRetainPtr<WKPageGroupRef> pageGroup = adoptWK(WKPageGroupCreateWithIdentifier(WKStringCreateWithUTF8CString("DOMWindowExtensionNoCachePageGroup")));
87
88 WKRetainPtr<WKContextRef> context = adoptWK(Util::createContextForInjectedBundleTest("DOMWindowExtensionNoCache", pageGroup.get()));
89
90 WKContextInjectedBundleClientV1 injectedBundleClient;
91 memset(&injectedBundleClient, 0, sizeof(injectedBundleClient));
92
93 injectedBundleClient.base.version = 1;
94 injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle;
95
96 WKContextSetInjectedBundleClient(context.get(), &injectedBundleClient.base);
97
98 // Disable the page cache.
99 WKContextSetCacheModel(context.get(), kWKCacheModelDocumentViewer);
100
101 PlatformWebView webView(context.get(), pageGroup.get());
102
103 // Make sure the extensions for each frame are installed in each world.
104 WKRetainPtr<WKURLRef> url1 = adoptWK(Util::createURLForResource("simple-iframe", "html"));
105 WKPageLoadURL(webView.page(), url1.get());
106
107 Util::run(&finished);
108 finished = false;
109
110 // Make sure those first 4 extensions are destroyed, and 2 new ones are installed.
111 WKRetainPtr<WKURLRef> url2 = adoptWK(Util::createURLForResource("simple", "html"));
112 WKPageLoadURL(webView.page(), url2.get());
113
114 Util::run(&finished);
115 finished = false;
116
117 // Make sure those 2 are destroyed, and the first 4 are recreated.
118 WKPageGoBack(webView.page());
119
120 Util::run(&finished);
121 finished = false;
122
123 WKPageClose(webView.page());
124
125 Util::run(&finished);
126
127 const size_t expectedSize = sizeof(expectedMessages) / sizeof(const char*);
128 EXPECT_EQ(expectedSize, messages.size());
129
130 if (messages.size() != expectedSize)
131 return;
132
133 for (size_t i = 0; i < messages.size(); ++i)
134 EXPECT_WK_STREQ(expectedMessages[i], messages[i].get());
135}
136
137} // namespace TestWebKitAPI
138
139#endif
140