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

Side by Side Diff: ios/chrome/browser/ui/settings/settings_egtest.mm

Issue 2734963004: Refactor Assert[No]CookieExists to return a boolean (Closed)
Patch Set: Refactor Assert[No]CookieExists to return a boolean Created 3 years, 9 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <UIKit/UIKit.h> 6 #import <UIKit/UIKit.h>
7 #import <XCTest/XCTest.h> 7 #import <XCTest/XCTest.h>
8 #include <map> 8 #include <map>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 157 }
158 // Matcher for the Privacy Translate Settings button on the privacy UI. 158 // Matcher for the Privacy Translate Settings button on the privacy UI.
159 id<GREYMatcher> TranslateSettingsButton() { 159 id<GREYMatcher> TranslateSettingsButton() {
160 return ButtonWithAccessibilityLabelId(IDS_IOS_TRANSLATE_SETTING); 160 return ButtonWithAccessibilityLabelId(IDS_IOS_TRANSLATE_SETTING);
161 } 161 }
162 // Matcher for the save button in the save password bar. 162 // Matcher for the save button in the save password bar.
163 id<GREYMatcher> savePasswordButton() { 163 id<GREYMatcher> savePasswordButton() {
164 return ButtonWithAccessibilityLabelId(IDS_IOS_PASSWORD_MANAGER_SAVE_BUTTON); 164 return ButtonWithAccessibilityLabelId(IDS_IOS_PASSWORD_MANAGER_SAVE_BUTTON);
165 } 165 }
166 166
167 // Asserts that there is no cookie in current web state. 167 // Returns true if there is no cookie in current web state.
168 void AssertNoCookieExists() { 168 bool WebStateHasNoCookie() {
169 chrome_test_util::ExecuteJavaScript(
170 base::SysUTF8ToNSString(kJavaScriptGetCookies), nil);
169 NSError* error = nil; 171 NSError* error = nil;
170 chrome_test_util::ExecuteJavaScript(
171 base::SysUTF8ToNSString(kJavaScriptGetCookies), &error);
172 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( 172 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
173 kNoCookieText)] 173 kNoCookieText)]
174 assertWithMatcher:grey_notNil()]; 174 assertWithMatcher:grey_notNil()
175 error:&error];
176
177 return error == nil;
175 } 178 }
176 179
177 // Asserts |cookie| exists in current web state. 180 // 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.
178 void AssertCookieExists(const char cookie[]) { 181 bool WebStateHasCookie(const char cookie[]) {
179 NSError* error = nil;
180 chrome_test_util::ExecuteJavaScript( 182 chrome_test_util::ExecuteJavaScript(
181 base::SysUTF8ToNSString(kJavaScriptGetCookies), &error); 183 base::SysUTF8ToNSString(kJavaScriptGetCookies), nil);
182 NSString* const expectedCookieText = 184 NSString* const expectedCookieText =
183 [NSString stringWithFormat:@"OK: %@", base::SysUTF8ToNSString(cookie)]; 185 [NSString stringWithFormat:@"OK: %@", base::SysUTF8ToNSString(cookie)];
186 NSError* error = nil;
184 [[EarlGrey 187 [[EarlGrey
185 selectElementWithMatcher:chrome_test_util::WebViewContainingText( 188 selectElementWithMatcher:chrome_test_util::WebViewContainingText(
186 base::SysNSStringToUTF8(expectedCookieText))] 189 base::SysNSStringToUTF8(expectedCookieText))]
187 assertWithMatcher:grey_notNil()]; 190 assertWithMatcher:grey_notNil()
191 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.
192 return error == nil;
188 } 193 }
189 194
190 // Run as a task to check if a certificate has been added to the ChannelIDStore. 195 // Run as a task to check if a certificate has been added to the ChannelIDStore.
191 // Signals the given |semaphore| if the cert was added, or reposts itself 196 // Signals the given |semaphore| if the cert was added, or reposts itself
192 // otherwise. 197 // otherwise.
193 void CheckCertificate(scoped_refptr<net::URLRequestContextGetter> getter, 198 void CheckCertificate(scoped_refptr<net::URLRequestContextGetter> getter,
194 dispatch_semaphore_t semaphore) { 199 dispatch_semaphore_t semaphore) {
195 net::ChannelIDService* channel_id_service = 200 net::ChannelIDService* channel_id_service =
196 getter->GetURLRequestContext()->channel_id_service(); 201 getter->GetURLRequestContext()->channel_id_service();
197 if (channel_id_service->channel_id_count() == 0) { 202 if (channel_id_service->channel_id_count() == 0) {
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 response[web::test::HttpServer::MakeUrl(kUrl)] = 685 response[web::test::HttpServer::MakeUrl(kUrl)] =
681 std::pair<std::string, std::string>("", kResponse); 686 std::pair<std::string, std::string>("", kResponse);
682 687
683 web::test::SetUpSimpleHttpServerWithSetCookies(response); 688 web::test::SetUpSimpleHttpServerWithSetCookies(response);
684 689
685 // Load |kUrl| and check that cookie is not set. 690 // Load |kUrl| and check that cookie is not set.
686 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kUrl)]; 691 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kUrl)];
687 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( 692 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
688 kResponse)] 693 kResponse)]
689 assertWithMatcher:grey_notNil()]; 694 assertWithMatcher:grey_notNil()];
690 AssertNoCookieExists(); 695
696 GREYAssertTrue(WebStateHasNoCookie(),
697 @"Web state is expected to have no cookie.");
691 698
692 // Visit |kUrlWithSetCookie| to set a cookie and then load |kUrl| to check it 699 // Visit |kUrlWithSetCookie| to set a cookie and then load |kUrl| to check it
693 // is still set. 700 // is still set.
694 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kUrlWithSetCookie)]; 701 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kUrlWithSetCookie)];
695 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( 702 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
696 kResponseWithSetCookie)] 703 kResponseWithSetCookie)]
697 assertWithMatcher:grey_notNil()]; 704 assertWithMatcher:grey_notNil()];
698 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kUrl)]; 705 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kUrl)];
699 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( 706 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
700 kResponse)] 707 kResponse)]
701 assertWithMatcher:grey_notNil()]; 708 assertWithMatcher:grey_notNil()];
702 709
703 AssertCookieExists(kCookie); 710 NSString* const errorMessage = [NSString
711 stringWithFormat:@"Web state is expected to have following cookie: %@.",
712 base::SysUTF8ToNSString(kCookie)];
713 GREYAssertTrue(WebStateHasCookie(kCookie), errorMessage);
704 714
705 // Restore the Clear Browsing Data checkmarks prefs to their default state in 715 // Restore the Clear Browsing Data checkmarks prefs to their default state in
706 // Teardown. 716 // Teardown.
707 [self setTearDownHandler:^{ 717 [self setTearDownHandler:^{
708 [self restoreClearBrowsingDataCheckmarksToDefault]; 718 [self restoreClearBrowsingDataCheckmarksToDefault];
709 }]; 719 }];
710 720
711 // Clear all cookies. 721 // Clear all cookies.
712 [self clearCookiesAndSiteData]; 722 [self clearCookiesAndSiteData];
713 723
714 // Reload and test that there are no cookies left. 724 // Reload and test that there are no cookies left.
715 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kUrl)]; 725 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kUrl)];
716 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( 726 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
717 kResponse)] 727 kResponse)]
718 assertWithMatcher:grey_notNil()]; 728 assertWithMatcher:grey_notNil()];
719 AssertNoCookieExists(); 729 GREYAssertTrue(WebStateHasNoCookie(),
730 @"Web state is expected to have no cookie.");
720 chrome_test_util::CloseAllTabs(); 731 chrome_test_util::CloseAllTabs();
721 } 732 }
722 733
723 // Verifies that logging into a form on a web page allows the user to save and 734 // Verifies that logging into a form on a web page allows the user to save and
724 // then clear a password. 735 // then clear a password.
725 - (void)testClearPasswords { 736 - (void)testClearPasswords {
726 737
727 ios::ChromeBrowserState* browserState = 738 ios::ChromeBrowserState* browserState =
728 chrome_test_util::GetOriginalBrowserState(); 739 chrome_test_util::GetOriginalBrowserState();
729 PrefService* preferences = browserState->GetPrefs(); 740 PrefService* preferences = browserState->GetPrefs();
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 performAction:grey_tap()]; 1066 performAction:grey_tap()];
1056 [[EarlGrey selectElementWithMatcher:PrivacyButton()] 1067 [[EarlGrey selectElementWithMatcher:PrivacyButton()]
1057 performAction:grey_tap()]; 1068 performAction:grey_tap()];
1058 [[EarlGrey selectElementWithMatcher:SendUsageDataButton()] 1069 [[EarlGrey selectElementWithMatcher:SendUsageDataButton()]
1059 performAction:grey_tap()]; 1070 performAction:grey_tap()];
1060 chrome_test_util::VerifyAccessibilityForCurrentScreen(); 1071 chrome_test_util::VerifyAccessibilityForCurrentScreen();
1061 [self closeSubSettingsMenu]; 1072 [self closeSubSettingsMenu];
1062 } 1073 }
1063 1074
1064 @end 1075 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698