| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/mac/bind_objc_block.h" | 5 #include "base/mac/bind_objc_block.h" |
| 6 #include "base/memory/ptr_util.h" | 6 #include "base/memory/ptr_util.h" |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #import "base/test/ios/wait_util.h" | 10 #import "base/test/ios/wait_util.h" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 Wait(matcher, name); | 84 Wait(matcher, name); |
| 85 [[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()]; | 85 [[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()]; |
| 86 } | 86 } |
| 87 | 87 |
| 88 // Creates a new main tab and load |url|. Wait until |word| is visible on the | 88 // Creates a new main tab and load |url|. Wait until |word| is visible on the |
| 89 // page. | 89 // page. |
| 90 void NewMainTabWithURL(const GURL& url, const std::string& word) { | 90 void NewMainTabWithURL(const GURL& url, const std::string& word) { |
| 91 int number_of_tabs = chrome_test_util::GetMainTabCount(); | 91 int number_of_tabs = chrome_test_util::GetMainTabCount(); |
| 92 chrome_test_util::OpenNewTab(); | 92 chrome_test_util::OpenNewTab(); |
| 93 [ChromeEarlGrey loadURL:url]; | 93 [ChromeEarlGrey loadURL:url]; |
| 94 [[EarlGrey | 94 [ChromeEarlGrey waitForWebViewContainingText:word]; |
| 95 selectElementWithMatcher:chrome_test_util::WebViewContainingText(word)] | |
| 96 assertWithMatcher:grey_notNil()]; | |
| 97 chrome_test_util::AssertMainTabCount(number_of_tabs + 1); | 95 chrome_test_util::AssertMainTabCount(number_of_tabs + 1); |
| 98 } | 96 } |
| 99 | 97 |
| 100 // Opens 2 new tabs with different URLs. | 98 // Opens 2 new tabs with different URLs. |
| 101 void OpenTwoTabs() { | 99 void OpenTwoTabs() { |
| 102 chrome_test_util::CloseAllTabsInCurrentMode(); | 100 chrome_test_util::CloseAllTabsInCurrentMode(); |
| 103 | 101 |
| 104 const GURL url1 = web::test::HttpServer::MakeUrl(kTestUrl1); | 102 const GURL url1 = web::test::HttpServer::MakeUrl(kTestUrl1); |
| 105 const GURL url2 = web::test::HttpServer::MakeUrl(kTestUrl2); | 103 const GURL url2 = web::test::HttpServer::MakeUrl(kTestUrl2); |
| 106 NewMainTabWithURL(url1, kURL1FirstWord); | 104 NewMainTabWithURL(url1, kURL1FirstWord); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 histogramTester.ExpectUniqueSample( | 196 histogramTester.ExpectUniqueSample( |
| 199 kSelectedTabHistogramName, TabUsageRecorder::IN_MEMORY, 1, failureBlock); | 197 kSelectedTabHistogramName, TabUsageRecorder::IN_MEMORY, 1, failureBlock); |
| 200 | 198 |
| 201 // Evict the tab. | 199 // Evict the tab. |
| 202 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); | 200 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); |
| 203 GREYAssertTrue(chrome_test_util::IsIncognitoMode(), | 201 GREYAssertTrue(chrome_test_util::IsIncognitoMode(), |
| 204 @"Failed to switch to incognito mode"); | 202 @"Failed to switch to incognito mode"); |
| 205 | 203 |
| 206 // Switch back to the normal tabs. Should be on tab one. | 204 // Switch back to the normal tabs. Should be on tab one. |
| 207 SwitchToNormalMode(); | 205 SwitchToNormalMode(); |
| 208 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 206 [ChromeEarlGrey waitForWebViewContainingText:kURL1FirstWord]; |
| 209 kURL1FirstWord)] | |
| 210 assertWithMatcher:grey_notNil()]; | |
| 211 | 207 |
| 212 histogramTester.ExpectTotalCount(kSelectedTabHistogramName, 2, failureBlock); | 208 histogramTester.ExpectTotalCount(kSelectedTabHistogramName, 2, failureBlock); |
| 213 histogramTester.ExpectBucketCount(kSelectedTabHistogramName, | 209 histogramTester.ExpectBucketCount(kSelectedTabHistogramName, |
| 214 TabUsageRecorder::EVICTED, 1, failureBlock); | 210 TabUsageRecorder::EVICTED, 1, failureBlock); |
| 215 } | 211 } |
| 216 | 212 |
| 217 // Verifies the UMA metric for page loads before a tab eviction by loading | 213 // Verifies the UMA metric for page loads before a tab eviction by loading |
| 218 // some tabs, forcing a tab eviction, then checking the histogram. | 214 // some tabs, forcing a tab eviction, then checking the histogram. |
| 219 - (void)testPageLoadCountBeforeEvictedTab { | 215 - (void)testPageLoadCountBeforeEvictedTab { |
| 220 web::test::SetUpFileBasedHttpServer(); | 216 web::test::SetUpFileBasedHttpServer(); |
| 221 chrome_test_util::HistogramTester histogramTester; | 217 chrome_test_util::HistogramTester histogramTester; |
| 222 ResetTabUsageRecorder(); | 218 ResetTabUsageRecorder(); |
| 223 const GURL url1 = web::test::HttpServer::MakeUrl(kTestUrl1); | 219 const GURL url1 = web::test::HttpServer::MakeUrl(kTestUrl1); |
| 224 FailureBlock failureBlock = ^(NSString* error) { | 220 FailureBlock failureBlock = ^(NSString* error) { |
| 225 GREYFail(error); | 221 GREYFail(error); |
| 226 }; | 222 }; |
| 227 | 223 |
| 228 // This test opens three tabs. | 224 // This test opens three tabs. |
| 229 const int numberOfTabs = 3; | 225 const int numberOfTabs = 3; |
| 230 chrome_test_util::CloseAllTabsInCurrentMode(); | 226 chrome_test_util::CloseAllTabsInCurrentMode(); |
| 231 // Open three tabs with http:// urls. | 227 // Open three tabs with http:// urls. |
| 232 for (NSUInteger i = 0; i < numberOfTabs; i++) { | 228 for (NSUInteger i = 0; i < numberOfTabs; i++) { |
| 233 chrome_test_util::OpenNewTab(); | 229 chrome_test_util::OpenNewTab(); |
| 234 [ChromeEarlGrey loadURL:url1]; | 230 [ChromeEarlGrey loadURL:url1]; |
| 235 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 231 [ChromeEarlGrey waitForWebViewContainingText:kURL1FirstWord]; |
| 236 kURL1FirstWord)] | |
| 237 assertWithMatcher:grey_notNil()]; | |
| 238 } | 232 } |
| 239 chrome_test_util::AssertMainTabCount(numberOfTabs); | 233 chrome_test_util::AssertMainTabCount(numberOfTabs); |
| 240 | 234 |
| 241 // Switch between the tabs. They are currently in memory. | 235 // Switch between the tabs. They are currently in memory. |
| 242 chrome_test_util::SelectTabAtIndexInCurrentMode(0); | 236 chrome_test_util::SelectTabAtIndexInCurrentMode(0); |
| 243 | 237 |
| 244 // Verify that no page-load count has been recorded. | 238 // Verify that no page-load count has been recorded. |
| 245 histogramTester.ExpectTotalCount(kPageLoadsBeforeEvictedTabSelected, 0, | 239 histogramTester.ExpectTotalCount(kPageLoadsBeforeEvictedTabSelected, 0, |
| 246 failureBlock); | 240 failureBlock); |
| 247 | 241 |
| 248 // Reload each tab. | 242 // Reload each tab. |
| 249 for (NSUInteger i = 0; i < numberOfTabs; i++) { | 243 for (NSUInteger i = 0; i < numberOfTabs; i++) { |
| 250 chrome_test_util::SelectTabAtIndexInCurrentMode(i); | 244 chrome_test_util::SelectTabAtIndexInCurrentMode(i); |
| 251 // Clear the page so that we can check when page reload is complete. | 245 // Clear the page so that we can check when page reload is complete. |
| 252 __block bool finished = false; | 246 __block bool finished = false; |
| 253 chrome_test_util::GetCurrentWebState()->ExecuteJavaScript( | 247 chrome_test_util::GetCurrentWebState()->ExecuteJavaScript( |
| 254 base::UTF8ToUTF16(kClearPageScript), | 248 base::UTF8ToUTF16(kClearPageScript), |
| 255 base::BindBlockArc(^(const base::Value*) { | 249 base::BindBlockArc(^(const base::Value*) { |
| 256 finished = true; | 250 finished = true; |
| 257 })); | 251 })); |
| 258 | 252 |
| 259 GREYAssert(testing::WaitUntilConditionOrTimeout(1.0, | 253 GREYAssert(testing::WaitUntilConditionOrTimeout(1.0, |
| 260 ^{ | 254 ^{ |
| 261 return finished; | 255 return finished; |
| 262 }), | 256 }), |
| 263 @"JavaScript to reload each tab did not finish"); | 257 @"JavaScript to reload each tab did not finish"); |
| 264 [ChromeEarlGreyUI reload]; | 258 [ChromeEarlGreyUI reload]; |
| 265 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 259 [ChromeEarlGrey waitForWebViewContainingText:kURL1FirstWord]; |
| 266 kURL1FirstWord)] | |
| 267 assertWithMatcher:grey_notNil()]; | |
| 268 } | 260 } |
| 269 | 261 |
| 270 // Evict the tab. Create a dummy tab so that switching back to normal mode | 262 // Evict the tab. Create a dummy tab so that switching back to normal mode |
| 271 // does not trigger a reload immediatly. | 263 // does not trigger a reload immediatly. |
| 272 chrome_test_util::OpenNewTab(); | 264 chrome_test_util::OpenNewTab(); |
| 273 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); | 265 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); |
| 274 chrome_test_util::AssertIncognitoTabCount(1); | 266 chrome_test_util::AssertIncognitoTabCount(1); |
| 275 | 267 |
| 276 // Switch back to the normal tabs. Should be on tab one. | 268 // Switch back to the normal tabs. Should be on tab one. |
| 277 SwitchToNormalMode(); | 269 SwitchToNormalMode(); |
| 278 chrome_test_util::SelectTabAtIndexInCurrentMode(0); | 270 chrome_test_util::SelectTabAtIndexInCurrentMode(0); |
| 279 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 271 [ChromeEarlGrey waitForWebViewContainingText:kURL1FirstWord]; |
| 280 kURL1FirstWord)] | |
| 281 assertWithMatcher:grey_notNil()]; | |
| 282 | 272 |
| 283 // Verify that one page-load count has been recorded. It should contain two | 273 // Verify that one page-load count has been recorded. It should contain two |
| 284 // page loads for each tab created. | 274 // page loads for each tab created. |
| 285 histogramTester.ExpectTotalCount(kPageLoadsBeforeEvictedTabSelected, 1, | 275 histogramTester.ExpectTotalCount(kPageLoadsBeforeEvictedTabSelected, 1, |
| 286 failureBlock); | 276 failureBlock); |
| 287 | 277 |
| 288 std::unique_ptr<base::HistogramSamples> samples = | 278 std::unique_ptr<base::HistogramSamples> samples = |
| 289 histogramTester.GetHistogramSamplesSinceCreation( | 279 histogramTester.GetHistogramSamplesSinceCreation( |
| 290 kPageLoadsBeforeEvictedTabSelected); | 280 kPageLoadsBeforeEvictedTabSelected); |
| 291 int sampleSum = samples ? samples->sum() : 0; | 281 int sampleSum = samples ? samples->sum() : 0; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 308 GREYAssertTrue(chrome_test_util::SetCurrentTabsToBeColdStartTabs(), | 298 GREYAssertTrue(chrome_test_util::SetCurrentTabsToBeColdStartTabs(), |
| 309 @"Fail to state tabs as cold start tabs"); | 299 @"Fail to state tabs as cold start tabs"); |
| 310 | 300 |
| 311 // Open two incognito tabs with urls, clearing normal tabs from memory. | 301 // Open two incognito tabs with urls, clearing normal tabs from memory. |
| 312 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); | 302 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); |
| 313 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); | 303 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); |
| 314 chrome_test_util::AssertIncognitoTabCount(2); | 304 chrome_test_util::AssertIncognitoTabCount(2); |
| 315 | 305 |
| 316 // Switch back to the normal tabs. | 306 // Switch back to the normal tabs. |
| 317 SwitchToNormalMode(); | 307 SwitchToNormalMode(); |
| 318 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 308 [ChromeEarlGrey waitForWebViewContainingText:kURL2FirstWord]; |
| 319 kURL2FirstWord)] | |
| 320 assertWithMatcher:grey_notNil()]; | |
| 321 | 309 |
| 322 // Select the other one so it also reloads. | 310 // Select the other one so it also reloads. |
| 323 chrome_test_util::SelectTabAtIndexInCurrentMode(0); | 311 chrome_test_util::SelectTabAtIndexInCurrentMode(0); |
| 324 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 312 [ChromeEarlGrey waitForWebViewContainingText:kURL1FirstWord]; |
| 325 kURL1FirstWord)] | |
| 326 assertWithMatcher:grey_notNil()]; | |
| 327 | |
| 328 FailureBlock failureBlock = ^(NSString* error) { | 313 FailureBlock failureBlock = ^(NSString* error) { |
| 329 GREYFail(error); | 314 GREYFail(error); |
| 330 }; | 315 }; |
| 331 // Make sure that one of the 2 tab loads (excluding the selected tab) is | 316 // Make sure that one of the 2 tab loads (excluding the selected tab) is |
| 332 // counted as a cold start eviction. | 317 // counted as a cold start eviction. |
| 333 histogramTester.ExpectBucketCount(kSelectedTabHistogramName, | 318 histogramTester.ExpectBucketCount(kSelectedTabHistogramName, |
| 334 TabUsageRecorder::EVICTED_DUE_TO_COLD_START, | 319 TabUsageRecorder::EVICTED_DUE_TO_COLD_START, |
| 335 1, failureBlock); | 320 1, failureBlock); |
| 336 | 321 |
| 337 histogramTester.ExpectBucketCount( | 322 histogramTester.ExpectBucketCount( |
| 338 kSelectedTabHistogramName, TabUsageRecorder::IN_MEMORY, 0, failureBlock); | 323 kSelectedTabHistogramName, TabUsageRecorder::IN_MEMORY, 0, failureBlock); |
| 339 // Re-select the same tab and make sure it is not counted again as evicted. | 324 // Re-select the same tab and make sure it is not counted again as evicted. |
| 340 chrome_test_util::SelectTabAtIndexInCurrentMode(1); | 325 chrome_test_util::SelectTabAtIndexInCurrentMode(1); |
| 341 chrome_test_util::SelectTabAtIndexInCurrentMode(0); | 326 chrome_test_util::SelectTabAtIndexInCurrentMode(0); |
| 342 | 327 |
| 343 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 328 [ChromeEarlGrey waitForWebViewContainingText:kURL1FirstWord]; |
| 344 kURL1FirstWord)] | |
| 345 assertWithMatcher:grey_notNil()]; | |
| 346 histogramTester.ExpectBucketCount(kSelectedTabHistogramName, | 329 histogramTester.ExpectBucketCount(kSelectedTabHistogramName, |
| 347 TabUsageRecorder::EVICTED_DUE_TO_COLD_START, | 330 TabUsageRecorder::EVICTED_DUE_TO_COLD_START, |
| 348 1, failureBlock); | 331 1, failureBlock); |
| 349 | 332 |
| 350 histogramTester.ExpectBucketCount( | 333 histogramTester.ExpectBucketCount( |
| 351 kSelectedTabHistogramName, TabUsageRecorder::IN_MEMORY, 2, failureBlock); | 334 kSelectedTabHistogramName, TabUsageRecorder::IN_MEMORY, 2, failureBlock); |
| 352 } | 335 } |
| 353 | 336 |
| 354 // Tests that tabs reloads after backgrounding and eviction. | 337 // Tests that tabs reloads after backgrounding and eviction. |
| 355 - (void)testBackgroundingReloadCount { | 338 - (void)testBackgroundingReloadCount { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 369 @"Fail to simulate tab backgrounding."); | 352 @"Fail to simulate tab backgrounding."); |
| 370 | 353 |
| 371 // Open incognito and clear normal tabs from memory. | 354 // Open incognito and clear normal tabs from memory. |
| 372 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); | 355 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); |
| 373 GREYAssertTrue(chrome_test_util::IsIncognitoMode(), | 356 GREYAssertTrue(chrome_test_util::IsIncognitoMode(), |
| 374 @"Failed to switch to incognito mode"); | 357 @"Failed to switch to incognito mode"); |
| 375 histogramTester.ExpectTotalCount(kEvictedTabReloadTime, 0, failureBlock); | 358 histogramTester.ExpectTotalCount(kEvictedTabReloadTime, 0, failureBlock); |
| 376 | 359 |
| 377 // Switch back to the normal tabs. | 360 // Switch back to the normal tabs. |
| 378 SwitchToNormalMode(); | 361 SwitchToNormalMode(); |
| 379 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 362 [ChromeEarlGrey waitForWebViewContainingText:kURL2FirstWord]; |
| 380 kURL2FirstWord)] | |
| 381 assertWithMatcher:grey_notNil()]; | |
| 382 | 363 |
| 383 const GURL url1 = web::test::HttpServer::MakeUrl(kTestUrl1); | 364 const GURL url1 = web::test::HttpServer::MakeUrl(kTestUrl1); |
| 384 const GURL url2 = web::test::HttpServer::MakeUrl(kTestUrl2); | 365 const GURL url2 = web::test::HttpServer::MakeUrl(kTestUrl2); |
| 385 [[EarlGrey | 366 [[EarlGrey |
| 386 selectElementWithMatcher:chrome_test_util::OmniboxText(url2.GetContent())] | 367 selectElementWithMatcher:chrome_test_util::OmniboxText(url2.GetContent())] |
| 387 assertWithMatcher:grey_notNil()]; | 368 assertWithMatcher:grey_notNil()]; |
| 388 histogramTester.ExpectTotalCount(kEvictedTabReloadTime, 1, failureBlock); | 369 histogramTester.ExpectTotalCount(kEvictedTabReloadTime, 1, failureBlock); |
| 389 | 370 |
| 390 chrome_test_util::SelectTabAtIndexInCurrentMode(0); | 371 chrome_test_util::SelectTabAtIndexInCurrentMode(0); |
| 391 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 372 [ChromeEarlGrey waitForWebViewContainingText:kURL1FirstWord]; |
| 392 kURL1FirstWord)] | |
| 393 assertWithMatcher:grey_notNil()]; | |
| 394 [[EarlGrey | 373 [[EarlGrey |
| 395 selectElementWithMatcher:chrome_test_util::OmniboxText(url1.GetContent())] | 374 selectElementWithMatcher:chrome_test_util::OmniboxText(url1.GetContent())] |
| 396 assertWithMatcher:grey_notNil()]; | 375 assertWithMatcher:grey_notNil()]; |
| 397 histogramTester.ExpectTotalCount(kEvictedTabReloadTime, 2, failureBlock); | 376 histogramTester.ExpectTotalCount(kEvictedTabReloadTime, 2, failureBlock); |
| 398 } | 377 } |
| 399 | 378 |
| 400 // Verify correct recording of metrics when the reloading of an evicted tab | 379 // Verify correct recording of metrics when the reloading of an evicted tab |
| 401 // succeeds. | 380 // succeeds. |
| 402 - (void)testEvictedTabReloadSuccess { | 381 - (void)testEvictedTabReloadSuccess { |
| 403 web::test::SetUpFileBasedHttpServer(); | 382 web::test::SetUpFileBasedHttpServer(); |
| 404 chrome_test_util::HistogramTester histogramTester; | 383 chrome_test_util::HistogramTester histogramTester; |
| 405 FailureBlock failureBlock = ^(NSString* error) { | 384 FailureBlock failureBlock = ^(NSString* error) { |
| 406 GREYFail(error); | 385 GREYFail(error); |
| 407 }; | 386 }; |
| 408 | 387 |
| 409 GURL URL = web::test::HttpServer::MakeUrl(kTestUrl1); | 388 GURL URL = web::test::HttpServer::MakeUrl(kTestUrl1); |
| 410 NewMainTabWithURL(URL, kURL1FirstWord); | 389 NewMainTabWithURL(URL, kURL1FirstWord); |
| 411 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); | 390 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); |
| 412 SwitchToNormalMode(); | 391 SwitchToNormalMode(); |
| 413 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 392 [ChromeEarlGrey waitForWebViewContainingText:kURL1FirstWord]; |
| 414 kURL1FirstWord)] | |
| 415 assertWithMatcher:grey_notNil()]; | |
| 416 | 393 |
| 417 histogramTester.ExpectUniqueSample(kEvictedTabReloadSuccessRate, | 394 histogramTester.ExpectUniqueSample(kEvictedTabReloadSuccessRate, |
| 418 TabUsageRecorder::LOAD_SUCCESS, 1, | 395 TabUsageRecorder::LOAD_SUCCESS, 1, |
| 419 failureBlock); | 396 failureBlock); |
| 420 histogramTester.ExpectUniqueSample(kDidUserWaitForEvictedTabReload, | 397 histogramTester.ExpectUniqueSample(kDidUserWaitForEvictedTabReload, |
| 421 TabUsageRecorder::USER_WAITED, 1, | 398 TabUsageRecorder::USER_WAITED, 1, |
| 422 failureBlock); | 399 failureBlock); |
| 423 histogramTester.ExpectTotalCount(kEvictedTabReloadTime, 1, failureBlock); | 400 histogramTester.ExpectTotalCount(kEvictedTabReloadTime, 1, failureBlock); |
| 424 } | 401 } |
| 425 | 402 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 [[GREYConfiguration sharedInstance] | 504 [[GREYConfiguration sharedInstance] |
| 528 setValue:@(NO) | 505 setValue:@(NO) |
| 529 forConfigKey:kGREYConfigKeySynchronizationEnabled]; | 506 forConfigKey:kGREYConfigKeySynchronizationEnabled]; |
| 530 OpenSettingsMenuUnsynced(); | 507 OpenSettingsMenuUnsynced(); |
| 531 OpenSettingsSubMenuUnsynced(IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY); | 508 OpenSettingsSubMenuUnsynced(IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY); |
| 532 Wait(grey_accessibilityID(kPrivacyCollectionViewId), | 509 Wait(grey_accessibilityID(kPrivacyCollectionViewId), |
| 533 @"Privacy settings view."); | 510 @"Privacy settings view."); |
| 534 | 511 |
| 535 WaitAndTap(chrome_test_util::NavigationBarDoneButton(), @"Close settings"); | 512 WaitAndTap(chrome_test_util::NavigationBarDoneButton(), @"Close settings"); |
| 536 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; | 513 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; |
| 537 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 514 [ChromeEarlGrey waitForWebViewContainingText:responses[slowURL]]; |
| 538 responses[slowURL])] | |
| 539 assertWithMatcher:grey_notNil()]; | |
| 540 | 515 |
| 541 [[GREYConfiguration sharedInstance] | 516 [[GREYConfiguration sharedInstance] |
| 542 setValue:@(YES) | 517 setValue:@(YES) |
| 543 forConfigKey:kGREYConfigKeySynchronizationEnabled]; | 518 forConfigKey:kGREYConfigKeySynchronizationEnabled]; |
| 544 | 519 |
| 545 histogramTester.ExpectBucketCount(kDidUserWaitForEvictedTabReload, | 520 histogramTester.ExpectBucketCount(kDidUserWaitForEvictedTabReload, |
| 546 TabUsageRecorder::USER_DID_NOT_WAIT, 0, | 521 TabUsageRecorder::USER_DID_NOT_WAIT, 0, |
| 547 failureBlock); | 522 failureBlock); |
| 548 histogramTester.ExpectBucketCount(kDidUserWaitForEvictedTabReload, | 523 histogramTester.ExpectBucketCount(kDidUserWaitForEvictedTabReload, |
| 549 TabUsageRecorder::USER_WAITED, 1, | 524 TabUsageRecorder::USER_WAITED, 1, |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 | 615 |
| 641 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( | 616 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 642 destinationURL.GetContent())] | 617 destinationURL.GetContent())] |
| 643 assertWithMatcher:grey_notNil()]; | 618 assertWithMatcher:grey_notNil()]; |
| 644 | 619 |
| 645 NSUInteger tabIndex = chrome_test_util::GetMainTabCount() - 1; | 620 NSUInteger tabIndex = chrome_test_util::GetMainTabCount() - 1; |
| 646 chrome_test_util::OpenNewTab(); | 621 chrome_test_util::OpenNewTab(); |
| 647 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); | 622 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); |
| 648 SwitchToNormalMode(); | 623 SwitchToNormalMode(); |
| 649 chrome_test_util::SelectTabAtIndexInCurrentMode(tabIndex); | 624 chrome_test_util::SelectTabAtIndexInCurrentMode(tabIndex); |
| 650 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 625 [ChromeEarlGrey waitForWebViewContainingText:"arrived"]; |
| 651 "arrived")] | |
| 652 assertWithMatcher:grey_notNil()]; | |
| 653 | 626 |
| 654 FailureBlock failureBlock = ^(NSString* error) { | 627 FailureBlock failureBlock = ^(NSString* error) { |
| 655 GREYFail(error); | 628 GREYFail(error); |
| 656 }; | 629 }; |
| 657 // Verify that one page-load count has been recorded. It should contain a | 630 // Verify that one page-load count has been recorded. It should contain a |
| 658 // sum of 1 - one sample with 1 page load. | 631 // sum of 1 - one sample with 1 page load. |
| 659 histogramTester.ExpectTotalCount(kPageLoadsBeforeEvictedTabSelected, 1, | 632 histogramTester.ExpectTotalCount(kPageLoadsBeforeEvictedTabSelected, 1, |
| 660 failureBlock); | 633 failureBlock); |
| 661 | 634 |
| 662 std::unique_ptr<base::HistogramSamples> samples = | 635 std::unique_ptr<base::HistogramSamples> samples = |
| (...skipping 19 matching lines...) Expand all Loading... |
| 682 responses[destinationURL] = "Whee!"; | 655 responses[destinationURL] = "Whee!"; |
| 683 web::test::SetUpHttpServer(base::MakeUnique<HtmlResponseProvider>(responses)); | 656 web::test::SetUpHttpServer(base::MakeUnique<HtmlResponseProvider>(responses)); |
| 684 chrome_test_util::HistogramTester histogramTester; | 657 chrome_test_util::HistogramTester histogramTester; |
| 685 ResetTabUsageRecorder(); | 658 ResetTabUsageRecorder(); |
| 686 | 659 |
| 687 // Open a tab with a link to click. | 660 // Open a tab with a link to click. |
| 688 NewMainTabWithURL(initialURL, "link"); | 661 NewMainTabWithURL(initialURL, "link"); |
| 689 // Click the link. | 662 // Click the link. |
| 690 chrome_test_util::TapWebViewElementWithId("link"); | 663 chrome_test_util::TapWebViewElementWithId("link"); |
| 691 | 664 |
| 692 [[EarlGrey | 665 [ChromeEarlGrey waitForWebViewContainingText:"Whee"]; |
| 693 selectElementWithMatcher:chrome_test_util::WebViewContainingText("Whee")] | |
| 694 assertWithMatcher:grey_notNil()]; | |
| 695 | |
| 696 NSUInteger tabIndex = chrome_test_util::GetMainTabCount() - 1; | 666 NSUInteger tabIndex = chrome_test_util::GetMainTabCount() - 1; |
| 697 chrome_test_util::OpenNewTab(); | 667 chrome_test_util::OpenNewTab(); |
| 698 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); | 668 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); |
| 699 SwitchToNormalMode(); | 669 SwitchToNormalMode(); |
| 700 chrome_test_util::SelectTabAtIndexInCurrentMode(tabIndex); | 670 chrome_test_util::SelectTabAtIndexInCurrentMode(tabIndex); |
| 701 [[EarlGrey | 671 [ChromeEarlGrey waitForWebViewContainingText:"Whee"]; |
| 702 selectElementWithMatcher:chrome_test_util::WebViewContainingText("Whee")] | |
| 703 assertWithMatcher:grey_notNil()]; | |
| 704 | 672 |
| 705 // Verify that the page-load count has been recorded. It should contain a | 673 // Verify that the page-load count has been recorded. It should contain a |
| 706 // sum of 2 - one sample with 2 page loads. | 674 // sum of 2 - one sample with 2 page loads. |
| 707 std::unique_ptr<base::HistogramSamples> samples = | 675 std::unique_ptr<base::HistogramSamples> samples = |
| 708 histogramTester.GetHistogramSamplesSinceCreation( | 676 histogramTester.GetHistogramSamplesSinceCreation( |
| 709 kPageLoadsBeforeEvictedTabSelected); | 677 kPageLoadsBeforeEvictedTabSelected); |
| 710 int sampleSum = samples->sum(); | 678 int sampleSum = samples->sum(); |
| 711 GREYAssertEqual(sampleSum, 2, @"Expected page loads is %d, actual %d.", 2, | 679 GREYAssertEqual(sampleSum, 2, @"Expected page loads is %d, actual %d.", 2, |
| 712 sampleSum); | 680 sampleSum); |
| 713 | 681 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 performAction:chrome_test_util::LongPressElementForContextMenu( | 718 performAction:chrome_test_util::LongPressElementForContextMenu( |
| 751 "link", true /* menu should appear */)]; | 719 "link", true /* menu should appear */)]; |
| 752 | 720 |
| 753 [[EarlGrey selectElementWithMatcher:OpenLinkInNewTabButton()] | 721 [[EarlGrey selectElementWithMatcher:OpenLinkInNewTabButton()] |
| 754 performAction:grey_tap()]; | 722 performAction:grey_tap()]; |
| 755 chrome_test_util::AssertMainTabCount(numberOfTabs + 1); | 723 chrome_test_util::AssertMainTabCount(numberOfTabs + 1); |
| 756 | 724 |
| 757 SelectTabUsingUI(base::SysUTF8ToNSString(destinationURL.GetContent())); | 725 SelectTabUsingUI(base::SysUTF8ToNSString(destinationURL.GetContent())); |
| 758 | 726 |
| 759 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; | 727 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; |
| 760 [[EarlGrey | 728 [ChromeEarlGrey waitForWebViewContainingText:"Whee"]; |
| 761 selectElementWithMatcher:chrome_test_util::WebViewContainingText("Whee")] | |
| 762 assertWithMatcher:grey_notNil()]; | |
| 763 | 729 |
| 764 FailureBlock failureBlock = ^(NSString* error) { | 730 FailureBlock failureBlock = ^(NSString* error) { |
| 765 GREYFail(error); | 731 GREYFail(error); |
| 766 }; | 732 }; |
| 767 histogramTester.ExpectTotalCount(kSelectedTabHistogramName, 1, failureBlock); | 733 histogramTester.ExpectTotalCount(kSelectedTabHistogramName, 1, failureBlock); |
| 768 histogramTester.ExpectBucketCount( | 734 histogramTester.ExpectBucketCount( |
| 769 kSelectedTabHistogramName, TabUsageRecorder::IN_MEMORY, 1, failureBlock); | 735 kSelectedTabHistogramName, TabUsageRecorder::IN_MEMORY, 1, failureBlock); |
| 770 } | 736 } |
| 771 | 737 |
| 772 // Tests that opening tabs from external app will not cause tab eviction. | 738 // Tests that opening tabs from external app will not cause tab eviction. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; | 799 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; |
| 834 } | 800 } |
| 835 // The deleted tabs are purged during foregrounding and backgrounding. | 801 // The deleted tabs are purged during foregrounding and backgrounding. |
| 836 chrome_test_util::SimulateTabsBackgrounding(); | 802 chrome_test_util::SimulateTabsBackgrounding(); |
| 837 // Make sure |evicted_tabs_| purged the deleted tabs. | 803 // Make sure |evicted_tabs_| purged the deleted tabs. |
| 838 int evicted = chrome_test_util::GetEvictedMainTabCount(); | 804 int evicted = chrome_test_util::GetEvictedMainTabCount(); |
| 839 GREYAssertEqual(evicted, 0, @"Check number of evicted tabs"); | 805 GREYAssertEqual(evicted, 0, @"Check number of evicted tabs"); |
| 840 } | 806 } |
| 841 | 807 |
| 842 @end | 808 @end |
| OLD | NEW |