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() {" | |
|
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.
| |
| 75 " var c = document.cookie ? document.cookie.split(/;\\s*/) : [];" | |
| 76 " return c;" | |
| 77 "})();"; | |
| 78 | |
| 79 // TODO(crbug.com/690057): Remove __unsafe_unretained once all callers of | |
| 80 // |ExecuteJavaScript| are converted to ARC. | |
| 81 NSError* __unsafe_unretained error = nil; | |
| 82 id result = chrome_test_util::ExecuteJavaScript(kGetCookiesScript, &error); | |
| 83 | |
| 84 GREYAssertTrue(result && !error, @"Failed to get cookies."); | |
| 85 | |
| 86 NSArray* nameValuePairs = base::mac::ObjCCastStrict<NSArray>(result); | |
| 87 NSMutableDictionary* cookies = [NSMutableDictionary dictionary]; | |
| 88 for (NSString* nameValuePair in nameValuePairs) { | |
| 89 NSArray* cookieNameValue = [nameValuePair componentsSeparatedByString:@"="]; | |
| 90 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.
| |
| 91 | |
| 92 NSString* cookieName = cookieNameValue[0]; | |
| 93 NSString* cookieValue = cookieNameValue[1]; | |
| 94 cookies[cookieName] = cookieValue; | |
| 95 } | |
| 96 | |
| 97 return cookies; | |
| 98 } | |
| 99 | |
| 69 #pragma mark - Navigation Utilities | 100 #pragma mark - Navigation Utilities |
| 70 | 101 |
| 71 + (void)loadURL:(GURL)URL { | 102 + (void)loadURL:(GURL)URL { |
| 72 chrome_test_util::LoadUrl(URL); | 103 chrome_test_util::LoadUrl(URL); |
| 73 // Make sure that the page started loading. | 104 // Make sure that the page started loading. |
| 74 GREYAssert(chrome_test_util::IsLoading(), @"Page did not start loading."); | 105 GREYAssert(chrome_test_util::IsLoading(), @"Page did not start loading."); |
| 75 [ChromeEarlGrey waitForPageToFinishLoading]; | 106 [ChromeEarlGrey waitForPageToFinishLoading]; |
| 76 | 107 |
| 77 web::WebState* webState = chrome_test_util::GetCurrentWebState(); | 108 web::WebState* webState = chrome_test_util::GetCurrentWebState(); |
| 78 if (webState->ContentIsHTML()) | 109 if (webState->ContentIsHTML()) |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 91 | 122 |
| 92 + (void)tapWebViewElementWithID:(NSString*)elementID { | 123 + (void)tapWebViewElementWithID:(NSString*)elementID { |
| 93 BOOL success = | 124 BOOL success = |
| 94 web::test::TapWebViewElementWithId(chrome_test_util::GetCurrentWebState(), | 125 web::test::TapWebViewElementWithId(chrome_test_util::GetCurrentWebState(), |
| 95 base::SysNSStringToUTF8(elementID)); | 126 base::SysNSStringToUTF8(elementID)); |
| 96 GREYAssertTrue(success, @"Failed to tap web view element with ID: %@", | 127 GREYAssertTrue(success, @"Failed to tap web view element with ID: %@", |
| 97 elementID); | 128 elementID); |
| 98 } | 129 } |
| 99 | 130 |
| 100 @end | 131 @end |
| OLD | NEW |