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 <XCTest/XCTest.h> | 6 #import <XCTest/XCTest.h> |
7 | 7 |
8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
9 #include "components/bookmarks/browser/bookmark_model.h" | 9 #include "components/bookmarks/browser/bookmark_model.h" |
10 #include "components/bookmarks/browser/titled_url_match.h" | 10 #include "components/bookmarks/browser/titled_url_match.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 31 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |
32 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h" | 32 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity.h" |
33 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.
h" | 33 #import "ios/public/provider/chrome/browser/signin/fake_chrome_identity_service.
h" |
34 #import "ios/testing/wait_util.h" | 34 #import "ios/testing/wait_util.h" |
35 #import "ios/web/public/test/http_server/http_server.h" | 35 #import "ios/web/public/test/http_server/http_server.h" |
36 #include "ios/web/public/test/http_server/http_server_util.h" | 36 #include "ios/web/public/test/http_server/http_server_util.h" |
37 #import "net/base/mac/url_conversions.h" | 37 #import "net/base/mac/url_conversions.h" |
38 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
39 #include "url/gurl.h" | 39 #include "url/gurl.h" |
40 | 40 |
| 41 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 42 #error "This file requires ARC support." |
| 43 #endif |
| 44 |
41 namespace { | 45 namespace { |
42 | 46 |
43 // Constant for timeout while waiting for asynchronous sync operations. | 47 // Constant for timeout while waiting for asynchronous sync operations. |
44 const NSTimeInterval kSyncOperationTimeout = 10.0; | 48 const NSTimeInterval kSyncOperationTimeout = 10.0; |
45 | 49 |
46 // Returns a fake identity. | 50 // Returns a fake identity. |
47 ChromeIdentity* GetFakeIdentity1() { | 51 ChromeIdentity* GetFakeIdentity1() { |
48 return [FakeChromeIdentity identityWithEmail:@"foo@gmail.com" | 52 return [FakeChromeIdentity identityWithEmail:@"foo@gmail.com" |
49 gaiaID:@"fooID" | 53 gaiaID:@"fooID" |
50 name:@"Fake Foo"]; | 54 name:@"Fake Foo"]; |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 block:^BOOL { | 452 block:^BOOL { |
449 NSError* error = nil; | 453 NSError* error = nil; |
450 BOOL result = | 454 BOOL result = |
451 chrome_test_util::VerifyNumberOfSyncEntitiesWithName( | 455 chrome_test_util::VerifyNumberOfSyncEntitiesWithName( |
452 syncer::TYPED_URLS, mockURL.spec(), 1, &error); | 456 syncer::TYPED_URLS, mockURL.spec(), 1, &error); |
453 blockSafeError = [error copy]; | 457 blockSafeError = [error copy]; |
454 return result; | 458 return result; |
455 }]; | 459 }]; |
456 BOOL success = [condition waitWithTimeout:kSyncOperationTimeout]; | 460 BOOL success = [condition waitWithTimeout:kSyncOperationTimeout]; |
457 DCHECK(success || blockSafeError); | 461 DCHECK(success || blockSafeError); |
458 if (blockSafeError) { | |
459 [blockSafeError autorelease]; | |
460 } | |
461 GREYAssertTrue(success, [blockSafeError localizedDescription]); | 462 GREYAssertTrue(success, [blockSafeError localizedDescription]); |
462 } | 463 } |
463 | 464 |
464 // Tests that typed url is downloaded from sync server. | 465 // Tests that typed url is downloaded from sync server. |
465 - (void)testSyncTypedUrlDownload { | 466 - (void)testSyncTypedUrlDownload { |
466 const GURL mockURL("http://not-a-real-site/"); | 467 const GURL mockURL("http://not-a-real-site/"); |
467 | 468 |
468 chrome_test_util::ClearBrowsingHistory(); | 469 chrome_test_util::ClearBrowsingHistory(); |
469 [self setTearDownHandler:^{ | 470 [self setTearDownHandler:^{ |
470 chrome_test_util::ClearBrowsingHistory(); | 471 chrome_test_util::ClearBrowsingHistory(); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 conditionWithName:@"Wait for typed URL to be downloaded." | 574 conditionWithName:@"Wait for typed URL to be downloaded." |
574 block:^BOOL { | 575 block:^BOOL { |
575 NSError* error = nil; | 576 NSError* error = nil; |
576 BOOL result = chrome_test_util::IsTypedUrlPresentOnClient( | 577 BOOL result = chrome_test_util::IsTypedUrlPresentOnClient( |
577 mockURL, NO, &error); | 578 mockURL, NO, &error); |
578 blockSafeError = [error copy]; | 579 blockSafeError = [error copy]; |
579 return result; | 580 return result; |
580 }]; | 581 }]; |
581 BOOL success = [condition waitWithTimeout:kSyncOperationTimeout]; | 582 BOOL success = [condition waitWithTimeout:kSyncOperationTimeout]; |
582 DCHECK(success || blockSafeError); | 583 DCHECK(success || blockSafeError); |
583 if (blockSafeError) { | |
584 [blockSafeError autorelease]; | |
585 } | |
586 GREYAssert(success, [blockSafeError localizedDescription]); | 584 GREYAssert(success, [blockSafeError localizedDescription]); |
587 } | 585 } |
588 | 586 |
589 #pragma mark - Test Utilities | 587 #pragma mark - Test Utilities |
590 | 588 |
591 // Adds a bookmark with the given |url| and |title| into the Mobile Bookmarks | 589 // Adds a bookmark with the given |url| and |title| into the Mobile Bookmarks |
592 // folder. | 590 // folder. |
593 // TODO(crbug.com/646164): This is copied from bookmarks_egtest.mm and should | 591 // TODO(crbug.com/646164): This is copied from bookmarks_egtest.mm and should |
594 // move to common location. | 592 // move to common location. |
595 - (void)addBookmark:(const GURL)url withTitle:(NSString*)title { | 593 - (void)addBookmark:(const GURL)url withTitle:(NSString*)title { |
(...skipping 23 matching lines...) Expand all Loading... |
619 | 617 |
620 // Verify the correct number of bookmarks exist. | 618 // Verify the correct number of bookmarks exist. |
621 base::string16 matchString = base::SysNSStringToUTF16(title); | 619 base::string16 matchString = base::SysNSStringToUTF16(title); |
622 std::vector<bookmarks::TitledUrlMatch> matches; | 620 std::vector<bookmarks::TitledUrlMatch> matches; |
623 bookmarkModel->GetBookmarksMatching(matchString, 50, &matches); | 621 bookmarkModel->GetBookmarksMatching(matchString, 50, &matches); |
624 const size_t count = matches.size(); | 622 const size_t count = matches.size(); |
625 GREYAssertEqual(expectedCount, count, @"Unexpected number of bookmarks"); | 623 GREYAssertEqual(expectedCount, count, @"Unexpected number of bookmarks"); |
626 } | 624 } |
627 | 625 |
628 @end | 626 @end |
OLD | NEW |