Index: ios/web/navigation/window_location_inttest.mm |
diff --git a/ios/web/navigation/window_location_inttest.mm b/ios/web/navigation/window_location_inttest.mm |
index fcfe4f712870f6c6e22df398a2ca13c7281195fd..984754e831eca6e5af0d95acabd511a360af6157 100644 |
--- a/ios/web/navigation/window_location_inttest.mm |
+++ b/ios/web/navigation/window_location_inttest.mm |
@@ -45,6 +45,7 @@ |
NSString* const kUpdateURLScriptFormat = @"updateUrlToLoadText('%s')"; |
NSString* const kGetURLScript = @"getUrl()"; |
NSString* const kOnLoadCheckScript = @"isOnLoadTextVisible()"; |
+NSString* const kNoOpCheckScript = @"isNoOpTextVisible()"; |
// URL of a sample file-based page. |
const char kSampleFileBasedURL[] = |
@@ -92,6 +93,15 @@ bool IsOnLoadTextVisible() { |
return [text_visible boolValue]; |
} |
+ // Executes JavaScript on the window.location test page and returns whether |
+ // the no-op text is visible. It is displayed 0.5 seconds after a button is |
+ // tapped, and can be used to verify that a navigation did not occur. |
+ bool IsNoOpTextVisible() { |
+ NSNumber* text_visible = base::mac::ObjCCastStrict<NSNumber>( |
+ ExecuteJavaScript(kNoOpCheckScript)); |
+ return [text_visible boolValue]; |
+ } |
+ |
private: |
GURL window_location_url_; |
}; |
@@ -127,17 +137,15 @@ bool IsOnLoadTextVisible() { |
// about:blank. |
TEST_F(WindowLocationTest, WindowLocationAssignUnresolvable) { |
// Attempt to call window.location.assign() using an unresolvable URL. |
- GURL about_blank("about:blank"); |
GURL unresolvable_url("http:https:not a url"); |
SetWindowLocationUrl(unresolvable_url); |
- ExecuteBlockAndWaitForLoad(about_blank, ^{ |
- ASSERT_TRUE(web::test::TapWebViewElementWithId(web_state(), |
- kWindowLocationAssignID)); |
- }); |
+ ASSERT_TRUE( |
+ web::test::TapWebViewElementWithId(web_state(), kWindowLocationAssignID)); |
- // Verify that about:blank was actually loaded. |
- EXPECT_EQ(about_blank, |
- navigation_manager()->GetLastCommittedItem()->GetURL()); |
+ // Wait for the no-op text to appear. |
+ base::test::ios::WaitUntilCondition(^bool { |
+ return IsNoOpTextVisible(); |
+ }); |
} |
// Tests that calling window.location.replace() doesn't create a new |
@@ -172,21 +180,19 @@ bool IsOnLoadTextVisible() { |
GetIndexOfNavigationItem(about_blank_item)); |
} |
-// Tests that calling window.location.replace() with an unresolvable URL loads |
-// about:blank. |
+// Tests that calling window.location.replace() with an unresolvable URL is a |
+// no-op. |
TEST_F(WindowLocationTest, WindowLocationReplaceUnresolvable) { |
// Attempt to call window.location.assign() using an unresolvable URL. |
- GURL about_blank("about:blank"); |
GURL unresolvable_url("http:https:not a url"); |
SetWindowLocationUrl(unresolvable_url); |
- ExecuteBlockAndWaitForLoad(about_blank, ^{ |
- ASSERT_TRUE(web::test::TapWebViewElementWithId(web_state(), |
- kWindowLocationReplaceID)); |
- }); |
+ ASSERT_TRUE(web::test::TapWebViewElementWithId(web_state(), |
+ kWindowLocationReplaceID)); |
- // Verify that about:blank was actually loaded. |
- EXPECT_EQ(about_blank, |
- navigation_manager()->GetLastCommittedItem()->GetURL()); |
+ // Wait for the no-op text to appear. |
+ base::test::ios::WaitUntilCondition(^bool { |
+ return IsNoOpTextVisible(); |
+ }); |
} |
// Tests that calling window.location.reload() causes an onload event to occur. |