WebKit Bugzilla
Attachment 357857 Details for
Bug 192951
: navigator.userAgent in service workers does not reflect customUserAgent set by client
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
API test
192951_api_test.patch (text/plain), 3.87 KB, created by
Chris Dumez
on 2018-12-20 13:25:04 PST
(
hide
)
Description:
API test
Filename:
MIME Type:
Creator:
Chris Dumez
Created:
2018-12-20 13:25:04 PST
Size:
3.87 KB
patch
obsolete
>diff --git a/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm b/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm >index 61ddbc3d63a..93812583920 100644 >--- a/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm >+++ b/Tools/TestWebKitAPI/Tests/WebKitCocoa/ServiceWorkerBasic.mm >@@ -37,6 +37,7 @@ > #import <WebKit/WebKit.h> > #import <WebKit/_WKExperimentalFeature.h> > #import <WebKit/_WKWebsiteDataStoreConfiguration.h> >+#import <WebKit/_WKWebsitePolicies.h> > #import <wtf/Deque.h> > #import <wtf/HashMap.h> > #import <wtf/RetainPtr.h> >@@ -62,7 +63,7 @@ @end > @implementation SWMessageHandler > - (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message > { >- EXPECT_TRUE([[message body] isEqualToString:@"Message from worker: ServiceWorker received: Hello from the web page"]); >+ EXPECT_WK_STREQ(@"Message from worker: ServiceWorker received: Hello from the web page", [message body]); > done = true; > } > @end >@@ -508,6 +509,76 @@ TEST(ServiceWorkers, Basic) > done = false; > } > >+@interface SWCustomUserAgentDelegate : NSObject <WKNavigationDelegate> { >+} >+@end >+ >+@implementation SWCustomUserAgentDelegate >+ >+- (void)_webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction userInfo:(id <NSSecureCoding>)userInfo decisionHandler:(void (^)(WKNavigationActionPolicy, _WKWebsitePolicies *))decisionHandler >+{ >+ _WKWebsitePolicies *websitePolicies = [[[_WKWebsitePolicies alloc] init] autorelease]; >+ if (navigationAction.targetFrame.mainFrame) >+ [websitePolicies setCustomUserAgent:@"Foo Custom UserAgent"]; >+ >+ decisionHandler(WKNavigationActionPolicyAllow, websitePolicies); >+} >+ >+@end >+ >+@interface SWUserAgentMessageHandler : NSObject <WKScriptMessageHandler> >+@end >+ >+@implementation SWUserAgentMessageHandler >+- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message >+{ >+ EXPECT_WK_STREQ(@"Message from worker: Foo Custom UserAgent", [message body]); >+ done = true; >+} >+@end >+ >+static const char* userAgentSWBytes = R"SWRESOURCE( >+ >+self.addEventListener("message", (event) => { >+ event.source.postMessage(navigator.userAgent); >+}); >+ >+)SWRESOURCE"; >+ >+TEST(ServiceWorkers, UserAgentOverride) >+{ >+ [WKWebsiteDataStore _allowWebsiteDataRecordsForAllOrigins]; >+ >+ // Start with a clean slate data store >+ [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:[NSDate distantPast] completionHandler:^() { >+ done = true; >+ }]; >+ TestWebKitAPI::Util::run(&done); >+ done = false; >+ >+ auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); >+ >+ auto messageHandler = adoptNS([[SWUserAgentMessageHandler alloc] init]); >+ [[configuration userContentController] addScriptMessageHandler:messageHandler.get() name:@"sw"]; >+ >+ auto handler = adoptNS([[SWSchemes alloc] init]); >+ handler->resources.set("sw://host/main.html", ResourceInfo { @"text/html", mainBytes }); >+ handler->resources.set("sw://host/sw.js", ResourceInfo { @"application/javascript", userAgentSWBytes }); >+ [configuration setURLSchemeHandler:handler.get() forURLScheme:@"SW"]; >+ >+ RetainPtr<WKWebView> webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); >+ [webView.get().configuration.processPool _registerURLSchemeServiceWorkersCanHandle:@"sw"]; >+ >+ auto delegate = adoptNS([[SWCustomUserAgentDelegate alloc] init]); >+ [webView setNavigationDelegate:delegate.get()]; >+ >+ NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"sw://host/main.html"]]; >+ [webView loadRequest:request]; >+ >+ TestWebKitAPI::Util::run(&done); >+ done = false; >+} >+ > TEST(ServiceWorkers, RestoreFromDisk) > { > ASSERT(mainRegisteringWorkerBytes);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 192951
:
357857
|
357971
|
357994
|
358012