Chromium Code Reviews| 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..df17980729b519d3a812723acb85aa209d1abac4 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,36 @@ + (void)clearBrowsingHistory { |
| [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; |
| } |
| +#pragma mark - Cookie Utilities |
| + |
| ++ (NSDictionary*)cookies { |
| + NSString* const kGetCookiesScript = |
| + @"(function getCookies() {" |
|
Eugene But (OOO till 7-30)
2017/03/14 17:32:02
@"document.cookie ? document.cookie.split(/;\\s*/)
liaoyuke
2017/03/14 20:08:55
Done.
|
| + " var c = document.cookie ? document.cookie.split(/;\\s*/) : [];" |
| + " 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* nameValuePairs = base::mac::ObjCCastStrict<NSArray>(result); |
| + NSMutableDictionary* cookies = [NSMutableDictionary dictionary]; |
| + for (NSString* nameValuePair in nameValuePairs) { |
| + NSArray* cookieNameValue = [nameValuePair componentsSeparatedByString:@"="]; |
| + GREYAssertEqual(2, cookieNameValue.count, @"Cookie has invalid format."); |
|
Eugene But (OOO till 7-30)
2017/03/14 17:32:02
s/2/2U ?
liaoyuke
2017/03/14 20:08:55
Done.
|
| + |
| + NSString* cookieName = cookieNameValue[0]; |
| + NSString* cookieValue = cookieNameValue[1]; |
| + cookies[cookieName] = cookieValue; |
| + } |
| + |
| + return cookies; |
| +} |
| + |
| #pragma mark - Navigation Utilities |
| + (void)loadURL:(GURL)URL { |