Chromium Code Reviews| Index: ios/web/navigation/history_state_operations_inttest.mm |
| diff --git a/ios/web/navigation/history_state_operations_inttest.mm b/ios/web/navigation/history_state_operations_inttest.mm |
| index 88cf460e25434131019335143948add5a4aad046..c10d82a14b2396a386bb7537e30526512f2ff398 100644 |
| --- a/ios/web/navigation/history_state_operations_inttest.mm |
| +++ b/ios/web/navigation/history_state_operations_inttest.mm |
| @@ -6,7 +6,7 @@ |
| #include "base/strings/string_number_conversions.h" |
| #include "base/strings/sys_string_conversions.h" |
| #include "base/strings/utf_string_conversions.h" |
| -#include "base/test/ios/wait_util.h" |
| +#import "ios/testing/wait_util.h" |
| #import "ios/web/navigation/navigation_item_impl.h" |
| #import "ios/web/public/navigation_item.h" |
| #import "ios/web/public/navigation_manager.h" |
| @@ -110,9 +110,11 @@ class HistoryStateOperationsTest : public web::WebIntTest { |
| // Waits for the NoOp text to be visible. |
| void WaitForNoOpText() { |
| - base::test::ios::WaitUntilCondition(^bool { |
| - return IsNoOpTextVisible(); |
| - }); |
| + BOOL completed = testing::WaitUntilConditionOrTimeout( |
| + testing::kWaitForJSCompletionTimeout, ^{ |
|
Eugene But (OOO till 7-30)
2017/03/07 21:10:38
This does not look like JS execution. Is there a b
michaeldo
2017/03/07 22:21:54
This one is JS execution (defined in the helper ab
Eugene But (OOO till 7-30)
2017/03/08 00:55:00
Those are all State Update operations, which is ha
michaeldo
2017/03/08 07:26:54
Thanks for the explanation, it wasn't immediately
|
| + return IsNoOpTextVisible(); |
| + }); |
| + EXPECT_TRUE(completed) << "NoOp text failed to be visible."; |
| } |
| private: |
| @@ -247,9 +249,11 @@ TEST_F(HistoryStateOperationsTest, DISABLED_TitleReplacement) { |
| SetStateParams(empty_state, new_title, empty_url); |
| ASSERT_TRUE(web::test::TapWebViewElementWithId(web_state(), kReplaceStateId)); |
| // Wait for the title to be reflected in the NavigationItem. |
| - base::test::ios::WaitUntilCondition(^bool { |
| - return GetLastCommittedItem()->GetTitle() == ASCIIToUTF16(new_title); |
| - }); |
| + BOOL completed = testing::WaitUntilConditionOrTimeout( |
| + testing::kWaitForJSCompletionTimeout, ^{ |
| + return GetLastCommittedItem()->GetTitle() == ASCIIToUTF16(new_title); |
| + }); |
| + EXPECT_TRUE(completed) << "Failed to validate NavigationItem title."; |
| // Verify that the forward navigation was not pruned. |
| EXPECT_EQ(GetIndexOfNavigationItem(GetLastCommittedItem()) + 1, |
| GetIndexOfNavigationItem(about_blank_item)); |
| @@ -275,18 +279,25 @@ TEST_F(HistoryStateOperationsTest, StateReplacement) { |
| SetStateParams(new_state, empty_title, empty_url); |
| ASSERT_TRUE(web::test::TapWebViewElementWithId(web_state(), kReplaceStateId)); |
| // Verify that the state is reflected in the JavaScript context. |
| - base::test::ios::WaitUntilCondition(^bool { |
| - return GetJavaScriptState() == new_state; |
| - }); |
| + BOOL verify_java_script_context_completed = |
| + testing::WaitUntilConditionOrTimeout( |
| + testing::kWaitForJSCompletionTimeout, ^{ |
| + return GetJavaScriptState() == new_state; |
| + }); |
| + EXPECT_TRUE(verify_java_script_context_completed) |
| + << "Failed to validate JavaScript state."; |
| // Verify that the state is reflected in the latest NavigationItem. |
| std::string serialized_state("\"STATE OBJECT\""); |
| - base::test::ios::WaitUntilCondition(^bool { |
| - web::NavigationItemImpl* item = |
| - static_cast<web::NavigationItemImpl*>(GetLastCommittedItem()); |
| - std::string item_state = |
| - base::SysNSStringToUTF8(item->GetSerializedStateObject()); |
| - return item_state == serialized_state; |
| - }); |
| + BOOL verify_navigation_item_completed = testing::WaitUntilConditionOrTimeout( |
| + testing::kWaitForJSCompletionTimeout, ^{ |
| + web::NavigationItemImpl* item = |
| + static_cast<web::NavigationItemImpl*>(GetLastCommittedItem()); |
| + std::string item_state = |
| + base::SysNSStringToUTF8(item->GetSerializedStateObject()); |
| + return item_state == serialized_state; |
| + }); |
| + EXPECT_TRUE(verify_navigation_item_completed) |
| + << "Failed to validate NavigationItem state."; |
| // Verify that the forward navigation was not pruned. |
| EXPECT_EQ(GetIndexOfNavigationItem(GetLastCommittedItem()) + 1, |
| GetIndexOfNavigationItem(about_blank_item)); |
| @@ -304,9 +315,11 @@ TEST_F(HistoryStateOperationsTest, StateReplacementReload) { |
| // Reload the page and check that the state object is present. |
| Reload(); |
| ASSERT_TRUE(IsOnLoadTextVisible()); |
| - base::test::ios::WaitUntilCondition(^bool { |
| - return GetJavaScriptState() == new_state; |
| - }); |
| + BOOL completed = testing::WaitUntilConditionOrTimeout( |
| + testing::kWaitForJSCompletionTimeout, ^{ |
| + return GetJavaScriptState() == new_state; |
| + }); |
| + EXPECT_TRUE(completed) << "Failed to validate JavaScript state."; |
| } |
| // Tests that the state object is correctly set for a page after a back/forward |
| @@ -335,9 +348,11 @@ TEST_F(HistoryStateOperationsTest, StateReplacementBackForward) { |
| navigation_manager()->GoBack(); |
| }); |
| ASSERT_TRUE(IsOnLoadTextVisible()); |
| - base::test::ios::WaitUntilCondition(^bool { |
| - return GetJavaScriptState() == new_state; |
| - }); |
| + BOOL completed = testing::WaitUntilConditionOrTimeout( |
| + testing::kWaitForJSCompletionTimeout, ^{ |
| + return GetJavaScriptState() == new_state; |
| + }); |
| + EXPECT_TRUE(completed) << "Failed to validate JavaScript state."; |
| } |
| // Tests that calling window.history.pushState() creates a new NavigationItem |
| @@ -361,9 +376,11 @@ TEST_F(HistoryStateOperationsTest, PushState) { |
| SetStateParams(empty_state, empty_title, new_url); |
| ASSERT_TRUE(web::test::TapWebViewElementWithId(web_state(), kPushStateId)); |
| // Verify that the url with the path is pushed. |
| - base::test::ios::WaitUntilCondition(^bool { |
| - return GetLastCommittedItem()->GetURL() == new_url; |
| - }); |
| + BOOL completed = testing::WaitUntilConditionOrTimeout( |
| + testing::kWaitForJSCompletionTimeout, ^{ |
| + return GetLastCommittedItem()->GetURL() == new_url; |
| + }); |
| + EXPECT_TRUE(completed) << "Failed to validate current url."; |
| // Verify that a new NavigationItem was created and that the forward item was |
| // pruned. |
| EXPECT_EQ(GetIndexOfNavigationItem(non_pushed_item) + 1, |
| @@ -386,9 +403,11 @@ TEST_F(HistoryStateOperationsTest, ReplaceStatePostRequest) { |
| SetStateParams(new_state, empty_title, new_url); |
| ASSERT_TRUE(web::test::TapWebViewElementWithId(web_state(), kReplaceStateId)); |
| // Verify that url has been replaced. |
| - base::test::ios::WaitUntilCondition(^bool { |
| - return GetLastCommittedItem()->GetURL() == new_url; |
| - }); |
| + BOOL completed = testing::WaitUntilConditionOrTimeout( |
| + testing::kWaitForJSCompletionTimeout, ^{ |
| + return GetLastCommittedItem()->GetURL() == new_url; |
| + }); |
| + EXPECT_TRUE(completed) << "Failed to validate current url."; |
| // Verify that the NavigationItem no longer has POST data. |
| EXPECT_FALSE(GetLastCommittedItem()->HasPostData()); |
| } |
| @@ -403,9 +422,11 @@ TEST_F(HistoryStateOperationsTest, ReplaceStateNoHashChangeEvent) { |
| SetStateParams(empty_state, empty_title, new_url); |
| ASSERT_TRUE(web::test::TapWebViewElementWithId(web_state(), kReplaceStateId)); |
| // Verify that url has been replaced. |
| - base::test::ios::WaitUntilCondition(^bool { |
| - return GetLastCommittedItem()->GetURL() == new_url; |
| - }); |
| + BOOL completed = testing::WaitUntilConditionOrTimeout( |
| + testing::kWaitForJSCompletionTimeout, ^{ |
| + return GetLastCommittedItem()->GetURL() == new_url; |
| + }); |
| + EXPECT_TRUE(completed) << "Failed to validate current url."; |
| // Verify that the hashchange event was not fired. |
| EXPECT_FALSE(static_cast<web::NavigationItemImpl*>(GetLastCommittedItem()) |
| ->IsCreatedFromHashChange()); |