| 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/memory/ptr_util.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "base/test/ios/wait_util.h" |
| 11 #include "components/reading_list/core/reading_list_model.h" | 13 #include "components/reading_list/core/reading_list_model.h" |
| 12 #include "ios/chrome/browser/reading_list/reading_list_model_factory.h" | 14 #include "ios/chrome/browser/reading_list/reading_list_model_factory.h" |
| 13 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" | 15 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" |
| 14 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" | 16 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" |
| 15 #import "ios/chrome/browser/ui/reading_list/reading_list_collection_view_item.h" | 17 #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" | 18 #import "ios/chrome/browser/ui/reading_list/reading_list_empty_collection_backgr
ound.h" |
| 17 #include "ios/chrome/browser/ui/ui_util.h" | 19 #include "ios/chrome/browser/ui/ui_util.h" |
| 18 #include "ios/chrome/grit/ios_strings.h" | 20 #include "ios/chrome/grit/ios_strings.h" |
| 19 #include "ios/chrome/grit/ios_theme_resources.h" | 21 #include "ios/chrome/grit/ios_theme_resources.h" |
| 20 #import "ios/chrome/test/app/chrome_test_util.h" | 22 #import "ios/chrome/test/app/chrome_test_util.h" |
| 23 #include "ios/chrome/test/app/navigation_test_util.h" |
| 24 #import "ios/chrome/test/app/tab_test_util.h" |
| 21 #import "ios/chrome/test/earl_grey/accessibility_util.h" | 25 #import "ios/chrome/test/earl_grey/accessibility_util.h" |
| 22 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" | 26 #import "ios/chrome/test/earl_grey/chrome_earl_grey.h" |
| 23 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" | 27 #import "ios/chrome/test/earl_grey/chrome_earl_grey_ui.h" |
| 24 #import "ios/chrome/test/earl_grey/chrome_matchers.h" | 28 #import "ios/chrome/test/earl_grey/chrome_matchers.h" |
| 25 #import "ios/chrome/test/earl_grey/chrome_test_case.h" | 29 #import "ios/chrome/test/earl_grey/chrome_test_case.h" |
| 26 #import "ios/testing/wait_util.h" | 30 #import "ios/testing/wait_util.h" |
| 27 #import "ios/third_party/material_components_ios/src/components/Snackbar/src/Mat
erialSnackbar.h" | 31 #import "ios/third_party/material_components_ios/src/components/Snackbar/src/Mat
erialSnackbar.h" |
| 32 #import "ios/web/public/navigation_manager.h" |
| 33 #import "ios/web/public/reload_type.h" |
| 28 #import "ios/web/public/test/http_server.h" | 34 #import "ios/web/public/test/http_server.h" |
| 29 #import "ios/web/public/test/http_server_util.h" | 35 #import "ios/web/public/test/http_server_util.h" |
| 36 #import "ios/web/public/test/response_providers/delayed_response_provider.h" |
| 37 #import "ios/web/public/test/response_providers/html_response_provider.h" |
| 30 | 38 |
| 31 #if !defined(__has_feature) || !__has_feature(objc_arc) | 39 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 32 #error "This file requires ARC support." | 40 #error "This file requires ARC support." |
| 33 #endif | 41 #endif |
| 34 | 42 |
| 35 namespace { | 43 namespace { |
| 44 const char kContentToRemove[] = "Text that distillation should remove."; |
| 45 const char kContentToKeep[] = "Text that distillation should keep."; |
| 46 const char kDistillableTitle[] = "Tomato"; |
| 47 const char kDistillableURL[] = "http://potato"; |
| 48 const char kNonDistillableURL[] = "http://beans"; |
| 36 const char kReadTitle[] = "foobar"; | 49 const char kReadTitle[] = "foobar"; |
| 37 const char kReadURL[] = "http://readfoobar.com"; | 50 const char kReadURL[] = "http://readfoobar.com"; |
| 38 const char kUnreadTitle[] = "I am an unread entry"; | 51 const char kUnreadTitle[] = "I am an unread entry"; |
| 39 const char kUnreadURL[] = "http://unreadfoobar.com"; | 52 const char kUnreadURL[] = "http://unreadfoobar.com"; |
| 40 const char kReadURL2[] = "http://kReadURL2.com"; | 53 const char kReadURL2[] = "http://kReadURL2.com"; |
| 41 const char kReadTitle2[] = "read item 2"; | 54 const char kReadTitle2[] = "read item 2"; |
| 42 const char kUnreadTitle2[] = "I am another unread entry"; | 55 const char kUnreadTitle2[] = "I am another unread entry"; |
| 43 const char kUnreadURL2[] = "http://unreadfoobar2.com"; | 56 const char kUnreadURL2[] = "http://unreadfoobar2.com"; |
| 44 const size_t kNumberReadEntries = 2; | 57 const size_t kNumberReadEntries = 2; |
| 45 const size_t kNumberUnreadEntries = 2; | 58 const size_t kNumberUnreadEntries = 2; |
| 46 const CFTimeInterval kSnackbarAppearanceTimeout = 5; | 59 const CFTimeInterval kSnackbarAppearanceTimeout = 5; |
| 47 const CFTimeInterval kSnackbarDisappearanceTimeout = | 60 const CFTimeInterval kSnackbarDisappearanceTimeout = |
| 48 MDCSnackbarMessageDurationMax + 1; | 61 MDCSnackbarMessageDurationMax + 1; |
| 62 const CFTimeInterval kLoadOfflineTimeout = 5; |
| 49 const CFTimeInterval kLongPressDuration = 1.0; | 63 const CFTimeInterval kLongPressDuration = 1.0; |
| 50 const char kReadHeader[] = "Read"; | 64 const char kReadHeader[] = "Read"; |
| 51 const char kUnreadHeader[] = "Unread"; | 65 const char kUnreadHeader[] = "Unread"; |
| 52 | 66 |
| 53 // Returns the string concatenated |n| times. | 67 // Returns the string concatenated |n| times. |
| 54 std::string operator*(const std::string& s, unsigned int n) { | 68 std::string operator*(const std::string& s, unsigned int n) { |
| 55 std::ostringstream out; | 69 std::ostringstream out; |
| 56 for (unsigned int i = 0; i < n; i++) | 70 for (unsigned int i = 0; i < n; i++) |
| 57 out << s; | 71 out << s; |
| 58 return out.str(); | 72 return out.str(); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 } | 208 } |
| 195 } | 209 } |
| 196 return size; | 210 return size; |
| 197 } | 211 } |
| 198 | 212 |
| 199 // Returns a match for the Reading List Empty Collection Background. | 213 // Returns a match for the Reading List Empty Collection Background. |
| 200 id<GREYMatcher> EmptyBackground() { | 214 id<GREYMatcher> EmptyBackground() { |
| 201 return grey_accessibilityID( | 215 return grey_accessibilityID( |
| 202 [ReadingListEmptyCollectionBackground accessibilityIdentifier]); | 216 [ReadingListEmptyCollectionBackground accessibilityIdentifier]); |
| 203 } | 217 } |
| 218 |
| 219 // Adds the current page to the Reading List. |
| 220 void AddCurrentPageToReadingList() { |
| 221 // Add the page to the reading list. |
| 222 [ChromeEarlGreyUI openShareMenu]; |
| 223 TapButtonWithID(IDS_IOS_SHARE_MENU_READING_LIST_ACTION); |
| 224 |
| 225 // Wait for the snackbar to appear. |
| 226 id<GREYMatcher> snackbar_matcher = |
| 227 chrome_test_util::ButtonWithAccessibilityLabelId( |
| 228 IDS_IOS_READING_LIST_SNACKBAR_MESSAGE); |
| 229 ConditionBlock wait_for_appearance = ^{ |
| 230 NSError* error = nil; |
| 231 [[EarlGrey selectElementWithMatcher:snackbar_matcher] |
| 232 assertWithMatcher:grey_notNil() |
| 233 error:&error]; |
| 234 return error == nil; |
| 235 }; |
| 236 GREYAssert(testing::WaitUntilConditionOrTimeout(kSnackbarAppearanceTimeout, |
| 237 wait_for_appearance), |
| 238 @"Snackbar did not appear."); |
| 239 |
| 240 // Wait for the snackbar to disappear. |
| 241 ConditionBlock wait_for_disappearance = ^{ |
| 242 NSError* error = nil; |
| 243 [[EarlGrey selectElementWithMatcher:snackbar_matcher] |
| 244 assertWithMatcher:grey_nil() |
| 245 error:&error]; |
| 246 return error == nil; |
| 247 }; |
| 248 GREYAssert(testing::WaitUntilConditionOrTimeout(kSnackbarDisappearanceTimeout, |
| 249 wait_for_disappearance), |
| 250 @"Snackbar did not disappear."); |
| 251 } |
| 252 |
| 253 // Returns the responses for a web server that can serve a distillable content |
| 254 // at kDistillableURL and a not distillable content at kNotDistillableURL. |
| 255 std::map<GURL, std::string> ResponsesForDistillationServer() { |
| 256 // Setup a server serving a distillable page at http://potato with the title |
| 257 // "tomato", and a non distillable page at http://beans |
| 258 std::map<GURL, std::string> responses; |
| 259 std::string page_title = "Tomato"; |
| 260 const GURL distillable_page_url = |
| 261 web::test::HttpServer::MakeUrl(kDistillableURL); |
| 262 |
| 263 std::string content_to_remove(kContentToRemove); |
| 264 std::string content_to_keep(kContentToKeep); |
| 265 // Distillation only occurs on pages that are not too small. |
| 266 responses[distillable_page_url] = |
| 267 "<html><head><title>" + page_title + "</title></head>" + |
| 268 content_to_remove * 20 + "<article>" + content_to_keep * 20 + |
| 269 "</article>" + content_to_remove * 20 + "</html>"; |
| 270 const GURL non_distillable_page_url = |
| 271 web::test::HttpServer::MakeUrl(kNonDistillableURL); |
| 272 responses[non_distillable_page_url] = |
| 273 "<html><head><title>greens</title></head></html>"; |
| 274 return responses; |
| 275 } |
| 276 |
| 277 // Tests that the correct version of kDistillableURL is displayed. |
| 278 void AssertIsShowingDistillablePage(bool online) { |
| 279 // There will be multiple reload. Wait. |
| 280 id<GREYMatcher> web_view_match = nil; |
| 281 if (online) { |
| 282 web_view_match = chrome_test_util::WebViewContainingText(kContentToKeep); |
| 283 } else { |
| 284 web_view_match = chrome_test_util::StaticHtmlViewContainingText( |
| 285 base::SysUTF8ToNSString(kContentToKeep)); |
| 286 } |
| 287 ConditionBlock wait_for_loading = ^{ |
| 288 NSError* error = nil; |
| 289 [[EarlGrey selectElementWithMatcher:web_view_match] |
| 290 assertWithMatcher:grey_notNil() |
| 291 error:&error]; |
| 292 return error == nil; |
| 293 }; |
| 294 GREYAssert(testing::WaitUntilConditionOrTimeout(kLoadOfflineTimeout, |
| 295 wait_for_loading), |
| 296 @"Page did not load."); |
| 297 |
| 298 // Test Omnibox URL |
| 299 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 300 "localhost:8080/potato/")] |
| 301 assertWithMatcher:grey_notNil()]; |
| 302 |
| 303 // Test presence of online page |
| 304 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| 305 kContentToKeep)] |
| 306 assertWithMatcher:online ? grey_notNil() : grey_nil()]; |
| 307 |
| 308 // Test presence of offline page |
| 309 [[EarlGrey |
| 310 selectElementWithMatcher:chrome_test_util::StaticHtmlViewContainingText( |
| 311 base::SysUTF8ToNSString(kContentToKeep))] |
| 312 assertWithMatcher:online ? grey_nil() : grey_notNil()]; |
| 313 |
| 314 // Test the presence of the omnibox offline chip. |
| 315 [[EarlGrey |
| 316 selectElementWithMatcher:grey_allOf( |
| 317 chrome_test_util::PageSecurityInfoButton(), |
| 318 chrome_test_util::ButtonWithImage( |
| 319 IDR_IOS_OMNIBOX_OFFLINE), |
| 320 nil)] |
| 321 assertWithMatcher:online ? grey_nil() : grey_notNil()]; |
| 322 } |
| 323 |
| 204 } // namespace | 324 } // namespace |
| 205 | 325 |
| 206 // Test class for the Reading List menu. | 326 // Test class for the Reading List menu. |
| 207 @interface ReadingListTestCase : ChromeTestCase | 327 @interface ReadingListTestCase : ChromeTestCase |
| 208 | 328 |
| 209 @end | 329 @end |
| 210 | 330 |
| 211 @implementation ReadingListTestCase | 331 @implementation ReadingListTestCase |
| 212 | 332 |
| 213 - (void)setUp { | 333 - (void)setUp { |
| 214 [super setUp]; | 334 [super setUp]; |
| 215 ReadingListModel* model = GetReadingListModel(); | 335 ReadingListModel* model = GetReadingListModel(); |
| 216 for (const GURL& url : model->Keys()) | 336 for (const GURL& url : model->Keys()) |
| 217 model->RemoveEntryByURL(url); | 337 model->RemoveEntryByURL(url); |
| 218 } | 338 } |
| 219 | 339 |
| 340 - (void)tearDown { |
| 341 web::test::HttpServer& server = web::test::HttpServer::GetSharedInstance(); |
| 342 if (!server.IsRunning()) { |
| 343 server.StartOrDie(); |
| 344 } |
| 345 [super tearDown]; |
| 346 } |
| 347 |
| 220 // Tests that the Reading List view is accessible. | 348 // Tests that the Reading List view is accessible. |
| 221 - (void)testAccessibility { | 349 - (void)testAccessibility { |
| 222 AddEntriesAndEnterEdit(); | 350 AddEntriesAndEnterEdit(); |
| 223 // In edit mode. | 351 // In edit mode. |
| 224 chrome_test_util::VerifyAccessibilityForCurrentScreen(); | 352 chrome_test_util::VerifyAccessibilityForCurrentScreen(); |
| 225 TapButtonWithID(IDS_IOS_READING_LIST_CANCEL_BUTTON); | 353 TapButtonWithID(IDS_IOS_READING_LIST_CANCEL_BUTTON); |
| 226 chrome_test_util::VerifyAccessibilityForCurrentScreen(); | 354 chrome_test_util::VerifyAccessibilityForCurrentScreen(); |
| 227 } | 355 } |
| 228 | 356 |
| 229 // Tests that sharing a web page to the Reading List results in a snackbar | 357 // Tests that sharing a web page to the Reading List results in a snackbar |
| 230 // appearing, and that the Reading List entry is present in the Reading List. | 358 // appearing, and that the Reading List entry is present in the Reading List. |
| 231 - (void)testSavingToReadingList { | 359 // Loads offline version via context menu. |
| 232 // Setup a server serving a distillable page at http://potato with the title | 360 - (void)testSavingToReadingListAndLoadDistilled { |
| 233 // "tomato", and a non distillable page at http://beans | 361 web::test::SetUpSimpleHttpServer(ResponsesForDistillationServer()); |
| 234 std::map<GURL, std::string> responses; | 362 GURL distillablePageURL(web::test::HttpServer::MakeUrl(kDistillableURL)); |
| 235 const GURL distillablePageURL = | 363 GURL nonDistillablePageURL( |
| 236 web::test::HttpServer::MakeUrl("http://potato"); | 364 web::test::HttpServer::MakeUrl(kNonDistillableURL)); |
| 237 std::string pageTitle = "tomato"; | 365 std::string pageTitle(kDistillableTitle); |
| 238 | |
| 239 std::string contentToRemove = "Text that distillation should remove."; | |
| 240 std::string contentToKeep = "Text that distillation should keep."; | |
| 241 // Distillation only occurs on pages that are not too small. | |
| 242 responses[distillablePageURL] = | |
| 243 "<html><head><title>" + pageTitle + "</title></head>" + | |
| 244 contentToRemove * 20 + "<article>" + contentToKeep * 20 + "</article>" + | |
| 245 contentToRemove * 20 + "</html>"; | |
| 246 const GURL nonDistillablePageURL = | |
| 247 web::test::HttpServer::MakeUrl("http://beans"); | |
| 248 responses[nonDistillablePageURL] = | |
| 249 "<html><head><title>greens</title></head></html>"; | |
| 250 | |
| 251 web::test::SetUpSimpleHttpServer(responses); | |
| 252 | |
| 253 // Open http://potato | 366 // Open http://potato |
| 254 [ChromeEarlGrey loadURL:distillablePageURL]; | 367 [ChromeEarlGrey loadURL:distillablePageURL]; |
| 255 | 368 |
| 256 // Add the page to the reading list. | 369 AddCurrentPageToReadingList(); |
| 257 [ChromeEarlGreyUI openShareMenu]; | |
| 258 TapButtonWithID(IDS_IOS_SHARE_MENU_READING_LIST_ACTION); | |
| 259 | |
| 260 // Wait for the snackbar to appear. | |
| 261 id<GREYMatcher> snackbarMatcher = | |
| 262 chrome_test_util::ButtonWithAccessibilityLabelId( | |
| 263 IDS_IOS_READING_LIST_SNACKBAR_MESSAGE); | |
| 264 ConditionBlock waitForAppearance = ^{ | |
| 265 NSError* error = nil; | |
| 266 [[EarlGrey selectElementWithMatcher:snackbarMatcher] | |
| 267 assertWithMatcher:grey_notNil() | |
| 268 error:&error]; | |
| 269 return error == nil; | |
| 270 }; | |
| 271 GREYAssert(testing::WaitUntilConditionOrTimeout(kSnackbarAppearanceTimeout, | |
| 272 waitForAppearance), | |
| 273 @"Snackbar did not appear."); | |
| 274 | |
| 275 // Wait for the snackbar to disappear. | |
| 276 ConditionBlock waitForDisappearance = ^{ | |
| 277 NSError* error = nil; | |
| 278 [[EarlGrey selectElementWithMatcher:snackbarMatcher] | |
| 279 assertWithMatcher:grey_nil() | |
| 280 error:&error]; | |
| 281 return error == nil; | |
| 282 }; | |
| 283 GREYAssert(testing::WaitUntilConditionOrTimeout(kSnackbarDisappearanceTimeout, | |
| 284 waitForDisappearance), | |
| 285 @"Snackbar did not disappear."); | |
| 286 | 370 |
| 287 // Navigate to http://beans | 371 // Navigate to http://beans |
| 288 [ChromeEarlGrey loadURL:nonDistillablePageURL]; | 372 [ChromeEarlGrey loadURL:nonDistillablePageURL]; |
| 289 [ChromeEarlGrey waitForPageToFinishLoading]; | 373 [ChromeEarlGrey waitForPageToFinishLoading]; |
| 290 | 374 |
| 291 // Verify that an entry with the correct title is present in the reading list. | 375 // Verify that an entry with the correct title is present in the reading list. |
| 292 OpenReadingList(); | 376 OpenReadingList(); |
| 293 AssertEntryVisible(pageTitle); | 377 AssertEntryVisible(pageTitle); |
| 294 | 378 |
| 295 // Long press the entry, and open it offline. | 379 // Long press the entry, and open it offline. |
| 296 LongPressEntry(pageTitle); | 380 LongPressEntry(pageTitle); |
| 297 TapButtonWithID(IDS_IOS_READING_LIST_CONTENT_CONTEXT_OFFLINE); | 381 TapButtonWithID(IDS_IOS_READING_LIST_CONTENT_CONTEXT_OFFLINE); |
| 298 | 382 AssertIsShowingDistillablePage(false); |
| 299 // Verify that the correct distilled content is shown. | |
| 300 [[EarlGrey | |
| 301 selectElementWithMatcher:chrome_test_util::StaticHtmlViewContainingText( | |
| 302 base::SysUTF8ToNSString( | |
| 303 contentToKeep.c_str()))] | |
| 304 assertWithMatcher:grey_notNil()]; | |
| 305 [[EarlGrey | |
| 306 selectElementWithMatcher:chrome_test_util::StaticHtmlViewContainingText( | |
| 307 base::SysUTF8ToNSString( | |
| 308 contentToRemove.c_str()))] | |
| 309 assertWithMatcher:grey_nil()]; | |
| 310 | |
| 311 // Verify that the Omnibox' Info Bubble uses the offline icon. | |
| 312 [[EarlGrey | |
| 313 selectElementWithMatcher:chrome_test_util::PageSecurityInfoButton()] | |
| 314 assertWithMatcher:chrome_test_util::ButtonWithImage( | |
| 315 IDR_IOS_OMNIBOX_OFFLINE)]; | |
| 316 | 383 |
| 317 // Tap the Omnibox' Info Bubble to open the Page Info. | 384 // Tap the Omnibox' Info Bubble to open the Page Info. |
| 318 [[EarlGrey | 385 [[EarlGrey |
| 319 selectElementWithMatcher:chrome_test_util::PageSecurityInfoButton()] | 386 selectElementWithMatcher:chrome_test_util::PageSecurityInfoButton()] |
| 320 performAction:grey_tap()]; | 387 performAction:grey_tap()]; |
| 321 | |
| 322 // Verify that the Page Info is about offline pages. | 388 // Verify that the Page Info is about offline pages. |
| 323 id<GREYMatcher> pageInfoTitleMatcher = | 389 id<GREYMatcher> pageInfoTitleMatcher = |
| 324 chrome_test_util::StaticTextWithAccessibilityLabelId( | 390 chrome_test_util::StaticTextWithAccessibilityLabelId( |
| 325 IDS_IOS_PAGE_INFO_OFFLINE_TITLE); | 391 IDS_IOS_PAGE_INFO_OFFLINE_TITLE); |
| 326 [[EarlGrey selectElementWithMatcher:pageInfoTitleMatcher] | 392 [[EarlGrey selectElementWithMatcher:pageInfoTitleMatcher] |
| 327 assertWithMatcher:grey_notNil()]; | 393 assertWithMatcher:grey_notNil()]; |
| 328 | 394 |
| 329 // Verify that the webState's title is correct. | 395 // Verify that the webState's title is correct. |
| 330 XCTAssertTrue(chrome_test_util::GetCurrentWebState()->GetTitle() == | 396 XCTAssertTrue(chrome_test_util::GetCurrentWebState()->GetTitle() == |
| 331 base::ASCIIToUTF16(pageTitle.c_str())); | 397 base::ASCIIToUTF16(pageTitle.c_str())); |
| 332 } | 398 } |
| 333 | 399 |
| 400 // Tests that sharing a web page to the Reading List results in a snackbar |
| 401 // appearing, and that the Reading List entry is present in the Reading List. |
| 402 // Loads online version by tapping on entry. |
| 403 - (void)testSavingToReadingListAndLoadNormal { |
| 404 web::test::SetUpSimpleHttpServer(ResponsesForDistillationServer()); |
| 405 web::test::HttpServer& server = web::test::HttpServer::GetSharedInstance(); |
| 406 std::string pageTitle(kDistillableTitle); |
| 407 |
| 408 // Open http://potato |
| 409 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kDistillableURL)]; |
| 410 |
| 411 AddCurrentPageToReadingList(); |
| 412 |
| 413 // Navigate to http://beans |
| 414 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kNonDistillableURL)]; |
| 415 [ChromeEarlGrey waitForPageToFinishLoading]; |
| 416 |
| 417 // Verify that an entry with the correct title is present in the reading list. |
| 418 OpenReadingList(); |
| 419 AssertEntryVisible(pageTitle); |
| 420 // Long press the entry, and open it offline. |
| 421 TapEntry(pageTitle); |
| 422 |
| 423 AssertIsShowingDistillablePage(true); |
| 424 // Stop server to reload offline. |
| 425 server.Stop(); |
| 426 |
| 427 chrome_test_util::GetCurrentWebState()->GetNavigationManager()->Reload( |
| 428 web::ReloadType::NORMAL, false); |
| 429 AssertIsShowingDistillablePage(false); |
| 430 } |
| 431 |
| 432 // Tests that sharing a web page to the Reading List results in a snackbar |
| 433 // appearing, and that the Reading List entry is present in the Reading List. |
| 434 // Loads offline version by tapping on entry without web server. |
| 435 - (void)testSavingToReadingListAndLoadNoNetwork { |
| 436 web::test::SetUpSimpleHttpServer(ResponsesForDistillationServer()); |
| 437 std::string pageTitle(kDistillableTitle); |
| 438 web::test::HttpServer& server = web::test::HttpServer::GetSharedInstance(); |
| 439 // Open http://potato |
| 440 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kDistillableURL)]; |
| 441 |
| 442 AddCurrentPageToReadingList(); |
| 443 |
| 444 // Navigate to http://beans |
| 445 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kNonDistillableURL)]; |
| 446 [ChromeEarlGrey waitForPageToFinishLoading]; |
| 447 |
| 448 // Stop server to generate error. |
| 449 server.Stop(); |
| 450 |
| 451 // Verify that an entry with the correct title is present in the reading list. |
| 452 OpenReadingList(); |
| 453 AssertEntryVisible(pageTitle); |
| 454 // Long press the entry, and open it offline. |
| 455 TapEntry(pageTitle); |
| 456 |
| 457 AssertIsShowingDistillablePage(false); |
| 458 // Start server to reload online error. |
| 459 server.StartOrDie(); |
| 460 web::test::SetUpSimpleHttpServer(ResponsesForDistillationServer()); |
| 461 |
| 462 chrome_test_util::GetCurrentWebState()->GetNavigationManager()->Reload( |
| 463 web::ReloadType::NORMAL, false); |
| 464 AssertIsShowingDistillablePage(true); |
| 465 } |
| 466 |
| 467 // Tests that sharing a web page to the Reading List results in a snackbar |
| 468 // appearing, and that the Reading List entry is present in the Reading List. |
| 469 // Loads offline version by tapping on entry with delayed web server. |
| 470 - (void)testSavingToReadingListAndLoadBadNetwork { |
| 471 web::test::SetUpSimpleHttpServer(ResponsesForDistillationServer()); |
| 472 std::string pageTitle(kDistillableTitle); |
| 473 // Open http://potato |
| 474 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kDistillableURL)]; |
| 475 |
| 476 AddCurrentPageToReadingList(); |
| 477 |
| 478 // Navigate to http://beans |
| 479 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kNonDistillableURL)]; |
| 480 [ChromeEarlGrey waitForPageToFinishLoading]; |
| 481 |
| 482 web::test::SetUpHttpServer(base::MakeUnique<web::DelayedResponseProvider>( |
| 483 base::MakeUnique<HtmlResponseProvider>(ResponsesForDistillationServer()), |
| 484 5)); |
| 485 |
| 486 // Verify that an entry with the correct title is present in the reading list. |
| 487 OpenReadingList(); |
| 488 AssertEntryVisible(pageTitle); |
| 489 // Long press the entry, and open it offline. |
| 490 TapEntry(pageTitle); |
| 491 |
| 492 AssertIsShowingDistillablePage(false); |
| 493 // Reload should load online page. |
| 494 chrome_test_util::GetCurrentWebState()->GetNavigationManager()->Reload( |
| 495 web::ReloadType::NORMAL, false); |
| 496 AssertIsShowingDistillablePage(true); |
| 497 // Reload should load offline page. |
| 498 chrome_test_util::GetCurrentWebState()->GetNavigationManager()->Reload( |
| 499 web::ReloadType::NORMAL, false); |
| 500 AssertIsShowingDistillablePage(false); |
| 501 } |
| 502 |
| 334 // Tests that only the "Edit" button is showing when not editing. | 503 // Tests that only the "Edit" button is showing when not editing. |
| 335 - (void)testVisibleButtonsNonEditingMode { | 504 - (void)testVisibleButtonsNonEditingMode { |
| 336 GetReadingListModel()->AddEntry(GURL(kUnreadURL), std::string(kUnreadTitle), | 505 GetReadingListModel()->AddEntry(GURL(kUnreadURL), std::string(kUnreadTitle), |
| 337 reading_list::ADDED_VIA_CURRENT_APP); | 506 reading_list::ADDED_VIA_CURRENT_APP); |
| 338 OpenReadingList(); | 507 OpenReadingList(); |
| 339 | 508 |
| 340 AssertButtonNotVisibleWithID(IDS_IOS_READING_LIST_DELETE_BUTTON); | 509 AssertButtonNotVisibleWithID(IDS_IOS_READING_LIST_DELETE_BUTTON); |
| 341 AssertButtonNotVisibleWithID(IDS_IOS_READING_LIST_DELETE_ALL_READ_BUTTON); | 510 AssertButtonNotVisibleWithID(IDS_IOS_READING_LIST_DELETE_ALL_READ_BUTTON); |
| 342 AssertButtonNotVisibleWithID(IDS_IOS_READING_LIST_MARK_READ_BUTTON); | 511 AssertButtonNotVisibleWithID(IDS_IOS_READING_LIST_MARK_READ_BUTTON); |
| 343 AssertButtonNotVisibleWithID(IDS_IOS_READING_LIST_MARK_UNREAD_BUTTON); | 512 AssertButtonNotVisibleWithID(IDS_IOS_READING_LIST_MARK_UNREAD_BUTTON); |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 assertWithMatcher:grey_nil()]; | 722 assertWithMatcher:grey_nil()]; |
| 554 TapButtonWithID(IDS_IOS_READING_LIST_EDIT_BUTTON); | 723 TapButtonWithID(IDS_IOS_READING_LIST_EDIT_BUTTON); |
| 555 TapButtonWithID(IDS_IOS_READING_LIST_DELETE_ALL_READ_BUTTON); | 724 TapButtonWithID(IDS_IOS_READING_LIST_DELETE_ALL_READ_BUTTON); |
| 556 | 725 |
| 557 // Verify the background string is displayed. | 726 // Verify the background string is displayed. |
| 558 [[EarlGrey selectElementWithMatcher:EmptyBackground()] | 727 [[EarlGrey selectElementWithMatcher:EmptyBackground()] |
| 559 assertWithMatcher:grey_notNil()]; | 728 assertWithMatcher:grey_notNil()]; |
| 560 } | 729 } |
| 561 | 730 |
| 562 @end | 731 @end |
| OLD | NEW |