| 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/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_earl_grey.h" |
| 13 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 14 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |
| 14 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 15 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |
| 15 #import "ios/testing/wait_util.h" | 16 #import "ios/testing/wait_util.h" |
| 16 #import "ios/web/public/test/http_server.h" | 17 #import "ios/web/public/test/http_server.h" |
| 17 #include "ios/web/public/test/http_server_util.h" | 18 #include "ios/web/public/test/http_server_util.h" |
| 18 #import "ios/web/public/test/response_providers/http_auth_response_provider.h" | 19 #import "ios/web/public/test/response_providers/http_auth_response_provider.h" |
| 19 #include "ui/base/l10n/l10n_util_mac.h" | 20 #include "ui/base/l10n/l10n_util_mac.h" |
| 20 #include "url/gurl.h" | 21 #include "url/gurl.h" |
| 21 | 22 |
| 22 using testing::WaitUntilConditionOrTimeout; | 23 using testing::WaitUntilConditionOrTimeout; |
| 23 using testing::kWaitForPageLoadTimeout; | 24 using testing::kWaitForPageLoadTimeout; |
| 24 using chrome_test_util::WebViewContainingText; | |
| 25 | 25 |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 // Returns matcher for HTTP Authentication dialog. | 28 // Returns matcher for HTTP Authentication dialog. |
| 29 id<GREYMatcher> HttpAuthDialog() { | 29 id<GREYMatcher> HttpAuthDialog() { |
| 30 NSString* title = l10n_util::GetNSStringWithFixup(IDS_LOGIN_DIALOG_TITLE); | 30 NSString* title = l10n_util::GetNSStringWithFixup(IDS_LOGIN_DIALOG_TITLE); |
| 31 return chrome_test_util::StaticTextWithAccessibilityLabel(title); | 31 return chrome_test_util::StaticTextWithAccessibilityLabel(title); |
| 32 } | 32 } |
| 33 | 33 |
| 34 // Returns matcher for Username text field. | 34 // Returns matcher for Username text field. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 chrome_test_util::LoadUrl(URL); | 84 chrome_test_util::LoadUrl(URL); |
| 85 WaitForHttpAuthDialog(); | 85 WaitForHttpAuthDialog(); |
| 86 | 86 |
| 87 // Enter valid username and password. | 87 // Enter valid username and password. |
| 88 [[EarlGrey selectElementWithMatcher:UsernameField()] | 88 [[EarlGrey selectElementWithMatcher:UsernameField()] |
| 89 performAction:grey_typeText(@"gooduser")]; | 89 performAction:grey_typeText(@"gooduser")]; |
| 90 [[EarlGrey selectElementWithMatcher:PasswordField()] | 90 [[EarlGrey selectElementWithMatcher:PasswordField()] |
| 91 performAction:grey_typeText(@"goodpass")]; | 91 performAction:grey_typeText(@"goodpass")]; |
| 92 [[EarlGrey selectElementWithMatcher:LoginButton()] performAction:grey_tap()]; | 92 [[EarlGrey selectElementWithMatcher:LoginButton()] performAction:grey_tap()]; |
| 93 | 93 |
| 94 const std::string pageText = web::HttpAuthResponseProvider::page_text(); | 94 NSString* pageText = |
| 95 [[EarlGrey selectElementWithMatcher:WebViewContainingText(pageText)] | 95 base::SysUTF8ToNSString(web::HttpAuthResponseProvider::page_text()); |
| 96 assertWithMatcher:grey_notNil()]; | 96 [ChromeEarlGrey waitForWebViewContainingText:pageText]; |
| 97 } | 97 } |
| 98 | 98 |
| 99 // Tests Basic HTTP Authentication with incorrect username and password. | 99 // Tests Basic HTTP Authentication with incorrect username and password. |
| 100 - (void)testUnsuccessfullBasicAuth { | 100 - (void)testUnsuccessfullBasicAuth { |
| 101 if (IsIPadIdiom()) { | 101 if (IsIPadIdiom()) { |
| 102 // EG does not allow interactions with HTTP Dialog when loading spinner is | 102 // EG does not allow interactions with HTTP Dialog when loading spinner is |
| 103 // animated. TODO(crbug.com/680290): Enable this test on iPad when EarlGrey | 103 // animated. TODO(crbug.com/680290): Enable this test on iPad when EarlGrey |
| 104 // allows tapping dialog buttons with active page load spinner. | 104 // allows tapping dialog buttons with active page load spinner. |
| 105 EARL_GREY_TEST_DISABLED(@"Tab Title not displayed on handset."); | 105 EARL_GREY_TEST_DISABLED(@"Tab Title not displayed on handset."); |
| 106 } | 106 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 137 chrome_test_util::LoadUrl(URL); | 137 chrome_test_util::LoadUrl(URL); |
| 138 WaitForHttpAuthDialog(); | 138 WaitForHttpAuthDialog(); |
| 139 | 139 |
| 140 [[EarlGrey selectElementWithMatcher:chrome_test_util::CancelButton()] | 140 [[EarlGrey selectElementWithMatcher:chrome_test_util::CancelButton()] |
| 141 performAction:grey_tap()]; | 141 performAction:grey_tap()]; |
| 142 [[EarlGrey selectElementWithMatcher:HttpAuthDialog()] | 142 [[EarlGrey selectElementWithMatcher:HttpAuthDialog()] |
| 143 assertWithMatcher:grey_nil()]; | 143 assertWithMatcher:grey_nil()]; |
| 144 } | 144 } |
| 145 | 145 |
| 146 @end | 146 @end |
| OLD | NEW |