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/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 wait_for_loading), | 332 wait_for_loading), |
| 333 @"Page did not load."); | 333 @"Page did not load."); |
| 334 } else { | 334 } else { |
| 335 [ChromeEarlGrey waitForStaticHTMLViewContainingText:contentToKeep]; | 335 [ChromeEarlGrey waitForStaticHTMLViewContainingText:contentToKeep]; |
| 336 } | 336 } |
| 337 | 337 |
| 338 // Test Omnibox URL | 338 // Test Omnibox URL |
| 339 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( | 339 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 340 web::test::HttpServer::MakeUrl( | 340 web::test::HttpServer::MakeUrl( |
| 341 kDistillableURL) | 341 kDistillableURL) |
| 342 .GetContent())] | 342 .GetContent())] |
|
baxley
2017/06/07 18:21:06
nit: what do you think about creating a variable f
huangml1
2017/06/08 01:02:51
Done.
| |
| 343 assertWithMatcher:grey_notNil()]; | 343 assertWithMatcher:grey_notNil()]; |
| 344 | 344 |
| 345 // Test presence of online page | 345 // Test presence of online page |
| 346 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 346 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| 347 kContentToKeep)] | 347 kContentToKeep)] |
| 348 assertWithMatcher:online ? grey_notNil() : grey_nil()]; | 348 assertWithMatcher:online ? grey_notNil() : grey_nil()]; |
| 349 | 349 |
| 350 // Test presence of offline page. | 350 // Test presence of offline page. |
| 351 if (online) { | 351 if (online) { |
| 352 [ChromeEarlGrey waitForStaticHTMLViewNotContainingText:contentToKeep]; | 352 [ChromeEarlGrey waitForStaticHTMLViewNotContainingText:contentToKeep]; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 375 | 375 |
| 376 - (void)setUp { | 376 - (void)setUp { |
| 377 [super setUp]; | 377 [super setUp]; |
| 378 ReadingListModel* model = GetReadingListModel(); | 378 ReadingListModel* model = GetReadingListModel(); |
| 379 for (const GURL& url : model->Keys()) | 379 for (const GURL& url : model->Keys()) |
| 380 model->RemoveEntryByURL(url); | 380 model->RemoveEntryByURL(url); |
| 381 } | 381 } |
| 382 | 382 |
| 383 - (void)tearDown { | 383 - (void)tearDown { |
| 384 web::test::HttpServer& server = web::test::HttpServer::GetSharedInstance(); | 384 web::test::HttpServer& server = web::test::HttpServer::GetSharedInstance(); |
| 385 server.SetSuspend(NO); | |
|
baxley
2017/06/07 18:21:06
are there any side-effects to calling this after t
huangml1
2017/06/08 01:02:51
No. The method just sets the variable to "NO" and
| |
| 385 if (!server.IsRunning()) { | 386 if (!server.IsRunning()) { |
| 386 server.StartOrDie(); | 387 server.StartOrDie(); |
| 387 base::test::ios::SpinRunLoopWithMinDelay( | 388 base::test::ios::SpinRunLoopWithMinDelay( |
| 388 base::TimeDelta::FromSecondsD(kServerOperationDelay)); | 389 base::TimeDelta::FromSecondsD(kServerOperationDelay)); |
| 389 } | 390 } |
| 390 [super tearDown]; | 391 [super tearDown]; |
| 391 } | 392 } |
| 392 | 393 |
| 393 // Tests that the Reading List view is accessible. | 394 // Tests that the Reading List view is accessible. |
| 394 - (void)testAccessibility { | 395 - (void)testAccessibility { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 443 assertWithMatcher:grey_notNil()]; | 444 assertWithMatcher:grey_notNil()]; |
| 444 | 445 |
| 445 // Verify that the webState's title is correct. | 446 // Verify that the webState's title is correct. |
| 446 XCTAssertTrue(chrome_test_util::GetCurrentWebState()->GetTitle() == | 447 XCTAssertTrue(chrome_test_util::GetCurrentWebState()->GetTitle() == |
| 447 base::ASCIIToUTF16(pageTitle.c_str())); | 448 base::ASCIIToUTF16(pageTitle.c_str())); |
| 448 } | 449 } |
| 449 | 450 |
| 450 // Tests that sharing a web page to the Reading List results in a snackbar | 451 // Tests that sharing a web page to the Reading List results in a snackbar |
| 451 // appearing, and that the Reading List entry is present in the Reading List. | 452 // appearing, and that the Reading List entry is present in the Reading List. |
| 452 // Loads online version by tapping on entry. | 453 // Loads online version by tapping on entry. |
| 453 // TODO(crbug.com/724555): Re-enable the test. | 454 - (void)testSavingToReadingListAndLoadNormal { |
| 454 - (void)DISABLED_testSavingToReadingListAndLoadNormal { | |
| 455 auto network_change_disabler = | 455 auto network_change_disabler = |
| 456 base::MakeUnique<net::NetworkChangeNotifier::DisableForTest>(); | 456 base::MakeUnique<net::NetworkChangeNotifier::DisableForTest>(); |
| 457 auto wifi_network = base::MakeUnique<WifiNetworkChangeNotifier>(); | 457 auto wifi_network = base::MakeUnique<WifiNetworkChangeNotifier>(); |
| 458 web::test::SetUpSimpleHttpServer(ResponsesForDistillationServer()); | 458 web::test::SetUpSimpleHttpServer(ResponsesForDistillationServer()); |
| 459 web::test::HttpServer& server = web::test::HttpServer::GetSharedInstance(); | 459 web::test::HttpServer& server = web::test::HttpServer::GetSharedInstance(); |
| 460 std::string pageTitle(kDistillableTitle); | 460 std::string pageTitle(kDistillableTitle); |
| 461 | 461 |
| 462 // Open http://potato | 462 // Open http://potato |
| 463 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kDistillableURL)]; | 463 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kDistillableURL)]; |
| 464 | 464 |
| 465 AddCurrentPageToReadingList(); | 465 AddCurrentPageToReadingList(); |
| 466 | 466 |
| 467 // Navigate to http://beans | 467 // Navigate to http://beans |
| 468 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kNonDistillableURL)]; | 468 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kNonDistillableURL)]; |
| 469 [ChromeEarlGrey waitForPageToFinishLoading]; | 469 [ChromeEarlGrey waitForPageToFinishLoading]; |
| 470 | 470 |
| 471 // Verify that an entry with the correct title is present in the reading list. | 471 // Verify that an entry with the correct title is present in the reading list. |
| 472 OpenReadingList(); | 472 OpenReadingList(); |
| 473 AssertEntryVisible(pageTitle); | 473 AssertEntryVisible(pageTitle); |
| 474 WaitForDistillation(); | 474 WaitForDistillation(); |
| 475 | 475 |
| 476 // Long press the entry, and open it offline. | 476 // Long press the entry, and open it offline. |
| 477 TapEntry(pageTitle); | 477 TapEntry(pageTitle); |
| 478 | 478 |
| 479 AssertIsShowingDistillablePage(true); | 479 AssertIsShowingDistillablePage(true); |
| 480 // Stop server to reload offline. | 480 // Stop server to reload offline. |
| 481 server.Stop(); | 481 server.SetSuspend(YES); |
| 482 base::test::ios::SpinRunLoopWithMinDelay( | 482 base::test::ios::SpinRunLoopWithMinDelay( |
| 483 base::TimeDelta::FromSecondsD(kServerOperationDelay)); | 483 base::TimeDelta::FromSecondsD(kServerOperationDelay)); |
| 484 | 484 |
| 485 chrome_test_util::GetCurrentWebState()->GetNavigationManager()->Reload( | 485 chrome_test_util::GetCurrentWebState()->GetNavigationManager()->Reload( |
| 486 web::ReloadType::NORMAL, false); | 486 web::ReloadType::NORMAL, false); |
| 487 AssertIsShowingDistillablePage(false); | 487 AssertIsShowingDistillablePage(false); |
| 488 } | 488 } |
| 489 | 489 |
| 490 // Tests that sharing a web page to the Reading List results in a snackbar | 490 // Tests that sharing a web page to the Reading List results in a snackbar |
| 491 // appearing, and that the Reading List entry is present in the Reading List. | 491 // appearing, and that the Reading List entry is present in the Reading List. |
| 492 // Loads offline version by tapping on entry without web server. | 492 // Loads offline version by tapping on entry without web server. |
| 493 // TODO(crbug.com/724555): Re-enable the test. | 493 - (void)testSavingToReadingListAndLoadNoNetwork { |
| 494 - (void)DISABLED_testSavingToReadingListAndLoadNoNetwork { | |
| 495 auto network_change_disabler = | 494 auto network_change_disabler = |
| 496 base::MakeUnique<net::NetworkChangeNotifier::DisableForTest>(); | 495 base::MakeUnique<net::NetworkChangeNotifier::DisableForTest>(); |
| 497 auto wifi_network = base::MakeUnique<WifiNetworkChangeNotifier>(); | 496 auto wifi_network = base::MakeUnique<WifiNetworkChangeNotifier>(); |
| 498 web::test::SetUpSimpleHttpServer(ResponsesForDistillationServer()); | 497 web::test::SetUpSimpleHttpServer(ResponsesForDistillationServer()); |
| 499 std::string pageTitle(kDistillableTitle); | 498 std::string pageTitle(kDistillableTitle); |
| 500 web::test::HttpServer& server = web::test::HttpServer::GetSharedInstance(); | 499 web::test::HttpServer& server = web::test::HttpServer::GetSharedInstance(); |
| 501 // Open http://potato | 500 // Open http://potato |
| 502 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kDistillableURL)]; | 501 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kDistillableURL)]; |
| 503 | 502 |
| 504 AddCurrentPageToReadingList(); | 503 AddCurrentPageToReadingList(); |
| 505 | 504 |
| 506 // Navigate to http://beans | 505 // Navigate to http://beans |
| 507 | 506 |
| 508 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kNonDistillableURL)]; | 507 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kNonDistillableURL)]; |
| 509 [ChromeEarlGrey waitForPageToFinishLoading]; | 508 [ChromeEarlGrey waitForPageToFinishLoading]; |
| 510 | 509 |
| 511 // Verify that an entry with the correct title is present in the reading list. | 510 // Verify that an entry with the correct title is present in the reading list. |
| 512 OpenReadingList(); | 511 OpenReadingList(); |
| 513 AssertEntryVisible(pageTitle); | 512 AssertEntryVisible(pageTitle); |
| 514 WaitForDistillation(); | 513 WaitForDistillation(); |
| 515 | 514 |
| 516 // Stop server to generate error. | 515 // Stop server to generate error. |
| 517 server.Stop(); | 516 server.SetSuspend(YES); |
| 518 base::test::ios::SpinRunLoopWithMinDelay( | 517 base::test::ios::SpinRunLoopWithMinDelay( |
| 519 base::TimeDelta::FromSecondsD(kServerOperationDelay)); | 518 base::TimeDelta::FromSecondsD(kServerOperationDelay)); |
| 520 // Long press the entry, and open it offline. | 519 // Long press the entry, and open it offline. |
| 521 TapEntry(pageTitle); | 520 TapEntry(pageTitle); |
| 522 | 521 |
| 523 AssertIsShowingDistillablePage(false); | 522 AssertIsShowingDistillablePage(false); |
| 524 // Start server to reload online error. | 523 // Start server to reload online error. |
| 525 server.StartOrDie(); | 524 server.SetSuspend(NO); |
| 526 base::test::ios::SpinRunLoopWithMinDelay( | 525 base::test::ios::SpinRunLoopWithMinDelay( |
| 527 base::TimeDelta::FromSecondsD(kServerOperationDelay)); | 526 base::TimeDelta::FromSecondsD(kServerOperationDelay)); |
| 528 web::test::SetUpSimpleHttpServer(ResponsesForDistillationServer()); | 527 web::test::SetUpSimpleHttpServer(ResponsesForDistillationServer()); |
| 529 | 528 |
| 530 chrome_test_util::GetCurrentWebState()->GetNavigationManager()->Reload( | 529 chrome_test_util::GetCurrentWebState()->GetNavigationManager()->Reload( |
| 531 web::ReloadType::NORMAL, false); | 530 web::ReloadType::NORMAL, false); |
| 532 AssertIsShowingDistillablePage(true); | 531 AssertIsShowingDistillablePage(true); |
| 533 } | 532 } |
| 534 | 533 |
| 535 // Tests that sharing a web page to the Reading List results in a snackbar | 534 // Tests that sharing a web page to the Reading List results in a snackbar |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 798 assertWithMatcher:grey_nil()]; | 797 assertWithMatcher:grey_nil()]; |
| 799 TapButtonWithID(IDS_IOS_READING_LIST_EDIT_BUTTON); | 798 TapButtonWithID(IDS_IOS_READING_LIST_EDIT_BUTTON); |
| 800 TapButtonWithID(IDS_IOS_READING_LIST_DELETE_ALL_READ_BUTTON); | 799 TapButtonWithID(IDS_IOS_READING_LIST_DELETE_ALL_READ_BUTTON); |
| 801 | 800 |
| 802 // Verify the background string is displayed. | 801 // Verify the background string is displayed. |
| 803 [[EarlGrey selectElementWithMatcher:EmptyBackground()] | 802 [[EarlGrey selectElementWithMatcher:EmptyBackground()] |
| 804 assertWithMatcher:grey_notNil()]; | 803 assertWithMatcher:grey_notNil()]; |
| 805 } | 804 } |
| 806 | 805 |
| 807 @end | 806 @end |
| OLD | NEW |