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

Side by Side Diff: ios/web/web_state/js/common_js_unittest.mm

Issue 1641893003: [ios] Removed WEB_TEST_F from web unit tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merged with origin Created 4 years, 10 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 | ios/web/web_state/js/core_js_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 <stddef.h> 5 #include <stddef.h>
6 #import <UIKit/UIKit.h> 6 #include <Foundation/Foundation.h>
7 7
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/strings/stringprintf.h"
10 #include "base/strings/sys_string_conversions.h"
11 #include "ios/web/public/test/web_test_util.h"
12 #import "ios/web/test/web_test.h" 9 #import "ios/web/test/web_test.h"
13 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
14 #include "testing/gtest_mac.h" 11 #include "testing/gtest_mac.h"
15 12
16 // Unit tests for ios/web/web_state/js/resources/common.js.
17
18 namespace { 13 namespace {
19 14
20 // Struct for isTextField() test data. 15 // Struct for isTextField() test data.
21 struct TextFieldTestElement { 16 struct TextFieldTestElement {
22 // The element name. 17 // The element name.
23 const char* element_name; 18 const char* element_name;
24 // The index of this element in those that have the same name. 19 // The index of this element in those that have the same name.
25 const int element_index; 20 const int element_index;
26 // True if this is expected to be a text field. 21 // True if this is expected to be a text field.
27 const bool expected_is_text_field; 22 const bool expected_is_text_field;
28 }; 23 };
29 24
30 // A mixin class for testing with CRWWKWebViewWebController or 25 } // namespace
31 // CRWUIWebViewWebController.
32 template <typename WebTestT>
33 class CommonJsTest : public WebTestT {};
34 26
35 // Concrete test fixture to test core.js using UIWebView-based web controller. 27 namespace web {
36 typedef CommonJsTest<web::WebTestWithUIWebViewWebController>
37 CommonJSUIWebViewTest;
38 28
39 // Concrete test fixture to test core.js using WKWebView-based web controller. 29 // Test fixture to test common.js.
40 typedef CommonJsTest<web::WebTestWithWKWebViewWebController> 30 typedef web::WebTestWithWKWebViewWebController CommonJsTest;
41 CommonJSWKWebViewTest;
42 31
43 WEB_TEST_F(CommonJSUIWebViewTest, CommonJSWKWebViewTest, Foo) { 32 // Tests __gCrWeb.common.isTextField JavaScript API.
44 this->LoadHtml(@"<html><body>" 33 TEST_F(CommonJsTest, IsTestField) {
45 "<input type='text' name='firstname'>" 34 LoadHtml(@"<html><body>"
46 "<input type='text' name='lastname'>" 35 "<input type='text' name='firstname'>"
47 "<input type='email' name='email'>" 36 "<input type='text' name='lastname'>"
48 "<input type='tel' name='phone'>" 37 "<input type='email' name='email'>"
49 "<input type='url' name='blog'>" 38 "<input type='tel' name='phone'>"
50 "<input type='number' name='expected number of clicks'>" 39 "<input type='url' name='blog'>"
51 "<input type='password' name='pwd'>" 40 "<input type='number' name='expected number of clicks'>"
52 "<input type='checkbox' name='vehicle' value='Bike'>" 41 "<input type='password' name='pwd'>"
53 "<input type='checkbox' name='vehicle' value='Car'>" 42 "<input type='checkbox' name='vehicle' value='Bike'>"
54 "<input type='checkbox' name='vehicle' value='Rocket'>" 43 "<input type='checkbox' name='vehicle' value='Car'>"
55 "<input type='radio' name='boolean' value='true'>" 44 "<input type='checkbox' name='vehicle' value='Rocket'>"
56 "<input type='radio' name='boolean' value='false'>" 45 "<input type='radio' name='boolean' value='true'>"
57 "<input type='radio' name='boolean' value='other'>" 46 "<input type='radio' name='boolean' value='false'>"
58 "<select name='state'>" 47 "<input type='radio' name='boolean' value='other'>"
59 " <option value='CA'>CA</option>" 48 "<select name='state'>"
60 " <option value='MA'>MA</option>" 49 " <option value='CA'>CA</option>"
61 "</select>" 50 " <option value='MA'>MA</option>"
62 "<select name='cars' multiple>" 51 "</select>"
63 " <option value='volvo'>Volvo</option>" 52 "<select name='cars' multiple>"
64 " <option value='saab'>Saab</option>" 53 " <option value='volvo'>Volvo</option>"
65 " <option value='opel'>Opel</option>" 54 " <option value='saab'>Saab</option>"
66 " <option value='audi'>Audi</option>" 55 " <option value='opel'>Opel</option>"
67 "</select>" 56 " <option value='audi'>Audi</option>"
68 "<input type='submit' name='submit' value='Submit'>" 57 "</select>"
69 "</body></html>"); 58 "<input type='submit' name='submit' value='Submit'>"
59 "</body></html>");
70 60
71 static const struct TextFieldTestElement testElements[] = { 61 static const struct TextFieldTestElement testElements[] = {
72 {"firstname", 0, true}, 62 {"firstname", 0, true},
73 {"lastname", 0, true}, 63 {"lastname", 0, true},
74 {"email", 0, true}, 64 {"email", 0, true},
75 {"phone", 0, true}, 65 {"phone", 0, true},
76 {"blog", 0, true}, 66 {"blog", 0, true},
77 {"expected number of clicks", 0, true}, 67 {"expected number of clicks", 0, true},
78 {"pwd", 0, true}, 68 {"pwd", 0, true},
79 {"vehicle", 0, false}, 69 {"vehicle", 0, false},
80 {"vehicle", 1, false}, 70 {"vehicle", 1, false},
81 {"vehicle", 2, false}, 71 {"vehicle", 2, false},
82 {"boolean", 0, false}, 72 {"boolean", 0, false},
83 {"boolean", 1, false}, 73 {"boolean", 1, false},
84 {"boolean", 2, false}, 74 {"boolean", 2, false},
85 {"state", 0, false}, 75 {"state", 0, false},
86 {"cars", 0, false}, 76 {"cars", 0, false},
87 {"submit", 0, false}}; 77 {"submit", 0, false}};
88 for (size_t i = 0; i < arraysize(testElements); ++i) { 78 for (size_t i = 0; i < arraysize(testElements); ++i) {
89 TextFieldTestElement element = testElements[i]; 79 TextFieldTestElement element = testElements[i];
90 NSString* result = 80 NSString* result = RunJavaScript([NSString
91 this->RunJavaScript(base::SysUTF8ToNSString(base::StringPrintf( 81 stringWithFormat:@"__gCrWeb.common.isTextField("
92 "__gCrWeb.common.isTextField(" 82 "window.document.getElementsByName('%s')[%d])",
93 "window.document.getElementsByName('%s')[%u])", 83 element.element_name, element.element_index]);
94 element.element_name, element.element_index)));
95 EXPECT_NSEQ(element.expected_is_text_field ? @"true" : @"false", result) 84 EXPECT_NSEQ(element.expected_is_text_field ? @"true" : @"false", result)
96 << element.element_name << " with index " << element.element_index 85 << element.element_name << " with index " << element.element_index
97 << " isTextField(): " << element.expected_is_text_field; 86 << " isTextField(): " << element.expected_is_text_field;
98 } 87 }
99 } 88 }
100 89
101 } // namespace 90 } // namespace web
OLDNEW
« no previous file with comments | « no previous file | ios/web/web_state/js/core_js_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698