| OLD | NEW |
| (Empty) |
| 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 #include "PlatformUtilities.h" | |
| 28 #include "PlatformWebView.h" | |
| 29 #include <wtf/RetainPtr.h> | |
| 30 | |
| 31 #import <WebKit/DOM.h> | |
| 32 #import <WebKit/WebViewPrivate.h> | |
| 33 | |
| 34 @interface SimplifyMarkupTest : NSObject { | |
| 35 } | |
| 36 @end | |
| 37 | |
| 38 static bool didFinishLoad; | |
| 39 | |
| 40 @implementation SimplifyMarkupTest | |
| 41 | |
| 42 - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame | |
| 43 { | |
| 44 didFinishLoad = true; | |
| 45 } | |
| 46 @end | |
| 47 | |
| 48 namespace TestWebKitAPI { | |
| 49 | |
| 50 TEST(WebKit1, SimplifyMarkupTest) | |
| 51 { | |
| 52 RetainPtr<WebView> webView1(AdoptNS, [[WebView alloc] initWithFrame:NSMakeRe
ct(0, 0, 120, 200) frameName:nil groupName:nil]); | |
| 53 RetainPtr<WebView> webView2(AdoptNS, [[WebView alloc] initWithFrame:NSMakeRe
ct(0, 0, 120, 200) frameName:nil groupName:nil]); | |
| 54 RetainPtr<SimplifyMarkupTest> testController(AdoptNS, [SimplifyMarkupTest ne
w]); | |
| 55 | |
| 56 webView1.get().frameLoadDelegate = testController.get(); | |
| 57 [[webView1.get() mainFrame] loadRequest:[NSURLRequest requestWithURL:[[NSBun
dle mainBundle] URLForResource:@"verboseMarkup" withExtension:@"html" subdirecto
ry:@"TestWebKitAPI.resources"]]]; | |
| 58 | |
| 59 Util::run(&didFinishLoad); | |
| 60 didFinishLoad = false; | |
| 61 | |
| 62 webView2.get().frameLoadDelegate = testController.get(); | |
| 63 [[webView2.get() mainFrame] loadRequest:[NSURLRequest requestWithURL:[[NSBun
dle mainBundle] URLForResource:@"verboseMarkup" withExtension:@"html" subdirecto
ry:@"TestWebKitAPI.resources"]]]; | |
| 64 | |
| 65 Util::run(&didFinishLoad); | |
| 66 didFinishLoad = false; | |
| 67 | |
| 68 DOMDocument *document1 = webView1.get().mainFrameDocument; | |
| 69 NSString* markupBefore = [[document1 body] innerHTML]; | |
| 70 DOMDocument *document2 = webView2.get().mainFrameDocument; | |
| 71 | |
| 72 // If start is after end, nothing is done | |
| 73 DOMNode *start = [document1 getElementById:@"test2"]; | |
| 74 DOMNode *end = [document1 getElementById:@"test1"]; | |
| 75 | |
| 76 [webView1.get() _simplifyMarkup:[document1 body] endNode:end]; | |
| 77 NSString* markupAfter = [[document1 body] innerHTML]; | |
| 78 | |
| 79 EXPECT_WK_STREQ(markupBefore, markupAfter); | |
| 80 EXPECT_EQ([markupBefore length], [markupAfter length]); | |
| 81 | |
| 82 // If the two nodes are not in the same webView, nothing is done. | |
| 83 start = [document1 getElementById:@"test1"]; | |
| 84 end = [document2 getElementById:@"test2"]; | |
| 85 [webView1.get() _simplifyMarkup:start endNode:end]; | |
| 86 markupAfter = [[document1 body] innerHTML]; | |
| 87 | |
| 88 EXPECT_WK_STREQ(markupBefore, markupAfter); | |
| 89 EXPECT_EQ([markupBefore length], [markupAfter length]); | |
| 90 | |
| 91 // If the two nodes are not in the same document, nothing is done. | |
| 92 DOMHTMLFrameElement* frame = (DOMHTMLFrameElement *)[document1 getElementByI
d:@"test3"]; | |
| 93 end = [[frame contentDocument] firstChild]; | |
| 94 | |
| 95 [webView1.get() _simplifyMarkup:start endNode:end]; | |
| 96 markupAfter = [[document1 body] innerHTML]; | |
| 97 | |
| 98 EXPECT_WK_STREQ(markupBefore, markupAfter); | |
| 99 EXPECT_EQ([markupBefore length], [markupAfter length]); | |
| 100 | |
| 101 // If the nodes are in the same webView, same document and in the right orde
r, | |
| 102 // we should have a simplified markup. | |
| 103 [webView1.get() _simplifyMarkup:[document1 body] endNode:nil]; | |
| 104 markupAfter = [[document1 body] innerHTML]; | |
| 105 // We only verify that the markup has changed and that it is less verbose | |
| 106 // then the original version. | |
| 107 // The accuracy of the operation is tested by the DRT tests already. | |
| 108 EXPECT_GT([markupBefore length], [markupAfter length]); | |
| 109 } | |
| 110 | |
| 111 } // namespace TestWebKitAPI | |
| OLD | NEW |