| 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 "base/mac/bind_objc_block.h" | 5 #import "base/mac/bind_objc_block.h" |
| 6 #include "base/mac/foundation_util.h" | 6 #include "base/mac/foundation_util.h" |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #import "base/strings/sys_string_conversions.h" | 8 #import "base/strings/sys_string_conversions.h" |
| 9 #include "base/test/ios/wait_util.h" | 9 #include "base/test/ios/wait_util.h" |
| 10 #import "ios/web/public/navigation_item.h" | 10 #import "ios/web/public/navigation_item.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 ExecuteBlockAndWaitForLoad(sample_url, ^{ | 114 ExecuteBlockAndWaitForLoad(sample_url, ^{ |
| 115 ASSERT_TRUE(web::test::TapWebViewElementWithId(web_state(), | 115 ASSERT_TRUE(web::test::TapWebViewElementWithId(web_state(), |
| 116 kWindowLocationAssignID)); | 116 kWindowLocationAssignID)); |
| 117 }); | 117 }); |
| 118 | 118 |
| 119 // Verify that |sample_url| was loaded and that |about_blank_item| was pruned. | 119 // Verify that |sample_url| was loaded and that |about_blank_item| was pruned. |
| 120 EXPECT_EQ(sample_url, navigation_manager()->GetLastCommittedItem()->GetURL()); | 120 EXPECT_EQ(sample_url, navigation_manager()->GetLastCommittedItem()->GetURL()); |
| 121 EXPECT_EQ(NSNotFound, GetIndexOfNavigationItem(about_blank_item)); | 121 EXPECT_EQ(NSNotFound, GetIndexOfNavigationItem(about_blank_item)); |
| 122 } | 122 } |
| 123 | 123 |
| 124 // Tests that calling window.location.assign() with an unresolvable URL loads |
| 125 // about:blank. |
| 126 TEST_F(WindowLocationTest, WindowLocationAssignUnresolvable) { |
| 127 // Attempt to call window.location.assign() using an unresolvable URL. |
| 128 GURL about_blank("about:blank"); |
| 129 GURL unresolvable_url("http:https:not a url"); |
| 130 SetWindowLocationUrl(unresolvable_url); |
| 131 ExecuteBlockAndWaitForLoad(about_blank, ^{ |
| 132 ASSERT_TRUE(web::test::TapWebViewElementWithId(web_state(), |
| 133 kWindowLocationAssignID)); |
| 134 }); |
| 135 |
| 136 // Verify that about:blank was actually loaded. |
| 137 EXPECT_EQ(about_blank, |
| 138 navigation_manager()->GetLastCommittedItem()->GetURL()); |
| 139 } |
| 140 |
| 124 // Tests that calling window.location.replace() doesn't create a new | 141 // Tests that calling window.location.replace() doesn't create a new |
| 125 // NavigationItem. | 142 // NavigationItem. |
| 126 // TODO(crbug.com/307072): Enable test when location.replace is fixed. | 143 // TODO(crbug.com/307072): Enable test when location.replace is fixed. |
| 127 TEST_F(WindowLocationTest, DISABLED_Replace) { | 144 TEST_F(WindowLocationTest, DISABLED_Replace) { |
| 128 // Navigate to about:blank so there is a forward entry. | 145 // Navigate to about:blank so there is a forward entry. |
| 129 GURL about_blank("about:blank"); | 146 GURL about_blank("about:blank"); |
| 130 LoadUrl(about_blank); | 147 LoadUrl(about_blank); |
| 131 web::NavigationItem* about_blank_item = | 148 web::NavigationItem* about_blank_item = |
| 132 navigation_manager()->GetLastCommittedItem(); | 149 navigation_manager()->GetLastCommittedItem(); |
| 133 | 150 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 145 kWindowLocationReplaceID)); | 162 kWindowLocationReplaceID)); |
| 146 }); | 163 }); |
| 147 | 164 |
| 148 // Verify that |sample_url| was loaded and that |about_blank_item| was pruned. | 165 // Verify that |sample_url| was loaded and that |about_blank_item| was pruned. |
| 149 web::NavigationItem* current_item = | 166 web::NavigationItem* current_item = |
| 150 navigation_manager()->GetLastCommittedItem(); | 167 navigation_manager()->GetLastCommittedItem(); |
| 151 EXPECT_EQ(sample_url, current_item->GetURL()); | 168 EXPECT_EQ(sample_url, current_item->GetURL()); |
| 152 EXPECT_EQ(GetIndexOfNavigationItem(current_item) + 1, | 169 EXPECT_EQ(GetIndexOfNavigationItem(current_item) + 1, |
| 153 GetIndexOfNavigationItem(about_blank_item)); | 170 GetIndexOfNavigationItem(about_blank_item)); |
| 154 } | 171 } |
| OLD | NEW |