Changeset 246360 in webkit
- Timestamp:
- Jun 12, 2019 10:18:24 AM (5 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r246357 r246360 1 2019-06-12 Brent Fulgham <bfulgham@apple.com> 2 3 Add mechanism and test case to check if ITP is active 4 https://bugs.webkit.org/show_bug.cgi?id=198694 5 <rdar://problem/51557704> 6 7 Reviewed by Youenn Fablet. 8 9 Add a new private SPI call on the WebsiteDataStore object that allows test code 10 to mark a domain as prevalent, and check the prevalance of a resource. This 11 is then used to build a test to confirm ITP is active and working. 12 13 * UIProcess/API/Cocoa/WKWebsiteDataStore.mm: 14 (-[WKWebsiteDataStore _setPrevalentDomain:completionHandler:]): 15 (-[WKWebsiteDataStore _getIsPrevalentDomain:completionHandler:]): 16 * UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h: 17 1 18 2019-06-12 Wenson Hsieh <wenson_hsieh@apple.com> 2 19 -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStore.mm
r245979 r246360 481 481 } 482 482 483 - (void)_setPrevalentDomain:(NSURL *)domain completionHandler:(void (^)(void))completionHandler 484 { 485 #if ENABLE(RESOURCE_LOAD_STATISTICS) 486 _websiteDataStore->websiteDataStore().setPrevalentResource(URL(domain), [completionHandler = makeBlockPtr(completionHandler)]() { 487 completionHandler(); 488 }); 489 #endif 490 completionHandler(); 491 } 492 493 - (void)_getIsPrevalentDomain:(NSURL *)domain completionHandler:(void (^)(BOOL))completionHandler 494 { 495 #if ENABLE(RESOURCE_LOAD_STATISTICS) 496 _websiteDataStore->websiteDataStore().isPrevalentResource(URL(domain), [completionHandler = makeBlockPtr(completionHandler)](bool enabled) { 497 completionHandler(enabled); 498 }); 499 #else 500 completionHandler(NO); 501 #endif 502 } 503 483 504 - (bool)_hasRegisteredServiceWorker 484 505 { -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebsiteDataStorePrivate.h
r245294 r246360 68 68 - (bool)_hasRegisteredServiceWorker WK_API_AVAILABLE(macos(10.14), ios(12.0)); 69 69 70 - (void)_setPrevalentDomain:(NSURL *)domain completionHandler:(void (^)(void))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)); 71 - (void)_getIsPrevalentDomain:(NSURL *)domain completionHandler:(void (^)(BOOL))completionHandler WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)); 72 70 73 @property (nullable, nonatomic, weak) id <_WKWebsiteDataStoreDelegate> _delegate WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)); 71 74 -
trunk/Tools/ChangeLog
r246353 r246360 1 22019-06-11 Brent Fulgham <bfulgham@apple.com> 2 3 Add mechanism and test case to check if ITP is active 4 https://bugs.webkit.org/show_bug.cgi?id=198694 5 <rdar://problem/51557704> 6 7 Reviewed by Youenn Fablet. 8 9 * TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadStatistics.mm: 10 (TEST): 11 1 12 2019-06-12 Michael Catanzaro <mcatanzaro@igalia.com> 2 13 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadStatistics.mm
r244390 r246360 27 27 28 28 #import "PlatformUtilities.h" 29 #import "TestNavigationDelegate.h" 29 30 #import <WebKit/WKFoundation.h> 30 31 #import <WebKit/WKProcessPoolPrivate.h> … … 205 206 TestWebKitAPI::Util::run(&finishedNavigation); 206 207 } 208 209 TEST(ResourceLoadStatistics, EnableDisableITP) 210 { 211 // Ensure the shared process pool exists so the data store operations we're about to do work with it. 212 WKProcessPool *sharedProcessPool = [WKProcessPool _sharedProcessPool]; 213 auto *dataStore = [WKWebsiteDataStore defaultDataStore]; 214 215 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 216 [configuration setProcessPool: sharedProcessPool]; 217 configuration.get().websiteDataStore = dataStore; 218 219 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600) configuration:configuration.get()]); 220 221 [webView loadHTMLString:@"WebKit Test" baseURL:[NSURL URLWithString:@"http://webkit.org"]]; 222 [webView _test_waitForDidFinishNavigation]; 223 224 // ITP should be off, no URLs are prevalent. 225 static bool doneFlag; 226 [dataStore _getIsPrevalentDomain:[NSURL URLWithString:@"http://evil.com"] completionHandler: ^(BOOL prevalent) { 227 EXPECT_FALSE(prevalent); 228 doneFlag = true; 229 }]; 230 231 TestWebKitAPI::Util::run(&doneFlag); 232 233 // Turn it on 234 [dataStore _setResourceLoadStatisticsEnabled:YES]; 235 236 [webView loadHTMLString:@"WebKit Test" baseURL:[NSURL URLWithString:@"http://webkit.org"]]; 237 [webView _test_waitForDidFinishNavigation]; 238 239 // ITP should be on, but nothing was registered as prevalent yet. 240 doneFlag = false; 241 [dataStore _getIsPrevalentDomain:[NSURL URLWithString:@"http://evil.com"] completionHandler: ^(BOOL prevalent) { 242 EXPECT_FALSE(prevalent); 243 doneFlag = true; 244 }]; 245 246 TestWebKitAPI::Util::run(&doneFlag); 247 248 // Teach ITP about a bad origin: 249 doneFlag = false; 250 [dataStore _setPrevalentDomain:[NSURL URLWithString:@"http://evil.com"] completionHandler: ^(void) { 251 doneFlag = true; 252 }]; 253 254 TestWebKitAPI::Util::run(&doneFlag); 255 256 [webView loadHTMLString:@"WebKit Test" baseURL:[NSURL URLWithString:@"http://webkit.org"]]; 257 [webView _test_waitForDidFinishNavigation]; 258 259 // ITP should be on, and know about 'evil.com' 260 doneFlag = false; 261 [dataStore _getIsPrevalentDomain:[NSURL URLWithString:@"http://evil.com"] completionHandler: ^(BOOL prevalent) { 262 EXPECT_TRUE(prevalent); 263 doneFlag = true; 264 }]; 265 266 TestWebKitAPI::Util::run(&doneFlag); 267 268 // Turn it off 269 [dataStore _setResourceLoadStatisticsEnabled:NO]; 270 271 [webView loadHTMLString:@"WebKit Test" baseURL:[NSURL URLWithString:@"http://webkit.org"]]; 272 [webView _test_waitForDidFinishNavigation]; 273 274 // ITP should be off, no URLs are prevalent. 275 doneFlag = false; 276 [dataStore _getIsPrevalentDomain:[NSURL URLWithString:@"http://evil.com"] completionHandler: ^(BOOL prevalent) { 277 EXPECT_FALSE(prevalent); 278 doneFlag = true; 279 }]; 280 281 TestWebKitAPI::Util::run(&doneFlag); 282 } 283
Note: See TracChangeset
for help on using the changeset viewer.