| 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 | 8 |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "components/reading_list/ios/reading_list_model.h" | 11 #include "components/reading_list/ios/reading_list_model.h" |
| 12 #include "ios/chrome/browser/reading_list/reading_list_model_factory.h" | 12 #include "ios/chrome/browser/reading_list/reading_list_model_factory.h" |
| 13 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" | 13 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" |
| 14 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" | 14 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" |
| 15 #import "ios/chrome/browser/ui/reading_list/reading_list_collection_view_item.h" | 15 #import "ios/chrome/browser/ui/reading_list/reading_list_collection_view_item.h" |
| 16 #import "ios/chrome/browser/ui/reading_list/reading_list_empty_collection_backgr
ound.h" |
| 16 #include "ios/chrome/browser/ui/ui_util.h" | 17 #include "ios/chrome/browser/ui/ui_util.h" |
| 17 #include "ios/chrome/grit/ios_strings.h" | 18 #include "ios/chrome/grit/ios_strings.h" |
| 18 #include "ios/chrome/grit/ios_theme_resources.h" | 19 #include "ios/chrome/grit/ios_theme_resources.h" |
| 19 #import "ios/chrome/test/app/chrome_test_util.h" | 20 #import "ios/chrome/test/app/chrome_test_util.h" |
| 20 #import "ios/chrome/test/earl_grey/accessibility_util.h" | 21 #import "ios/chrome/test/earl_grey/accessibility_util.h" |
| 21 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" | 22 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" |
| 22 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" | 23 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" |
| 23 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 24 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |
| 24 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 25 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |
| 25 #import "ios/testing/earl_grey/disabled_test_macros.h" | 26 #import "ios/testing/earl_grey/disabled_test_macros.h" |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 // Computes the number of read entries in the model. | 189 // Computes the number of read entries in the model. |
| 189 size_t ModelReadSize(ReadingListModel* model) { | 190 size_t ModelReadSize(ReadingListModel* model) { |
| 190 size_t size = 0; | 191 size_t size = 0; |
| 191 for (const auto& url : model->Keys()) { | 192 for (const auto& url : model->Keys()) { |
| 192 if (model->GetEntryByURL(url)->IsRead()) { | 193 if (model->GetEntryByURL(url)->IsRead()) { |
| 193 size++; | 194 size++; |
| 194 } | 195 } |
| 195 } | 196 } |
| 196 return size; | 197 return size; |
| 197 } | 198 } |
| 199 |
| 200 // Returns a match for the Reading List Empty Collection Background. |
| 201 id<GREYMatcher> EmptyBackground() { |
| 202 return grey_accessibilityID( |
| 203 [ReadingListEmptyCollectionBackground accessibilityIdentifier]); |
| 204 } |
| 198 } // namespace | 205 } // namespace |
| 199 | 206 |
| 200 // Test class for the Reading List menu. | 207 // Test class for the Reading List menu. |
| 201 @interface ReadingListTestCase : ChromeTestCase | 208 @interface ReadingListTestCase : ChromeTestCase |
| 202 | 209 |
| 203 @end | 210 @end |
| 204 | 211 |
| 205 @implementation ReadingListTestCase | 212 @implementation ReadingListTestCase |
| 206 | 213 |
| 207 - (void)setUp { | 214 - (void)setUp { |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 | 528 |
| 522 // Tap the action sheet. | 529 // Tap the action sheet. |
| 523 TapButtonWithID(IDS_IOS_READING_LIST_MARK_READ_BUTTON); | 530 TapButtonWithID(IDS_IOS_READING_LIST_MARK_READ_BUTTON); |
| 524 | 531 |
| 525 AssertAllEntriesVisible(); | 532 AssertAllEntriesVisible(); |
| 526 XCTAssertEqual(kNumberReadEntries + 1, ModelReadSize(GetReadingListModel())); | 533 XCTAssertEqual(kNumberReadEntries + 1, ModelReadSize(GetReadingListModel())); |
| 527 XCTAssertEqual(kNumberUnreadEntries - 1, | 534 XCTAssertEqual(kNumberUnreadEntries - 1, |
| 528 GetReadingListModel()->unread_size()); | 535 GetReadingListModel()->unread_size()); |
| 529 } | 536 } |
| 530 | 537 |
| 538 // Tests that you can delete multiple read items in the Reading List without |
| 539 // creating a crash (crbug.com/701956). |
| 540 - (void)testDeleteMultipleItems { |
| 541 // Add entries. |
| 542 ReadingListModel* model = GetReadingListModel(); |
| 543 for (int i = 0; i < 11; i++) { |
| 544 std::string increment = std::to_string(i); |
| 545 model->AddEntry(GURL(kReadURL + increment), |
| 546 std::string(kReadTitle + increment), |
| 547 reading_list::ADDED_VIA_CURRENT_APP); |
| 548 model->SetReadStatus(GURL(kReadURL + increment), true); |
| 549 } |
| 550 |
| 551 // Delete them from the Reading List view. |
| 552 OpenReadingList(); |
| 553 [[EarlGrey selectElementWithMatcher:EmptyBackground()] |
| 554 assertWithMatcher:grey_nil()]; |
| 555 TapButtonWithID(IDS_IOS_READING_LIST_EDIT_BUTTON); |
| 556 TapButtonWithID(IDS_IOS_READING_LIST_DELETE_ALL_READ_BUTTON); |
| 557 |
| 558 // Verify the background string is displayed. |
| 559 [[EarlGrey selectElementWithMatcher:EmptyBackground()] |
| 560 assertWithMatcher:grey_notNil()]; |
| 561 } |
| 562 |
| 531 @end | 563 @end |
| OLD | NEW |