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

Side by Side Diff: ios/web/navigation/window_location_inttest.mm

Issue 2594363003: Created a test for assigning a string to window.location. (Closed)
Patch Set: rebase Created 3 years, 11 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 21 matching lines...) Expand all
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 const char kWindowLocationReplaceID[] = "location-replace";
41 const char kWindowLocationReloadID[] = "location-reload"; 41 const char kWindowLocationReloadID[] = "location-reload";
42 const char kWindowLocationSetToDOMStringID[] = "set-location-to-dom-string";
42 43
43 // JavaScript functions on the window.location test page. 44 // JavaScript functions on the window.location test page.
44 NSString* const kUpdateURLScriptFormat = @"updateUrlToLoadText('%s')"; 45 NSString* const kUpdateURLScriptFormat = @"updateUrlToLoadText('%s')";
45 NSString* const kGetURLScript = @"getUrl()"; 46 NSString* const kGetURLScript = @"getUrl()";
46 NSString* const kOnLoadCheckScript = @"isOnLoadTextVisible()"; 47 NSString* const kOnLoadCheckScript = @"isOnLoadTextVisible()";
47 48
48 // URL of a sample file-based page. 49 // URL of a sample file-based page.
49 const char kSampleFileBasedURL[] = 50 const char kSampleFileBasedURL[] =
50 "http://ios/testing/data/http_server_files/chromium_logo_page.html"; 51 "http://ios/testing/data/http_server_files/chromium_logo_page.html";
51 52
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 ExecuteBlockAndWaitForLoad(window_location_url(), ^{ 195 ExecuteBlockAndWaitForLoad(window_location_url(), ^{
195 ASSERT_TRUE(web::test::TapWebViewElementWithId(web_state(), 196 ASSERT_TRUE(web::test::TapWebViewElementWithId(web_state(),
196 kWindowLocationReloadID)); 197 kWindowLocationReloadID));
197 }); 198 });
198 199
199 // Verify that |kOnLoadText| is displayed and that no additional 200 // Verify that |kOnLoadText| is displayed and that no additional
200 // NavigationItems are added. 201 // NavigationItems are added.
201 EXPECT_TRUE(IsOnLoadTextVisible()); 202 EXPECT_TRUE(IsOnLoadTextVisible());
202 EXPECT_EQ(1, navigation_manager()->GetItemCount()); 203 EXPECT_EQ(1, navigation_manager()->GetItemCount());
203 } 204 }
205
206 // Tests that calling window.location.assign() creates a new NavigationItem.
207 TEST_F(WindowLocationTest, WindowLocationSetToDOMString) {
208 // Navigate to about:blank so there is a forward entry to prune.
209 GURL about_blank("about:blank");
210 LoadUrl(about_blank);
211 web::NavigationItem* about_blank_item =
212 navigation_manager()->GetLastCommittedItem();
213
214 // Navigate back to the window.location test page.
215 ExecuteBlockAndWaitForLoad(window_location_url(), ^{
216 navigation_manager()->GoBack();
217 });
218
219 // Set the window.location test URL and tap the window.location.assign()
220 // button.
221 GURL sample_url = web::test::HttpServer::MakeUrl(kSampleFileBasedURL);
222 SetWindowLocationUrl(sample_url);
223 ExecuteBlockAndWaitForLoad(sample_url, ^{
224 ASSERT_TRUE(web::test::TapWebViewElementWithId(
225 web_state(), kWindowLocationSetToDOMStringID));
226 });
227
228 // Verify that |sample_url| was loaded and that |about_blank_item| was pruned.
229 EXPECT_EQ(sample_url, navigation_manager()->GetLastCommittedItem()->GetURL());
230 EXPECT_EQ(NSNotFound, GetIndexOfNavigationItem(about_blank_item));
231 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698