Chromium Code Reviews| 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/mac/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 49 chrome_test_util::GetOriginalBrowserState()); | 49 chrome_test_util::GetOriginalBrowserState()); |
| 50 GREYAssert(testing::WaitUntilConditionOrTimeout(2, | 50 GREYAssert(testing::WaitUntilConditionOrTimeout(2, |
| 51 ^{ | 51 ^{ |
| 52 return model->loaded(); | 52 return model->loaded(); |
| 53 }), | 53 }), |
| 54 @"Reading List model did not load"); | 54 @"Reading List model did not load"); |
| 55 return model; | 55 return model; |
| 56 } | 56 } |
| 57 | 57 |
| 58 // Asserts the |button_id| button is not visible. | 58 // Asserts the |button_id| button is not visible. |
| 59 void AssertButtonNotVisibleWithID(int button_id) { | 59 void AssertButtonNotVisibleWithID(int button_id) { |
|
Eugene But (OOO till 7-30)
2017/01/23 19:39:03
Do you want to file a bug to get rid of these meth
baxley
2017/01/24 22:18:49
Filed a bug. I'll include it in updating the desig
| |
| 60 [[EarlGrey | 60 [[EarlGrey |
| 61 selectElementWithMatcher:chrome_test_util::buttonWithAccessibilityLabelId( | 61 selectElementWithMatcher:chrome_test_util::ButtonWithAccessibilityLabelId( |
| 62 button_id)] | 62 button_id)] |
| 63 assertWithMatcher:grey_notVisible()]; | 63 assertWithMatcher:grey_notVisible()]; |
| 64 } | 64 } |
| 65 | 65 |
| 66 // Assert the |button_id| button is visible. | 66 // Assert the |button_id| button is visible. |
| 67 void AssertButtonVisibleWithID(int button_id) { | 67 void AssertButtonVisibleWithID(int button_id) { |
| 68 [[EarlGrey | 68 [[EarlGrey |
| 69 selectElementWithMatcher:chrome_test_util::buttonWithAccessibilityLabelId( | 69 selectElementWithMatcher:chrome_test_util::ButtonWithAccessibilityLabelId( |
| 70 button_id)] | 70 button_id)] |
| 71 assertWithMatcher:grey_sufficientlyVisible()]; | 71 assertWithMatcher:grey_sufficientlyVisible()]; |
| 72 } | 72 } |
| 73 | 73 |
| 74 // Taps the |button_id| button. | 74 // Taps the |button_id| button. |
| 75 void TapButtonWithID(int button_id) { | 75 void TapButtonWithID(int button_id) { |
| 76 [[EarlGrey | 76 [[EarlGrey |
| 77 selectElementWithMatcher:chrome_test_util::buttonWithAccessibilityLabelId( | 77 selectElementWithMatcher:chrome_test_util::ButtonWithAccessibilityLabelId( |
| 78 button_id)] performAction:grey_tap()]; | 78 button_id)] performAction:grey_tap()]; |
| 79 } | 79 } |
| 80 | 80 |
| 81 // Taps the entry |title|. | 81 // Taps the entry |title|. |
| 82 void TapEntry(std::string title) { | 82 void TapEntry(std::string title) { |
| 83 [[EarlGrey selectElementWithMatcher: | 83 [[EarlGrey selectElementWithMatcher: |
| 84 grey_allOf(chrome_test_util::staticTextWithAccessibilityLabel( | 84 grey_allOf(chrome_test_util::StaticTextWithAccessibilityLabel( |
| 85 base::SysUTF8ToNSString(title)), | 85 base::SysUTF8ToNSString(title)), |
| 86 grey_sufficientlyVisible(), nil)] | 86 grey_sufficientlyVisible(), nil)] |
| 87 performAction:grey_tap()]; | 87 performAction:grey_tap()]; |
| 88 } | 88 } |
| 89 | 89 |
| 90 // Asserts that the entry |title| is visible. | 90 // Asserts that the entry |title| is visible. |
| 91 void AssertEntryVisible(std::string title) { | 91 void AssertEntryVisible(std::string title) { |
| 92 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; | 92 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; |
| 93 [[EarlGrey | 93 [[EarlGrey |
| 94 selectElementWithMatcher: | 94 selectElementWithMatcher: |
| 95 grey_allOf(chrome_test_util::staticTextWithAccessibilityLabel( | 95 grey_allOf(chrome_test_util::StaticTextWithAccessibilityLabel( |
| 96 base::SysUTF8ToNSString(title)), | 96 base::SysUTF8ToNSString(title)), |
| 97 grey_ancestor(grey_kindOfClass([ReadingListCell class])), | 97 grey_ancestor(grey_kindOfClass([ReadingListCell class])), |
| 98 nil)] assertWithMatcher:grey_sufficientlyVisible()]; | 98 nil)] assertWithMatcher:grey_sufficientlyVisible()]; |
| 99 } | 99 } |
| 100 | 100 |
| 101 // Asserts that all the entries are visible. | 101 // Asserts that all the entries are visible. |
| 102 void AssertAllEntriesVisible() { | 102 void AssertAllEntriesVisible() { |
| 103 AssertEntryVisible(kReadTitle); | 103 AssertEntryVisible(kReadTitle); |
| 104 AssertEntryVisible(kReadTitle2); | 104 AssertEntryVisible(kReadTitle2); |
| 105 AssertEntryVisible(kUnreadTitle); | 105 AssertEntryVisible(kUnreadTitle); |
| 106 AssertEntryVisible(kUnreadTitle2); | 106 AssertEntryVisible(kUnreadTitle2); |
| 107 | 107 |
| 108 // If the number of entries changes, make sure this assert gets updated. | 108 // If the number of entries changes, make sure this assert gets updated. |
| 109 GREYAssertEqual((size_t)2, kNumberReadEntries, | 109 GREYAssertEqual((size_t)2, kNumberReadEntries, |
| 110 @"The number of entries have changed"); | 110 @"The number of entries have changed"); |
| 111 GREYAssertEqual((size_t)2, kNumberUnreadEntries, | 111 GREYAssertEqual((size_t)2, kNumberUnreadEntries, |
| 112 @"The number of entries have changed"); | 112 @"The number of entries have changed"); |
| 113 } | 113 } |
| 114 | 114 |
| 115 // Asserts that the entry |title| is not visible. | 115 // Asserts that the entry |title| is not visible. |
| 116 void AssertEntryNotVisible(std::string title) { | 116 void AssertEntryNotVisible(std::string title) { |
| 117 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; | 117 [[GREYUIThreadExecutor sharedInstance] drainUntilIdle]; |
| 118 [[EarlGrey | 118 [[EarlGrey |
| 119 selectElementWithMatcher: | 119 selectElementWithMatcher: |
| 120 grey_allOf(chrome_test_util::staticTextWithAccessibilityLabel( | 120 grey_allOf(chrome_test_util::StaticTextWithAccessibilityLabel( |
| 121 base::SysUTF8ToNSString(title)), | 121 base::SysUTF8ToNSString(title)), |
| 122 grey_ancestor(grey_kindOfClass([ReadingListCell class])), | 122 grey_ancestor(grey_kindOfClass([ReadingListCell class])), |
| 123 nil)] assertWithMatcher:grey_notVisible()]; | 123 nil)] assertWithMatcher:grey_notVisible()]; |
| 124 } | 124 } |
| 125 | 125 |
| 126 // Asserts |header| is visible. | 126 // Asserts |header| is visible. |
| 127 void AssertHeaderNotVisible(std::string header) { | 127 void AssertHeaderNotVisible(std::string header) { |
| 128 [[EarlGrey selectElementWithMatcher:chrome_test_util:: | 128 [[EarlGrey selectElementWithMatcher:chrome_test_util:: |
| 129 staticTextWithAccessibilityLabel( | 129 StaticTextWithAccessibilityLabel( |
| 130 base::SysUTF8ToNSString(header))] | 130 base::SysUTF8ToNSString(header))] |
| 131 assertWithMatcher:grey_notVisible()]; | 131 assertWithMatcher:grey_notVisible()]; |
| 132 } | 132 } |
| 133 | 133 |
| 134 // Opens the reading list menu using command line. | 134 // Opens the reading list menu using command line. |
| 135 void OpenReadingList() { | 135 void OpenReadingList() { |
| 136 base::scoped_nsobject<GenericChromeCommand> command( | 136 base::scoped_nsobject<GenericChromeCommand> command( |
| 137 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_READING_LIST]); | 137 [[GenericChromeCommand alloc] initWithTag:IDC_SHOW_READING_LIST]); |
| 138 chrome_test_util::RunCommandWithActiveViewController(command); | 138 chrome_test_util::RunCommandWithActiveViewController(command); |
| 139 } | 139 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 | 203 |
| 204 // Open http://potato | 204 // Open http://potato |
| 205 [ChromeEarlGrey loadURL:regularPageURL]; | 205 [ChromeEarlGrey loadURL:regularPageURL]; |
| 206 | 206 |
| 207 // Add the page to the reading list. | 207 // Add the page to the reading list. |
| 208 [ChromeEarlGreyUI openShareMenu]; | 208 [ChromeEarlGreyUI openShareMenu]; |
| 209 TapButtonWithID(IDS_IOS_SHARE_MENU_READING_LIST_ACTION); | 209 TapButtonWithID(IDS_IOS_SHARE_MENU_READING_LIST_ACTION); |
| 210 | 210 |
| 211 // Wait for the snackbar to appear. | 211 // Wait for the snackbar to appear. |
| 212 id<GREYMatcher> snackbarMatcher = | 212 id<GREYMatcher> snackbarMatcher = |
| 213 chrome_test_util::buttonWithAccessibilityLabelId( | 213 chrome_test_util::ButtonWithAccessibilityLabelId( |
| 214 IDS_IOS_READING_LIST_SNACKBAR_MESSAGE); | 214 IDS_IOS_READING_LIST_SNACKBAR_MESSAGE); |
| 215 ConditionBlock waitForAppearance = ^{ | 215 ConditionBlock waitForAppearance = ^{ |
| 216 NSError* error = nil; | 216 NSError* error = nil; |
| 217 [[EarlGrey selectElementWithMatcher:snackbarMatcher] | 217 [[EarlGrey selectElementWithMatcher:snackbarMatcher] |
| 218 assertWithMatcher:grey_notNil() | 218 assertWithMatcher:grey_notNil() |
| 219 error:&error]; | 219 error:&error]; |
| 220 return error == nil; | 220 return error == nil; |
| 221 }; | 221 }; |
| 222 // Wait for the snackbar to disappear. | 222 // Wait for the snackbar to disappear. |
| 223 GREYAssert(testing::WaitUntilConditionOrTimeout(kSnackbarAppearanceTimeout, | 223 GREYAssert(testing::WaitUntilConditionOrTimeout(kSnackbarAppearanceTimeout, |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 436 // Tap the action sheet. | 436 // Tap the action sheet. |
| 437 TapButtonWithID(IDS_IOS_READING_LIST_MARK_READ_BUTTON); | 437 TapButtonWithID(IDS_IOS_READING_LIST_MARK_READ_BUTTON); |
| 438 | 438 |
| 439 AssertAllEntriesVisible(); | 439 AssertAllEntriesVisible(); |
| 440 XCTAssertEqual(kNumberReadEntries + 1, ModelReadSize(GetReadingListModel())); | 440 XCTAssertEqual(kNumberReadEntries + 1, ModelReadSize(GetReadingListModel())); |
| 441 XCTAssertEqual(kNumberUnreadEntries - 1, | 441 XCTAssertEqual(kNumberUnreadEntries - 1, |
| 442 GetReadingListModel()->unread_size()); | 442 GetReadingListModel()->unread_size()); |
| 443 } | 443 } |
| 444 | 444 |
| 445 @end | 445 @end |
| OLD | NEW |