| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include <vector> | |
| 6 | |
| 7 #include "base/macros.h" | |
| 8 #include "base/strings/stringprintf.h" | |
| 9 #include "base/strings/sys_string_conversions.h" | |
| 10 #import "ios/web/public/test/web_test_with_web_state.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 #include "testing/gtest_mac.h" | |
| 13 | |
| 14 // Unit tests for ios/web/web_state/js/resources/core.js. | |
| 15 | |
| 16 namespace web { | |
| 17 | |
| 18 // Test fixture to test core.js. | |
| 19 typedef web::WebTestWithWebState CoreJsTest; | |
| 20 | |
| 21 struct TestDataForPasswordFormDetection { | |
| 22 NSString* pageContent; | |
| 23 NSNumber* containsPassword; | |
| 24 }; | |
| 25 | |
| 26 TEST_F(CoreJsTest, HasPasswordField) { | |
| 27 TestDataForPasswordFormDetection testData[] = { | |
| 28 // Form without a password field. | |
| 29 {@"<form><input type='text' name='password'></form>", @NO}, | |
| 30 // Form with a password field. | |
| 31 {@"<form><input type='password' name='password'></form>", @YES}}; | |
| 32 for (size_t i = 0; i < arraysize(testData); i++) { | |
| 33 TestDataForPasswordFormDetection& data = testData[i]; | |
| 34 LoadHtml(data.pageContent); | |
| 35 id result = ExecuteJavaScript(@"__gCrWeb.hasPasswordField()"); | |
| 36 EXPECT_NSEQ(data.containsPassword, result) | |
| 37 << " in test " << i << ": " | |
| 38 << base::SysNSStringToUTF8(data.pageContent); | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 TEST_F(CoreJsTest, HasPasswordFieldinFrame) { | |
| 43 TestDataForPasswordFormDetection data = { | |
| 44 // Form with a password field in a nested iframe. | |
| 45 @"<iframe name='pf'></iframe>" | |
| 46 "<script>" | |
| 47 " var doc = frames['pf'].document.open();" | |
| 48 " doc.write('<form><input type=\\'password\\'></form>');" | |
| 49 " doc.close();" | |
| 50 "</script>", | |
| 51 @YES | |
| 52 }; | |
| 53 LoadHtml(data.pageContent); | |
| 54 id result = ExecuteJavaScript(@"__gCrWeb.hasPasswordField()"); | |
| 55 EXPECT_NSEQ(data.containsPassword, result) | |
| 56 << base::SysNSStringToUTF8(data.pageContent); | |
| 57 } | |
| 58 | |
| 59 } // namespace web | |
| OLD | NEW |