OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 #include <vector> | 5 #include <vector> |
6 #import <Foundation/Foundation.h> | 6 #import <Foundation/Foundation.h> |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/strings/stringprintf.h" | 9 #include "base/strings/stringprintf.h" |
10 #import "ios/web/public/test/web_test_with_web_state.h" | 10 #import "ios/web/public/test/web_test_with_web_state.h" |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 // Tests the javascript of the url of the an image present in the DOM. | 233 // Tests the javascript of the url of the an image present in the DOM. |
234 TEST_F(CoreJsTest, LinkOfImage) { | 234 TEST_F(CoreJsTest, LinkOfImage) { |
235 // A page with a large image surrounded by a link. | 235 // A page with a large image surrounded by a link. |
236 static const char image[] = | 236 static const char image[] = |
237 "<a href='%s'><img width=400 height=400 src='foo'></img></a>"; | 237 "<a href='%s'><img width=400 height=400 src='foo'></img></a>"; |
238 | 238 |
239 // A page with a link to a destination URL. | 239 // A page with a link to a destination URL. |
240 LoadHtml(base::StringPrintf(image, "http://destination")); | 240 LoadHtml(base::StringPrintf(image, "http://destination")); |
241 id result = ExecuteJavaScript(@"__gCrWeb['getElementFromPoint'](200, 200)"); | 241 id result = ExecuteJavaScript(@"__gCrWeb['getElementFromPoint'](200, 200)"); |
242 NSDictionary* expected_result = @{ | 242 NSDictionary* expected_result = @{ |
243 @"src" : @"foo", | 243 @"src" : [NSString stringWithFormat:@"%sfoo", BaseUrl().c_str()], |
244 @"referrerPolicy" : @"default", | 244 @"referrerPolicy" : @"default", |
245 @"href" : @"http://destination/", | 245 @"href" : @"http://destination/", |
246 }; | 246 }; |
247 EXPECT_NSEQ(expected_result, result); | 247 EXPECT_NSEQ(expected_result, result); |
248 | 248 |
249 // A page with a link with some JavaScript that does not result in a NOP. | 249 // A page with a link with some JavaScript that does not result in a NOP. |
250 LoadHtml(base::StringPrintf(image, "javascript:console.log('whatever')")); | 250 LoadHtml(base::StringPrintf(image, "javascript:console.log('whatever')")); |
251 result = ExecuteJavaScript(@"__gCrWeb['getElementFromPoint'](200, 200)"); | 251 result = ExecuteJavaScript(@"__gCrWeb['getElementFromPoint'](200, 200)"); |
252 expected_result = @{ | 252 expected_result = @{ |
253 @"src" : @"foo", | 253 @"src" : [NSString stringWithFormat:@"%sfoo", BaseUrl().c_str()], |
254 @"referrerPolicy" : @"default", | 254 @"referrerPolicy" : @"default", |
255 @"href" : @"javascript:console.log(", | 255 @"href" : @"javascript:console.log(", |
256 }; | 256 }; |
257 EXPECT_NSEQ(expected_result, result); | 257 EXPECT_NSEQ(expected_result, result); |
258 | 258 |
259 // A list of JavaScripts that result in a NOP. | 259 // A list of JavaScripts that result in a NOP. |
260 std::vector<std::string> nop_javascripts; | 260 std::vector<std::string> nop_javascripts; |
261 nop_javascripts.push_back(";"); | 261 nop_javascripts.push_back(";"); |
262 nop_javascripts.push_back("void(0);"); | 262 nop_javascripts.push_back("void(0);"); |
263 nop_javascripts.push_back("void(0); void(0); void(0)"); | 263 nop_javascripts.push_back("void(0); void(0); void(0)"); |
264 | 264 |
265 for (auto js : nop_javascripts) { | 265 for (auto js : nop_javascripts) { |
266 // A page with a link with some JavaScript that results in a NOP. | 266 // A page with a link with some JavaScript that results in a NOP. |
267 const std::string javascript = std::string("javascript:") + js; | 267 const std::string javascript = std::string("javascript:") + js; |
268 LoadHtml(base::StringPrintf(image, javascript.c_str())); | 268 LoadHtml(base::StringPrintf(image, javascript.c_str())); |
269 result = ExecuteJavaScript(@"__gCrWeb['getElementFromPoint'](200, 200)"); | 269 result = ExecuteJavaScript(@"__gCrWeb['getElementFromPoint'](200, 200)"); |
270 expected_result = @{ | 270 expected_result = @{ |
271 @"src" : @"foo", | 271 @"src" : [NSString stringWithFormat:@"%sfoo", BaseUrl().c_str()], |
272 @"referrerPolicy" : @"default", | 272 @"referrerPolicy" : @"default", |
273 }; | 273 }; |
274 // Make sure the returned JSON does not have an 'href' key. | 274 // Make sure the returned JSON does not have an 'href' key. |
275 EXPECT_NSEQ(expected_result, result); | 275 EXPECT_NSEQ(expected_result, result); |
276 } | 276 } |
277 } | 277 } |
278 | 278 |
279 } // namespace web | 279 } // namespace web |
OLD | NEW |