OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (C) 2011, 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 #import "config.h" | |
27 #import "PlatformUtilities.h" | |
28 #import <wtf/RetainPtr.h> | |
29 | |
30 @interface InspectorBarController : NSObject { | |
31 } | |
32 @end | |
33 | |
34 static bool didFinishLoad; | |
35 | |
36 @implementation InspectorBarController | |
37 | |
38 - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame | |
39 { | |
40 didFinishLoad = true; | |
41 } | |
42 | |
43 - (NSDictionary *)convertAttributes:(NSDictionary *)dictionary | |
44 { | |
45 NSMutableDictionary *newDictionary = [dictionary mutableCopy]; | |
46 [newDictionary removeObjectForKey:NSForegroundColorAttributeName]; | |
47 return [newDictionary autorelease]; | |
48 } | |
49 @end | |
50 | |
51 namespace TestWebKitAPI { | |
52 | |
53 TEST(WebKit1, InspectorBarTest) | |
54 { | |
55 RetainPtr<WebView> webView(AdoptNS, [[WebView alloc] initWithFrame:NSMakeRec
t(0, 0, 120, 200) frameName:nil groupName:nil]); | |
56 RetainPtr<InspectorBarController> inspectorBarController(AdoptNS, [Inspector
BarController new]); | |
57 | |
58 webView.get().frameLoadDelegate = inspectorBarController.get(); | |
59 [webView.get().mainFrame loadHTMLString:@"<body contenteditable style=\"colo
r: green\"><u>Lorem ipsum sit amet</u></body>" baseURL:[NSURL URLWithString:@"ab
out:blank"]]; | |
60 | |
61 Util::run(&didFinishLoad); | |
62 | |
63 DOMDocument *document = webView.get().mainFrameDocument; | |
64 [[document body] focus]; | |
65 | |
66 EXPECT_TRUE([webView.get() respondsToSelector:@selector(typingAttributes)]); | |
67 NSDictionary *attributes = [(id)webView.get() typingAttributes]; | |
68 [(id)[[[webView.get() mainFrame] frameView] documentView] doCommandBySelecto
r:@selector(bold:)]; | |
69 EXPECT_FALSE([attributes isEqual:[(id)webView.get() typingAttributes]]); | |
70 | |
71 [webView.get() selectAll:nil]; | |
72 NSAttributedString *attrString = [(NSView <NSTextInput> *)[[[webView.get() m
ainFrame] frameView] documentView] attributedSubstringFromRange:NSMakeRange(0, 5
)]; | |
73 attributes = [attrString attributesAtIndex:0 effectiveRange:0]; | |
74 | |
75 EXPECT_TRUE([[attributes objectForKey:NSUnderlineStyleAttributeName] intValu
e] != 0); | |
76 | |
77 [webView.get() changeAttributes:inspectorBarController.get()]; | |
78 | |
79 DOMNode *currentNode = [document body]; | |
80 while ([[currentNode firstChild] nodeType] != DOM_TEXT_NODE) | |
81 currentNode = [currentNode firstChild]; | |
82 | |
83 DOMCSSStyleDeclaration *style = [document getComputedStyle:(DOMElement *)cur
rentNode pseudoElement:nil]; | |
84 EXPECT_WK_STREQ(@"rgb(0, 0, 0)", [style color]); | |
85 } | |
86 | |
87 } // namespace TestWebKitAPI | |
OLD | NEW |