Chromium Code Reviews| Index: ios/chrome/browser/ui/settings/settings_egtest.mm |
| diff --git a/ios/chrome/browser/ui/settings/settings_egtest.mm b/ios/chrome/browser/ui/settings/settings_egtest.mm |
| index 2c18971ac806df1614f158ad74af625b82deeb4c..778d672495f5c0bef3b63931e1f93814cae7e712 100644 |
| --- a/ios/chrome/browser/ui/settings/settings_egtest.mm |
| +++ b/ios/chrome/browser/ui/settings/settings_egtest.mm |
| @@ -164,27 +164,32 @@ |
| return ButtonWithAccessibilityLabelId(IDS_IOS_PASSWORD_MANAGER_SAVE_BUTTON); |
| } |
| -// Asserts that there is no cookie in current web state. |
| -void AssertNoCookieExists() { |
| - NSError* error = nil; |
| +// Returns true if there is no cookie in current web state. |
| +bool WebStateHasNoCookie() { |
| chrome_test_util::ExecuteJavaScript( |
| - base::SysUTF8ToNSString(kJavaScriptGetCookies), &error); |
| + base::SysUTF8ToNSString(kJavaScriptGetCookies), nil); |
| + NSError* error = nil; |
| [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| kNoCookieText)] |
| - assertWithMatcher:grey_notNil()]; |
| + assertWithMatcher:grey_notNil() |
| + error:&error]; |
| + |
| + return error == nil; |
| } |
| -// Asserts |cookie| exists in current web state. |
| -void AssertCookieExists(const char cookie[]) { |
| - NSError* error = nil; |
| +// Returns true if |cookie| is the only cookie exists in current web state. |
|
baxley
2017/03/08 16:20:50
will this return true if it's the "only" cookie? I
liaoyuke
2017/03/08 21:27:26
Resolved per offline discussion.
|
| +bool WebStateHasCookie(const char cookie[]) { |
| chrome_test_util::ExecuteJavaScript( |
| - base::SysUTF8ToNSString(kJavaScriptGetCookies), &error); |
| + base::SysUTF8ToNSString(kJavaScriptGetCookies), nil); |
| NSString* const expectedCookieText = |
| [NSString stringWithFormat:@"OK: %@", base::SysUTF8ToNSString(cookie)]; |
| + NSError* error = nil; |
| [[EarlGrey |
| selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| base::SysNSStringToUTF8(expectedCookieText))] |
| - assertWithMatcher:grey_notNil()]; |
| + assertWithMatcher:grey_notNil() |
| + error:&error]; |
|
baxley
2017/03/08 16:20:50
Sorry, I'm not great at reading regex. Could you c
liaoyuke
2017/03/08 21:27:26
Resolved per offline discussion.
|
| + return error == nil; |
| } |
| // Run as a task to check if a certificate has been added to the ChannelIDStore. |
| @@ -687,7 +692,9 @@ - (void)testClearCookies { |
| [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| kResponse)] |
| assertWithMatcher:grey_notNil()]; |
| - AssertNoCookieExists(); |
| + |
| + GREYAssertTrue(WebStateHasNoCookie(), |
| + @"Web state is expected to have no cookie."); |
| // Visit |kUrlWithSetCookie| to set a cookie and then load |kUrl| to check it |
| // is still set. |
| @@ -700,7 +707,10 @@ - (void)testClearCookies { |
| kResponse)] |
| assertWithMatcher:grey_notNil()]; |
| - AssertCookieExists(kCookie); |
| + NSString* const errorMessage = [NSString |
| + stringWithFormat:@"Web state is expected to have following cookie: %@.", |
| + base::SysUTF8ToNSString(kCookie)]; |
| + GREYAssertTrue(WebStateHasCookie(kCookie), errorMessage); |
| // Restore the Clear Browsing Data checkmarks prefs to their default state in |
| // Teardown. |
| @@ -716,7 +726,8 @@ - (void)testClearCookies { |
| [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| kResponse)] |
| assertWithMatcher:grey_notNil()]; |
| - AssertNoCookieExists(); |
| + GREYAssertTrue(WebStateHasNoCookie(), |
| + @"Web state is expected to have no cookie."); |
| chrome_test_util::CloseAllTabs(); |
| } |