| 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 19 matching lines...) Expand all Loading... |
| 30 // - isOnLoadTextVisible(), which returns whether a placeholder string is | 30 // - isOnLoadTextVisible(), which returns whether a placeholder string is |
| 31 // present on the page. This string is added to the page in the onload event | 31 // present on the page. This string is added to the page in the onload event |
| 32 // and is removed once a button is tapped. Verifying that the onload text is | 32 // and is removed once a button is tapped. Verifying that the onload text is |
| 33 // visible after tapping a button is equivalent to checking that a load has | 33 // visible after tapping a button is equivalent to checking that a load has |
| 34 // occurred as the result of the button tap. | 34 // occurred as the result of the button tap. |
| 35 const char kWindowLocationTestURL[] = | 35 const char kWindowLocationTestURL[] = |
| 36 "http://ios/testing/data/http_server_files/window_location.html"; | 36 "http://ios/testing/data/http_server_files/window_location.html"; |
| 37 | 37 |
| 38 // Button IDs used in the window.location test page. | 38 // Button IDs used in the window.location test page. |
| 39 const char kWindowLocationAssignID[] = "location-assign"; | 39 const char kWindowLocationAssignID[] = "location-assign"; |
| 40 const char kWindowLocationReplaceID[] = "location-replace"; |
| 40 | 41 |
| 41 // JavaScript functions on the window.location test page. | 42 // JavaScript functions on the window.location test page. |
| 42 NSString* const kUpdateURLScriptFormat = @"updateUrlToLoadText('%s')"; | 43 NSString* const kUpdateURLScriptFormat = @"updateUrlToLoadText('%s')"; |
| 43 NSString* const kGetURLScript = @"getUrl()"; | 44 NSString* const kGetURLScript = @"getUrl()"; |
| 44 NSString* const kOnLoadCheckScript = @"isOnLoadTextVisible()"; | 45 NSString* const kOnLoadCheckScript = @"isOnLoadTextVisible()"; |
| 45 | 46 |
| 46 // URL of a sample file-based page. | 47 // URL of a sample file-based page. |
| 47 const char kSampleFileBasedURL[] = | 48 const char kSampleFileBasedURL[] = |
| 48 "http://ios/testing/data/http_server_files/chromium_logo_page.html"; | 49 "http://ios/testing/data/http_server_files/chromium_logo_page.html"; |
| 49 | 50 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 SetWindowLocationUrl(sample_url); | 113 SetWindowLocationUrl(sample_url); |
| 113 ExecuteBlockAndWaitForLoad(sample_url, ^{ | 114 ExecuteBlockAndWaitForLoad(sample_url, ^{ |
| 114 ASSERT_TRUE(web::test::TapWebViewElementWithId(web_state(), | 115 ASSERT_TRUE(web::test::TapWebViewElementWithId(web_state(), |
| 115 kWindowLocationAssignID)); | 116 kWindowLocationAssignID)); |
| 116 }); | 117 }); |
| 117 | 118 |
| 118 // 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. |
| 119 EXPECT_EQ(sample_url, navigation_manager()->GetLastCommittedItem()->GetURL()); | 120 EXPECT_EQ(sample_url, navigation_manager()->GetLastCommittedItem()->GetURL()); |
| 120 EXPECT_EQ(NSNotFound, GetIndexOfNavigationItem(about_blank_item)); | 121 EXPECT_EQ(NSNotFound, GetIndexOfNavigationItem(about_blank_item)); |
| 121 } | 122 } |
| 123 |
| 124 // Tests that calling window.location.replace() doesn't create a new |
| 125 // NavigationItem. |
| 126 // TODO(crbug.com/307072): Enable test when location.replace is fixed. |
| 127 TEST_F(WindowLocationTest, DISABLED_Replace) { |
| 128 // Navigate to about:blank so there is a forward entry. |
| 129 GURL about_blank("about:blank"); |
| 130 LoadUrl(about_blank); |
| 131 web::NavigationItem* about_blank_item = |
| 132 navigation_manager()->GetLastCommittedItem(); |
| 133 |
| 134 // Navigate back to the window.location test page. |
| 135 ExecuteBlockAndWaitForLoad(window_location_url(), ^{ |
| 136 navigation_manager()->GoBack(); |
| 137 }); |
| 138 |
| 139 // Set the window.location test URL and tap the window.location.replace() |
| 140 // button. |
| 141 GURL sample_url = web::test::HttpServer::MakeUrl(kSampleFileBasedURL); |
| 142 SetWindowLocationUrl(sample_url); |
| 143 ExecuteBlockAndWaitForLoad(sample_url, ^{ |
| 144 ASSERT_TRUE(web::test::TapWebViewElementWithId(web_state(), |
| 145 kWindowLocationReplaceID)); |
| 146 }); |
| 147 |
| 148 // Verify that |sample_url| was loaded and that |about_blank_item| was pruned. |
| 149 web::NavigationItem* current_item = |
| 150 navigation_manager()->GetLastCommittedItem(); |
| 151 EXPECT_EQ(sample_url, current_item->GetURL()); |
| 152 EXPECT_EQ(GetIndexOfNavigationItem(current_item) + 1, |
| 153 GetIndexOfNavigationItem(about_blank_item)); |
| 154 } |
| OLD | NEW |