| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 44 #import "ios/web/public/test/web_view_interaction_test_util.h" | 44 #import "ios/web/public/test/web_view_interaction_test_util.h" | 
| 45 #import "ios/web/public/web_state/web_state.h" | 45 #import "ios/web/public/web_state/web_state.h" | 
| 46 #include "ios/web/public/web_thread.h" | 46 #include "ios/web/public/web_thread.h" | 
| 47 #include "net/ssl/channel_id_service.h" | 47 #include "net/ssl/channel_id_service.h" | 
| 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) | 
|  | 55 #error "This file requires ARC support." | 
|  | 56 #endif | 
|  | 57 | 
| 54 using chrome_test_util::ButtonWithAccessibilityLabelId; | 58 using chrome_test_util::ButtonWithAccessibilityLabelId; | 
| 55 using chrome_test_util::NavigationBarDoneButton; | 59 using chrome_test_util::NavigationBarDoneButton; | 
| 56 | 60 | 
| 57 namespace { | 61 namespace { | 
| 58 | 62 | 
| 59 const char kTestOrigin1[] = "http://host1:1/"; | 63 const char kTestOrigin1[] = "http://host1:1/"; | 
| 60 | 64 | 
| 61 const char kUrl[] = "http://foo/browsing"; | 65 const char kUrl[] = "http://foo/browsing"; | 
| 62 const char kUrlWithSetCookie[] = "http://foo/set_cookie"; | 66 const char kUrlWithSetCookie[] = "http://foo/set_cookie"; | 
| 63 const char kResponse[] = "bar"; | 67 const char kResponse[] = "bar"; | 
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 181 } | 185 } | 
| 182 | 186 | 
| 183 // Set certificate for host |kTestOrigin1| for testing. | 187 // Set certificate for host |kTestOrigin1| for testing. | 
| 184 void SetCertificate() { | 188 void SetCertificate() { | 
| 185   ios::ChromeBrowserState* browserState = | 189   ios::ChromeBrowserState* browserState = | 
| 186       chrome_test_util::GetOriginalBrowserState(); | 190       chrome_test_util::GetOriginalBrowserState(); | 
| 187   dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); | 191   dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); | 
| 188   scoped_refptr<net::URLRequestContextGetter> getter = | 192   scoped_refptr<net::URLRequestContextGetter> getter = | 
| 189       browserState->GetRequestContext(); | 193       browserState->GetRequestContext(); | 
| 190   web::WebThread::PostTask( | 194   web::WebThread::PostTask( | 
| 191       web::WebThread::IO, FROM_HERE, base::BindBlock(^{ | 195       web::WebThread::IO, FROM_HERE, base::BindBlockArc(^{ | 
| 192         net::ChannelIDService* channel_id_service = | 196         net::ChannelIDService* channel_id_service = | 
| 193             getter->GetURLRequestContext()->channel_id_service(); | 197             getter->GetURLRequestContext()->channel_id_service(); | 
| 194         net::ChannelIDStore* channel_id_store = | 198         net::ChannelIDStore* channel_id_store = | 
| 195             channel_id_service->GetChannelIDStore(); | 199             channel_id_service->GetChannelIDStore(); | 
| 196         base::Time now = base::Time::Now(); | 200         base::Time now = base::Time::Now(); | 
| 197         channel_id_store->SetChannelID( | 201         channel_id_store->SetChannelID( | 
| 198             base::MakeUnique<net::ChannelIDStore::ChannelID>( | 202             base::MakeUnique<net::ChannelIDStore::ChannelID>( | 
| 199                 kTestOrigin1, now, crypto::ECPrivateKey::Create())); | 203                 kTestOrigin1, now, crypto::ECPrivateKey::Create())); | 
| 200       })); | 204       })); | 
| 201 | 205 | 
| 202   // The ChannelIDStore may not be loaded, so adding the new cert may not happen | 206   // The ChannelIDStore may not be loaded, so adding the new cert may not happen | 
| 203   // immediately.  This posted task signals the semaphore if the cert was added, | 207   // immediately.  This posted task signals the semaphore if the cert was added, | 
| 204   // or re-posts itself to check again later otherwise. | 208   // or re-posts itself to check again later otherwise. | 
| 205   web::WebThread::PostTask(web::WebThread::IO, FROM_HERE, | 209   web::WebThread::PostTask(web::WebThread::IO, FROM_HERE, | 
| 206                            base::Bind(&CheckCertificate, getter, semaphore)); | 210                            base::Bind(&CheckCertificate, getter, semaphore)); | 
| 207 | 211 | 
| 208   dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); | 212   dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); | 
| 209   dispatch_release(semaphore); |  | 
| 210 } | 213 } | 
| 211 | 214 | 
| 212 // Fetching channel id is expected to complete immediately in this test, so a | 215 // Fetching channel id is expected to complete immediately in this test, so a | 
| 213 // dummy callback function is set for testing. | 216 // dummy callback function is set for testing. | 
| 214 void CertCallback(int err, | 217 void CertCallback(int err, | 
| 215                   const std::string& server_identifier, | 218                   const std::string& server_identifier, | 
| 216                   std::unique_ptr<crypto::ECPrivateKey> key) {} | 219                   std::unique_ptr<crypto::ECPrivateKey> key) {} | 
| 217 | 220 | 
| 218 // Check if certificate is empty for host |kTestOrigin1|. | 221 // Check if certificate is empty for host |kTestOrigin1|. | 
| 219 bool IsCertificateCleared() { | 222 bool IsCertificateCleared() { | 
| 220   ios::ChromeBrowserState* browserState = | 223   ios::ChromeBrowserState* browserState = | 
| 221       chrome_test_util::GetOriginalBrowserState(); | 224       chrome_test_util::GetOriginalBrowserState(); | 
| 222   __block int result; | 225   __block int result; | 
| 223   dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); | 226   dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); | 
| 224   scoped_refptr<net::URLRequestContextGetter> getter = | 227   scoped_refptr<net::URLRequestContextGetter> getter = | 
| 225       browserState->GetRequestContext(); | 228       browserState->GetRequestContext(); | 
| 226   web::WebThread::PostTask( | 229   web::WebThread::PostTask( | 
| 227       web::WebThread::IO, FROM_HERE, base::BindBlock(^{ | 230       web::WebThread::IO, FROM_HERE, base::BindBlockArc(^{ | 
| 228         net::ChannelIDService* channel_id_service = | 231         net::ChannelIDService* channel_id_service = | 
| 229             getter->GetURLRequestContext()->channel_id_service(); | 232             getter->GetURLRequestContext()->channel_id_service(); | 
| 230         std::unique_ptr<crypto::ECPrivateKey> dummy_key; | 233         std::unique_ptr<crypto::ECPrivateKey> dummy_key; | 
| 231         result = channel_id_service->GetChannelIDStore()->GetChannelID( | 234         result = channel_id_service->GetChannelIDStore()->GetChannelID( | 
| 232             kTestOrigin1, &dummy_key, base::Bind(CertCallback)); | 235             kTestOrigin1, &dummy_key, base::Bind(CertCallback)); | 
| 233         dispatch_semaphore_signal(semaphore); | 236         dispatch_semaphore_signal(semaphore); | 
| 234       })); | 237       })); | 
| 235   dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); | 238   dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); | 
| 236   dispatch_release(semaphore); |  | 
| 237   return result == net::ERR_FILE_NOT_FOUND; | 239   return result == net::ERR_FILE_NOT_FOUND; | 
| 238 } | 240 } | 
| 239 | 241 | 
| 240 }  // namespace | 242 }  // namespace | 
| 241 | 243 | 
| 242 // Settings tests for Chrome. | 244 // Settings tests for Chrome. | 
| 243 @interface SettingsTestCase : ChromeTestCase | 245 @interface SettingsTestCase : ChromeTestCase | 
| 244 @end | 246 @end | 
| 245 | 247 | 
| 246 @implementation SettingsTestCase | 248 @implementation SettingsTestCase | 
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 665                                           kResponse)] | 667                                           kResponse)] | 
| 666       assertWithMatcher:grey_notNil()]; | 668       assertWithMatcher:grey_notNil()]; | 
| 667 | 669 | 
| 668   cookies = [ChromeEarlGrey cookies]; | 670   cookies = [ChromeEarlGrey cookies]; | 
| 669   GREYAssertEqualObjects(kCookieValue, cookies[kCookieName], | 671   GREYAssertEqualObjects(kCookieValue, cookies[kCookieName], | 
| 670                          @"Failed to set cookie."); | 672                          @"Failed to set cookie."); | 
| 671   GREYAssertEqual(1U, cookies.count, @"Only one cookie should be found."); | 673   GREYAssertEqual(1U, cookies.count, @"Only one cookie should be found."); | 
| 672 | 674 | 
| 673   // Restore the Clear Browsing Data checkmarks prefs to their default state | 675   // Restore the Clear Browsing Data checkmarks prefs to their default state | 
| 674   // in Teardown. | 676   // in Teardown. | 
|  | 677   __weak SettingsTestCase* weakSelf = self; | 
| 675   [self setTearDownHandler:^{ | 678   [self setTearDownHandler:^{ | 
| 676     [self restoreClearBrowsingDataCheckmarksToDefault]; | 679     [weakSelf restoreClearBrowsingDataCheckmarksToDefault]; | 
| 677   }]; | 680   }]; | 
| 678 | 681 | 
| 679   // Clear all cookies. | 682   // Clear all cookies. | 
| 680   [self clearCookiesAndSiteData]; | 683   [self clearCookiesAndSiteData]; | 
| 681 | 684 | 
| 682   // Reload and test that there are no cookies left. | 685   // Reload and test that there are no cookies left. | 
| 683   [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kUrl)]; | 686   [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kUrl)]; | 
| 684   [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 687   [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 
| 685                                           kResponse)] | 688                                           kResponse)] | 
| 686       assertWithMatcher:grey_notNil()]; | 689       assertWithMatcher:grey_notNil()]; | 
| 687 | 690 | 
| 688   cookies = [ChromeEarlGrey cookies]; | 691   cookies = [ChromeEarlGrey cookies]; | 
| 689   GREYAssertEqual(0U, cookies.count, @"No cookie should be found."); | 692   GREYAssertEqual(0U, cookies.count, @"No cookie should be found."); | 
| 690 | 693 | 
| 691   chrome_test_util::CloseAllTabs(); | 694   chrome_test_util::CloseAllTabs(); | 
| 692 } | 695 } | 
| 693 | 696 | 
| 694 // Verifies that logging into a form on a web page allows the user to save and | 697 // Verifies that logging into a form on a web page allows the user to save and | 
| 695 // then clear a password. | 698 // then clear a password. | 
| 696 - (void)testClearPasswords { | 699 - (void)testClearPasswords { | 
| 697   ios::ChromeBrowserState* browserState = | 700   ios::ChromeBrowserState* browserState = | 
| 698       chrome_test_util::GetOriginalBrowserState(); | 701       chrome_test_util::GetOriginalBrowserState(); | 
| 699   PrefService* preferences = browserState->GetPrefs(); | 702   PrefService* preferences = browserState->GetPrefs(); | 
| 700   bool defaultPasswordManagerSavingPref = preferences->GetBoolean( | 703   bool defaultPasswordManagerSavingPref = preferences->GetBoolean( | 
| 701       password_manager::prefs::kPasswordManagerSavingEnabled); | 704       password_manager::prefs::kPasswordManagerSavingEnabled); | 
| 702 | 705 | 
| 703   [self enablePasswordManagement]; | 706   [self enablePasswordManagement]; | 
|  | 707   __weak SettingsTestCase* weakSelf = self; | 
| 704   [self setTearDownHandler:^{ | 708   [self setTearDownHandler:^{ | 
| 705     [self passwordsTearDown:defaultPasswordManagerSavingPref]; | 709     [weakSelf passwordsTearDown:defaultPasswordManagerSavingPref]; | 
| 706   }]; | 710   }]; | 
| 707 | 711 | 
| 708   // Clear passwords and check that none are saved. | 712   // Clear passwords and check that none are saved. | 
| 709   [self clearPasswords]; | 713   [self clearPasswords]; | 
| 710   [self checkIfPasswordsSaved:NO]; | 714   [self checkIfPasswordsSaved:NO]; | 
| 711 | 715 | 
| 712   // Login to page and click to save password and check that its saved. | 716   // Login to page and click to save password and check that its saved. | 
| 713   [self loadFormAndLogin]; | 717   [self loadFormAndLogin]; | 
| 714   [self checkIfPasswordsSaved:YES]; | 718   [self checkIfPasswordsSaved:YES]; | 
| 715 } | 719 } | 
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 749   chrome_test_util::SetFirstLaunchStateTo(YES); | 753   chrome_test_util::SetFirstLaunchStateTo(YES); | 
| 750   [self assertsMetricsPrefsForService:kBreakpadFirstLaunch]; | 754   [self assertsMetricsPrefsForService:kBreakpadFirstLaunch]; | 
| 751 } | 755 } | 
| 752 | 756 | 
| 753 // Set a server bound certificate, clears the site data through the UI and | 757 // Set a server bound certificate, clears the site data through the UI and | 
| 754 // checks that the certificate is deleted. | 758 // checks that the certificate is deleted. | 
| 755 - (void)testClearCertificates { | 759 - (void)testClearCertificates { | 
| 756   SetCertificate(); | 760   SetCertificate(); | 
| 757   // Restore the Clear Browsing Data checkmarks prefs to their default state in | 761   // Restore the Clear Browsing Data checkmarks prefs to their default state in | 
| 758   // Teardown. | 762   // Teardown. | 
|  | 763   __weak SettingsTestCase* weakSelf = self; | 
| 759   [self setTearDownHandler:^{ | 764   [self setTearDownHandler:^{ | 
| 760     [self restoreClearBrowsingDataCheckmarksToDefault]; | 765     [weakSelf restoreClearBrowsingDataCheckmarksToDefault]; | 
| 761   }]; | 766   }]; | 
| 762   GREYAssertFalse(IsCertificateCleared(), @"Failed to set certificate."); | 767   GREYAssertFalse(IsCertificateCleared(), @"Failed to set certificate."); | 
| 763   [self clearCookiesAndSiteData]; | 768   [self clearCookiesAndSiteData]; | 
| 764   GREYAssertTrue(IsCertificateCleared(), | 769   GREYAssertTrue(IsCertificateCleared(), | 
| 765                  @"Certificate is expected to be deleted."); | 770                  @"Certificate is expected to be deleted."); | 
| 766 } | 771 } | 
| 767 | 772 | 
| 768 // Verifies that Settings opens when signed-out and in Incognito mode. | 773 // Verifies that Settings opens when signed-out and in Incognito mode. | 
| 769 // This tests that crbug.com/607335 has not regressed. | 774 // This tests that crbug.com/607335 has not regressed. | 
| 770 - (void)testSettingsSignedOutIncognito { | 775 - (void)testSettingsSignedOutIncognito { | 
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 942   [self clearPasswords]; | 947   [self clearPasswords]; | 
| 943   [self checkIfPasswordsSaved:NO]; | 948   [self checkIfPasswordsSaved:NO]; | 
| 944 | 949 | 
| 945   ios::ChromeBrowserState* browserState = | 950   ios::ChromeBrowserState* browserState = | 
| 946       chrome_test_util::GetOriginalBrowserState(); | 951       chrome_test_util::GetOriginalBrowserState(); | 
| 947   PrefService* preferences = browserState->GetPrefs(); | 952   PrefService* preferences = browserState->GetPrefs(); | 
| 948   bool defaultPasswordManagerSavingPref = preferences->GetBoolean( | 953   bool defaultPasswordManagerSavingPref = preferences->GetBoolean( | 
| 949       password_manager::prefs::kPasswordManagerSavingEnabled); | 954       password_manager::prefs::kPasswordManagerSavingEnabled); | 
| 950 | 955 | 
| 951   [self enablePasswordManagement]; | 956   [self enablePasswordManagement]; | 
|  | 957   __weak SettingsTestCase* weakSelf = self; | 
| 952   [self setTearDownHandler:^{ | 958   [self setTearDownHandler:^{ | 
| 953     [self passwordsTearDown:defaultPasswordManagerSavingPref]; | 959     [weakSelf passwordsTearDown:defaultPasswordManagerSavingPref]; | 
| 954   }]; | 960   }]; | 
| 955 | 961 | 
| 956   [self loadFormAndLogin]; | 962   [self loadFormAndLogin]; | 
| 957   [self openPasswordSettings]; | 963   [self openPasswordSettings]; | 
| 958 | 964 | 
| 959   // Switch on edit mode. | 965   // Switch on edit mode. | 
| 960   [[EarlGrey selectElementWithMatcher:ButtonWithAccessibilityLabelId( | 966   [[EarlGrey selectElementWithMatcher:ButtonWithAccessibilityLabelId( | 
| 961                                           IDS_IOS_NAVIGATION_BAR_EDIT_BUTTON)] | 967                                           IDS_IOS_NAVIGATION_BAR_EDIT_BUTTON)] | 
| 962       performAction:grey_tap()]; | 968       performAction:grey_tap()]; | 
| 963   chrome_test_util::VerifyAccessibilityForCurrentScreen(); | 969   chrome_test_util::VerifyAccessibilityForCurrentScreen(); | 
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1025       performAction:grey_tap()]; | 1031       performAction:grey_tap()]; | 
| 1026   [[EarlGrey selectElementWithMatcher:PrivacyButton()] | 1032   [[EarlGrey selectElementWithMatcher:PrivacyButton()] | 
| 1027       performAction:grey_tap()]; | 1033       performAction:grey_tap()]; | 
| 1028   [[EarlGrey selectElementWithMatcher:SendUsageDataButton()] | 1034   [[EarlGrey selectElementWithMatcher:SendUsageDataButton()] | 
| 1029       performAction:grey_tap()]; | 1035       performAction:grey_tap()]; | 
| 1030   chrome_test_util::VerifyAccessibilityForCurrentScreen(); | 1036   chrome_test_util::VerifyAccessibilityForCurrentScreen(); | 
| 1031   [self closeSubSettingsMenu]; | 1037   [self closeSubSettingsMenu]; | 
| 1032 } | 1038 } | 
| 1033 | 1039 | 
| 1034 @end | 1040 @end | 
| OLD | NEW | 
|---|