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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 const CFTimeInterval kSnackbarAppearanceTimeout = 5; | 60 const CFTimeInterval kSnackbarAppearanceTimeout = 5; |
| 61 const CFTimeInterval kSnackbarDisappearanceTimeout = | 61 const CFTimeInterval kSnackbarDisappearanceTimeout = |
| 62 MDCSnackbarMessageDurationMax + 1; | 62 MDCSnackbarMessageDurationMax + 1; |
| 63 const CFTimeInterval kDelayForSlowWebServer = 4; | 63 const CFTimeInterval kDelayForSlowWebServer = 4; |
| 64 const CFTimeInterval kLoadOfflineTimeout = kDelayForSlowWebServer + 1; | 64 const CFTimeInterval kLoadOfflineTimeout = kDelayForSlowWebServer + 1; |
| 65 const CFTimeInterval kLongPressDuration = 1.0; | 65 const CFTimeInterval kLongPressDuration = 1.0; |
| 66 const CFTimeInterval kDistillationTimeout = 5; | 66 const CFTimeInterval kDistillationTimeout = 5; |
| 67 const CFTimeInterval kServerOperationDelay = 1; | 67 const CFTimeInterval kServerOperationDelay = 1; |
| 68 const char kReadHeader[] = "Read"; | 68 const char kReadHeader[] = "Read"; |
| 69 const char kUnreadHeader[] = "Unread"; | 69 const char kUnreadHeader[] = "Unread"; |
| 70 GURL kDistillableFullURL; | |
| 70 | 71 |
| 71 // Overrides the NetworkChangeNotifier to enable distillation even if the device | 72 // Overrides the NetworkChangeNotifier to enable distillation even if the device |
| 72 // does not have network. | 73 // does not have network. |
| 73 class WifiNetworkChangeNotifier : public net::NetworkChangeNotifier { | 74 class WifiNetworkChangeNotifier : public net::NetworkChangeNotifier { |
| 74 public: | 75 public: |
| 75 WifiNetworkChangeNotifier() : net::NetworkChangeNotifier() {} | 76 WifiNetworkChangeNotifier() : net::NetworkChangeNotifier() {} |
| 76 | 77 |
| 77 ConnectionType GetCurrentConnectionType() const override { | 78 ConnectionType GetCurrentConnectionType() const override { |
| 78 return CONNECTION_WIFI; | 79 return CONNECTION_WIFI; |
| 79 } | 80 } |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 }; | 331 }; |
| 331 GREYAssert(testing::WaitUntilConditionOrTimeout(kLoadOfflineTimeout, | 332 GREYAssert(testing::WaitUntilConditionOrTimeout(kLoadOfflineTimeout, |
| 332 wait_for_loading), | 333 wait_for_loading), |
| 333 @"Page did not load."); | 334 @"Page did not load."); |
| 334 } else { | 335 } else { |
| 335 [ChromeEarlGrey waitForStaticHTMLViewContainingText:contentToKeep]; | 336 [ChromeEarlGrey waitForStaticHTMLViewContainingText:contentToKeep]; |
| 336 } | 337 } |
| 337 | 338 |
| 338 // Test Omnibox URL | 339 // Test Omnibox URL |
| 339 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( | 340 [[EarlGrey selectElementWithMatcher:chrome_test_util::OmniboxText( |
| 340 web::test::HttpServer::MakeUrl( | 341 kDistillableFullURL.GetContent())] |
| 341 kDistillableURL) | |
| 342 .GetContent())] | |
| 343 assertWithMatcher:grey_notNil()]; | 342 assertWithMatcher:grey_notNil()]; |
| 344 | 343 |
| 345 // Test presence of online page | 344 // Test presence of online page |
| 346 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( | 345 [[EarlGrey selectElementWithMatcher:chrome_test_util::WebViewContainingText( |
| 347 kContentToKeep)] | 346 kContentToKeep)] |
| 348 assertWithMatcher:online ? grey_notNil() : grey_nil()]; | 347 assertWithMatcher:online ? grey_notNil() : grey_nil()]; |
| 349 | 348 |
| 350 // Test presence of offline page. | 349 // Test presence of offline page. |
| 351 if (online) { | 350 if (online) { |
| 352 [ChromeEarlGrey waitForStaticHTMLViewNotContainingText:contentToKeep]; | 351 [ChromeEarlGrey waitForStaticHTMLViewNotContainingText:contentToKeep]; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 368 | 367 |
| 369 // Test class for the Reading List menu. | 368 // Test class for the Reading List menu. |
| 370 @interface ReadingListTestCase : ChromeTestCase | 369 @interface ReadingListTestCase : ChromeTestCase |
| 371 | 370 |
| 372 @end | 371 @end |
| 373 | 372 |
| 374 @implementation ReadingListTestCase | 373 @implementation ReadingListTestCase |
| 375 | 374 |
| 376 - (void)setUp { | 375 - (void)setUp { |
| 377 [super setUp]; | 376 [super setUp]; |
| 377 kDistillableFullURL = web::test::HttpServer::MakeUrl(kDistillableURL); | |
|
baxley
2017/06/06 18:14:16
Can we just replace kDistillableRullURL on line 34
huangml1
2017/06/07 18:10:54
Yes we can! Sorry that I mixed it up with previous
| |
| 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 if (!server.IsRunning()) { | 385 if (!server.IsRunning()) { |
| 386 server.StartOrDie(); | 386 server.StartOrDie(); |
| 387 base::test::ios::SpinRunLoopWithMinDelay( | 387 base::test::ios::SpinRunLoopWithMinDelay( |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 443 assertWithMatcher:grey_notNil()]; | 443 assertWithMatcher:grey_notNil()]; |
| 444 | 444 |
| 445 // Verify that the webState's title is correct. | 445 // Verify that the webState's title is correct. |
| 446 XCTAssertTrue(chrome_test_util::GetCurrentWebState()->GetTitle() == | 446 XCTAssertTrue(chrome_test_util::GetCurrentWebState()->GetTitle() == |
| 447 base::ASCIIToUTF16(pageTitle.c_str())); | 447 base::ASCIIToUTF16(pageTitle.c_str())); |
| 448 } | 448 } |
| 449 | 449 |
| 450 // Tests that sharing a web page to the Reading List results in a snackbar | 450 // 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. | 451 // appearing, and that the Reading List entry is present in the Reading List. |
| 452 // Loads online version by tapping on entry. | 452 // Loads online version by tapping on entry. |
| 453 // TODO(crbug.com/724555): Re-enable the test. | 453 - (void)testSavingToReadingListAndLoadNormal { |
| 454 - (void)DISABLED_testSavingToReadingListAndLoadNormal { | |
| 455 auto network_change_disabler = | 454 auto network_change_disabler = |
| 456 base::MakeUnique<net::NetworkChangeNotifier::DisableForTest>(); | 455 base::MakeUnique<net::NetworkChangeNotifier::DisableForTest>(); |
| 457 auto wifi_network = base::MakeUnique<WifiNetworkChangeNotifier>(); | 456 auto wifi_network = base::MakeUnique<WifiNetworkChangeNotifier>(); |
| 458 web::test::SetUpSimpleHttpServer(ResponsesForDistillationServer()); | 457 web::test::SetUpSimpleHttpServer(ResponsesForDistillationServer()); |
| 459 web::test::HttpServer& server = web::test::HttpServer::GetSharedInstance(); | 458 web::test::HttpServer& server = web::test::HttpServer::GetSharedInstance(); |
| 460 std::string pageTitle(kDistillableTitle); | 459 std::string pageTitle(kDistillableTitle); |
| 461 | 460 |
| 462 // Open http://potato | 461 // Open http://potato |
| 463 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kDistillableURL)]; | 462 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kDistillableURL)]; |
| 464 | 463 |
| 465 AddCurrentPageToReadingList(); | 464 AddCurrentPageToReadingList(); |
| 466 | 465 |
| 467 // Navigate to http://beans | 466 // Navigate to http://beans |
| 468 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kNonDistillableURL)]; | 467 [ChromeEarlGrey loadURL:web::test::HttpServer::MakeUrl(kNonDistillableURL)]; |
| 469 [ChromeEarlGrey waitForPageToFinishLoading]; | 468 [ChromeEarlGrey waitForPageToFinishLoading]; |
| 470 | 469 |
| 471 // Verify that an entry with the correct title is present in the reading list. | 470 // Verify that an entry with the correct title is present in the reading list. |
| 472 OpenReadingList(); | 471 OpenReadingList(); |
| 473 AssertEntryVisible(pageTitle); | 472 AssertEntryVisible(pageTitle); |
| 474 WaitForDistillation(); | 473 WaitForDistillation(); |
| 475 | 474 |
| 476 // Long press the entry, and open it offline. | 475 // Long press the entry, and open it offline. |
| 477 TapEntry(pageTitle); | 476 TapEntry(pageTitle); |
| 478 | 477 |
| 479 AssertIsShowingDistillablePage(true); | 478 AssertIsShowingDistillablePage(true); |
| 480 // Stop server to reload offline. | 479 // Stop server to reload offline. |
| 481 server.Stop(); | 480 server.setSuspend(YES); |
| 482 base::test::ios::SpinRunLoopWithMinDelay( | 481 base::test::ios::SpinRunLoopWithMinDelay( |
| 483 base::TimeDelta::FromSecondsD(kServerOperationDelay)); | 482 base::TimeDelta::FromSecondsD(kServerOperationDelay)); |
| 484 | 483 |
| 485 chrome_test_util::GetCurrentWebState()->GetNavigationManager()->Reload( | 484 chrome_test_util::GetCurrentWebState()->GetNavigationManager()->Reload( |
| 486 web::ReloadType::NORMAL, false); | 485 web::ReloadType::NORMAL, false); |
| 487 AssertIsShowingDistillablePage(false); | 486 AssertIsShowingDistillablePage(false); |
| 487 server.setSuspend(NO); | |
|
baxley
2017/06/06 18:14:17
What if the assert above fails? will the server be
huangml1
2017/06/07 18:10:54
You're right. I missed the condition. Now I stop
| |
| 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); |
|
baxley
2017/06/06 18:14:16
Same as last question, will this always get set pr
| |
| 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 |