Commit 051cd9d3 authored by Maksym Onufriienko's avatar Maksym Onufriienko Committed by Commit Bot

Converted [ChromeEarlGrey cookies] to compile under EG2.

Bug: 922813
Change-Id: I608412fb0c8b41e347f1363b5e4da58dab464efe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1623269
Commit-Queue: Maksym Onufriienko <monufriienko@chromium.org>
Reviewed-by: default avatarEugene But <eugenebut@chromium.org>
Cr-Commit-Position: refs/heads/master@{#664978}
parent 51ef201c
......@@ -266,6 +266,13 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
// induced.
- (id)executeJavaScript:(NSString*)javaScript;
#pragma mark - Cookie Utilities
// Returns cookies as key value pairs, where key is a cookie name and value is a
// cookie value.
// A GREYAssert is induced if cookies can not be returned.
- (NSDictionary*)cookies;
@end
// Helpers that only compile under EarlGrey 1 are included in this "EG1"
......@@ -274,13 +281,6 @@ id ExecuteJavaScript(NSString* javascript, NSError* __autoreleasing* out_error);
// them into the main class declaration as they are converted.
@interface ChromeEarlGreyImpl (EG1)
#pragma mark - Cookie Utilities
// Returns cookies as key value pairs, where key is a cookie name and value is a
// cookie value.
// NOTE: this method fails the test if there are errors getting cookies.
- (NSDictionary*)cookies;
#pragma mark - Navigation Utilities
// Waits for a static html view containing |text|. If the condition is not met
......
......@@ -228,6 +228,30 @@ GREY_STUB_CLASS_IN_APP_MAIN_QUEUE(ChromeEarlGreyAppInterface)
return nil;
}
#pragma mark - Cookie Utilities (EG2)
- (NSDictionary*)cookies {
NSString* const kGetCookiesScript =
@"document.cookie ? document.cookie.split(/;\\s*/) : [];";
id result = [self executeJavaScript:kGetCookiesScript];
EG_TEST_HELPER_ASSERT_TRUE([result isKindOfClass:[NSArray class]],
@"Unexpected script response");
NSArray* nameValuePairs = base::mac::ObjCCastStrict<NSArray>(result);
NSMutableDictionary* cookies = [NSMutableDictionary dictionary];
for (NSString* nameValuePair in nameValuePairs) {
NSArray* cookieNameValue = [nameValuePair componentsSeparatedByString:@"="];
EG_TEST_HELPER_ASSERT_TRUE((2 == cookieNameValue.count),
@"Cookie has invalid format.");
NSString* cookieName = cookieNameValue[0];
NSString* cookieValue = cookieNameValue[1];
cookies[cookieName] = cookieValue;
}
return cookies;
}
#pragma mark - WebState Utilities (EG2)
- (NSError*)waitForWebStateContainingElement:(ElementSelector*)selector {
......@@ -415,31 +439,6 @@ id ExecuteJavaScript(NSString* javascript,
@implementation ChromeEarlGreyImpl (EG1)
#pragma mark - Cookie Utilities
- (NSDictionary*)cookies {
NSString* const kGetCookiesScript =
@"document.cookie ? document.cookie.split(/;\\s*/) : [];";
NSError* 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
- (NSError*)waitForErrorPage {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment