Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1223)

Side by Side Diff: ios/chrome/browser/web/http_auth_egtest.mm

Issue 2642193012: Make EarlGrey matchers compliant with Chromium style. (Closed)
Patch Set: build.gn and rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/chrome/browser/web/forms_egtest.mm ('k') | ios/chrome/browser/web/js_print_egtest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "base/strings/sys_string_conversions.h" 8 #include "base/strings/sys_string_conversions.h"
9 #include "components/strings/grit/components_strings.h" 9 #include "components/strings/grit/components_strings.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 #include "ios/chrome/test/app/navigation_test_util.h" 12 #include "ios/chrome/test/app/navigation_test_util.h"
13 #import "ios/chrome/test/earl_grey/chrome_matchers.h" 13 #import "ios/chrome/test/earl_grey/chrome_matchers.h"
14 #import "ios/chrome/test/earl_grey/chrome_test_case.h" 14 #import "ios/chrome/test/earl_grey/chrome_test_case.h"
15 #import "ios/testing/wait_util.h" 15 #import "ios/testing/wait_util.h"
16 #import "ios/web/public/test/http_server.h" 16 #import "ios/web/public/test/http_server.h"
17 #include "ios/web/public/test/http_server_util.h" 17 #include "ios/web/public/test/http_server_util.h"
18 #import "ios/web/public/test/response_providers/http_auth_response_provider.h" 18 #import "ios/web/public/test/response_providers/http_auth_response_provider.h"
19 #import "ios/testing/earl_grey/disabled_test_macros.h" 19 #import "ios/testing/earl_grey/disabled_test_macros.h"
20 #include "ui/base/l10n/l10n_util_mac.h" 20 #include "ui/base/l10n/l10n_util_mac.h"
21 #include "url/gurl.h" 21 #include "url/gurl.h"
22 22
23 using testing::WaitUntilConditionOrTimeout; 23 using testing::WaitUntilConditionOrTimeout;
24 using testing::kWaitForPageLoadTimeout; 24 using testing::kWaitForPageLoadTimeout;
25 using chrome_test_util::webViewContainingText; 25 using chrome_test_util::WebViewContainingText;
26 26
27 namespace { 27 namespace {
28 28
29 // Returns matcher for HTTP Authentication dialog. 29 // Returns matcher for HTTP Authentication dialog.
30 id<GREYMatcher> httpAuthDialog() { 30 id<GREYMatcher> HttpAuthDialog() {
31 NSString* title = l10n_util::GetNSStringWithFixup(IDS_LOGIN_DIALOG_TITLE); 31 NSString* title = l10n_util::GetNSStringWithFixup(IDS_LOGIN_DIALOG_TITLE);
32 return chrome_test_util::staticTextWithAccessibilityLabel(title); 32 return chrome_test_util::StaticTextWithAccessibilityLabel(title);
33 } 33 }
34 34
35 // Returns matcher for Username text field. 35 // Returns matcher for Username text field.
36 id<GREYMatcher> usernameField() { 36 id<GREYMatcher> UsernameField() {
37 return chrome_test_util::staticTextWithAccessibilityLabelId( 37 return chrome_test_util::StaticTextWithAccessibilityLabelId(
38 IDS_IOS_HTTP_LOGIN_DIALOG_USERNAME_PLACEHOLDER); 38 IDS_IOS_HTTP_LOGIN_DIALOG_USERNAME_PLACEHOLDER);
39 } 39 }
40 40
41 // Returns matcher for Password text field. 41 // Returns matcher for Password text field.
42 id<GREYMatcher> passwordField() { 42 id<GREYMatcher> PasswordField() {
43 return chrome_test_util::staticTextWithAccessibilityLabelId( 43 return chrome_test_util::StaticTextWithAccessibilityLabelId(
44 IDS_IOS_HTTP_LOGIN_DIALOG_PASSWORD_PLACEHOLDER); 44 IDS_IOS_HTTP_LOGIN_DIALOG_PASSWORD_PLACEHOLDER);
45 } 45 }
46 46
47 // Returns matcher for Login button. 47 // Returns matcher for Login button.
48 id<GREYMatcher> loginButton() { 48 id<GREYMatcher> LoginButton() {
49 return chrome_test_util::buttonWithAccessibilityLabelId( 49 return chrome_test_util::ButtonWithAccessibilityLabelId(
50 IDS_LOGIN_DIALOG_OK_BUTTON_LABEL); 50 IDS_LOGIN_DIALOG_OK_BUTTON_LABEL);
51 } 51 }
52 52
53 // Waits until static text with IDS_LOGIN_DIALOG_TITLE label is displayed. 53 // Waits until static text with IDS_LOGIN_DIALOG_TITLE label is displayed.
54 void WaitForHttpAuthDialog() { 54 void WaitForHttpAuthDialog() {
55 BOOL dialog_shown = WaitUntilConditionOrTimeout(kWaitForPageLoadTimeout, ^{ 55 BOOL dialog_shown = WaitUntilConditionOrTimeout(kWaitForPageLoadTimeout, ^{
56 NSError* error = nil; 56 NSError* error = nil;
57 [[EarlGrey selectElementWithMatcher:httpAuthDialog()] 57 [[EarlGrey selectElementWithMatcher:HttpAuthDialog()]
58 assertWithMatcher:grey_notNil() 58 assertWithMatcher:grey_notNil()
59 error:&error]; 59 error:&error];
60 return !error; 60 return !error;
61 }); 61 });
62 GREYAssert(dialog_shown, @"HTTP Authentication dialog was not shown"); 62 GREYAssert(dialog_shown, @"HTTP Authentication dialog was not shown");
63 } 63 }
64 64
65 } // namespace 65 } // namespace
66 66
67 // Test case for HTTP Authentication flow. 67 // Test case for HTTP Authentication flow.
(...skipping 11 matching lines...) Expand all
79 EARL_GREY_TEST_DISABLED(@"Tab Title not displayed on handset."); 79 EARL_GREY_TEST_DISABLED(@"Tab Title not displayed on handset.");
80 } 80 }
81 81
82 GURL URL = web::test::HttpServer::MakeUrl("http://good-auth"); 82 GURL URL = web::test::HttpServer::MakeUrl("http://good-auth");
83 web::test::SetUpHttpServer(base::MakeUnique<web::HttpAuthResponseProvider>( 83 web::test::SetUpHttpServer(base::MakeUnique<web::HttpAuthResponseProvider>(
84 URL, "GoodRealm", "gooduser", "goodpass")); 84 URL, "GoodRealm", "gooduser", "goodpass"));
85 chrome_test_util::LoadUrl(URL); 85 chrome_test_util::LoadUrl(URL);
86 WaitForHttpAuthDialog(); 86 WaitForHttpAuthDialog();
87 87
88 // Enter valid username and password. 88 // Enter valid username and password.
89 [[EarlGrey selectElementWithMatcher:usernameField()] 89 [[EarlGrey selectElementWithMatcher:UsernameField()]
90 performAction:grey_typeText(@"gooduser")]; 90 performAction:grey_typeText(@"gooduser")];
91 [[EarlGrey selectElementWithMatcher:passwordField()] 91 [[EarlGrey selectElementWithMatcher:PasswordField()]
92 performAction:grey_typeText(@"goodpass")]; 92 performAction:grey_typeText(@"goodpass")];
93 [[EarlGrey selectElementWithMatcher:loginButton()] performAction:grey_tap()]; 93 [[EarlGrey selectElementWithMatcher:LoginButton()] performAction:grey_tap()];
94 94
95 const std::string pageText = web::HttpAuthResponseProvider::page_text(); 95 const std::string pageText = web::HttpAuthResponseProvider::page_text();
96 [[EarlGrey selectElementWithMatcher:webViewContainingText(pageText)] 96 [[EarlGrey selectElementWithMatcher:WebViewContainingText(pageText)]
97 assertWithMatcher:grey_notNil()]; 97 assertWithMatcher:grey_notNil()];
98 } 98 }
99 99
100 // Tests Basic HTTP Authentication with incorrect username and password. 100 // Tests Basic HTTP Authentication with incorrect username and password.
101 - (void)testUnsuccessfullBasicAuth { 101 - (void)testUnsuccessfullBasicAuth {
102 if (IsIPadIdiom()) { 102 if (IsIPadIdiom()) {
103 // EG does not allow interactions with HTTP Dialog when loading spinner is 103 // EG does not allow interactions with HTTP Dialog when loading spinner is
104 // animated. TODO(crbug.com/680290): Enable this test on iPad when EarlGrey 104 // animated. TODO(crbug.com/680290): Enable this test on iPad when EarlGrey
105 // allows tapping dialog buttons with active page load spinner. 105 // allows tapping dialog buttons with active page load spinner.
106 EARL_GREY_TEST_DISABLED(@"Tab Title not displayed on handset."); 106 EARL_GREY_TEST_DISABLED(@"Tab Title not displayed on handset.");
107 } 107 }
108 108
109 GURL URL = web::test::HttpServer::MakeUrl("http://bad-auth"); 109 GURL URL = web::test::HttpServer::MakeUrl("http://bad-auth");
110 web::test::SetUpHttpServer(base::MakeUnique<web::HttpAuthResponseProvider>( 110 web::test::SetUpHttpServer(base::MakeUnique<web::HttpAuthResponseProvider>(
111 URL, "BadRealm", "baduser", "badpass")); 111 URL, "BadRealm", "baduser", "badpass"));
112 chrome_test_util::LoadUrl(URL); 112 chrome_test_util::LoadUrl(URL);
113 WaitForHttpAuthDialog(); 113 WaitForHttpAuthDialog();
114 114
115 // Enter invalid username and password. 115 // Enter invalid username and password.
116 [[EarlGrey selectElementWithMatcher:usernameField()] 116 [[EarlGrey selectElementWithMatcher:UsernameField()]
117 performAction:grey_typeText(@"gooduser")]; 117 performAction:grey_typeText(@"gooduser")];
118 [[EarlGrey selectElementWithMatcher:passwordField()] 118 [[EarlGrey selectElementWithMatcher:PasswordField()]
119 performAction:grey_typeText(@"goodpass")]; 119 performAction:grey_typeText(@"goodpass")];
120 [[EarlGrey selectElementWithMatcher:loginButton()] performAction:grey_tap()]; 120 [[EarlGrey selectElementWithMatcher:LoginButton()] performAction:grey_tap()];
121 121
122 // Verifies that authentication was requested again. 122 // Verifies that authentication was requested again.
123 WaitForHttpAuthDialog(); 123 WaitForHttpAuthDialog();
124 } 124 }
125 125
126 // Tests Cancelling Basic HTTP Authentication. 126 // Tests Cancelling Basic HTTP Authentication.
127 - (void)testCancellingBasicAuth { 127 - (void)testCancellingBasicAuth {
128 if (IsIPadIdiom()) { 128 if (IsIPadIdiom()) {
129 // EG does not allow interactions with HTTP Dialog when loading spinner is 129 // EG does not allow interactions with HTTP Dialog when loading spinner is
130 // animated. TODO(crbug.com/680290): Enable this test on iPad when EarlGrey 130 // animated. TODO(crbug.com/680290): Enable this test on iPad when EarlGrey
131 // allows tapping dialog buttons with active page load spinner. 131 // allows tapping dialog buttons with active page load spinner.
132 EARL_GREY_TEST_DISABLED(@"Tab Title not displayed on handset."); 132 EARL_GREY_TEST_DISABLED(@"Tab Title not displayed on handset.");
133 } 133 }
134 134
135 GURL URL = web::test::HttpServer::MakeUrl("http://cancel-auth"); 135 GURL URL = web::test::HttpServer::MakeUrl("http://cancel-auth");
136 web::test::SetUpHttpServer(base::MakeUnique<web::HttpAuthResponseProvider>( 136 web::test::SetUpHttpServer(base::MakeUnique<web::HttpAuthResponseProvider>(
137 URL, "CancellingRealm", "", "")); 137 URL, "CancellingRealm", "", ""));
138 chrome_test_util::LoadUrl(URL); 138 chrome_test_util::LoadUrl(URL);
139 WaitForHttpAuthDialog(); 139 WaitForHttpAuthDialog();
140 140
141 [[EarlGrey selectElementWithMatcher:chrome_test_util::cancelButton()] 141 [[EarlGrey selectElementWithMatcher:chrome_test_util::CancelButton()]
142 performAction:grey_tap()]; 142 performAction:grey_tap()];
143 [[EarlGrey selectElementWithMatcher:httpAuthDialog()] 143 [[EarlGrey selectElementWithMatcher:HttpAuthDialog()]
144 assertWithMatcher:grey_nil()]; 144 assertWithMatcher:grey_nil()];
145 } 145 }
146 146
147 @end 147 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/web/forms_egtest.mm ('k') | ios/chrome/browser/web/js_print_egtest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698