Chromium Code Reviews| Index: ios/chrome/browser/metrics/external_url_tab_usage_recorder_egtest.mm |
| diff --git a/ios/chrome/browser/metrics/external_url_tab_usage_recorder_egtest.mm b/ios/chrome/browser/metrics/external_url_tab_usage_recorder_egtest.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5075d1414dd881b3d67ab8c1474875d6f4092c43 |
| --- /dev/null |
| +++ b/ios/chrome/browser/metrics/external_url_tab_usage_recorder_egtest.mm |
| @@ -0,0 +1,61 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import <EarlGrey/EarlGrey.h> |
| + |
| +#import "ios/chrome/browser/metrics/tab_usage_recorder.h" |
| +#import "ios/chrome/browser/metrics/tab_usage_recorder_test_util.h" |
| +#import "ios/chrome/test/app/histogram_test_util.h" |
| +#import "ios/chrome/test/app/tab_test_util.h" |
| +#import "ios/chrome/test/earl_grey/chrome_earl_grey.h" |
| +#import "ios/chrome/test/earl_grey/chrome_test_case.h" |
| +#include "ios/web/public/test/http_server_util.h" |
| + |
| +#if !defined(__has_feature) || !__has_feature(objc_arc) |
| +#error "This file requires ARC support." |
| +#endif |
| + |
| +namespace { |
| + |
| +const char kTestUrl[] = |
| + "http://ios/testing/data/http_server_files/memory_usage.html"; |
| + |
| +} // namespace |
| + |
| +// Test for the TabUsageRecorder class. |
|
baxley
2017/05/01 23:20:06
Update comment to mention external URL tests for T
lpromero
2017/05/02 13:56:01
Done.
|
| +@interface ExternalURLTabUsageRecorderTestCase : ChromeTestCase |
| +@end |
| + |
| +@implementation ExternalURLTabUsageRecorderTestCase |
| + |
| +// Verify correct recording of metrics when the reloading of an evicted tab |
| +// fails. |
| +- (void)testEvictedTabReloadFailure { |
| + web::test::SetUpFileBasedHttpServer(); |
| + chrome_test_util::HistogramTester histogramTester; |
| + FailureBlock failureBlock = ^(NSString* error) { |
| + GREYFail(error); |
| + }; |
| + |
| + // This URL is purposely invalid so it triggers a navigation error. |
| + GURL invalidURL(kTestUrl); |
| + |
| + chrome_test_util::OpenNewTab(); |
| + [ChromeEarlGrey loadURL:invalidURL]; |
| + [ChromeEarlGrey waitForErrorPage]; |
| + tab_usage_recorder_test_util::OpenNewIncognitoTabUsingUIAndEvictMainTabs(); |
| + |
| + tab_usage_recorder_test_util::SwitchToNormalMode(); |
| + [ChromeEarlGrey waitForErrorPage]; |
| + |
| + histogramTester.ExpectUniqueSample(kEvictedTabReloadSuccessRate, |
| + TabUsageRecorder::LOAD_FAILURE, 1, |
| + failureBlock); |
| + histogramTester.ExpectUniqueSample(kDidUserWaitForEvictedTabReload, |
| + TabUsageRecorder::USER_WAITED, 1, |
| + failureBlock); |
| + histogramTester.ExpectTotalCount(kEvictedTabReloadTime, 0, failureBlock); |
| +} |
| + |
| +@end |