| 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 #import <EarlGrey/EarlGrey.h> | 5 #import <EarlGrey/EarlGrey.h> |
| 6 #import <XCTest/XCTest.h> | 6 #import <XCTest/XCTest.h> |
| 7 | 7 |
| 8 #include "base/mac/bind_objc_block.h" | 8 #include "base/mac/bind_objc_block.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #if !defined(__has_feature) || !__has_feature(objc_arc) | 44 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 45 #error "This file requires ARC support." | 45 #error "This file requires ARC support." |
| 46 #endif | 46 #endif |
| 47 | 47 |
| 48 using chrome_test_util::OpenLinkInNewTabButton; | 48 using chrome_test_util::OpenLinkInNewTabButton; |
| 49 | 49 |
| 50 namespace { | 50 namespace { |
| 51 | 51 |
| 52 const char kTestUrl1[] = | 52 const char kTestUrl1[] = |
| 53 "http://ios/testing/data/http_server_files/memory_usage.html"; | 53 "http://ios/testing/data/http_server_files/memory_usage.html"; |
| 54 const char kURL1FirstWord[] = "Page"; | 54 NSString* const kURL1FirstWord = @"Page"; |
| 55 const char kTestUrl2[] = | 55 const char kTestUrl2[] = |
| 56 "http://ios/testing/data/http_server_files/fullscreen.html"; | 56 "http://ios/testing/data/http_server_files/fullscreen.html"; |
| 57 const char kURL2FirstWord[] = "Rugby"; | 57 NSString* const kURL2FirstWord = @"Rugby"; |
| 58 const char kClearPageScript[] = "document.body.innerHTML='';"; | 58 const char kClearPageScript[] = "document.body.innerHTML='';"; |
| 59 | 59 |
| 60 // The delay to use to serve slow URLs. | 60 // The delay to use to serve slow URLs. |
| 61 const CGFloat kSlowURLDelay = 3; | 61 const CGFloat kSlowURLDelay = 3; |
| 62 | 62 |
| 63 // The delay to wait for an element to appear before tapping on it. | 63 // The delay to wait for an element to appear before tapping on it. |
| 64 const CGFloat kWaitElementTimeout = 3; | 64 const CGFloat kWaitElementTimeout = 3; |
| 65 | 65 |
| 66 void ResetTabUsageRecorder() { | 66 void ResetTabUsageRecorder() { |
| 67 GREYAssertTrue(chrome_test_util::ResetTabUsageRecorder(), | 67 GREYAssertTrue(chrome_test_util::ResetTabUsageRecorder(), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 82 } | 82 } |
| 83 | 83 |
| 84 // Wait until |matcher| is accessible (not nil) and tap on it. | 84 // Wait until |matcher| is accessible (not nil) and tap on it. |
| 85 void WaitAndTap(id<GREYMatcher> matcher, NSString* name) { | 85 void WaitAndTap(id<GREYMatcher> matcher, NSString* name) { |
| 86 Wait(matcher, name); | 86 Wait(matcher, name); |
| 87 [[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()]; | 87 [[EarlGrey selectElementWithMatcher:matcher] performAction:grey_tap()]; |
| 88 } | 88 } |
| 89 | 89 |
| 90 // Creates a new main tab and load |url|. Wait until |word| is visible on the | 90 // Creates a new main tab and load |url|. Wait until |word| is visible on the |
| 91 // page. | 91 // page. |
| 92 void NewMainTabWithURL(const GURL& url, const std::string& word) { | 92 void NewMainTabWithURL(const GURL& url, NSString* word) { |
| 93 int number_of_tabs = chrome_test_util::GetMainTabCount(); | 93 int number_of_tabs = chrome_test_util::GetMainTabCount(); |
| 94 chrome_test_util::OpenNewTab(); | 94 chrome_test_util::OpenNewTab(); |
| 95 [ChromeEarlGrey loadURL:url]; | 95 [ChromeEarlGrey loadURL:url]; |
| 96 [[EarlGrey | 96 [ChromeEarlGrey waitForWebViewContainingText:word]; |
| 97 selectElementWithMatcher:chrome_test_util::WebViewContainingText(word)] | |
| 98 assertWithMatcher:grey_notNil()]; | |
| 99 chrome_test_util::AssertMainTabCount(number_of_tabs + 1); | 97 chrome_test_util::AssertMainTabCount(number_of_tabs + 1); |
| 100 } | 98 } |
| 101 | 99 |
| 102 // Opens 2 new tabs with different URLs. | 100 // Opens 2 new tabs with different URLs. |
| 103 void OpenTwoTabs() { | 101 void OpenTwoTabs() { |
| 104 chrome_test_util::CloseAllTabsInCurrentMode(); | 102 chrome_test_util::CloseAllTabsInCurrentMode(); |
| 105 | 103 |
| 106 const GURL url1 = web::test::HttpServer::MakeUrl(kTestUrl1); | 104 const GURL url1 = web::test::HttpServer::MakeUrl(kTestUrl1); |
| 107 const GURL url2 = web::test::HttpServer::MakeUrl(kTestUrl2); | 105 const GURL url2 = web::test::HttpServer::MakeUrl(kTestUrl2); |
| 108 NewMainTabWithURL(url1, kURL1FirstWord); | 106 NewMainTabWithURL(url1, kURL1FirstWord); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 histogramTester.ExpectUniqueSample( | 265 histogramTester.ExpectUniqueSample( |
| 268 kSelectedTabHistogramName, TabUsageRecorder::IN_MEMORY, 1, failureBlock); | 266 kSelectedTabHistogramName, TabUsageRecorder::IN_MEMORY, 1, failureBlock); |
| 269 | 267 |
| 270 // Evict the tab. | 268 // Evict the tab. |
| 271 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); | 269 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); |
| 272 GREYAssertTrue(chrome_test_util::IsIncognitoMode(), | 270 GREYAssertTrue(chrome_test_util::IsIncognitoMode(), |
| 273 @"Failed to switch to incognito mode"); | 271 @"Failed to switch to incognito mode"); |
| 274 | 272 |
| 275 // Switch back to the normal tabs. Should be on tab one. | 273 // Switch back to the normal tabs. Should be on tab one. |
| 276 SwitchToNormalMode(); | 274 SwitchToNormalMode(); |
| 277 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 275 [ChromeEarlGrey waitForWebViewContainingText:kURL1FirstWord]; |
| 278 kURL1FirstWord)] | |
| 279 assertWithMatcher:grey_notNil()]; | |
| 280 | 276 |
| 281 histogramTester.ExpectTotalCount(kSelectedTabHistogramName, 2, failureBlock); | 277 histogramTester.ExpectTotalCount(kSelectedTabHistogramName, 2, failureBlock); |
| 282 histogramTester.ExpectBucketCount(kSelectedTabHistogramName, | 278 histogramTester.ExpectBucketCount(kSelectedTabHistogramName, |
| 283 TabUsageRecorder::EVICTED, 1, failureBlock); | 279 TabUsageRecorder::EVICTED, 1, failureBlock); |
| 284 } | 280 } |
| 285 | 281 |
| 286 // Verifies the UMA metric for page loads before a tab eviction by loading | 282 // Verifies the UMA metric for page loads before a tab eviction by loading |
| 287 // some tabs, forcing a tab eviction, then checking the histogram. | 283 // some tabs, forcing a tab eviction, then checking the histogram. |
| 288 - (void)testPageLoadCountBeforeEvictedTab { | 284 - (void)testPageLoadCountBeforeEvictedTab { |
| 289 web::test::SetUpFileBasedHttpServer(); | 285 web::test::SetUpFileBasedHttpServer(); |
| 290 chrome_test_util::HistogramTester histogramTester; | 286 chrome_test_util::HistogramTester histogramTester; |
| 291 ResetTabUsageRecorder(); | 287 ResetTabUsageRecorder(); |
| 292 const GURL url1 = web::test::HttpServer::MakeUrl(kTestUrl1); | 288 const GURL url1 = web::test::HttpServer::MakeUrl(kTestUrl1); |
| 293 FailureBlock failureBlock = ^(NSString* error) { | 289 FailureBlock failureBlock = ^(NSString* error) { |
| 294 GREYFail(error); | 290 GREYFail(error); |
| 295 }; | 291 }; |
| 296 | 292 |
| 297 // This test opens three tabs. | 293 // This test opens three tabs. |
| 298 const int numberOfTabs = 3; | 294 const int numberOfTabs = 3; |
| 299 chrome_test_util::CloseAllTabsInCurrentMode(); | 295 chrome_test_util::CloseAllTabsInCurrentMode(); |
| 300 // Open three tabs with http:// urls. | 296 // Open three tabs with http:// urls. |
| 301 for (NSUInteger i = 0; i < numberOfTabs; i++) { | 297 for (NSUInteger i = 0; i < numberOfTabs; i++) { |
| 302 chrome_test_util::OpenNewTab(); | 298 chrome_test_util::OpenNewTab(); |
| 303 [ChromeEarlGrey loadURL:url1]; | 299 [ChromeEarlGrey loadURL:url1]; |
| 304 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 300 [ChromeEarlGrey waitForWebViewContainingText:kURL1FirstWord]; |
| 305 kURL1FirstWord)] | |
| 306 assertWithMatcher:grey_notNil()]; | |
| 307 } | 301 } |
| 308 chrome_test_util::AssertMainTabCount(numberOfTabs); | 302 chrome_test_util::AssertMainTabCount(numberOfTabs); |
| 309 | 303 |
| 310 // Switch between the tabs. They are currently in memory. | 304 // Switch between the tabs. They are currently in memory. |
| 311 chrome_test_util::SelectTabAtIndexInCurrentMode(0); | 305 chrome_test_util::SelectTabAtIndexInCurrentMode(0); |
| 312 | 306 |
| 313 // Verify that no page-load count has been recorded. | 307 // Verify that no page-load count has been recorded. |
| 314 histogramTester.ExpectTotalCount(kPageLoadsBeforeEvictedTabSelected, 0, | 308 histogramTester.ExpectTotalCount(kPageLoadsBeforeEvictedTabSelected, 0, |
| 315 failureBlock); | 309 failureBlock); |
| 316 | 310 |
| 317 // Reload each tab. | 311 // Reload each tab. |
| 318 for (NSUInteger i = 0; i < numberOfTabs; i++) { | 312 for (NSUInteger i = 0; i < numberOfTabs; i++) { |
| 319 chrome_test_util::SelectTabAtIndexInCurrentMode(i); | 313 chrome_test_util::SelectTabAtIndexInCurrentMode(i); |
| 320 // Clear the page so that we can check when page reload is complete. | 314 // Clear the page so that we can check when page reload is complete. |
| 321 __block bool finished = false; | 315 __block bool finished = false; |
| 322 chrome_test_util::GetCurrentWebState()->ExecuteJavaScript( | 316 chrome_test_util::GetCurrentWebState()->ExecuteJavaScript( |
| 323 base::UTF8ToUTF16(kClearPageScript), | 317 base::UTF8ToUTF16(kClearPageScript), |
| 324 base::BindBlockArc(^(const base::Value*) { | 318 base::BindBlockArc(^(const base::Value*) { |
| 325 finished = true; | 319 finished = true; |
| 326 })); | 320 })); |
| 327 | 321 |
| 328 GREYAssert(testing::WaitUntilConditionOrTimeout(1.0, | 322 GREYAssert(testing::WaitUntilConditionOrTimeout(1.0, |
| 329 ^{ | 323 ^{ |
| 330 return finished; | 324 return finished; |
| 331 }), | 325 }), |
| 332 @"JavaScript to reload each tab did not finish"); | 326 @"JavaScript to reload each tab did not finish"); |
| 333 [ChromeEarlGreyUI reload]; | 327 [ChromeEarlGreyUI reload]; |
| 334 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 328 [ChromeEarlGrey waitForWebViewContainingText:kURL1FirstWord]; |
| 335 kURL1FirstWord)] | |
| 336 assertWithMatcher:grey_notNil()]; | |
| 337 } | 329 } |
| 338 | 330 |
| 339 // Evict the tab. Create a dummy tab so that switching back to normal mode | 331 // Evict the tab. Create a dummy tab so that switching back to normal mode |
| 340 // does not trigger a reload immediatly. | 332 // does not trigger a reload immediatly. |
| 341 chrome_test_util::OpenNewTab(); | 333 chrome_test_util::OpenNewTab(); |
| 342 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); | 334 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); |
| 343 chrome_test_util::AssertIncognitoTabCount(1); | 335 chrome_test_util::AssertIncognitoTabCount(1); |
| 344 | 336 |
| 345 // Switch back to the normal tabs. Should be on tab one. | 337 // Switch back to the normal tabs. Should be on tab one. |
| 346 SwitchToNormalMode(); | 338 SwitchToNormalMode(); |
| 347 chrome_test_util::SelectTabAtIndexInCurrentMode(0); | 339 chrome_test_util::SelectTabAtIndexInCurrentMode(0); |
| 348 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 340 [ChromeEarlGrey waitForWebViewContainingText:kURL1FirstWord]; |
| 349 kURL1FirstWord)] | |
| 350 assertWithMatcher:grey_notNil()]; | |
| 351 | 341 |
| 352 // Verify that one page-load count has been recorded. It should contain two | 342 // Verify that one page-load count has been recorded. It should contain two |
| 353 // page loads for each tab created. | 343 // page loads for each tab created. |
| 354 histogramTester.ExpectTotalCount(kPageLoadsBeforeEvictedTabSelected, 1, | 344 histogramTester.ExpectTotalCount(kPageLoadsBeforeEvictedTabSelected, 1, |
| 355 failureBlock); | 345 failureBlock); |
| 356 | 346 |
| 357 std::unique_ptr<base::HistogramSamples> samples = | 347 std::unique_ptr<base::HistogramSamples> samples = |
| 358 histogramTester.GetHistogramSamplesSinceCreation( | 348 histogramTester.GetHistogramSamplesSinceCreation( |
| 359 kPageLoadsBeforeEvictedTabSelected); | 349 kPageLoadsBeforeEvictedTabSelected); |
| 360 int sampleSum = samples ? samples->sum() : 0; | 350 int sampleSum = samples ? samples->sum() : 0; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 377 GREYAssertTrue(chrome_test_util::SetCurrentTabsToBeColdStartTabs(), | 367 GREYAssertTrue(chrome_test_util::SetCurrentTabsToBeColdStartTabs(), |
| 378 @"Fail to state tabs as cold start tabs"); | 368 @"Fail to state tabs as cold start tabs"); |
| 379 | 369 |
| 380 // Open two incognito tabs with urls, clearing normal tabs from memory. | 370 // Open two incognito tabs with urls, clearing normal tabs from memory. |
| 381 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); | 371 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); |
| 382 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); | 372 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); |
| 383 chrome_test_util::AssertIncognitoTabCount(2); | 373 chrome_test_util::AssertIncognitoTabCount(2); |
| 384 | 374 |
| 385 // Switch back to the normal tabs. | 375 // Switch back to the normal tabs. |
| 386 SwitchToNormalMode(); | 376 SwitchToNormalMode(); |
| 387 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 377 [ChromeEarlGrey waitForWebViewContainingText:kURL2FirstWord]; |
| 388 kURL2FirstWord)] | |
| 389 assertWithMatcher:grey_notNil()]; | |
| 390 | 378 |
| 391 // Select the other one so it also reloads. | 379 // Select the other one so it also reloads. |
| 392 chrome_test_util::SelectTabAtIndexInCurrentMode(0); | 380 chrome_test_util::SelectTabAtIndexInCurrentMode(0); |
| 393 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 381 [ChromeEarlGrey waitForWebViewContainingText:kURL1FirstWord]; |
| 394 kURL1FirstWord)] | |
| 395 assertWithMatcher:grey_notNil()]; | |
| 396 | |
| 397 FailureBlock failureBlock = ^(NSString* error) { | 382 FailureBlock failureBlock = ^(NSString* error) { |
| 398 GREYFail(error); | 383 GREYFail(error); |
| 399 }; | 384 }; |
| 400 // Make sure that one of the 2 tab loads (excluding the selected tab) is | 385 // Make sure that one of the 2 tab loads (excluding the selected tab) is |
| 401 // counted as a cold start eviction. | 386 // counted as a cold start eviction. |
| 402 histogramTester.ExpectBucketCount(kSelectedTabHistogramName, | 387 histogramTester.ExpectBucketCount(kSelectedTabHistogramName, |
| 403 TabUsageRecorder::EVICTED_DUE_TO_COLD_START, | 388 TabUsageRecorder::EVICTED_DUE_TO_COLD_START, |
| 404 1, failureBlock); | 389 1, failureBlock); |
| 405 | 390 |
| 406 histogramTester.ExpectBucketCount( | 391 histogramTester.ExpectBucketCount( |
| 407 kSelectedTabHistogramName, TabUsageRecorder::IN_MEMORY, 0, failureBlock); | 392 kSelectedTabHistogramName, TabUsageRecorder::IN_MEMORY, 0, failureBlock); |
| 408 // Re-select the same tab and make sure it is not counted again as evicted. | 393 // Re-select the same tab and make sure it is not counted again as evicted. |
| 409 chrome_test_util::SelectTabAtIndexInCurrentMode(1); | 394 chrome_test_util::SelectTabAtIndexInCurrentMode(1); |
| 410 chrome_test_util::SelectTabAtIndexInCurrentMode(0); | 395 chrome_test_util::SelectTabAtIndexInCurrentMode(0); |
| 411 | 396 |
| 412 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 397 [ChromeEarlGrey waitForWebViewContainingText:kURL1FirstWord]; |
| 413 kURL1FirstWord)] | |
| 414 assertWithMatcher:grey_notNil()]; | |
| 415 histogramTester.ExpectBucketCount(kSelectedTabHistogramName, | 398 histogramTester.ExpectBucketCount(kSelectedTabHistogramName, |
| 416 TabUsageRecorder::EVICTED_DUE_TO_COLD_START, | 399 TabUsageRecorder::EVICTED_DUE_TO_COLD_START, |
| 417 1, failureBlock); | 400 1, failureBlock); |
| 418 | 401 |
| 419 histogramTester.ExpectBucketCount( | 402 histogramTester.ExpectBucketCount( |
| 420 kSelectedTabHistogramName, TabUsageRecorder::IN_MEMORY, 2, failureBlock); | 403 kSelectedTabHistogramName, TabUsageRecorder::IN_MEMORY, 2, failureBlock); |
| 421 } | 404 } |
| 422 | 405 |
| 423 // Tests that tabs reloads after backgrounding and eviction. | 406 // Tests that tabs reloads after backgrounding and eviction. |
| 424 - (void)testBackgroundingReloadCount { | 407 - (void)testBackgroundingReloadCount { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 438 @"Fail to simulate tab backgrounding."); | 421 @"Fail to simulate tab backgrounding."); |
| 439 | 422 |
| 440 // Open incognito and clear normal tabs from memory. | 423 // Open incognito and clear normal tabs from memory. |
| 441 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); | 424 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); |
| 442 GREYAssertTrue(chrome_test_util::IsIncognitoMode(), | 425 GREYAssertTrue(chrome_test_util::IsIncognitoMode(), |
| 443 @"Failed to switch to incognito mode"); | 426 @"Failed to switch to incognito mode"); |
| 444 histogramTester.ExpectTotalCount(kEvictedTabReloadTime, 0, failureBlock); | 427 histogramTester.ExpectTotalCount(kEvictedTabReloadTime, 0, failureBlock); |
| 445 | 428 |
| 446 // Switch back to the normal tabs. | 429 // Switch back to the normal tabs. |
| 447 SwitchToNormalMode(); | 430 SwitchToNormalMode(); |
| 448 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 431 [ChromeEarlGrey waitForWebViewContainingText:kURL2FirstWord]; |
| 449 kURL2FirstWord)] | |
| 450 assertWithMatcher:grey_notNil()]; | |
| 451 | 432 |
| 452 const GURL url1 = web::test::HttpServer::MakeUrl(kTestUrl1); | 433 const GURL url1 = web::test::HttpServer::MakeUrl(kTestUrl1); |
| 453 const GURL url2 = web::test::HttpServer::MakeUrl(kTestUrl2); | 434 const GURL url2 = web::test::HttpServer::MakeUrl(kTestUrl2); |
| 454 [[EarlGrey | 435 [[EarlGrey |
| 455 selectElementWithMatcher:chrome_test_util::OmniboxText(url2.GetContent())] | 436 selectElementWithMatcher:chrome_test_util::OmniboxText(url2.GetContent())] |
| 456 assertWithMatcher:grey_notNil()]; | 437 assertWithMatcher:grey_notNil()]; |
| 457 histogramTester.ExpectTotalCount(kEvictedTabReloadTime, 1, failureBlock); | 438 histogramTester.ExpectTotalCount(kEvictedTabReloadTime, 1, failureBlock); |
| 458 | 439 |
| 459 chrome_test_util::SelectTabAtIndexInCurrentMode(0); | 440 chrome_test_util::SelectTabAtIndexInCurrentMode(0); |
| 460 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 441 [ChromeEarlGrey waitForWebViewContainingText:kURL1FirstWord]; |
| 461 kURL1FirstWord)] | |
| 462 assertWithMatcher:grey_notNil()]; | |
| 463 [[EarlGrey | 442 [[EarlGrey |
| 464 selectElementWithMatcher:chrome_test_util::OmniboxText(url1.GetContent())] | 443 selectElementWithMatcher:chrome_test_util::OmniboxText(url1.GetContent())] |
| 465 assertWithMatcher:grey_notNil()]; | 444 assertWithMatcher:grey_notNil()]; |
| 466 histogramTester.ExpectTotalCount(kEvictedTabReloadTime, 2, failureBlock); | 445 histogramTester.ExpectTotalCount(kEvictedTabReloadTime, 2, failureBlock); |
| 467 } | 446 } |
| 468 | 447 |
| 469 // Verify correct recording of metrics when the reloading of an evicted tab | 448 // Verify correct recording of metrics when the reloading of an evicted tab |
| 470 // succeeds. | 449 // succeeds. |
| 471 - (void)testEvictedTabReloadSuccess { | 450 - (void)testEvictedTabReloadSuccess { |
| 472 web::test::SetUpFileBasedHttpServer(); | 451 web::test::SetUpFileBasedHttpServer(); |
| 473 chrome_test_util::HistogramTester histogramTester; | 452 chrome_test_util::HistogramTester histogramTester; |
| 474 FailureBlock failureBlock = ^(NSString* error) { | 453 FailureBlock failureBlock = ^(NSString* error) { |
| 475 GREYFail(error); | 454 GREYFail(error); |
| 476 }; | 455 }; |
| 477 | 456 |
| 478 GURL URL = web::test::HttpServer::MakeUrl(kTestUrl1); | 457 GURL URL = web::test::HttpServer::MakeUrl(kTestUrl1); |
| 479 NewMainTabWithURL(URL, kURL1FirstWord); | 458 NewMainTabWithURL(URL, kURL1FirstWord); |
| 480 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); | 459 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); |
| 481 SwitchToNormalMode(); | 460 SwitchToNormalMode(); |
| 482 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 461 [ChromeEarlGrey waitForWebViewContainingText:kURL1FirstWord]; |
| 483 kURL1FirstWord)] | |
| 484 assertWithMatcher:grey_notNil()]; | |
| 485 | 462 |
| 486 histogramTester.ExpectUniqueSample(kEvictedTabReloadSuccessRate, | 463 histogramTester.ExpectUniqueSample(kEvictedTabReloadSuccessRate, |
| 487 TabUsageRecorder::LOAD_SUCCESS, 1, | 464 TabUsageRecorder::LOAD_SUCCESS, 1, |
| 488 failureBlock); | 465 failureBlock); |
| 489 histogramTester.ExpectUniqueSample(kDidUserWaitForEvictedTabReload, | 466 histogramTester.ExpectUniqueSample(kDidUserWaitForEvictedTabReload, |
| 490 TabUsageRecorder::USER_WAITED, 1, | 467 TabUsageRecorder::USER_WAITED, 1, |
| 491 failureBlock); | 468 failureBlock); |
| 492 histogramTester.ExpectTotalCount(kEvictedTabReloadTime, 1, failureBlock); | 469 histogramTester.ExpectTotalCount(kEvictedTabReloadTime, 1, failureBlock); |
| 493 } | 470 } |
| 494 | 471 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 const GURL slowURL = web::test::HttpServer::MakeUrl("http://slow"); | 553 const GURL slowURL = web::test::HttpServer::MakeUrl("http://slow"); |
| 577 responses[slowURL] = "Slow Page"; | 554 responses[slowURL] = "Slow Page"; |
| 578 | 555 |
| 579 web::test::SetUpHttpServer(base::MakeUnique<HtmlResponseProvider>(responses)); | 556 web::test::SetUpHttpServer(base::MakeUnique<HtmlResponseProvider>(responses)); |
| 580 | 557 |
| 581 chrome_test_util::HistogramTester histogramTester; | 558 chrome_test_util::HistogramTester histogramTester; |
| 582 FailureBlock failureBlock = ^(NSString* error) { | 559 FailureBlock failureBlock = ^(NSString* error) { |
| 583 GREYFail(error); | 560 GREYFail(error); |
| 584 }; | 561 }; |
| 585 | 562 |
| 586 NewMainTabWithURL(slowURL, "Slow"); | 563 NewMainTabWithURL(slowURL, @"Slow"); |
| 587 | 564 |
| 588 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); | 565 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); |
| 589 web::test::SetUpHttpServer(base::MakeUnique<web::DelayedResponseProvider>( | 566 web::test::SetUpHttpServer(base::MakeUnique<web::DelayedResponseProvider>( |
| 590 base::MakeUnique<HtmlResponseProvider>(responses), kSlowURLDelay)); | 567 base::MakeUnique<HtmlResponseProvider>(responses), kSlowURLDelay)); |
| 591 | 568 |
| 592 SwitchToNormalMode(); | 569 SwitchToNormalMode(); |
| 593 | 570 |
| 594 // TODO(crbug.com/640977): EarlGrey synchronize on some animations when a | 571 // TODO(crbug.com/640977): EarlGrey synchronize on some animations when a |
| 595 // page is loading. Need to handle synchronization manually for this test. | 572 // page is loading. Need to handle synchronization manually for this test. |
| 596 [[GREYConfiguration sharedInstance] | 573 [[GREYConfiguration sharedInstance] |
| (...skipping 16 matching lines...) Expand all Loading... |
| 613 responses[slowURL] = "Slow Page"; | 590 responses[slowURL] = "Slow Page"; |
| 614 | 591 |
| 615 web::test::SetUpHttpServer(base::MakeUnique<web::DelayedResponseProvider>( | 592 web::test::SetUpHttpServer(base::MakeUnique<web::DelayedResponseProvider>( |
| 616 base::MakeUnique<HtmlResponseProvider>(responses), kSlowURLDelay)); | 593 base::MakeUnique<HtmlResponseProvider>(responses), kSlowURLDelay)); |
| 617 | 594 |
| 618 chrome_test_util::HistogramTester histogramTester; | 595 chrome_test_util::HistogramTester histogramTester; |
| 619 FailureBlock failureBlock = ^(NSString* error) { | 596 FailureBlock failureBlock = ^(NSString* error) { |
| 620 GREYFail(error); | 597 GREYFail(error); |
| 621 }; | 598 }; |
| 622 | 599 |
| 623 NewMainTabWithURL(slowURL, responses[slowURL]); | 600 NewMainTabWithURL(slowURL, base::SysUTF8ToNSString(responses[slowURL])); |
| 624 | 601 |
| 625 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); | 602 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); |
| 626 | 603 |
| 627 SwitchToNormalMode(); | 604 SwitchToNormalMode(); |
| 628 // TODO(crbug.com/640977): EarlGrey synchronize on some animations when a | 605 // TODO(crbug.com/640977): EarlGrey synchronize on some animations when a |
| 629 // page is loading. Need to handle synchronization manually for this test. | 606 // page is loading. Need to handle synchronization manually for this test. |
| 630 [[GREYConfiguration sharedInstance] | 607 [[GREYConfiguration sharedInstance] |
| 631 setValue:@(NO) | 608 setValue:@(NO) |
| 632 forConfigKey:kGREYConfigKeySynchronizationEnabled]; | 609 forConfigKey:kGREYConfigKeySynchronizationEnabled]; |
| 633 OpenSettingsMenuUnsynced(); | 610 OpenSettingsMenuUnsynced(); |
| 634 OpenSettingsSubMenuUnsynced(IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY); | 611 OpenSettingsSubMenuUnsynced(IDS_OPTIONS_ADVANCED_SECTION_TITLE_PRIVACY); |
| 635 Wait(grey_accessibilityID(kPrivacyCollectionViewId), | 612 Wait(grey_accessibilityID(kPrivacyCollectionViewId), |
| 636 @"Privacy settings view."); | 613 @"Privacy settings view."); |
| 637 | 614 |
| 638 WaitAndTap(chrome_test_util::NavigationBarDoneButton(), @"Close settings"); | 615 WaitAndTap(chrome_test_util::NavigationBarDoneButton(), @"Close settings"); |
| 639 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; | 616 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; |
| 640 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 617 [ChromeEarlGrey |
| 641 responses[slowURL])] | 618 waitForWebViewContainingText:base::SysUTF8ToNSString(responses[slowURL])]; |
| 642 assertWithMatcher:grey_notNil()]; | |
| 643 | 619 |
| 644 [[GREYConfiguration sharedInstance] | 620 [[GREYConfiguration sharedInstance] |
| 645 setValue:@(YES) | 621 setValue:@(YES) |
| 646 forConfigKey:kGREYConfigKeySynchronizationEnabled]; | 622 forConfigKey:kGREYConfigKeySynchronizationEnabled]; |
| 647 | 623 |
| 648 histogramTester.ExpectBucketCount(kDidUserWaitForEvictedTabReload, | 624 histogramTester.ExpectBucketCount(kDidUserWaitForEvictedTabReload, |
| 649 TabUsageRecorder::USER_DID_NOT_WAIT, 0, | 625 TabUsageRecorder::USER_DID_NOT_WAIT, 0, |
| 650 failureBlock); | 626 failureBlock); |
| 651 histogramTester.ExpectBucketCount(kDidUserWaitForEvictedTabReload, | 627 histogramTester.ExpectBucketCount(kDidUserWaitForEvictedTabReload, |
| 652 TabUsageRecorder::USER_WAITED, 1, | 628 TabUsageRecorder::USER_WAITED, 1, |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 // Tests that redirecting pages are not reloaded after eviction. | 708 // Tests that redirecting pages are not reloaded after eviction. |
| 733 - (void)testPageRedirect { | 709 - (void)testPageRedirect { |
| 734 GURL redirectURL = web::test::HttpServer::MakeUrl( | 710 GURL redirectURL = web::test::HttpServer::MakeUrl( |
| 735 "http://ios/testing/data/http_server_files/redirect_refresh.html"); | 711 "http://ios/testing/data/http_server_files/redirect_refresh.html"); |
| 736 GURL destinationURL = web::test::HttpServer::MakeUrl( | 712 GURL destinationURL = web::test::HttpServer::MakeUrl( |
| 737 "http://ios/testing/data/http_server_files/destination.html"); | 713 "http://ios/testing/data/http_server_files/destination.html"); |
| 738 web::test::SetUpFileBasedHttpServer(); | 714 web::test::SetUpFileBasedHttpServer(); |
| 739 chrome_test_util::HistogramTester histogramTester; | 715 chrome_test_util::HistogramTester histogramTester; |
| 740 ResetTabUsageRecorder(); | 716 ResetTabUsageRecorder(); |
| 741 | 717 |
| 742 NewMainTabWithURL(redirectURL, "arrived"); | 718 NewMainTabWithURL(redirectURL, @"arrived"); |
| 743 | 719 |
| 744 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( | 720 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 745 destinationURL.GetContent())] | 721 destinationURL.GetContent())] |
| 746 assertWithMatcher:grey_notNil()]; | 722 assertWithMatcher:grey_notNil()]; |
| 747 | 723 |
| 748 NSUInteger tabIndex = chrome_test_util::GetMainTabCount() - 1; | 724 NSUInteger tabIndex = chrome_test_util::GetMainTabCount() - 1; |
| 749 chrome_test_util::OpenNewTab(); | 725 chrome_test_util::OpenNewTab(); |
| 750 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); | 726 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); |
| 751 SwitchToNormalMode(); | 727 SwitchToNormalMode(); |
| 752 chrome_test_util::SelectTabAtIndexInCurrentMode(tabIndex); | 728 chrome_test_util::SelectTabAtIndexInCurrentMode(tabIndex); |
| 753 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 729 [ChromeEarlGrey waitForWebViewContainingText:@"arrived"]; |
| 754 "arrived")] | |
| 755 assertWithMatcher:grey_notNil()]; | |
| 756 | 730 |
| 757 FailureBlock failureBlock = ^(NSString* error) { | 731 FailureBlock failureBlock = ^(NSString* error) { |
| 758 GREYFail(error); | 732 GREYFail(error); |
| 759 }; | 733 }; |
| 760 // Verify that one page-load count has been recorded. It should contain a | 734 // Verify that one page-load count has been recorded. It should contain a |
| 761 // sum of 1 - one sample with 1 page load. | 735 // sum of 1 - one sample with 1 page load. |
| 762 histogramTester.ExpectTotalCount(kPageLoadsBeforeEvictedTabSelected, 1, | 736 histogramTester.ExpectTotalCount(kPageLoadsBeforeEvictedTabSelected, 1, |
| 763 failureBlock); | 737 failureBlock); |
| 764 | 738 |
| 765 std::unique_ptr<base::HistogramSamples> samples = | 739 std::unique_ptr<base::HistogramSamples> samples = |
| (...skipping 15 matching lines...) Expand all Loading... |
| 781 web::test::HttpServer::MakeUrl("http://destination"); | 755 web::test::HttpServer::MakeUrl("http://destination"); |
| 782 responses[initialURL] = base::StringPrintf( | 756 responses[initialURL] = base::StringPrintf( |
| 783 "<body><a style='margin-left:50px' href='%s' id='link'>link</a></body>", | 757 "<body><a style='margin-left:50px' href='%s' id='link'>link</a></body>", |
| 784 destinationURL.spec().c_str()); | 758 destinationURL.spec().c_str()); |
| 785 responses[destinationURL] = "Whee!"; | 759 responses[destinationURL] = "Whee!"; |
| 786 web::test::SetUpHttpServer(base::MakeUnique<HtmlResponseProvider>(responses)); | 760 web::test::SetUpHttpServer(base::MakeUnique<HtmlResponseProvider>(responses)); |
| 787 chrome_test_util::HistogramTester histogramTester; | 761 chrome_test_util::HistogramTester histogramTester; |
| 788 ResetTabUsageRecorder(); | 762 ResetTabUsageRecorder(); |
| 789 | 763 |
| 790 // Open a tab with a link to click. | 764 // Open a tab with a link to click. |
| 791 NewMainTabWithURL(initialURL, "link"); | 765 NewMainTabWithURL(initialURL, @"link"); |
| 792 // Click the link. | 766 // Click the link. |
| 793 chrome_test_util::TapWebViewElementWithId("link"); | 767 chrome_test_util::TapWebViewElementWithId("link"); |
| 794 | 768 |
| 795 [[EarlGrey | 769 [ChromeEarlGrey waitForWebViewContainingText:@"Whee"]; |
| 796 selectElementWithMatcher:chrome_test_util::WebViewContainingText("Whee")] | |
| 797 assertWithMatcher:grey_notNil()]; | |
| 798 | |
| 799 NSUInteger tabIndex = chrome_test_util::GetMainTabCount() - 1; | 770 NSUInteger tabIndex = chrome_test_util::GetMainTabCount() - 1; |
| 800 chrome_test_util::OpenNewTab(); | 771 chrome_test_util::OpenNewTab(); |
| 801 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); | 772 OpenNewIncognitoTabUsingUIAndEvictMainTabs(); |
| 802 SwitchToNormalMode(); | 773 SwitchToNormalMode(); |
| 803 chrome_test_util::SelectTabAtIndexInCurrentMode(tabIndex); | 774 chrome_test_util::SelectTabAtIndexInCurrentMode(tabIndex); |
| 804 [[EarlGrey | 775 [ChromeEarlGrey waitForWebViewContainingText:@"Whee"]; |
| 805 selectElementWithMatcher:chrome_test_util::WebViewContainingText("Whee")] | |
| 806 assertWithMatcher:grey_notNil()]; | |
| 807 | 776 |
| 808 // Verify that the page-load count has been recorded. It should contain a | 777 // Verify that the page-load count has been recorded. It should contain a |
| 809 // sum of 2 - one sample with 2 page loads. | 778 // sum of 2 - one sample with 2 page loads. |
| 810 std::unique_ptr<base::HistogramSamples> samples = | 779 std::unique_ptr<base::HistogramSamples> samples = |
| 811 histogramTester.GetHistogramSamplesSinceCreation( | 780 histogramTester.GetHistogramSamplesSinceCreation( |
| 812 kPageLoadsBeforeEvictedTabSelected); | 781 kPageLoadsBeforeEvictedTabSelected); |
| 813 int sampleSum = samples->sum(); | 782 int sampleSum = samples->sum(); |
| 814 GREYAssertEqual(sampleSum, 2, @"Expected page loads is %d, actual %d.", 2, | 783 GREYAssertEqual(sampleSum, 2, @"Expected page loads is %d, actual %d.", 2, |
| 815 sampleSum); | 784 sampleSum); |
| 816 | 785 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 837 "<body style='width:auto; height:auto;'><a href='%s' " | 806 "<body style='width:auto; height:auto;'><a href='%s' " |
| 838 "id='link'><div style='width:100%%; " | 807 "id='link'><div style='width:100%%; " |
| 839 "height:100%%;'>link</div></a></body>", | 808 "height:100%%;'>link</div></a></body>", |
| 840 destinationURL.spec().c_str()); | 809 destinationURL.spec().c_str()); |
| 841 responses[destinationURL] = "Whee!"; | 810 responses[destinationURL] = "Whee!"; |
| 842 web::test::SetUpHttpServer(base::MakeUnique<HtmlResponseProvider>(responses)); | 811 web::test::SetUpHttpServer(base::MakeUnique<HtmlResponseProvider>(responses)); |
| 843 chrome_test_util::HistogramTester histogramTester; | 812 chrome_test_util::HistogramTester histogramTester; |
| 844 ResetTabUsageRecorder(); | 813 ResetTabUsageRecorder(); |
| 845 | 814 |
| 846 // Open a tab with a link to click. | 815 // Open a tab with a link to click. |
| 847 NewMainTabWithURL(initialURL, "link"); | 816 NewMainTabWithURL(initialURL, @"link"); |
| 848 | 817 |
| 849 int numberOfTabs = chrome_test_util::GetMainTabCount(); | 818 int numberOfTabs = chrome_test_util::GetMainTabCount(); |
| 850 id<GREYMatcher> webViewMatcher = | 819 id<GREYMatcher> webViewMatcher = |
| 851 web::WebViewInWebState(chrome_test_util::GetCurrentWebState()); | 820 web::WebViewInWebState(chrome_test_util::GetCurrentWebState()); |
| 852 [[EarlGrey selectElementWithMatcher:webViewMatcher] | 821 [[EarlGrey selectElementWithMatcher:webViewMatcher] |
| 853 performAction:chrome_test_util::LongPressElementForContextMenu( | 822 performAction:chrome_test_util::LongPressElementForContextMenu( |
| 854 "link", true /* menu should appear */)]; | 823 "link", true /* menu should appear */)]; |
| 855 | 824 |
| 856 [[EarlGrey selectElementWithMatcher:OpenLinkInNewTabButton()] | 825 [[EarlGrey selectElementWithMatcher:OpenLinkInNewTabButton()] |
| 857 performAction:grey_tap()]; | 826 performAction:grey_tap()]; |
| 858 chrome_test_util::AssertMainTabCount(numberOfTabs + 1); | 827 chrome_test_util::AssertMainTabCount(numberOfTabs + 1); |
| 859 | 828 |
| 860 SelectTabUsingUI(base::SysUTF8ToNSString(destinationURL.GetContent())); | 829 SelectTabUsingUI(base::SysUTF8ToNSString(destinationURL.GetContent())); |
| 861 | 830 |
| 862 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; | 831 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; |
| 863 [[EarlGrey | 832 [ChromeEarlGrey waitForWebViewContainingText:@"Whee"]; |
| 864 selectElementWithMatcher:chrome_test_util::WebViewContainingText("Whee")] | |
| 865 assertWithMatcher:grey_notNil()]; | |
| 866 | 833 |
| 867 FailureBlock failureBlock = ^(NSString* error) { | 834 FailureBlock failureBlock = ^(NSString* error) { |
| 868 GREYFail(error); | 835 GREYFail(error); |
| 869 }; | 836 }; |
| 870 histogramTester.ExpectTotalCount(kSelectedTabHistogramName, 1, failureBlock); | 837 histogramTester.ExpectTotalCount(kSelectedTabHistogramName, 1, failureBlock); |
| 871 histogramTester.ExpectBucketCount( | 838 histogramTester.ExpectBucketCount( |
| 872 kSelectedTabHistogramName, TabUsageRecorder::IN_MEMORY, 1, failureBlock); | 839 kSelectedTabHistogramName, TabUsageRecorder::IN_MEMORY, 1, failureBlock); |
| 873 } | 840 } |
| 874 | 841 |
| 875 // Tests that opening tabs from external app will not cause tab eviction. | 842 // 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... |
| 936 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; | 903 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; |
| 937 } | 904 } |
| 938 // The deleted tabs are purged during foregrounding and backgrounding. | 905 // The deleted tabs are purged during foregrounding and backgrounding. |
| 939 chrome_test_util::SimulateTabsBackgrounding(); | 906 chrome_test_util::SimulateTabsBackgrounding(); |
| 940 // Make sure |evicted_tabs_| purged the deleted tabs. | 907 // Make sure |evicted_tabs_| purged the deleted tabs. |
| 941 int evicted = chrome_test_util::GetEvictedMainTabCount(); | 908 int evicted = chrome_test_util::GetEvictedMainTabCount(); |
| 942 GREYAssertEqual(evicted, 0, @"Check number of evicted tabs"); | 909 GREYAssertEqual(evicted, 0, @"Check number of evicted tabs"); |
| 943 } | 910 } |
| 944 | 911 |
| 945 @end | 912 @end |
| OLD | NEW |