| 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 #import <UIKit/UIKit.h> | 6 #import <UIKit/UIKit.h> |
| 7 #import <XCTest/XCTest.h> | 7 #import <XCTest/XCTest.h> |
| 8 #include <map> | 8 #include <map> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 #include "net/ssl/channel_id_store.h" | 48 #include "net/ssl/channel_id_store.h" |
| 49 #include "net/url_request/url_request_context.h" | 49 #include "net/url_request/url_request_context.h" |
| 50 #include "net/url_request/url_request_context_getter.h" | 50 #include "net/url_request/url_request_context_getter.h" |
| 51 #include "ui/base/l10n/l10n_util.h" | 51 #include "ui/base/l10n/l10n_util.h" |
| 52 #include "url/gurl.h" | 52 #include "url/gurl.h" |
| 53 | 53 |
| 54 #if !defined(__has_feature) || !__has_feature(objc_arc) | 54 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 55 #error "This file requires ARC support." | 55 #error "This file requires ARC support." |
| 56 #endif | 56 #endif |
| 57 | 57 |
| 58 using base::SysUTF8ToNSString; |
| 58 using chrome_test_util::ButtonWithAccessibilityLabelId; | 59 using chrome_test_util::ButtonWithAccessibilityLabelId; |
| 59 using chrome_test_util::NavigationBarDoneButton; | 60 using chrome_test_util::NavigationBarDoneButton; |
| 60 | 61 |
| 61 namespace { | 62 namespace { |
| 62 | 63 |
| 63 const char kTestOrigin1[] = "http://host1:1/"; | 64 const char kTestOrigin1[] = "http://host1:1/"; |
| 64 | 65 |
| 65 const char kUrl[] = "http://foo/browsing"; | 66 const char kUrl[] = "http://foo/browsing"; |
| 66 const char kUrlWithSetCookie[] = "http://foo/set_cookie"; | 67 const char kUrlWithSetCookie[] = "http://foo/set_cookie"; |
| 67 const char kResponse[] = "bar"; | 68 const char kResponse[] = "bar"; |
| (...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 response[web::test::HttpServer::MakeUrl(kUrlWithSetCookie)] = | 643 response[web::test::HttpServer::MakeUrl(kUrlWithSetCookie)] = |
| 643 std::pair<std::string, std::string>(base::SysNSStringToUTF8(cookieForURL), | 644 std::pair<std::string, std::string>(base::SysNSStringToUTF8(cookieForURL), |
| 644 kResponseWithSetCookie); | 645 kResponseWithSetCookie); |
| 645 response[web::test::HttpServer::MakeUrl(kUrl)] = | 646 response[web::test::HttpServer::MakeUrl(kUrl)] = |
| 646 std::pair<std::string, std::string>("", kResponse); | 647 std::pair<std::string, std::string>("", kResponse); |
| 647 | 648 |
| 648 web::test::SetUpSimpleHttpServerWithSetCookies(response); | 649 web::test::SetUpSimpleHttpServerWithSetCookies(response); |
| 649 | 650 |
| 650 // Load |kUrl| and check that cookie is not set. | 651 // Load |kUrl| and check that cookie is not set. |
| 651 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kUrl)]; | 652 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kUrl)]; |
| 652 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 653 [ChromeEarlGrey waitForWebViewContainingText:SysUTF8ToNSString(kResponse)]; |
| 653 kResponse)] | |
| 654 assertWithMatcher:grey_notNil()]; | |
| 655 | 654 |
| 656 NSDictionary* cookies = [ChromeEarlGrey cookies]; | 655 NSDictionary* cookies = [ChromeEarlGrey cookies]; |
| 657 GREYAssertEqual(0U, cookies.count, @"No cookie should be found."); | 656 GREYAssertEqual(0U, cookies.count, @"No cookie should be found."); |
| 658 | 657 |
| 659 // Visit |kUrlWithSetCookie| to set a cookie and then load |kUrl| to check it | 658 // Visit |kUrlWithSetCookie| to set a cookie and then load |kUrl| to check it |
| 660 // is still set. | 659 // is still set. |
| 661 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kUrlWithSetCookie)]; | 660 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kUrlWithSetCookie)]; |
| 662 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 661 [ChromeEarlGrey |
| 663 kResponseWithSetCookie)] | 662 waitForWebViewContainingText:SysUTF8ToNSString(kResponseWithSetCookie)]; |
| 664 assertWithMatcher:grey_notNil()]; | |
| 665 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kUrl)]; | 663 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kUrl)]; |
| 666 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 664 [ChromeEarlGrey waitForWebViewContainingText:SysUTF8ToNSString(kResponse)]; |
| 667 kResponse)] | |
| 668 assertWithMatcher:grey_notNil()]; | |
| 669 | 665 |
| 670 cookies = [ChromeEarlGrey cookies]; | 666 cookies = [ChromeEarlGrey cookies]; |
| 671 GREYAssertEqualObjects(kCookieValue, cookies[kCookieName], | 667 GREYAssertEqualObjects(kCookieValue, cookies[kCookieName], |
| 672 @"Failed to set cookie."); | 668 @"Failed to set cookie."); |
| 673 GREYAssertEqual(1U, cookies.count, @"Only one cookie should be found."); | 669 GREYAssertEqual(1U, cookies.count, @"Only one cookie should be found."); |
| 674 | 670 |
| 675 // Restore the Clear Browsing Data checkmarks prefs to their default state | 671 // Restore the Clear Browsing Data checkmarks prefs to their default state |
| 676 // in Teardown. | 672 // in Teardown. |
| 677 __weak SettingsTestCase* weakSelf = self; | 673 __weak SettingsTestCase* weakSelf = self; |
| 678 [self setTearDownHandler:^{ | 674 [self setTearDownHandler:^{ |
| 679 [weakSelf restoreClearBrowsingDataCheckmarksToDefault]; | 675 [weakSelf restoreClearBrowsingDataCheckmarksToDefault]; |
| 680 }]; | 676 }]; |
| 681 | 677 |
| 682 // Clear all cookies. | 678 // Clear all cookies. |
| 683 [self clearCookiesAndSiteData]; | 679 [self clearCookiesAndSiteData]; |
| 684 | 680 |
| 685 // Reload and test that there are no cookies left. | 681 // Reload and test that there are no cookies left. |
| 686 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kUrl)]; | 682 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kUrl)]; |
| 687 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 683 [ChromeEarlGrey waitForWebViewContainingText:SysUTF8ToNSString(kResponse)]; |
| 688 kResponse)] | |
| 689 assertWithMatcher:grey_notNil()]; | |
| 690 | 684 |
| 691 cookies = [ChromeEarlGrey cookies]; | 685 cookies = [ChromeEarlGrey cookies]; |
| 692 GREYAssertEqual(0U, cookies.count, @"No cookie should be found."); | 686 GREYAssertEqual(0U, cookies.count, @"No cookie should be found."); |
| 693 | 687 |
| 694 chrome_test_util::CloseAllTabs(); | 688 chrome_test_util::CloseAllTabs(); |
| 695 } | 689 } |
| 696 | 690 |
| 697 // Verifies that logging into a form on a web page allows the user to save and | 691 // Verifies that logging into a form on a web page allows the user to save and |
| 698 // then clear a password. | 692 // then clear a password. |
| 699 - (void)testClearPasswords { | 693 - (void)testClearPasswords { |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1031 performAction:grey_tap()]; | 1025 performAction:grey_tap()]; |
| 1032 [[EarlGrey selectElementWithMatcher:PrivacyButton()] | 1026 [[EarlGrey selectElementWithMatcher:PrivacyButton()] |
| 1033 performAction:grey_tap()]; | 1027 performAction:grey_tap()]; |
| 1034 [[EarlGrey selectElementWithMatcher:SendUsageDataButton()] | 1028 [[EarlGrey selectElementWithMatcher:SendUsageDataButton()] |
| 1035 performAction:grey_tap()]; | 1029 performAction:grey_tap()]; |
| 1036 chrome_test_util::VerifyAccessibilityForCurrentScreen(); | 1030 chrome_test_util::VerifyAccessibilityForCurrentScreen(); |
| 1037 [self closeSubSettingsMenu]; | 1031 [self closeSubSettingsMenu]; |
| 1038 } | 1032 } |
| 1039 | 1033 |
| 1040 @end | 1034 @end |
| OLD | NEW |