Changeset 254397 in webkit
- Timestamp:
- Jan 11, 2020 6:57:57 AM (4 years ago)
- Location:
- trunk
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebKit/ChangeLog
r254392 r254397 1 2020-01-11 Kate Cheney <katherine_cheney@apple.com> 2 3 Add correct grandfathering functionality to the ITP database backend 4 https://bugs.webkit.org/show_bug.cgi?id=205844 5 <rdar://problem/58360450> 6 7 Reviewed by John Wilander. 8 9 This patch adds functionality for grandfathering statistics upon 10 creation of a new ITP database file. The memory store relies on 11 the presence of the ITP plist to indicate whether the data should 12 be grandfathered. Since the database does not use a plist, this patch 13 adds a boolean variable to track whether the database file previously 14 existed or not to indicate when to grandfather. 15 16 * NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp: 17 (WebKit::ResourceLoadStatisticsDatabaseStore::openITPDatabase): 18 * NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h: 19 The boolean variable m_isNewResourceLoadStatisticDatabaseFile is set 20 to true if the database file did not previously exist, indicating ITP 21 is being used for the first time and data should be grandfathered. 22 23 * NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp: 24 (WebKit::WebResourceLoadStatisticsStore::populateMemoryStoreFromDisk): 25 This is where the grandfathering happens. The call to logTestingEvent 26 is for API testing purposes only. 27 28 (WebKit::WebResourceLoadStatisticsStore::scheduleClearInMemoryAndPersistent): 29 If a scheduleClearInMemoryAndPersistent is called, the plist is 30 deleted, and data will be grandfathered upon recreation. To mimic 31 this, the ITP database store is cleared and becomes "new" again, so 32 the boolean is set to true. 33 34 * UIProcess/API/C/WKPreferences.cpp: 35 (WKPreferencesSetIsITPDatabaseEnabled): 36 (WKPreferencesGetIsITPDatabaseEnabled): 37 * UIProcess/API/C/WKPreferencesRef.h: 38 * UIProcess/API/Cocoa/WKPreferences.mm: 39 (-[WKPreferences _isITPDatabaseEnabled]): 40 * UIProcess/API/Cocoa/WKPreferencesPrivate.h: 41 In order to properly run the grandfathering 42 API tests, the 'isITPDatabaseEnabled' boolean needs to be exposed from 43 Web Preferences. 44 45 * UIProcess/Cocoa/WebProcessPoolCocoa.mm: 46 The API tests rely on the ITP database flag being set correctly. Since 47 being on-by-default, the ITP database flag does not show up in the 48 user defaults menu if enabled. This patch fixes this by first checking 49 to see if the value is in the defaults menu, otherwise returning the 50 default preferences value. This ensures the preferences value matches 51 the actual store being initialized. 52 1 53 2020-01-10 Eric Carlson <eric.carlson@apple.com> 2 54 -
trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.cpp
r254296 r254397 310 310 void ResourceLoadStatisticsDatabaseStore::openITPDatabase() 311 311 { 312 if (!FileSystem::fileExists(m_storageDirectoryPath)) 313 m_isNewResourceLoadStatisticsDatabaseFile = true; 314 else 315 m_isNewResourceLoadStatisticsDatabaseFile = false; 316 312 317 if (!m_database.open(m_storageDirectoryPath)) { 313 318 RELEASE_LOG_ERROR(Network, "%p - ResourceLoadStatisticsDatabaseStore::open failed, error message: %{public}s, database path: %{public}s", this, m_database.lastErrorMsg(), m_storageDirectoryPath.utf8().data()); -
trunk/Source/WebKit/NetworkProcess/Classifier/ResourceLoadStatisticsDatabaseStore.h
r254296 r254397 136 136 void resourceToString(StringBuilder&, const String&) const; 137 137 Seconds getMostRecentlyUpdatedTimestamp(const RegistrableDomain&, const TopFrameDomain&) const; 138 bool isNewResourceLoadStatisticsDatabaseFile() const { return m_isNewResourceLoadStatisticsDatabaseFile; } 139 void setIsNewResourceLoadStatisticsDatabaseFile(bool isNewResourceLoadStatisticsDatabaseFile) { m_isNewResourceLoadStatisticsDatabaseFile = isNewResourceLoadStatisticsDatabaseFile; } 138 140 139 141 private: … … 257 259 mutable WebCore::SQLiteStatement m_getMostRecentlyUpdatedTimestampStatement; 258 260 PAL::SessionID m_sessionID; 261 bool m_isNewResourceLoadStatisticsDatabaseFile { false }; 259 262 }; 260 263 -
trunk/Source/WebKit/NetworkProcess/Classifier/WebResourceLoadStatisticsStore.cpp
r254296 r254397 231 231 postTaskReply(WTFMove(completionHandler)); 232 232 }); 233 else 233 else if (is<ResourceLoadStatisticsDatabaseStore>(*m_statisticsStore)) { 234 auto& databaseStore = downcast<ResourceLoadStatisticsDatabaseStore>(*m_statisticsStore); 235 if (databaseStore.isNewResourceLoadStatisticsDatabaseFile()) { 236 m_statisticsStore->grandfatherExistingWebsiteData([protectedThis = WTFMove(protectedThis), completionHandler = WTFMove(completionHandler)]() mutable { 237 postTaskReply(WTFMove(completionHandler)); 238 }); 239 databaseStore.setIsNewResourceLoadStatisticsDatabaseFile(false); 240 } else 241 postTaskReply([this, protectedThis = WTFMove(protectedThis), completionHandler = WTFMove(completionHandler)]() mutable { 242 logTestingEvent("PopulatedWithoutGrandfathering"_s); 243 completionHandler(); 244 }); 245 } else 234 246 postTaskReply(WTFMove(completionHandler)); 235 247 }); … … 925 937 m_statisticsStore->clear([this, protectedThis = protectedThis.copyRef(), shouldGrandfather, callbackAggregator = callbackAggregator.copyRef()] () mutable { 926 938 if (shouldGrandfather == ShouldGrandfatherStatistics::Yes) { 927 if (m_statisticsStore) 939 if (m_statisticsStore) { 928 940 m_statisticsStore->grandfatherExistingWebsiteData([callbackAggregator = WTFMove(callbackAggregator)]() mutable { }); 929 else 941 if (is<ResourceLoadStatisticsDatabaseStore>(*m_statisticsStore)) 942 downcast<ResourceLoadStatisticsDatabaseStore>(*m_statisticsStore).setIsNewResourceLoadStatisticsDatabaseFile(true); 943 } else 930 944 RELEASE_LOG(ResourceLoadStatistics, "WebResourceLoadStatisticsStore::scheduleClearInMemoryAndPersistent After being cleared, m_statisticsStore is null when trying to grandfather data."); 931 945 } -
trunk/Source/WebKit/UIProcess/API/C/WKPreferences.cpp
r254130 r254397 119 119 } 120 120 121 void WKPreferencesSetIsITPDatabaseEnabled(WKPreferencesRef preferencesRef, bool isITPDatabaseEnabled) 122 { 123 toImpl(preferencesRef)->setIsITPDatabaseEnabled(isITPDatabaseEnabled); 124 } 125 126 bool WKPreferencesGetIsITPDatabaseEnabled(WKPreferencesRef preferencesRef) 127 { 128 return toImpl(preferencesRef)->isITPDatabaseEnabled(); 129 } 130 121 131 void WKPreferencesSetOfflineWebApplicationCacheEnabled(WKPreferencesRef preferencesRef, bool offlineWebApplicationCacheEnabled) 122 132 { -
trunk/Source/WebKit/UIProcess/API/C/WKPreferencesRef.h
r254130 r254397 79 79 80 80 // Defaults to true. 81 WK_EXPORT void WKPreferencesSetIsITPDatabaseEnabled(WKPreferencesRef preferences, bool isITPDatabaseEnabled); 82 WK_EXPORT bool WKPreferencesGetIsITPDatabaseEnabled(WKPreferencesRef preferences); 83 84 // Defaults to true. 81 85 WK_EXPORT void WKPreferencesSetOfflineWebApplicationCacheEnabled(WKPreferencesRef preferences, bool offlineWebApplicationCacheEnabled); 82 86 WK_EXPORT bool WKPreferencesGetOfflineWebApplicationCacheEnabled(WKPreferencesRef preferences); -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKPreferences.mm
r251859 r254397 903 903 } 904 904 905 - (BOOL)_isITPDatabaseEnabled 906 { 907 return _preferences->isITPDatabaseEnabled(); 908 } 909 905 910 #if PLATFORM(MAC) 906 911 - (void)_setJavaEnabledForLocalFiles:(BOOL)enabled -
trunk/Source/WebKit/UIProcess/API/Cocoa/WKPreferencesPrivate.h
r252174 r254397 162 162 @property (nonatomic, setter=_setAcceleratedCompositingEnabled:) BOOL _acceleratedCompositingEnabled WK_API_AVAILABLE(macos(10.13.4), ios(WK_IOS_TBA)); 163 163 @property (nonatomic, setter=_setRequestAnimationFrameEnabled:) BOOL _requestAnimationFrameEnabled WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)); 164 @property (nonatomic, readonly) BOOL _isITPDatabaseEnabled WK_API_AVAILABLE(macos(WK_MAC_TBA), ios(WK_IOS_TBA)); 164 165 165 166 #if !TARGET_OS_IPHONE -
trunk/Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm
r254373 r254397 402 402 parameters.storageAccessAPIEnabled = storageAccessAPIEnabled(); 403 403 404 parameters.shouldEnableITPDatabase = [defaults boolForKey:[NSString stringWithFormat:@"InternalDebug%@", WebPreferencesKey::isITPDatabaseEnabledKey().createCFString().get()]]; 404 NSNumber *databaseEnabledValue = [defaults objectForKey:[NSString stringWithFormat:@"InternalDebug%@", WebPreferencesKey::isITPDatabaseEnabledKey().createCFString().get()]]; 405 if (databaseEnabledValue) 406 parameters.shouldEnableITPDatabase = databaseEnabledValue.boolValue; 407 else 408 parameters.shouldEnableITPDatabase = m_defaultPageGroup->preferences().isITPDatabaseEnabled(); 405 409 406 410 parameters.enableAdClickAttributionDebugMode = [defaults boolForKey:[NSString stringWithFormat:@"Experimental%@", WebPreferencesKey::adClickAttributionDebugModeEnabledKey().createCFString().get()]]; -
trunk/Tools/ChangeLog
r254389 r254397 1 2020-01-11 Kate Cheney <katherine_cheney@apple.com> 2 3 Add correct grandfathering functionality to the ITP database backend 4 https://bugs.webkit.org/show_bug.cgi?id=205844 5 <rdar://problem/58360450> 6 7 Reviewed by John Wilander. 8 9 In order to test both the ITP database and memory stores, this patch 10 had to restructure the grandfathering API tests. 11 12 If the test is for the database backend (ends in *Database), it will 13 check if the default store matches. If so, it continues on with the 14 normal test. If not, it has to use an API call to reconstruct the 15 new store and ensure the grandfathering still happens. Vice versa for 16 the memory store tests. 17 18 * TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadStatistics.mm: 19 (isITPDatabaseEnabled): 20 (TEST): 21 1 22 2020-01-10 Myles C. Maxfield <mmaxfield@apple.com> 2 23 -
trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/ResourceLoadStatistics.mm
r253863 r254397 70 70 @end 71 71 72 bool isITPDatabaseEnabled() 73 { 74 NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 75 auto configuration = adoptNS([[WKWebViewConfiguration alloc] init]); 76 auto defaultDatabaseEnabled = [configuration preferences]._isITPDatabaseEnabled; 77 78 NSNumber *databaseEnabledValue = [defaults objectForKey:@"InternalDebugIsITPDatabaseEnabled"]; 79 if (databaseEnabledValue) 80 return databaseEnabledValue.boolValue; 81 82 return defaultDatabaseEnabled; 83 } 84 72 85 TEST(ResourceLoadStatistics, GrandfatherCallback) 73 86 { … … 84 97 85 98 [dataStore _setResourceLoadStatisticsTestingCallback:^(WKWebsiteDataStore *, NSString *message) { 86 ASSERT_TRUE([message isEqualToString:@"Grandfathered"]); 99 // Only if the database store is not default-enabled do we need to check that this first message is correct. 100 if (!isITPDatabaseEnabled()) 101 ASSERT_TRUE([message isEqualToString:@"Grandfathered"]); 87 102 grandfatheredFlag = true; 88 103 }]; … … 92 107 [dataStore _setResourceLoadStatisticsEnabled:YES]; 93 108 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]]; 109 110 if (isITPDatabaseEnabled()) { 111 TestWebKitAPI::Util::run(&grandfatheredFlag); 112 113 // Since the database store is enabled, we need to disable it to test this functionality with the plist. 114 // We already have a NetworkProcess up and running with ITP enabled. We now make another call initializing 115 // the memory store and testing grandfathering. 116 grandfatheredFlag = false; 117 [dataStore _setResourceLoadStatisticsTestingCallback:^(WKWebsiteDataStore *, NSString *message) { 118 ASSERT_TRUE([message isEqualToString:@"Grandfathered"]); 119 grandfatheredFlag = true; 120 }]; 121 122 [dataStore _setUseITPDatabase:false completionHandler: ^(void) { 123 doneFlag = true; 124 }]; 125 126 TestWebKitAPI::Util::run(&doneFlag); 127 } 94 128 95 129 TestWebKitAPI::Util::run(&grandfatheredFlag); … … 104 138 105 139 grandfatheredFlag = false; 140 doneFlag = false; 106 141 [dataStore removeDataOfTypes:[WKWebsiteDataStore _allWebsiteDataTypesIncludingPrivate] modifiedSince:[NSDate distantPast] completionHandler:^ { 107 142 doneFlag = true; … … 135 170 } 136 171 172 TEST(ResourceLoadStatistics, GrandfatherCallbackDatabase) 173 { 174 auto *dataStore = [WKWebsiteDataStore defaultDataStore]; 175 176 NSURL *statisticsDirectoryURL = [NSURL fileURLWithPath:[@"~/Library/WebKit/TestWebKitAPI/WebsiteData/ResourceLoadStatistics" stringByExpandingTildeInPath] isDirectory:YES]; 177 NSURL *fileURL = [statisticsDirectoryURL URLByAppendingPathComponent:@"observations.db"]; 178 [[NSFileManager defaultManager] removeItemAtURL:fileURL error:nil]; 179 [[NSFileManager defaultManager] removeItemAtURL:statisticsDirectoryURL error:nil]; 180 EXPECT_FALSE([[NSFileManager defaultManager] fileExistsAtPath:statisticsDirectoryURL.path]); 181 182 static bool grandfatheredFlag; 183 static bool doneFlag; 184 185 [dataStore _setResourceLoadStatisticsTestingCallback:^(WKWebsiteDataStore *, NSString *message) { 186 // Only if the database store is default-enabled do we need to check that this first message is correct. 187 if (isITPDatabaseEnabled()) 188 ASSERT_TRUE([message isEqualToString:@"Grandfathered"]); 189 grandfatheredFlag = true; 190 }]; 191 192 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); 193 [dataStore _setResourceLoadStatisticsEnabled:YES]; 194 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]]; 195 196 if (!isITPDatabaseEnabled()) { 197 TestWebKitAPI::Util::run(&grandfatheredFlag); 198 199 // Since the database store is not enabled, we need to update the store to use a database instead of a plist for this test. 200 // We already have a NetworkProcess up and running with ITP enabled. We now make another call initializing 201 // the database store and testing grandfathering. 202 grandfatheredFlag = false; 203 [dataStore _setResourceLoadStatisticsTestingCallback:^(WKWebsiteDataStore *, NSString *message) { 204 ASSERT_TRUE([message isEqualToString:@"Grandfathered"]); 205 grandfatheredFlag = true; 206 }]; 207 208 [dataStore _setUseITPDatabase:true completionHandler: ^(void) { 209 doneFlag = true; 210 }]; 211 212 TestWebKitAPI::Util::run(&doneFlag); 213 } 214 215 TestWebKitAPI::Util::run(&grandfatheredFlag); 216 217 // Spin the runloop until the resource load statistics file has written to disk. 218 // If the test enters a spin loop here, it has failed. 219 while (true) { 220 if ([[NSFileManager defaultManager] fileExistsAtPath:fileURL.path]) 221 break; 222 TestWebKitAPI::Util::spinRunLoop(1); 223 } 224 225 grandfatheredFlag = false; 226 doneFlag = false; 227 [dataStore removeDataOfTypes:[WKWebsiteDataStore _allWebsiteDataTypesIncludingPrivate] modifiedSince:[NSDate distantPast] completionHandler:^ { 228 doneFlag = true; 229 }]; 230 231 TestWebKitAPI::Util::run(&doneFlag); 232 TestWebKitAPI::Util::spinRunLoop(10); 233 234 // The website data store remove should have completed, but since we removed all of the data types that are monitored by resource load statistics, 235 // no grandfathering call should have been made. Note that the database file will not be deleted like in the persistent storage case, only cleared. 236 EXPECT_FALSE(grandfatheredFlag); 237 238 doneFlag = false; 239 [dataStore removeDataOfTypes:[NSSet setWithObjects:WKWebsiteDataTypeCookies, _WKWebsiteDataTypeResourceLoadStatistics, nil] modifiedSince:[NSDate distantPast] completionHandler:^ { 240 doneFlag = true; 241 }]; 242 243 // Since we did not remove every data type covered by resource load statistics, we do expect that grandfathering took place again. 244 // If the test hangs waiting on either of these conditions, it has failed. 245 TestWebKitAPI::Util::run(&grandfatheredFlag); 246 TestWebKitAPI::Util::run(&doneFlag); 247 } 248 137 249 TEST(ResourceLoadStatistics, ShouldNotGrandfatherOnStartup) 138 250 { … … 149 261 150 262 static bool callbackFlag; 263 static bool doneFlag; 264 151 265 [dataStore _setResourceLoadStatisticsTestingCallback:^(WKWebsiteDataStore *, NSString *message) { 152 ASSERT_TRUE([message isEqualToString:@"PopulatedWithoutGrandfathering"]); 266 // Only if the database store is not default-enabled do we need to check that this first message is correct. 267 if (!isITPDatabaseEnabled()) 268 ASSERT_TRUE([message isEqualToString:@"PopulatedWithoutGrandfathering"]); 153 269 callbackFlag = true; 154 270 }]; … … 159 275 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]]; 160 276 277 if (isITPDatabaseEnabled()) { 278 TestWebKitAPI::Util::run(&callbackFlag); 279 280 // Since the database store is enabled, we need to disable it to test this functionality with the plist. 281 // We already have a NetworkProcess up and running with ITP enabled. We now make another call initializing 282 // the memory store and testing grandfathering. 283 callbackFlag = false; 284 [dataStore _setResourceLoadStatisticsTestingCallback:^(WKWebsiteDataStore *, NSString *message) { 285 ASSERT_TRUE([message isEqualToString:@"PopulatedWithoutGrandfathering"]); 286 callbackFlag = true; 287 }]; 288 289 [dataStore _setUseITPDatabase:false completionHandler: ^(void) { 290 doneFlag = true; 291 }]; 292 293 TestWebKitAPI::Util::run(&doneFlag); 294 } 295 161 296 TestWebKitAPI::Util::run(&callbackFlag); 162 297 } 163 298 164 TEST(ResourceLoadStatistics, ChildProcessesNotLaunched) 165 { 166 // Ensure the shared process pool exists so the data store operations we're about to do work with it. 167 WKProcessPool *sharedProcessPool = [WKProcessPool _sharedProcessPool]; 168 169 EXPECT_EQ((size_t)0, [sharedProcessPool _pluginProcessCount]); 170 299 TEST(ResourceLoadStatistics, ShouldNotGrandfatherOnStartupDatabase) 300 { 171 301 auto *dataStore = [WKWebsiteDataStore defaultDataStore]; 172 302 173 303 NSURL *statisticsDirectoryURL = [NSURL fileURLWithPath:[@"~/Library/WebKit/TestWebKitAPI/WebsiteData/ResourceLoadStatistics" stringByExpandingTildeInPath] isDirectory:YES]; 174 NSURL *targetURL = [statisticsDirectoryURL URLByAppendingPathComponent:@" full_browsing_session_resourceLog.plist"];304 NSURL *targetURL = [statisticsDirectoryURL URLByAppendingPathComponent:@"observations.db"]; 175 305 NSURL *testResourceURL = [[NSBundle mainBundle] URLForResource:@"EmptyGrandfatheredResourceLoadStatistics" withExtension:@"plist" subdirectory:@"TestWebKitAPI.resources"]; 176 306 … … 180 310 EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:targetURL.path]); 181 311 312 static bool callbackFlag; 182 313 static bool doneFlag; 314 183 315 [dataStore _setResourceLoadStatisticsTestingCallback:^(WKWebsiteDataStore *, NSString *message) { 184 EXPECT_TRUE([message isEqualToString:@"PopulatedWithoutGrandfathering"]); 185 doneFlag = true; 316 // Only if the database store is default-enabled do we need to check that this first message is correct. 317 if (isITPDatabaseEnabled()) 318 ASSERT_TRUE([message isEqualToString:@"PopulatedWithoutGrandfathering"]); 319 callbackFlag = true; 186 320 }]; 187 321 … … 191 325 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]]; 192 326 193 TestWebKitAPI::Util::run(&doneFlag); 327 if (!isITPDatabaseEnabled()) { 328 TestWebKitAPI::Util::run(&callbackFlag); 329 330 // Since the database store is not enabled, we need to update the store to use a database instead of a plist for this test. 331 // We already have a NetworkProcess up and running with ITP enabled. We now make another call initializing 332 // the database store and testing grandfathering. 333 callbackFlag = false; 334 [dataStore _setResourceLoadStatisticsTestingCallback:^(WKWebsiteDataStore *, NSString *message) { 335 ASSERT_TRUE([message isEqualToString:@"PopulatedWithoutGrandfathering"]); 336 callbackFlag = true; 337 }]; 338 339 [dataStore _setUseITPDatabase:true completionHandler: ^(void) { 340 doneFlag = true; 341 }]; 342 343 TestWebKitAPI::Util::run(&doneFlag); 344 } 345 346 TestWebKitAPI::Util::run(&callbackFlag); 347 } 348 349 TEST(ResourceLoadStatistics, ChildProcessesNotLaunched) 350 { 351 // Ensure the shared process pool exists so the data store operations we're about to do work with it. 352 WKProcessPool *sharedProcessPool = [WKProcessPool _sharedProcessPool]; 353 354 EXPECT_EQ((size_t)0, [sharedProcessPool _pluginProcessCount]); 355 356 auto *dataStore = [WKWebsiteDataStore defaultDataStore]; 357 358 NSURL *statisticsDirectoryURL = [NSURL fileURLWithPath:[@"~/Library/WebKit/TestWebKitAPI/WebsiteData/ResourceLoadStatistics" stringByExpandingTildeInPath] isDirectory:YES]; 359 NSURL *targetURL = [statisticsDirectoryURL URLByAppendingPathComponent:@"full_browsing_session_resourceLog.plist"]; 360 NSURL *testResourceURL = [[NSBundle mainBundle] URLForResource:@"EmptyGrandfatheredResourceLoadStatistics" withExtension:@"plist" subdirectory:@"TestWebKitAPI.resources"]; 361 362 [[NSFileManager defaultManager] createDirectoryAtURL:statisticsDirectoryURL withIntermediateDirectories:YES attributes:nil error:nil]; 363 [[NSFileManager defaultManager] copyItemAtURL:testResourceURL toURL:targetURL error:nil]; 364 365 EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:targetURL.path]); 366 367 static bool callbackFlag; 368 static bool doneFlag; 369 [dataStore _setResourceLoadStatisticsTestingCallback:^(WKWebsiteDataStore *, NSString *message) { 370 // Only if the database store is not default-enabled do we need to check that this first message is correct. 371 if (!isITPDatabaseEnabled()) 372 EXPECT_TRUE([message isEqualToString:@"PopulatedWithoutGrandfathering"]); 373 callbackFlag = true; 374 }]; 375 376 // We need an active NetworkProcess to perform ResourceLoadStatistics operations. 377 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); 378 [dataStore _setResourceLoadStatisticsEnabled:YES]; 379 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]]; 380 381 if (isITPDatabaseEnabled()) { 382 TestWebKitAPI::Util::run(&callbackFlag); 383 384 // Since the database store is enabled, we need to disable it to test this functionality with the plist. 385 // We already have a NetworkProcess up and running with ITP enabled. We now make another call initializing 386 // the memory store and testing grandfathering. 387 callbackFlag = false; 388 [dataStore _setResourceLoadStatisticsTestingCallback:^(WKWebsiteDataStore *, NSString *message) { 389 ASSERT_TRUE([message isEqualToString:@"PopulatedWithoutGrandfathering"]); 390 callbackFlag = true; 391 }]; 392 393 [dataStore _setUseITPDatabase:false completionHandler: ^(void) { 394 doneFlag = true; 395 }]; 396 397 TestWebKitAPI::Util::run(&doneFlag); 398 } 399 400 TestWebKitAPI::Util::run(&callbackFlag); 401 402 EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:targetURL.path]); 403 404 webView.clear(); 405 406 EXPECT_EQ((size_t)0, [sharedProcessPool _pluginProcessCount]); 407 } 408 409 TEST(ResourceLoadStatistics, ChildProcessesNotLaunchedDatabase) 410 { 411 // Ensure the shared process pool exists so the data store operations we're about to do work with it. 412 WKProcessPool *sharedProcessPool = [WKProcessPool _sharedProcessPool]; 413 414 EXPECT_EQ((size_t)0, [sharedProcessPool _pluginProcessCount]); 415 416 auto *dataStore = [WKWebsiteDataStore defaultDataStore]; 417 418 NSURL *statisticsDirectoryURL = [NSURL fileURLWithPath:[@"~/Library/WebKit/TestWebKitAPI/WebsiteData/ResourceLoadStatistics" stringByExpandingTildeInPath] isDirectory:YES]; 419 NSURL *targetURL = [statisticsDirectoryURL URLByAppendingPathComponent:@"observations.db"]; 420 421 NSURL *testResourceURL = [[NSBundle mainBundle] URLForResource:@"EmptyGrandfatheredResourceLoadStatistics" withExtension:@"plist" subdirectory:@"TestWebKitAPI.resources"]; 422 423 [[NSFileManager defaultManager] createDirectoryAtURL:statisticsDirectoryURL withIntermediateDirectories:YES attributes:nil error:nil]; 424 [[NSFileManager defaultManager] copyItemAtURL:testResourceURL toURL:targetURL error:nil]; 425 426 EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:targetURL.path]); 427 428 static bool callbackFlag; 429 static bool doneFlag; 430 431 [dataStore _setResourceLoadStatisticsTestingCallback:^(WKWebsiteDataStore *, NSString *message) { 432 // Only if the database store is default-enabled do we need to check that this first message is correct. 433 if (isITPDatabaseEnabled()) 434 EXPECT_TRUE([message isEqualToString:@"PopulatedWithoutGrandfathering"]); 435 callbackFlag = true; 436 }]; 437 438 // We need an active NetworkProcess to perform ResourceLoadStatistics operations. 439 auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]); 440 [dataStore _setResourceLoadStatisticsEnabled:YES]; 441 [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"about:blank"]]]; 442 443 if (!isITPDatabaseEnabled()) { 444 TestWebKitAPI::Util::run(&callbackFlag); 445 446 // Since the database store is not enabled, we need to update the store to use a database instead of a plist for this test. 447 // We already have a NetworkProcess up and running with ITP enabled. We now make another call initializing 448 // the database store and testing grandfathering. 449 callbackFlag = false; 450 [dataStore _setResourceLoadStatisticsTestingCallback:^(WKWebsiteDataStore *, NSString *message) { 451 ASSERT_TRUE([message isEqualToString:@"PopulatedWithoutGrandfathering"]); 452 callbackFlag = true; 453 }]; 454 455 [dataStore _setUseITPDatabase:true completionHandler: ^(void) { 456 doneFlag = true; 457 }]; 458 459 TestWebKitAPI::Util::run(&doneFlag); 460 } 461 462 TestWebKitAPI::Util::run(&callbackFlag); 194 463 195 464 EXPECT_TRUE([[NSFileManager defaultManager] fileExistsAtPath:targetURL.path]);
Note: See TracChangeset
for help on using the changeset viewer.