Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" | 5 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" |
| 6 | 6 |
| 7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
| 8 #import <WebKit/WebKit.h> | 8 #import <WebKit/WebKit.h> |
| 9 | 9 |
| 10 #include "base/mac/foundation_util.h" | |
| 10 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
| 11 #import "ios/chrome/test/app/chrome_test_util.h" | 12 #import "ios/chrome/test/app/chrome_test_util.h" |
| 12 #import "ios/chrome/test/app/history_test_util.h" | 13 #import "ios/chrome/test/app/history_test_util.h" |
| 13 #include "ios/chrome/test/app/navigation_test_util.h" | 14 #include "ios/chrome/test/app/navigation_test_util.h" |
| 14 #import "ios/testing/wait_util.h" | 15 #import "ios/testing/wait_util.h" |
| 15 #import "ios/web/public/test/earl_grey/js_test_util.h" | 16 #import "ios/web/public/test/earl_grey/js_test_util.h" |
| 16 #import "ios/web/public/test/web_view_interaction_test_util.h" | 17 #import "ios/web/public/test/web_view_interaction_test_util.h" |
| 17 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" | 18 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" |
| 18 #import "ios/web/public/web_state/web_state.h" | 19 #import "ios/web/public/web_state/web_state.h" |
| 19 | 20 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 59 | 60 |
| 60 #pragma mark - History Utilities | 61 #pragma mark - History Utilities |
| 61 | 62 |
| 62 + (void)clearBrowsingHistory { | 63 + (void)clearBrowsingHistory { |
| 63 chrome_test_util::ClearBrowsingHistory(); | 64 chrome_test_util::ClearBrowsingHistory(); |
| 64 // After clearing browsing history via code, wait for the UI to be done | 65 // After clearing browsing history via code, wait for the UI to be done |
| 65 // with any updates. This includes icons from the new tab page being removed. | 66 // with any updates. This includes icons from the new tab page being removed. |
| 66 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; | 67 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; |
| 67 } | 68 } |
| 68 | 69 |
| 70 #pragma mark - Cookie Utilities | |
| 71 | |
| 72 + (NSDictionary*)cookies { | |
| 73 NSString* const kGetCookiesScript = | |
| 74 @"(function getCookies() {" | |
| 75 " var c = document.cookie ? document.cookie.split(/;\\s*/) : [];" | |
| 76 " if (!c.length) {" | |
| 77 " 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
| |
| 78 " } else {" | |
| 79 " document.documentElement.innerHTML = 'Cookies: ' + c.join(',');" | |
| 80 " }" | |
| 81 " return c;" | |
| 82 "})();"; | |
| 83 | |
| 84 // TODO(crbug.com/690057): Remove __unsafe_unretained once all callers of | |
| 85 // |ExecuteJavaScript| are converted to ARC. | |
| 86 NSError* __unsafe_unretained error = nil; | |
| 87 id result = chrome_test_util::ExecuteJavaScript(kGetCookiesScript, &error); | |
| 88 | |
| 89 GREYAssertTrue(result && !error, @"Failed to get cookies."); | |
| 90 | |
| 91 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.
| |
| 92 NSMutableDictionary* cookies = [NSMutableDictionary dictionary]; | |
| 93 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.
| |
| 94 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.
| |
| 95 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.
| |
| 96 NSString* cookieValue = cookieKeyValue[1]; | |
| 97 cookies[cookieKey] = cookieValue; | |
| 98 } | |
| 99 | |
| 100 return cookies; | |
| 101 } | |
| 102 | |
| 69 #pragma mark - Navigation Utilities | 103 #pragma mark - Navigation Utilities |
| 70 | 104 |
| 71 + (void)loadURL:(GURL)URL { | 105 + (void)loadURL:(GURL)URL { |
| 72 chrome_test_util::LoadUrl(URL); | 106 chrome_test_util::LoadUrl(URL); |
| 73 // Make sure that the page started loading. | 107 // Make sure that the page started loading. |
| 74 GREYAssert(chrome_test_util::IsLoading(), @"Page did not start loading."); | 108 GREYAssert(chrome_test_util::IsLoading(), @"Page did not start loading."); |
| 75 [ChromeEarlGrey waitForPageToFinishLoading]; | 109 [ChromeEarlGrey waitForPageToFinishLoading]; |
| 76 | 110 |
| 77 web::WebState* webState = chrome_test_util::GetCurrentWebState(); | 111 web::WebState* webState = chrome_test_util::GetCurrentWebState(); |
| 78 if (webState->ContentIsHTML()) | 112 if (webState->ContentIsHTML()) |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 91 | 125 |
| 92 + (void)tapWebViewElementWithID:(NSString*)elementID { | 126 + (void)tapWebViewElementWithID:(NSString*)elementID { |
| 93 BOOL success = | 127 BOOL success = |
| 94 web::test::TapWebViewElementWithId(chrome_test_util::GetCurrentWebState(), | 128 web::test::TapWebViewElementWithId(chrome_test_util::GetCurrentWebState(), |
| 95 base::SysNSStringToUTF8(elementID)); | 129 base::SysNSStringToUTF8(elementID)); |
| 96 GREYAssertTrue(success, @"Failed to tap web view element with ID: %@", | 130 GREYAssertTrue(success, @"Failed to tap web view element with ID: %@", |
| 97 elementID); | 131 elementID); |
| 98 } | 132 } |
| 99 | 133 |
| 100 @end | 134 @end |
| OLD | NEW |