Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(938)

Side by Side Diff: ios/chrome/browser/ui/reading_list/reading_list_egtest.mm

Issue 2762113002: Reading List iOS: Adapt loading offline for new reload process (Closed)
Patch Set: fix DCHECK Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/ios/reading_list_model.h" 13 #include "components/reading_list/ios/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 {
36 const char kReadTitle[] = "foobar"; 44 const char kReadTitle[] = "foobar";
37 const char kReadURL[] = "http://readfoobar.com"; 45 const char kReadURL[] = "http://readfoobar.com";
38 const char kUnreadTitle[] = "I am an unread entry"; 46 const char kUnreadTitle[] = "I am an unread entry";
39 const char kUnreadURL[] = "http://unreadfoobar.com"; 47 const char kUnreadURL[] = "http://unreadfoobar.com";
40 const char kReadURL2[] = "http://kReadURL2.com"; 48 const char kReadURL2[] = "http://kReadURL2.com";
41 const char kReadTitle2[] = "read item 2"; 49 const char kReadTitle2[] = "read item 2";
42 const char kUnreadTitle2[] = "I am another unread entry"; 50 const char kUnreadTitle2[] = "I am another unread entry";
43 const char kUnreadURL2[] = "http://unreadfoobar2.com"; 51 const char kUnreadURL2[] = "http://unreadfoobar2.com";
44 const size_t kNumberReadEntries = 2; 52 const size_t kNumberReadEntries = 2;
45 const size_t kNumberUnreadEntries = 2; 53 const size_t kNumberUnreadEntries = 2;
46 const CFTimeInterval kSnackbarAppearanceTimeout = 5; 54 const CFTimeInterval kSnackbarAppearanceTimeout = 5;
47 const CFTimeInterval kSnackbarDisappearanceTimeout = 55 const CFTimeInterval kSnackbarDisappearanceTimeout =
48 MDCSnackbarMessageDurationMax + 1; 56 MDCSnackbarMessageDurationMax + 1;
57 const CFTimeInterval kLoadOfflineTimeout = 5;
49 const CFTimeInterval kLongPressDuration = 1.0; 58 const CFTimeInterval kLongPressDuration = 1.0;
50 const char kReadHeader[] = "Read"; 59 const char kReadHeader[] = "Read";
51 const char kUnreadHeader[] = "Unread"; 60 const char kUnreadHeader[] = "Unread";
52 61
53 // Returns the string concatenated |n| times. 62 // Returns the string concatenated |n| times.
54 std::string operator*(const std::string& s, unsigned int n) { 63 std::string operator*(const std::string& s, unsigned int n) {
55 std::ostringstream out; 64 std::ostringstream out;
56 for (unsigned int i = 0; i < n; i++) 65 for (unsigned int i = 0; i < n; i++)
57 out << s; 66 out << s;
58 return out.str(); 67 return out.str();
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 } 203 }
195 } 204 }
196 return size; 205 return size;
197 } 206 }
198 207
199 // Returns a match for the Reading List Empty Collection Background. 208 // Returns a match for the Reading List Empty Collection Background.
200 id<GREYMatcher> EmptyBackground() { 209 id<GREYMatcher> EmptyBackground() {
201 return grey_accessibilityID( 210 return grey_accessibilityID(
202 [ReadingListEmptyCollectionBackground accessibilityIdentifier]); 211 [ReadingListEmptyCollectionBackground accessibilityIdentifier]);
203 } 212 }
213
214 // Adds an the current page to the Reading List.
215 void AddCurrentPageToReadingList() {
216 // Add the page to the reading list.
217 [ChromeEarlGreyUI openShareMenu];
218 TapButtonWithID(IDS_IOS_SHARE_MENU_READING_LIST_ACTION);
219
220 // Wait for the snackbar to appear.
221 id<GREYMatcher> snackbarMatcher =
222 chrome_test_util::ButtonWithAccessibilityLabelId(
223 IDS_IOS_READING_LIST_SNACKBAR_MESSAGE);
224 ConditionBlock waitForAppearance = ^{
225 NSError* error = nil;
226 [[EarlGrey selectElementWithMatcher:snackbarMatcher]
227 assertWithMatcher:grey_notNil()
228 error:&error];
229 return error == nil;
230 };
231 GREYAssert(testing::WaitUntilConditionOrTimeout(kSnackbarAppearanceTimeout,
232 waitForAppearance),
233 @"Snackbar did not appear.");
234
235 // Wait for the snackbar to disappear.
236 ConditionBlock waitForDisappearance = ^{
237 NSError* error = nil;
238 [[EarlGrey selectElementWithMatcher:snackbarMatcher]
239 assertWithMatcher:grey_nil()
240 error:&error];
241 return error == nil;
242 };
243 GREYAssert(testing::WaitUntilConditionOrTimeout(kSnackbarDisappearanceTimeout,
244 waitForDisappearance),
245 @"Snackbar did not disappear.");
246 }
204 } // namespace 247 } // namespace
205 248
206 // Test class for the Reading List menu. 249 // Test class for the Reading List menu.
207 @interface ReadingListTestCase : ChromeTestCase 250 @interface ReadingListTestCase : ChromeTestCase
208 251
209 @end 252 @end
210 253
211 @implementation ReadingListTestCase 254 @implementation ReadingListTestCase
212 255
213 - (void)setUp { 256 - (void)setUp {
214 [super setUp]; 257 [super setUp];
215 ReadingListModel* model = GetReadingListModel(); 258 ReadingListModel* model = GetReadingListModel();
216 for (const GURL& url : model->Keys()) 259 for (const GURL& url : model->Keys())
217 model->RemoveEntryByURL(url); 260 model->RemoveEntryByURL(url);
218 } 261 }
219 262
263 - (void)tearDown {
264 web::test::HttpServer& server = web::test::HttpServer::GetSharedInstance();
265 if (!server.IsRunning()) {
266 server.StartOrDie();
267 }
268 [super tearDown];
269 }
270
220 // Tests that the Reading List view is accessible. 271 // Tests that the Reading List view is accessible.
221 - (void)testAccessibility { 272 - (void)testAccessibility {
222 AddEntriesAndEnterEdit(); 273 AddEntriesAndEnterEdit();
223 // In edit mode. 274 // In edit mode.
224 chrome_test_util::VerifyAccessibilityForCurrentScreen(); 275 chrome_test_util::VerifyAccessibilityForCurrentScreen();
225 TapButtonWithID(IDS_IOS_READING_LIST_CANCEL_BUTTON); 276 TapButtonWithID(IDS_IOS_READING_LIST_CANCEL_BUTTON);
226 chrome_test_util::VerifyAccessibilityForCurrentScreen(); 277 chrome_test_util::VerifyAccessibilityForCurrentScreen();
227 } 278 }
228 279
229 // Tests that sharing a web page to the Reading List results in a snackbar 280 // 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. 281 // appearing, and that the Reading List entry is present in the Reading List.
231 - (void)testSavingToReadingList { 282 // Loads offline version via context menu.
283 - (void)testSavingToReadingListAndLoadDistilled {
232 // Setup a server serving a distillable page at http://potato with the title 284 // Setup a server serving a distillable page at http://potato with the title
233 // "tomato", and a non distillable page at http://beans 285 // "tomato", and a non distillable page at http://beans
234 std::map<GURL, std::string> responses; 286 std::map<GURL, std::string> responses;
287 std::string pageTitle = "Tomato";
235 const GURL distillablePageURL = 288 const GURL distillablePageURL =
236 web::test::HttpServer::MakeUrl("http://potato"); 289 web::test::HttpServer::MakeUrl("http://potato");
237 std::string pageTitle = "tomato";
238 290
239 std::string contentToRemove = "Text that distillation should remove."; 291 std::string contentToRemove = "Text that distillation should remove.";
240 std::string contentToKeep = "Text that distillation should keep."; 292 std::string contentToKeep = "Text that distillation should keep.";
241 // Distillation only occurs on pages that are not too small. 293 // Distillation only occurs on pages that are not too small.
242 responses[distillablePageURL] = 294 responses[distillablePageURL] =
243 "<html><head><title>" + pageTitle + "</title></head>" + 295 "<html><head><title>" + pageTitle + "</title></head>" +
244 contentToRemove * 20 + "<article>" + contentToKeep * 20 + "</article>" + 296 contentToRemove * 20 + "<article>" + contentToKeep * 20 + "</article>" +
245 contentToRemove * 20 + "</html>"; 297 contentToRemove * 20 + "</html>";
246 const GURL nonDistillablePageURL = 298 const GURL nonDistillablePageURL =
247 web::test::HttpServer::MakeUrl("http://beans"); 299 web::test::HttpServer::MakeUrl("http://beans");
248 responses[nonDistillablePageURL] = 300 responses[nonDistillablePageURL] =
249 "<html><head><title>greens</title></head></html>"; 301 "<html><head><title>greens</title></head></html>";
250 302
251 web::test::SetUpSimpleHttpServer(responses); 303 web::test::SetUpSimpleHttpServer(responses);
252 304
253 // Open http://potato 305 // Open http://potato
254 [ChromeEarlGrey loadURL:distillablePageURL]; 306 [ChromeEarlGrey loadURL:distillablePageURL];
255 307
256 // Add the page to the reading list. 308 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 309
287 // Navigate to http://beans 310 // Navigate to http://beans
288 [ChromeEarlGrey loadURL:nonDistillablePageURL]; 311 [ChromeEarlGrey loadURL:nonDistillablePageURL];
289 [ChromeEarlGrey waitForPageToFinishLoading]; 312 [ChromeEarlGrey waitForPageToFinishLoading];
290 313
291 // Verify that an entry with the correct title is present in the reading list. 314 // Verify that an entry with the correct title is present in the reading list.
292 OpenReadingList(); 315 OpenReadingList();
293 AssertEntryVisible(pageTitle); 316 AssertEntryVisible(pageTitle);
294 317
295 // Long press the entry, and open it offline. 318 // Long press the entry, and open it offline.
(...skipping 16 matching lines...) Expand all
312 [[EarlGrey 335 [[EarlGrey
313 selectElementWithMatcher:chrome_test_util::PageSecurityInfoButton()] 336 selectElementWithMatcher:chrome_test_util::PageSecurityInfoButton()]
314 assertWithMatcher:chrome_test_util::ButtonWithImage( 337 assertWithMatcher:chrome_test_util::ButtonWithImage(
315 IDR_IOS_OMNIBOX_OFFLINE)]; 338 IDR_IOS_OMNIBOX_OFFLINE)];
316 339
317 // Tap the Omnibox' Info Bubble to open the Page Info. 340 // Tap the Omnibox' Info Bubble to open the Page Info.
318 [[EarlGrey 341 [[EarlGrey
319 selectElementWithMatcher:chrome_test_util::PageSecurityInfoButton()] 342 selectElementWithMatcher:chrome_test_util::PageSecurityInfoButton()]
320 performAction:grey_tap()]; 343 performAction:grey_tap()];
321 344
345 // Test Omnibox URL
346 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText(
347 "localhost:8080/potato/")]
348 assertWithMatcher:grey_notNil()];
349
322 // Verify that the Page Info is about offline pages. 350 // Verify that the Page Info is about offline pages.
323 id<GREYMatcher> pageInfoTitleMatcher = 351 id<GREYMatcher> pageInfoTitleMatcher =
324 chrome_test_util::StaticTextWithAccessibilityLabelId( 352 chrome_test_util::StaticTextWithAccessibilityLabelId(
325 IDS_IOS_PAGE_INFO_OFFLINE_TITLE); 353 IDS_IOS_PAGE_INFO_OFFLINE_TITLE);
326 [[EarlGrey selectElementWithMatcher:pageInfoTitleMatcher] 354 [[EarlGrey selectElementWithMatcher:pageInfoTitleMatcher]
327 assertWithMatcher:grey_notNil()]; 355 assertWithMatcher:grey_notNil()];
328 356
329 // Verify that the webState's title is correct. 357 // Verify that the webState's title is correct.
330 XCTAssertTrue(chrome_test_util::GetCurrentWebState()->GetTitle() == 358 XCTAssertTrue(chrome_test_util::GetCurrentWebState()->GetTitle() ==
331 base::ASCIIToUTF16(pageTitle.c_str())); 359 base::ASCIIToUTF16(pageTitle.c_str()));
332 } 360 }
333 361
362 // Tests that sharing a web page to the Reading List results in a snackbar
363 // appearing, and that the Reading List entry is present in the Reading List.
364 // Loads online version by tapping on entry.
365 - (void)testSavingToReadingListAndLoadNormal {
366 // Setup a server serving a distillable page at http://potato with the title
jif 2017/03/21 13:11:01 Move the code creating the server and the pages to
367 // "tomato", and a non distillable page at http://beans
368 std::map<GURL, std::string> responses;
369 std::string pageTitle = "Tomato";
370 const GURL distillablePageURL =
371 web::test::HttpServer::MakeUrl("http://potato");
372 const GURL nonDistillablePageURL =
373 web::test::HttpServer::MakeUrl("http://beans");
374 responses[nonDistillablePageURL] =
375 "<html><head><title>greens</title></head></html>";
376
377 std::string contentToRemove = "Text that distillation should remove.";
378 std::string contentToKeep = "Text that distillation should keep.";
379 // Distillation only occurs on pages that are not too small.
380 responses[distillablePageURL] =
381 "<html><head><title>" + pageTitle + "</title></head>" +
382 contentToRemove * 20 + "<article>" + contentToKeep * 20 + "</article>" +
383 contentToRemove * 20 + "</html>";
384
385 web::test::SetUpSimpleHttpServer(responses);
386 web::test::HttpServer& server = web::test::HttpServer::GetSharedInstance();
387
388 // Open http://potato
389 [ChromeEarlGrey loadURL:distillablePageURL];
390
391 AddCurrentPageToReadingList();
392
393 // Navigate to http://beans
394 [ChromeEarlGrey loadURL:nonDistillablePageURL];
395 [ChromeEarlGrey waitForPageToFinishLoading];
396
397 // Verify that an entry with the correct title is present in the reading list.
398 OpenReadingList();
399 AssertEntryVisible(pageTitle);
400 // Long press the entry, and open it offline.
401 TapEntry(pageTitle);
402
403 // Verify there is no offline page.
404 [[EarlGrey
405 selectElementWithMatcher:chrome_test_util::StaticHtmlViewContainingText(
406 base::SysUTF8ToNSString(
407 contentToKeep.c_str()))]
408 assertWithMatcher:grey_nil()];
409
410 // Verify there is an online page.
411 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
412 contentToKeep.c_str())]
413 assertWithMatcher:grey_notNil()];
414
415 // Test Omnibox URL
416 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText(
417 "localhost:8080/potato/")]
418 assertWithMatcher:grey_notNil()];
419
420 // Stop server to reload offline.
421 server.Stop();
422
423 chrome_test_util::GetCurrentWebState()->GetNavigationManager()->Reload(
424 web::ReloadType::NORMAL, false);
425 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
426 contentToKeep.c_str())]
427 assertWithMatcher:grey_nil()];
428
429 [[EarlGrey
430 selectElementWithMatcher:chrome_test_util::StaticHtmlViewContainingText(
431 base::SysUTF8ToNSString(
432 contentToKeep.c_str()))]
433 assertWithMatcher:grey_notNil()];
434 }
435
436 // Tests that sharing a web page to the Reading List results in a snackbar
437 // appearing, and that the Reading List entry is present in the Reading List.
438 // Loads offline version by tapping on entry without web server.
439 - (void)testSavingToReadingListAndLoadNoNetwork {
440 // Setup a server serving a distillable page at http://potato with the title
441 // "tomato", and a non distillable page at http://beans
442 std::map<GURL, std::string> responses;
443 std::string pageTitle = "Tomato";
444 const GURL distillablePageURL =
445 web::test::HttpServer::MakeUrl("http://potato");
446 const GURL nonDistillablePageURL =
447 web::test::HttpServer::MakeUrl("http://beans");
448 responses[nonDistillablePageURL] =
449 "<html><head><title>greens</title></head></html>";
450 web::test::HttpServer& server = web::test::HttpServer::GetSharedInstance();
451
452 std::string contentToRemove = "Text that distillation should remove.";
453 std::string contentToKeep = "Text that distillation should keep.";
454 // Distillation only occurs on pages that are not too small.
455 responses[distillablePageURL] =
456 "<html><head><title>" + pageTitle + "</title></head>" +
457 contentToRemove * 20 + "<article>" + contentToKeep * 20 + "</article>" +
458 contentToRemove * 20 + "</html>";
459
460 web::test::SetUpSimpleHttpServer(responses);
461
462 // Open http://potato
463 [ChromeEarlGrey loadURL:distillablePageURL];
464
465 AddCurrentPageToReadingList();
466
467 // Navigate to http://beans
468 [ChromeEarlGrey loadURL:nonDistillablePageURL];
469 [ChromeEarlGrey waitForPageToFinishLoading];
470
471 // Stop server to generate error.
472 server.Stop();
473
474 // Verify that an entry with the correct title is present in the reading list.
475 OpenReadingList();
476 AssertEntryVisible(pageTitle);
477 // Long press the entry, and open it offline.
478 TapEntry(pageTitle);
479
480 // There will be multiple reload. Wait.
481 ConditionBlock waitForLoading = ^{
482 NSError* error = nil;
483 [[EarlGrey
484 selectElementWithMatcher:chrome_test_util::StaticHtmlViewContainingText(
485 base::SysUTF8ToNSString(
486 contentToKeep.c_str()))]
487 assertWithMatcher:grey_notNil()
488 error:&error];
489 return error == nil;
490 };
491 GREYAssert(
492 testing::WaitUntilConditionOrTimeout(kLoadOfflineTimeout, waitForLoading),
493 @"Offline page did not load.");
494
495 // Verify there is no online page.
496 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
497 contentToKeep.c_str())]
498 assertWithMatcher:grey_nil()];
499
500 // Test Omnibox URL
501 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText(
502 "localhost:8080/potato/")]
503 assertWithMatcher:grey_notNil()];
504
505 // Start server to reload online error.
506 server.StartOrDie();
507 web::test::SetUpSimpleHttpServer(responses);
508
509 chrome_test_util::GetCurrentWebState()->GetNavigationManager()->Reload(
510 web::ReloadType::NORMAL, false);
511 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
512 contentToKeep.c_str())]
513 assertWithMatcher:grey_notNil()];
514
515 [[EarlGrey
516 selectElementWithMatcher:chrome_test_util::StaticHtmlViewContainingText(
517 base::SysUTF8ToNSString(
518 contentToKeep.c_str()))]
519 assertWithMatcher:grey_nil()];
520 }
521
522 // Tests that sharing a web page to the Reading List results in a snackbar
523 // appearing, and that the Reading List entry is present in the Reading List.
524 // Loads offline version by tapping on entry with delayed web server.
525 - (void)testSavingToReadingListAndLoadBadNetwork {
526 // Setup a server serving a distillable page at http://potato with the title
527 // "tomato", and a non distillable page at http://beans
528 std::map<GURL, std::string> responses;
529 std::string pageTitle = "Tomato";
530 const GURL distillablePageURL =
531 web::test::HttpServer::MakeUrl("http://potato");
532 const GURL nonDistillablePageURL =
533 web::test::HttpServer::MakeUrl("http://beans");
534 responses[nonDistillablePageURL] =
535 "<html><head><title>greens</title></head></html>";
536
537 std::string contentToRemove = "Text that distillation should remove.";
538 std::string contentToKeep = "Text that distillation should keep.";
539 // Distillation only occurs on pages that are not too small.
540 responses[distillablePageURL] =
541 "<html><head><title>" + pageTitle + "</title></head>" +
542 contentToRemove * 20 + "<article>" + contentToKeep * 20 + "</article>" +
543 contentToRemove * 20 + "</html>";
544
545 web::test::SetUpSimpleHttpServer(responses);
546
547 // Open http://potato
548 [ChromeEarlGrey loadURL:distillablePageURL];
549
550 AddCurrentPageToReadingList();
551
552 // Navigate to http://beans
553 [ChromeEarlGrey loadURL:nonDistillablePageURL];
554 [ChromeEarlGrey waitForPageToFinishLoading];
555
556 web::test::SetUpHttpServer(base::MakeUnique<web::DelayedResponseProvider>(
557 base::MakeUnique<HtmlResponseProvider>(responses), 5));
558
559 // Verify that an entry with the correct title is present in the reading list.
560 OpenReadingList();
561 AssertEntryVisible(pageTitle);
562 // Long press the entry, and open it offline.
563 TapEntry(pageTitle);
564
565 // There will be multiple reload. Wait.
566 ConditionBlock waitForLoading = ^{
567 NSError* error = nil;
568 [[EarlGrey
569 selectElementWithMatcher:chrome_test_util::StaticHtmlViewContainingText(
570 base::SysUTF8ToNSString(
571 contentToKeep.c_str()))]
572 assertWithMatcher:grey_notNil()
573 error:&error];
574 return error == nil;
575 };
576 GREYAssert(
577 testing::WaitUntilConditionOrTimeout(kLoadOfflineTimeout, waitForLoading),
578 @"Offline page did not load.");
579
580 // Verify there is no online page.
581 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
582 contentToKeep.c_str())]
583 assertWithMatcher:grey_nil()];
584
585 // Test Omnibox URL
586 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText(
587 "localhost:8080/potato/")]
588 assertWithMatcher:grey_notNil()];
589
590 // Reload should lod online page.
591 chrome_test_util::GetCurrentWebState()->GetNavigationManager()->Reload(
592 web::ReloadType::NORMAL, false);
593 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText(
594 contentToKeep.c_str())]
595 assertWithMatcher:grey_notNil()];
596
597 [[EarlGrey
598 selectElementWithMatcher:chrome_test_util::StaticHtmlViewContainingText(
599 base::SysUTF8ToNSString(
600 contentToKeep.c_str()))]
601 assertWithMatcher:grey_nil()];
602 }
603
334 // Tests that only the "Edit" button is showing when not editing. 604 // Tests that only the "Edit" button is showing when not editing.
335 - (void)testVisibleButtonsNonEditingMode { 605 - (void)testVisibleButtonsNonEditingMode {
336 GetReadingListModel()->AddEntry(GURL(kUnreadURL), std::string(kUnreadTitle), 606 GetReadingListModel()->AddEntry(GURL(kUnreadURL), std::string(kUnreadTitle),
337 reading_list::ADDED_VIA_CURRENT_APP); 607 reading_list::ADDED_VIA_CURRENT_APP);
338 OpenReadingList(); 608 OpenReadingList();
339 609
340 AssertButtonNotVisibleWithID(IDS_IOS_READING_LIST_DELETE_BUTTON); 610 AssertButtonNotVisibleWithID(IDS_IOS_READING_LIST_DELETE_BUTTON);
341 AssertButtonNotVisibleWithID(IDS_IOS_READING_LIST_DELETE_ALL_READ_BUTTON); 611 AssertButtonNotVisibleWithID(IDS_IOS_READING_LIST_DELETE_ALL_READ_BUTTON);
342 AssertButtonNotVisibleWithID(IDS_IOS_READING_LIST_MARK_READ_BUTTON); 612 AssertButtonNotVisibleWithID(IDS_IOS_READING_LIST_MARK_READ_BUTTON);
343 AssertButtonNotVisibleWithID(IDS_IOS_READING_LIST_MARK_UNREAD_BUTTON); 613 AssertButtonNotVisibleWithID(IDS_IOS_READING_LIST_MARK_UNREAD_BUTTON);
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 assertWithMatcher:grey_nil()]; 823 assertWithMatcher:grey_nil()];
554 TapButtonWithID(IDS_IOS_READING_LIST_EDIT_BUTTON); 824 TapButtonWithID(IDS_IOS_READING_LIST_EDIT_BUTTON);
555 TapButtonWithID(IDS_IOS_READING_LIST_DELETE_ALL_READ_BUTTON); 825 TapButtonWithID(IDS_IOS_READING_LIST_DELETE_ALL_READ_BUTTON);
556 826
557 // Verify the background string is displayed. 827 // Verify the background string is displayed.
558 [[EarlGrey selectElementWithMatcher:EmptyBackground()] 828 [[EarlGrey selectElementWithMatcher:EmptyBackground()]
559 assertWithMatcher:grey_notNil()]; 829 assertWithMatcher:grey_notNil()];
560 } 830 }
561 831
562 @end 832 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/reading_list/offline_page_native_content.mm ('k') | ios/web/web_state/ui/crw_web_controller.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698