Changeset 239480 in webkit
- Timestamp:
- Dec 20, 2018 5:25:17 PM (5 years ago)
- Location:
- trunk/Tools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Tools/ChangeLog
r239477 r239480 1 2018-12-20 Chris Dumez <cdumez@apple.com> 2 3 Add API test coverage for customUserAgent client setting and service workers 4 https://bugs.webkit.org/show_bug.cgi?id=192952 5 6 Reviewed by Alex Christensen. 7 8 * TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm: 9 (-[SWMessageHandler userContentController:didReceiveScriptMessage:]): 10 (-[SWSchemes webView:startURLSchemeTask:]): 11 (-[SWCustomUserAgentDelegate _webView:decidePolicyForNavigationAction:userInfo:decisionHandler:]): 12 (-[SWUserAgentMessageHandler userContentController:didReceiveScriptMessage:]): 13 1 14 2018-12-20 Chris Dumez <cdumez@apple.com> 2 15 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm
r238157 r239480 38 38 #import <WebKit/_WKExperimentalFeature.h> 39 39 #import <WebKit/_WKWebsiteDataStoreConfiguration.h> 40 #import <WebKit/_WKWebsitePolicies.h> 40 41 #import <wtf/Deque.h> 41 42 #import <wtf/HashMap.h> … … 63 64 - (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message 64 65 { 65 EXPECT_ TRUE([[message body] isEqualToString:@"Message from worker: ServiceWorker received: Hello from the web page"]);66 EXPECT_WK_STREQ(@"Message from worker: ServiceWorker received: Hello from the web page", [message body]); 66 67 done = true; 67 68 } … … 118 119 @public 119 120 HashMap<String, ResourceInfo> resources; 121 NSString *expectedUserAgent; 120 122 } 121 123 … … 134 136 - (void)webView:(WKWebView *)webView startURLSchemeTask:(id <WKURLSchemeTask>)task 135 137 { 138 if (expectedUserAgent) 139 EXPECT_WK_STREQ(expectedUserAgent, [[task.request valueForHTTPHeaderField:@"User-Agent"] UTF8String]); 140 136 141 auto entry = resources.find([task.request.URL absoluteString]); 137 142 if (entry == resources.end()) { … … 509 514 } 510 515 516 @interface SWCustomUserAgentDelegate : NSObject <WKNavigationDelegate> { 517 } 518 @end 519 520 @implementation SWCustomUserAgentDelegate 521 522 - (void)_webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction userInfo:(id <NSSecureCoding>)userInfo decisionHandler:(void (^)(WKNavigationActionPolicy, _WKWebsitePolicies *))decisionHandler 523 { 524 _WKWebsitePolicies *websitePolicies = [[[_WKWebsitePolicies alloc] init] autorelease]; 525 if (navigationAction.targetFrame.mainFrame) 526 [websitePolicies setCustomUserAgent:@"Foo Custom UserAgent"]; 527 528 decisionHandler(WKNavigationActionPolicyAllow, websitePolicies); 529 } 530 531 @end 532 533 @interface SWUserAgentMessageHandler : NSObject <WKScriptMessageHandler> 534 @end 535 536 @implementation SWUserAgentMessageHandler 537 - (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message 538 { 539 // FIXME: navigator.userAgent currently does not reflect the custom user agent set by the client (https://bugs.webkit.org/show_bug.cgi?id=192951). 540 // EXPECT_WK_STREQ(@"Message from worker: Foo Custom UserAgent", [message body]); 541 done = true; 542 } 543 @end 544 545 static const char* userAgentSWBytes = R"SWRESOURCE( 546 547 self.addEventListener("message", (event) => { 548 event.source.postMessage(navigator.userAgent); 549 }); 550 551 )SWRESOURCE"; 552 553 TEST(ServiceWorkers, UserAgentOverride) 554 { 555 [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]; 556 557 // Start with a clean slate data store 558 [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() { 559 done = true; 560 }]; 561 TestWebKitAPI::Util::run(&done); 562 done = false; 563 564 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 565 566 auto messageHandler = adoptNS([[SWUserAgentMessageHandler alloc] init]); 567 [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; 568 569 auto handler = adoptNS([[SWSchemes alloc] init]); 570 handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainBytes }); 571 handler->resources.set("sw://host/sw.js", ResourceInfo { @"application/javascript", userAgentSWBytes }); 572 handler->expectedUserAgent = @"Foo Custom UserAgent"; 573 [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"]; 574 575 RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 576 [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"]; 577 578 auto delegate = adoptNS([[SWCustomUserAgentDelegate alloc] init]); 579 [webView setNavigationDelegate:delegate.get()]; 580 581 NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]; 582 [webView loadRequest:request]; 583 584 TestWebKitAPI::Util::run(&done); 585 done = false; 586 } 587 511 588 TEST(ServiceWorkers, RestoreFromDisk) 512 589 {
Note: See TracChangeset
for help on using the changeset viewer.