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

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

Issue 2807213003: Move stringify, form, navigation and scroll methods out of core.js. (Closed)
Patch Set: Created 3 years, 8 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
OLDNEW
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"
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 " doc.close();" 187 " doc.close();"
188 "</script>", 188 "</script>",
189 @YES 189 @YES
190 }; 190 };
191 LoadHtml(data.pageContent); 191 LoadHtml(data.pageContent);
192 id result = ExecuteJavaScript(@"__gCrWeb.hasPasswordField()"); 192 id result = ExecuteJavaScript(@"__gCrWeb.hasPasswordField()");
193 EXPECT_NSEQ(data.containsPassword, result) 193 EXPECT_NSEQ(data.containsPassword, result)
194 << base::SysNSStringToUTF8(data.pageContent); 194 << base::SysNSStringToUTF8(data.pageContent);
195 } 195 }
196 196
197 TEST_F(CoreJsTest, Stringify) {
198 // TODO(jeanfrancoisg): Test whether __gCrWeb.stringify(undefined) correctly
199 //returns undefined.
200 TestScriptAndExpectedValue testData[] = {
201 // Stringify a string that contains various characters that must
202 // be escaped.
203 {
204 @"__gCrWeb.stringify('a\\u000a\\t\\b\\\\\\\"Z')",
205 @"\"a\\n\\t\\b\\\\\\\"Z\""
206 },
207 // Stringify a number.
208 {
209 @"__gCrWeb.stringify(77.7)",
210 @"77.7"
211 },
212 // Stringify an array.
213 {
214 @"__gCrWeb.stringify(['a','b'])",
215 @"[\"a\",\"b\"]"
216 },
217 // Stringify an object.
218 {
219 @"__gCrWeb.stringify({'a':'b','c':'d'})",
220 @"{\"a\":\"b\",\"c\":\"d\"}"
221 },
222 // Stringify a hierarchy of objects and arrays.
223 {
224 @"__gCrWeb.stringify([{'a':['b','c'],'d':'e'},'f'])",
225 @"[{\"a\":[\"b\",\"c\"],\"d\":\"e\"},\"f\"]"
226 },
227 // Stringify null.
228 {
229 @"__gCrWeb.stringify(null)",
230 @"null"
231 },
232 // Stringify an object with a toJSON function.
233 {
234 @"temp = [1,2];"
235 "temp.toJSON = function (key) {return undefined};"
236 "__gCrWeb.stringify(temp)",
237 @"[1,2]"
238 },
239 // Stringify an object with a toJSON property that is not a function.
240 {
241 @"temp = [1,2];"
242 "temp.toJSON = 42;"
243 "__gCrWeb.stringify(temp)",
244 @"[1,2]"
245 },
246 };
247
248 for (size_t i = 0; i < arraysize(testData); i++) {
249 TestScriptAndExpectedValue& data = testData[i];
250 // Load a sample HTML page. As a side-effect, loading HTML via
251 // |webController_| will also inject core.js.
252 LoadHtml(@"<p>");
253 id result = ExecuteJavaScript(data.test_script);
254 EXPECT_NSEQ(data.expected_value, result)
255 << " in test " << i << ": "
256 << base::SysNSStringToUTF8(data.test_script);
257 }
258 }
259
260 // Tests the javascript of the url of the an image present in the DOM. 197 // Tests the javascript of the url of the an image present in the DOM.
261 TEST_F(CoreJsTest, LinkOfImage) { 198 TEST_F(CoreJsTest, LinkOfImage) {
262 // A page with a large image surrounded by a link. 199 // A page with a large image surrounded by a link.
263 static const char image[] = 200 static const char image[] =
264 "<a href='%s'><img width=400 height=400 src='foo'></img></a>"; 201 "<a href='%s'><img width=400 height=400 src='foo'></img></a>";
265 202
266 // A page with a link to a destination URL. 203 // A page with a link to a destination URL.
267 LoadHtml(base::StringPrintf(image, "http://destination")); 204 LoadHtml(base::StringPrintf(image, "http://destination"));
268 id result = ExecuteGetElementFromPointJavaScript(20, 20); 205 id result = ExecuteGetElementFromPointJavaScript(20, 20);
269 NSDictionary* expected_result = @{ 206 NSDictionary* expected_result = @{
(...skipping 27 matching lines...) Expand all
297 expected_result = @{ 234 expected_result = @{
298 @"src" : [NSString stringWithFormat:@"%sfoo", BaseUrl().c_str()], 235 @"src" : [NSString stringWithFormat:@"%sfoo", BaseUrl().c_str()],
299 @"referrerPolicy" : @"default", 236 @"referrerPolicy" : @"default",
300 }; 237 };
301 // Make sure the returned JSON does not have an 'href' key. 238 // Make sure the returned JSON does not have an 'href' key.
302 EXPECT_NSEQ(expected_result, result); 239 EXPECT_NSEQ(expected_result, result);
303 } 240 }
304 } 241 }
305 242
306 } // namespace web 243 } // namespace web
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698