| Index: ios/web/web_state/js/context_menu_js_unittest.mm
|
| diff --git a/ios/web/web_state/js/core_js_unittest.mm b/ios/web/web_state/js/context_menu_js_unittest.mm
|
| similarity index 65%
|
| copy from ios/web/web_state/js/core_js_unittest.mm
|
| copy to ios/web/web_state/js/context_menu_js_unittest.mm
|
| index 46e2703ce8e1f6d18fa7ba049afe60cb831508ff..b3dfed3d25e5be77add7bd076cc376bf08353b10 100644
|
| --- a/ios/web/web_state/js/core_js_unittest.mm
|
| +++ b/ios/web/web_state/js/context_menu_js_unittest.mm
|
| @@ -1,4 +1,4 @@
|
| -// Copyright 2012 The Chromium Authors. All rights reserved.
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| @@ -9,23 +9,17 @@
|
|
|
| #include "base/macros.h"
|
| #include "base/strings/stringprintf.h"
|
| -#import "base/strings/sys_string_conversions.h"
|
| #import "ios/web/public/test/web_test_with_web_state.h"
|
| #import "ios/web/public/web_state/ui/crw_web_view_proxy.h"
|
| #import "ios/web/public/web_state/ui/crw_web_view_scroll_view_proxy.h"
|
| #import "ios/web/public/web_state/web_state.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| -#import "testing/gtest_mac.h"
|
| +#include "testing/gtest_mac.h"
|
|
|
| -// Unit tests for ios/web/web_state/js/resources/core.js.
|
| +// Unit tests for ios/web/web_state/js/resources/context_menu.js.
|
|
|
| namespace {
|
|
|
| -struct TestScriptAndExpectedValue {
|
| - NSString* test_script;
|
| - id expected_value;
|
| -};
|
| -
|
| // Test coordinates and expected result for __gCrWeb.getElementFromPoint call.
|
| struct TestCoordinatesAndExpectedValue {
|
| TestCoordinatesAndExpectedValue(CGFloat x, CGFloat y, id expected_value)
|
| @@ -39,8 +33,8 @@ struct TestCoordinatesAndExpectedValue {
|
|
|
| namespace web {
|
|
|
| -// Test fixture to test core.js.
|
| -class CoreJsTest : public web::WebTestWithWebState {
|
| +// Test fixture to test context_menu.js.
|
| +class ContextMenuJsTest : public web::WebTestWithWebState {
|
| protected:
|
| // Verifies that __gCrWeb.getElementFromPoint returns |expected_value| for
|
| // the given image |html|.
|
| @@ -89,7 +83,7 @@ class CoreJsTest : public web::WebTestWithWebState {
|
| };
|
|
|
| // Tests that __gCrWeb.getElementFromPoint function returns correct src.
|
| -TEST_F(CoreJsTest, GetImageUrlAtPoint) {
|
| +TEST_F(ContextMenuJsTest, GetImageUrlAtPoint) {
|
| NSString* html =
|
| @"<img id='foo' style='width:200;height:200;' src='file:///bogus'/>";
|
| NSDictionary* expected_value = @{
|
| @@ -100,7 +94,7 @@ TEST_F(CoreJsTest, GetImageUrlAtPoint) {
|
| }
|
|
|
| // Tests that __gCrWeb.getElementFromPoint function returns correct title.
|
| -TEST_F(CoreJsTest, GetImageTitleAtPoint) {
|
| +TEST_F(ContextMenuJsTest, GetImageTitleAtPoint) {
|
| NSString* html = @"<img id='foo' title='Hello world!'"
|
| "style='width:200;height:200;' src='file:///bogus'/>";
|
| NSDictionary* expected_value = @{
|
| @@ -112,7 +106,7 @@ TEST_F(CoreJsTest, GetImageTitleAtPoint) {
|
| }
|
|
|
| // Tests that __gCrWeb.getElementFromPoint function returns correct href.
|
| -TEST_F(CoreJsTest, GetLinkImageUrlAtPoint) {
|
| +TEST_F(ContextMenuJsTest, GetLinkImageUrlAtPoint) {
|
| NSString* html =
|
| @"<a href='file:///linky'>"
|
| "<img id='foo' style='width:200;height:200;' src='file:///bogus'/>"
|
| @@ -125,7 +119,7 @@ TEST_F(CoreJsTest, GetLinkImageUrlAtPoint) {
|
| ImageTesterHelper(html, expected_value);
|
| }
|
|
|
| -TEST_F(CoreJsTest, TextAreaStopsProximity) {
|
| +TEST_F(ContextMenuJsTest, TextAreaStopsProximity) {
|
| NSString* html =
|
| @"<html><body style='margin-left:10px;margin-top:10px;'>"
|
| "<div style='width:100px;height:100px;'>"
|
| @@ -156,109 +150,8 @@ TEST_F(CoreJsTest, TextAreaStopsProximity) {
|
| }
|
| }
|
|
|
| -struct TestDataForPasswordFormDetection {
|
| - NSString* pageContent;
|
| - NSNumber* containsPassword;
|
| -};
|
| -
|
| -TEST_F(CoreJsTest, HasPasswordField) {
|
| - TestDataForPasswordFormDetection testData[] = {
|
| - // Form without a password field.
|
| - {@"<form><input type='text' name='password'></form>", @NO},
|
| - // Form with a password field.
|
| - {@"<form><input type='password' name='password'></form>", @YES}};
|
| - for (size_t i = 0; i < arraysize(testData); i++) {
|
| - TestDataForPasswordFormDetection& data = testData[i];
|
| - LoadHtml(data.pageContent);
|
| - id result = ExecuteJavaScript(@"__gCrWeb.hasPasswordField()");
|
| - EXPECT_NSEQ(data.containsPassword, result)
|
| - << " in test " << i << ": "
|
| - << base::SysNSStringToUTF8(data.pageContent);
|
| - }
|
| -}
|
| -
|
| -TEST_F(CoreJsTest, HasPasswordFieldinFrame) {
|
| - TestDataForPasswordFormDetection data = {
|
| - // Form with a password field in a nested iframe.
|
| - @"<iframe name='pf'></iframe>"
|
| - "<script>"
|
| - " var doc = frames['pf'].document.open();"
|
| - " doc.write('<form><input type=\\'password\\'></form>');"
|
| - " doc.close();"
|
| - "</script>",
|
| - @YES
|
| - };
|
| - LoadHtml(data.pageContent);
|
| - id result = ExecuteJavaScript(@"__gCrWeb.hasPasswordField()");
|
| - EXPECT_NSEQ(data.containsPassword, result)
|
| - << base::SysNSStringToUTF8(data.pageContent);
|
| -}
|
| -
|
| -TEST_F(CoreJsTest, Stringify) {
|
| - // TODO(jeanfrancoisg): Test whether __gCrWeb.stringify(undefined) correctly
|
| - //returns undefined.
|
| - TestScriptAndExpectedValue testData[] = {
|
| - // Stringify a string that contains various characters that must
|
| - // be escaped.
|
| - {
|
| - @"__gCrWeb.stringify('a\\u000a\\t\\b\\\\\\\"Z')",
|
| - @"\"a\\n\\t\\b\\\\\\\"Z\""
|
| - },
|
| - // Stringify a number.
|
| - {
|
| - @"__gCrWeb.stringify(77.7)",
|
| - @"77.7"
|
| - },
|
| - // Stringify an array.
|
| - {
|
| - @"__gCrWeb.stringify(['a','b'])",
|
| - @"[\"a\",\"b\"]"
|
| - },
|
| - // Stringify an object.
|
| - {
|
| - @"__gCrWeb.stringify({'a':'b','c':'d'})",
|
| - @"{\"a\":\"b\",\"c\":\"d\"}"
|
| - },
|
| - // Stringify a hierarchy of objects and arrays.
|
| - {
|
| - @"__gCrWeb.stringify([{'a':['b','c'],'d':'e'},'f'])",
|
| - @"[{\"a\":[\"b\",\"c\"],\"d\":\"e\"},\"f\"]"
|
| - },
|
| - // Stringify null.
|
| - {
|
| - @"__gCrWeb.stringify(null)",
|
| - @"null"
|
| - },
|
| - // Stringify an object with a toJSON function.
|
| - {
|
| - @"temp = [1,2];"
|
| - "temp.toJSON = function (key) {return undefined};"
|
| - "__gCrWeb.stringify(temp)",
|
| - @"[1,2]"
|
| - },
|
| - // Stringify an object with a toJSON property that is not a function.
|
| - {
|
| - @"temp = [1,2];"
|
| - "temp.toJSON = 42;"
|
| - "__gCrWeb.stringify(temp)",
|
| - @"[1,2]"
|
| - },
|
| - };
|
| -
|
| - for (size_t i = 0; i < arraysize(testData); i++) {
|
| - TestScriptAndExpectedValue& data = testData[i];
|
| - // Load a sample HTML page. As a side-effect, loading HTML via
|
| - // |webController_| will also inject core.js.
|
| - LoadHtml(@"<p>");
|
| - id result = ExecuteJavaScript(data.test_script);
|
| - EXPECT_NSEQ(data.expected_value, result)
|
| - << " in test " << i << ": "
|
| - << base::SysNSStringToUTF8(data.test_script);
|
| - }
|
| -}
|
| -
|
| // Tests the javascript of the url of the an image present in the DOM.
|
| -TEST_F(CoreJsTest, LinkOfImage) {
|
| +TEST_F(ContextMenuJsTest, LinkOfImage) {
|
| // A page with a large image surrounded by a link.
|
| static const char image[] =
|
| "<a href='%s'><img width=400 height=400 src='foo'></img></a>";
|
|
|