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

Unified Diff: ios/chrome/test/earl_grey/chrome_earl_grey.mm

Issue 2734963004: Refactor Assert[No]CookieExists to return a boolean (Closed)
Patch Set: Update comments 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 side-by-side diff with in-line comments
Download patch
Index: ios/chrome/test/earl_grey/chrome_earl_grey.mm
diff --git a/ios/chrome/test/earl_grey/chrome_earl_grey.mm b/ios/chrome/test/earl_grey/chrome_earl_grey.mm
index ffcfa516ad3b3d3a812db944a3de8698fd7cc1e5..36194a987ed6eb97e5919885a9770d44814a6bf7 100644
--- a/ios/chrome/test/earl_grey/chrome_earl_grey.mm
+++ b/ios/chrome/test/earl_grey/chrome_earl_grey.mm
@@ -7,6 +7,7 @@
#import <Foundation/Foundation.h>
#import <WebKit/WebKit.h>
+#include "base/mac/foundation_util.h"
#include "base/strings/sys_string_conversions.h"
#import "ios/chrome/test/app/chrome_test_util.h"
#import "ios/chrome/test/app/history_test_util.h"
@@ -66,6 +67,39 @@ + (void)clearBrowsingHistory {
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
}
+#pragma mark - Cookie Utilities
+
++ (NSDictionary*)cookies {
+ NSString* const kGetCookiesScript =
+ @"(function getCookies() {"
+ " var c = document.cookie ? document.cookie.split(/;\\s*/) : [];"
+ " if (!c.length) {"
+ " document.documentElement.innerHTML = 'No cookies!';"
Eugene But (OOO till 7-30) 2017/03/14 00:43:39 It is quite unexpected side effect that |cookies|
liaoyuke 2017/03/14 17:04:39 I talked to baxley@ about this issue, and we thoug
+ " } else {"
+ " document.documentElement.innerHTML = 'Cookies: ' + c.join(',');"
+ " }"
+ " return c;"
+ "})();";
+
+ // TODO(crbug.com/690057): Remove __unsafe_unretained once all callers of
+ // |ExecuteJavaScript| are converted to ARC.
+ NSError* __unsafe_unretained error = nil;
+ id result = chrome_test_util::ExecuteJavaScript(kGetCookiesScript, &error);
+
+ GREYAssertTrue(result && !error, @"Failed to get cookies.");
+
+ NSArray* stringCookies = base::mac::ObjCCastStrict<NSArray>(result);
Eugene But (OOO till 7-30) 2017/03/14 00:43:39 nit: s/stringCookie/nameValuePairs ?
liaoyuke 2017/03/14 17:04:39 Done.
+ NSMutableDictionary* cookies = [NSMutableDictionary dictionary];
+ for (NSString* stringCookie in stringCookies) {
Eugene But (OOO till 7-30) 2017/03/14 00:43:39 nit: s/stringCookie/nameValuePair ?
liaoyuke 2017/03/14 17:04:39 Done.
+ NSArray* cookieKeyValue = [stringCookie componentsSeparatedByString:@"="];
Eugene But (OOO till 7-30) 2017/03/14 00:43:39 s/cookieKeyValue/cookieNameValue
liaoyuke 2017/03/14 17:04:39 Done.
+ NSString* cookieKey = cookieKeyValue[0];
Eugene But (OOO till 7-30) 2017/03/14 00:43:39 s/cookieKey/cookieName
Eugene But (OOO till 7-30) 2017/03/14 00:43:39 Do you want to assert that array length is 2? Othe
liaoyuke 2017/03/14 17:04:39 Done.
liaoyuke 2017/03/14 17:04:39 Done.
+ NSString* cookieValue = cookieKeyValue[1];
+ cookies[cookieKey] = cookieValue;
+ }
+
+ return cookies;
+}
+
#pragma mark - Navigation Utilities
+ (void)loadURL:(GURL)URL {
« ios/chrome/test/earl_grey/chrome_earl_grey.h ('K') | « ios/chrome/test/earl_grey/chrome_earl_grey.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698