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

Unified Diff: ios/web/navigation/window_location_inttest.mm

Issue 2799953002: Treat loads of invalid URLs as no-ops unless triggered by window.open. (Closed)
Patch Set: Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
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.

Powered by Google App Engine
This is Rietveld 408576698