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

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

Issue 2734963004: Refactor Assert[No]CookieExists to return a boolean (Closed)
Patch Set: Rebase 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
« no previous file with comments | « ios/chrome/test/earl_grey/chrome_earl_grey.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..efbd2d3fef7d377ce8674f3420ac9e1d15c28355 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,33 @@ + (void)clearBrowsingHistory {
[[GREYUIThreadExecutor sharedInstance] drainUntilIdle];
}
+#pragma mark - Cookie Utilities
+
++ (NSDictionary*)cookies {
+ NSString* const kGetCookiesScript =
+ @"document.cookie ? document.cookie.split(/;\\s*/) : [];";
+
+ // 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* nameValuePairs = base::mac::ObjCCastStrict<NSArray>(result);
+ NSMutableDictionary* cookies = [NSMutableDictionary dictionary];
+ for (NSString* nameValuePair in nameValuePairs) {
+ NSArray* cookieNameValue = [nameValuePair componentsSeparatedByString:@"="];
+ GREYAssertEqual(2U, cookieNameValue.count, @"Cookie has invalid format.");
+
+ NSString* cookieName = cookieNameValue[0];
+ NSString* cookieValue = cookieNameValue[1];
+ cookies[cookieName] = cookieValue;
+ }
+
+ return cookies;
+}
+
#pragma mark - Navigation Utilities
+ (void)loadURL:(GURL)URL {
« no previous file with comments | « 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