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 <EarlGrey/EarlGrey.h> | 5 #import <EarlGrey/EarlGrey.h> |
6 | 6 |
7 #include "base/strings/sys_string_conversions.h" | 7 #include "base/strings/sys_string_conversions.h" |
8 #import "base/test/ios/wait_util.h" | 8 #import "base/test/ios/wait_util.h" |
9 #include "ios/chrome/browser/autofill/form_input_accessory_view_controller.h" | 9 #include "ios/chrome/browser/autofill/form_input_accessory_view_controller.h" |
10 #include "ios/chrome/browser/ui/ui_util.h" | 10 #include "ios/chrome/browser/ui/ui_util.h" |
11 #include "ios/chrome/grit/ios_strings.h" | 11 #include "ios/chrome/grit/ios_strings.h" |
12 #import "ios/chrome/test/app/chrome_test_util.h" | 12 #import "ios/chrome/test/app/chrome_test_util.h" |
13 #import "ios/chrome/test/app/tab_test_util.h" | 13 #import "ios/chrome/test/app/tab_test_util.h" |
14 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" | 14 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" |
15 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 15 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |
16 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 16 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |
17 #import "ios/testing/wait_util.h" | 17 #import "ios/testing/wait_util.h" |
18 #import "ios/web/public/test/earl_grey/web_view_actions.h" | 18 #import "ios/web/public/test/earl_grey/web_view_actions.h" |
19 #import "ios/web/public/test/earl_grey/web_view_matchers.h" | 19 #import "ios/web/public/test/earl_grey/web_view_matchers.h" |
20 #import "ios/web/public/test/http_server.h" | 20 #import "ios/web/public/test/http_server.h" |
21 #include "ios/web/public/test/http_server_util.h" | 21 #include "ios/web/public/test/http_server_util.h" |
22 | 22 |
| 23 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 24 #error "This file requires ARC support." |
| 25 #endif |
| 26 |
23 namespace { | 27 namespace { |
24 | 28 |
25 const char kFormElementId1[] = "username"; | 29 const char kFormElementId1[] = "username"; |
26 const char kFormElementId2[] = "otherstuff"; | 30 const char kFormElementId2[] = "otherstuff"; |
27 | 31 |
28 // If an element is focused in the webview, returns its ID. Returns an empty | 32 // If an element is focused in the webview, returns its ID. Returns an empty |
29 // NSString otherwise. | 33 // NSString otherwise. |
30 NSString* GetFocusedElementId() { | 34 NSString* GetFocusedElementId() { |
31 NSString* js = @"(function() {" | 35 NSString* js = @"(function() {" |
32 " return document.activeElement.id;" | 36 " return document.activeElement.id;" |
33 "})();"; | 37 "})();"; |
34 NSError* error = nil; | 38 __unsafe_unretained NSError* error = nil; |
35 NSString* result = chrome_test_util::ExecuteJavaScript(js, &error); | 39 NSString* result = chrome_test_util::ExecuteJavaScript(js, &error); |
36 GREYAssertTrue(!error, @"Unexpected error when executing JavaScript."); | 40 GREYAssertTrue(!error, @"Unexpected error when executing JavaScript."); |
37 return result; | 41 return result; |
38 } | 42 } |
39 | 43 |
40 // Verifies that |elementId| is the selected element in the web page. | 44 // Verifies that |elementId| is the selected element in the web page. |
41 void AssertElementIsFocused(const std::string& element_id) { | 45 void AssertElementIsFocused(const std::string& element_id) { |
42 NSString* description = | 46 NSString* description = |
43 [NSString stringWithFormat:@"Timeout waiting for the focused element in " | 47 [NSString stringWithFormat:@"Timeout waiting for the focused element in " |
44 @"the webview to be \"%@\"", | 48 @"the webview to be \"%@\"", |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 // visible doesn't crash the browser. | 155 // visible doesn't crash the browser. |
152 - (void)testCloseKeyboardWhenNotVisible { | 156 - (void)testCloseKeyboardWhenNotVisible { |
153 FormInputAccessoryViewController* inputAccessoryViewController = | 157 FormInputAccessoryViewController* inputAccessoryViewController = |
154 chrome_test_util::GetInputAccessoryViewController(); | 158 chrome_test_util::GetInputAccessoryViewController(); |
155 GREYAssertNotNil(inputAccessoryViewController, | 159 GREYAssertNotNil(inputAccessoryViewController, |
156 @"The tab's input accessory view should not be non nil."); | 160 @"The tab's input accessory view should not be non nil."); |
157 [inputAccessoryViewController closeKeyboardWithoutButtonPress]; | 161 [inputAccessoryViewController closeKeyboardWithoutButtonPress]; |
158 } | 162 } |
159 | 163 |
160 @end | 164 @end |
OLD | NEW |