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

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

Issue 2734963004: Refactor Assert[No]CookieExists to return a boolean (Closed)
Patch Set: Move cookie helpers to a shared location 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..d6cc21d0595edf81f3b0beaf4cf56a6f54a8130b 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,37 @@ + (void)clearBrowsingHistory {
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
}
+#pragma mark - Cookie Utilities
+
++ (NSDictionary*)getCookies {
+ NSString* const kGetCookiesScript =
+ @"(function getCookies() {"
+ " var c = document.cookie ? document.cookie.split(/;\\s*/) : [];"
+ " if (!c.length) {"
+ " document.documentElement.innerHTML = 'No cookies!';"
+ " } 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);
+
+ NSArray* stringCookies = base::mac::ObjCCastStrict<NSArray>(result);
+ NSMutableDictionary* cookies = [NSMutableDictionary dictionary];
+ for (NSString* stringCookie in stringCookies) {
+ NSArray* cookieKeyValue = [stringCookie componentsSeparatedByString:@"="];
+ NSString* cookieKey = cookieKeyValue[0];
+ NSString* cookieValue = cookieKeyValue[1];
+ cookies[cookieKey] = cookieValue;
+ }
+
+ return cookies;
baxley 2017/03/13 21:29:04 Sorry if I missed it, but the comment says it retu
liaoyuke 2017/03/13 22:50:40 Done.
+}
+
#pragma mark - Navigation Utilities
+ (void)loadURL:(GURL)URL {

Powered by Google App Engine
This is Rietveld 408576698