| 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 | 6 |
| 7 #import <CoreGraphics/CoreGraphics.h> | 7 #import <CoreGraphics/CoreGraphics.h> |
| 8 #import <Foundation/Foundation.h> | 8 #import <Foundation/Foundation.h> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #import "base/strings/sys_string_conversions.h" | |
| 13 #import "ios/web/public/test/web_test_with_web_state.h" | 12 #import "ios/web/public/test/web_test_with_web_state.h" |
| 14 #import "ios/web/public/web_state/ui/crw_web_view_proxy.h" | 13 #import "ios/web/public/web_state/ui/crw_web_view_proxy.h" |
| 15 #import "ios/web/public/web_state/ui/crw_web_view_scroll_view_proxy.h" | 14 #import "ios/web/public/web_state/ui/crw_web_view_scroll_view_proxy.h" |
| 16 #import "ios/web/public/web_state/web_state.h" | 15 #import "ios/web/public/web_state/web_state.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #import "testing/gtest_mac.h" | 17 #import "testing/gtest_mac.h" |
| 19 | 18 |
| 20 // Unit tests for ios/web/web_state/js/resources/core.js. | 19 // Unit tests for ios/web/web_state/js/resources/core.js. |
| 21 | 20 |
| 22 namespace { | 21 namespace { |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 148 |
| 150 for (size_t i = 0; i < arraysize(test_data); i++) { | 149 for (size_t i = 0; i < arraysize(test_data); i++) { |
| 151 const TestCoordinatesAndExpectedValue& data = test_data[i]; | 150 const TestCoordinatesAndExpectedValue& data = test_data[i]; |
| 152 LoadHtml(html); | 151 LoadHtml(html); |
| 153 id result = ExecuteGetElementFromPointJavaScript(data.x, data.y); | 152 id result = ExecuteGetElementFromPointJavaScript(data.x, data.y); |
| 154 EXPECT_NSEQ(data.expected_value, result) | 153 EXPECT_NSEQ(data.expected_value, result) |
| 155 << " in test " << i << ": (" << data.x << ", " << data.y << ")"; | 154 << " in test " << i << ": (" << data.x << ", " << data.y << ")"; |
| 156 } | 155 } |
| 157 } | 156 } |
| 158 | 157 |
| 159 struct TestDataForPasswordFormDetection { | |
| 160 NSString* pageContent; | |
| 161 NSNumber* containsPassword; | |
| 162 }; | |
| 163 | |
| 164 TEST_F(CoreJsTest, HasPasswordField) { | |
| 165 TestDataForPasswordFormDetection testData[] = { | |
| 166 // Form without a password field. | |
| 167 {@"<form><input type='text' name='password'></form>", @NO}, | |
| 168 // Form with a password field. | |
| 169 {@"<form><input type='password' name='password'></form>", @YES}}; | |
| 170 for (size_t i = 0; i < arraysize(testData); i++) { | |
| 171 TestDataForPasswordFormDetection& data = testData[i]; | |
| 172 LoadHtml(data.pageContent); | |
| 173 id result = ExecuteJavaScript(@"__gCrWeb.hasPasswordField()"); | |
| 174 EXPECT_NSEQ(data.containsPassword, result) | |
| 175 << " in test " << i << ": " | |
| 176 << base::SysNSStringToUTF8(data.pageContent); | |
| 177 } | |
| 178 } | |
| 179 | |
| 180 TEST_F(CoreJsTest, HasPasswordFieldinFrame) { | |
| 181 TestDataForPasswordFormDetection data = { | |
| 182 // Form with a password field in a nested iframe. | |
| 183 @"<iframe name='pf'></iframe>" | |
| 184 "<script>" | |
| 185 " var doc = frames['pf'].document.open();" | |
| 186 " doc.write('<form><input type=\\'password\\'></form>');" | |
| 187 " doc.close();" | |
| 188 "</script>", | |
| 189 @YES | |
| 190 }; | |
| 191 LoadHtml(data.pageContent); | |
| 192 id result = ExecuteJavaScript(@"__gCrWeb.hasPasswordField()"); | |
| 193 EXPECT_NSEQ(data.containsPassword, result) | |
| 194 << base::SysNSStringToUTF8(data.pageContent); | |
| 195 } | |
| 196 | |
| 197 // Tests the javascript of the url of the an image present in the DOM. | 158 // Tests the javascript of the url of the an image present in the DOM. |
| 198 TEST_F(CoreJsTest, LinkOfImage) { | 159 TEST_F(CoreJsTest, LinkOfImage) { |
| 199 // A page with a large image surrounded by a link. | 160 // A page with a large image surrounded by a link. |
| 200 static const char image[] = | 161 static const char image[] = |
| 201 "<a href='%s'><img width=400 height=400 src='foo'></img></a>"; | 162 "<a href='%s'><img width=400 height=400 src='foo'></img></a>"; |
| 202 | 163 |
| 203 // A page with a link to a destination URL. | 164 // A page with a link to a destination URL. |
| 204 LoadHtml(base::StringPrintf(image, "http://destination")); | 165 LoadHtml(base::StringPrintf(image, "http://destination")); |
| 205 id result = ExecuteGetElementFromPointJavaScript(20, 20); | 166 id result = ExecuteGetElementFromPointJavaScript(20, 20); |
| 206 NSDictionary* expected_result = @{ | 167 NSDictionary* expected_result = @{ |
| (...skipping 27 matching lines...) Expand all Loading... |
| 234 expected_result = @{ | 195 expected_result = @{ |
| 235 @"src" : [NSString stringWithFormat:@"%sfoo", BaseUrl().c_str()], | 196 @"src" : [NSString stringWithFormat:@"%sfoo", BaseUrl().c_str()], |
| 236 @"referrerPolicy" : @"default", | 197 @"referrerPolicy" : @"default", |
| 237 }; | 198 }; |
| 238 // Make sure the returned JSON does not have an 'href' key. | 199 // Make sure the returned JSON does not have an 'href' key. |
| 239 EXPECT_NSEQ(expected_result, result); | 200 EXPECT_NSEQ(expected_result, result); |
| 240 } | 201 } |
| 241 } | 202 } |
| 242 | 203 |
| 243 } // namespace web | 204 } // namespace web |
| OLD | NEW |