Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(47)

Unified Diff: ios/chrome/browser/metrics/tab_usage_recorder_egtest.mm

Issue 2798773002: Create ChromeEarlGrey waitForWebViewContainingText. (Closed)
Patch Set: better formatting Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/metrics/tab_usage_recorder_egtest.mm
diff --git a/ios/chrome/browser/metrics/tab_usage_recorder_egtest.mm b/ios/chrome/browser/metrics/tab_usage_recorder_egtest.mm
index 29e1a41696b3b59cf7a8af832f21e70b3d0d6f90..f4a9881bb538ef0641031ac9c8ebb2b4d3d23cb1 100644
--- a/ios/chrome/browser/metrics/tab_usage_recorder_egtest.mm
+++ b/ios/chrome/browser/metrics/tab_usage_recorder_egtest.mm
@@ -51,10 +51,10 @@ namespace {
const char kTestUrl1[] =
"http://ios/testing/data/http_server_files/memory_usage.html";
-const char kURL1FirstWord[] = "Page";
+NSString* const kURL1FirstWord = @"Page";
const char kTestUrl2[] =
"http://ios/testing/data/http_server_files/fullscreen.html";
-const char kURL2FirstWord[] = "Rugby";
+NSString* const kURL2FirstWord = @"Rugby";
const char kClearPageScript[] = "document.body.innerHTML='';";
// The delay to use to serve slow URLs.
@@ -89,13 +89,11 @@ void WaitAndTap(id<GREYMatcher> matcher, NSString* name) {
// Creates a new main tab and load |url|. Wait until |word| is visible on the
// page.
-void NewMainTabWithURL(const GURL& url, const std::string& word) {
+void NewMainTabWithURL(const GURL& url, NSString* word) {
int number_of_tabs = chrome_test_util::GetMainTabCount();
chrome_test_util::OpenNewTab();
[ChromeEarlGrey loadURL:url];
- [[EarlGrey
- selectElementWithMatcher:chrome_test_util::WebViewContainingText(word)]
- assertWithMatcher:grey_notNil()];
+ [ChromeEarlGrey waitForWebViewContainingText:word];
chrome_test_util::AssertMainTabCount(number_of_tabs + 1);
}
@@ -274,9 +272,7 @@ void SelectTabUsingUI(NSString* title) {
// Switch back to the normal tabs. Should be on tab one.
SwitchToNormalMode();
- [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
- kURL1FirstWord)]
- assertWithMatcher:grey_notNil()];
+ [ChromeEarlGrey waitForWebViewContainingText:kURL1FirstWord];
histogramTester.ExpectTotalCount(kSelectedTabHistogramName, 2, failureBlock);
histogramTester.ExpectBucketCount(kSelectedTabHistogramName,
@@ -301,9 +297,7 @@ void SelectTabUsingUI(NSString* title) {
for (NSUInteger i = 0; i < numberOfTabs; i++) {
chrome_test_util::OpenNewTab();
[ChromeEarlGrey loadURL:url1];
- [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
- kURL1FirstWord)]
- assertWithMatcher:grey_notNil()];
+ [ChromeEarlGrey waitForWebViewContainingText:kURL1FirstWord];
}
chrome_test_util::AssertMainTabCount(numberOfTabs);
@@ -331,9 +325,7 @@ void SelectTabUsingUI(NSString* title) {
}),
@"JavaScript to reload each tab did not finish");
[ChromeEarlGreyUI reload];
- [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
- kURL1FirstWord)]
- assertWithMatcher:grey_notNil()];
+ [ChromeEarlGrey waitForWebViewContainingText:kURL1FirstWord];
}
// Evict the tab. Create a dummy tab so that switching back to normal mode
@@ -345,9 +337,7 @@ void SelectTabUsingUI(NSString* title) {
// Switch back to the normal tabs. Should be on tab one.
SwitchToNormalMode();
chrome_test_util::SelectTabAtIndexInCurrentMode(0);
- [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
- kURL1FirstWord)]
- assertWithMatcher:grey_notNil()];
+ [ChromeEarlGrey waitForWebViewContainingText:kURL1FirstWord];
// Verify that one page-load count has been recorded. It should contain two
// page loads for each tab created.
@@ -384,16 +374,11 @@ void SelectTabUsingUI(NSString* title) {
// Switch back to the normal tabs.
SwitchToNormalMode();
- [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
- kURL2FirstWord)]
- assertWithMatcher:grey_notNil()];
+ [ChromeEarlGrey waitForWebViewContainingText:kURL2FirstWord];
// Select the other one so it also reloads.
chrome_test_util::SelectTabAtIndexInCurrentMode(0);
- [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
- kURL1FirstWord)]
- assertWithMatcher:grey_notNil()];
-
+ [ChromeEarlGrey waitForWebViewContainingText:kURL1FirstWord];
FailureBlock failureBlock = ^(NSString* error) {
GREYFail(error);
};
@@ -409,9 +394,7 @@ void SelectTabUsingUI(NSString* title) {
chrome_test_util::SelectTabAtIndexInCurrentMode(1);
chrome_test_util::SelectTabAtIndexInCurrentMode(0);
- [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
- kURL1FirstWord)]
- assertWithMatcher:grey_notNil()];
+ [ChromeEarlGrey waitForWebViewContainingText:kURL1FirstWord];
histogramTester.ExpectBucketCount(kSelectedTabHistogramName,
TabUsageRecorder::EVICTED_DUE_TO_COLD_START,
1, failureBlock);
@@ -445,9 +428,7 @@ void SelectTabUsingUI(NSString* title) {
// Switch back to the normal tabs.
SwitchToNormalMode();
- [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
- kURL2FirstWord)]
- assertWithMatcher:grey_notNil()];
+ [ChromeEarlGrey waitForWebViewContainingText:kURL2FirstWord];
const GURL url1 = web::test::HttpServer::MakeUrl(kTestUrl1);
const GURL url2 = web::test::HttpServer::MakeUrl(kTestUrl2);
@@ -457,9 +438,7 @@ void SelectTabUsingUI(NSString* title) {
histogramTester.ExpectTotalCount(kEvictedTabReloadTime, 1, failureBlock);
chrome_test_util::SelectTabAtIndexInCurrentMode(0);
- [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
- kURL1FirstWord)]
- assertWithMatcher:grey_notNil()];
+ [ChromeEarlGrey waitForWebViewContainingText:kURL1FirstWord];
[[EarlGrey
selectElementWithMatcher:chrome_test_util::OmniboxText(url1.GetContent())]
assertWithMatcher:grey_notNil()];
@@ -479,9 +458,7 @@ void SelectTabUsingUI(NSString* title) {
NewMainTabWithURL(URL, kURL1FirstWord);
OpenNewIncognitoTabUsingUIAndEvictMainTabs();
SwitchToNormalMode();
- [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
- kURL1FirstWord)]
- assertWithMatcher:grey_notNil()];
+ [ChromeEarlGrey waitForWebViewContainingText:kURL1FirstWord];
histogramTester.ExpectUniqueSample(kEvictedTabReloadSuccessRate,
TabUsageRecorder::LOAD_SUCCESS, 1,
@@ -583,7 +560,7 @@ void SelectTabUsingUI(NSString* title) {
GREYFail(error);
};
- NewMainTabWithURL(slowURL, "Slow");
+ NewMainTabWithURL(slowURL, @"Slow");
OpenNewIncognitoTabUsingUIAndEvictMainTabs();
web::test::SetUpHttpServer(base::MakeUnique<web::DelayedResponseProvider>(
@@ -620,7 +597,7 @@ void SelectTabUsingUI(NSString* title) {
GREYFail(error);
};
- NewMainTabWithURL(slowURL, responses[slowURL]);
+ NewMainTabWithURL(slowURL, base::SysUTF8ToNSString(responses[slowURL]));
OpenNewIncognitoTabUsingUIAndEvictMainTabs();
@@ -637,9 +614,8 @@ void SelectTabUsingUI(NSString* title) {
WaitAndTap(chrome_test_util::NavigationBarDoneButton(), @"Close settings");
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
- [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
- responses[slowURL])]
- assertWithMatcher:grey_notNil()];
+ [ChromeEarlGrey
+ waitForWebViewContainingText:base::SysUTF8ToNSString(responses[slowURL])];
[[GREYConfiguration sharedInstance]
setValue:@(YES)
@@ -739,7 +715,7 @@ void SelectTabUsingUI(NSString* title) {
chrome_test_util::HistogramTester histogramTester;
ResetTabUsageRecorder();
- NewMainTabWithURL(redirectURL, "arrived");
+ NewMainTabWithURL(redirectURL, @"arrived");
[[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText(
destinationURL.GetContent())]
@@ -750,9 +726,7 @@ void SelectTabUsingUI(NSString* title) {
OpenNewIncognitoTabUsingUIAndEvictMainTabs();
SwitchToNormalMode();
chrome_test_util::SelectTabAtIndexInCurrentMode(tabIndex);
- [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
- "arrived")]
- assertWithMatcher:grey_notNil()];
+ [ChromeEarlGrey waitForWebViewContainingText:@"arrived"];
FailureBlock failureBlock = ^(NSString* error) {
GREYFail(error);
@@ -788,22 +762,17 @@ void SelectTabUsingUI(NSString* title) {
ResetTabUsageRecorder();
// Open a tab with a link to click.
- NewMainTabWithURL(initialURL, "link");
+ NewMainTabWithURL(initialURL, @"link");
// Click the link.
chrome_test_util::TapWebViewElementWithId("link");
- [[EarlGrey
- selectElementWithMatcher:chrome_test_util::WebViewContainingText("Whee")]
- assertWithMatcher:grey_notNil()];
-
+ [ChromeEarlGrey waitForWebViewContainingText:@"Whee"];
NSUInteger tabIndex = chrome_test_util::GetMainTabCount() - 1;
chrome_test_util::OpenNewTab();
OpenNewIncognitoTabUsingUIAndEvictMainTabs();
SwitchToNormalMode();
chrome_test_util::SelectTabAtIndexInCurrentMode(tabIndex);
- [[EarlGrey
- selectElementWithMatcher:chrome_test_util::WebViewContainingText("Whee")]
- assertWithMatcher:grey_notNil()];
+ [ChromeEarlGrey waitForWebViewContainingText:@"Whee"];
// Verify that the page-load count has been recorded. It should contain a
// sum of 2 - one sample with 2 page loads.
@@ -844,7 +813,7 @@ void SelectTabUsingUI(NSString* title) {
ResetTabUsageRecorder();
// Open a tab with a link to click.
- NewMainTabWithURL(initialURL, "link");
+ NewMainTabWithURL(initialURL, @"link");
int numberOfTabs = chrome_test_util::GetMainTabCount();
id<GREYMatcher> webViewMatcher =
@@ -860,9 +829,7 @@ void SelectTabUsingUI(NSString* title) {
SelectTabUsingUI(base::SysUTF8ToNSString(destinationURL.GetContent()));
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
- [[EarlGrey
- selectElementWithMatcher:chrome_test_util::WebViewContainingText("Whee")]
- assertWithMatcher:grey_notNil()];
+ [ChromeEarlGrey waitForWebViewContainingText:@"Whee"];
FailureBlock failureBlock = ^(NSString* error) {
GREYFail(error);

Powered by Google App Engine
This is Rietveld 408576698