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

Side by Side Diff: ios/web/web_state/ui/web_view_js_utils_unittest.mm

Issue 2275513002: Support having javascript return dictionaries. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments. Created 4 years, 3 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #import "ios/web/web_state/ui/web_view_js_utils.h" 5 #import "ios/web/web_state/ui/web_view_js_utils.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #import "base/mac/scoped_nsobject.h" 8 #import "base/mac/scoped_nsobject.h"
9 #include "base/test/ios/wait_util.h" 9 #include "base/test/ios/wait_util.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 } 93 }
94 94
95 // Tests that ValueResultFromWKResult converts null to Value::TYPE_NULL. 95 // Tests that ValueResultFromWKResult converts null to Value::TYPE_NULL.
96 TEST_F(WebViewJsUtilsTest, ValueResultFromNullWKResult) { 96 TEST_F(WebViewJsUtilsTest, ValueResultFromNullWKResult) {
97 std::unique_ptr<base::Value> value( 97 std::unique_ptr<base::Value> value(
98 web::ValueResultFromWKResult([NSNull null])); 98 web::ValueResultFromWKResult([NSNull null]));
99 EXPECT_TRUE(value); 99 EXPECT_TRUE(value);
100 EXPECT_EQ(base::Value::TYPE_NULL, value->GetType()); 100 EXPECT_EQ(base::Value::TYPE_NULL, value->GetType());
101 } 101 }
102 102
103 // Tests that ValueResultFromWKResult converts NSDictionaries to properly
104 // initialized base::DictionaryValue.
105 TEST_F(WebViewJsUtilsTest, ValueResultFromDictionaryWKResult) {
106 NSDictionary* testDictionary =
107 @{ @"Key1" : @"Value1",
108 @"Key2" : @{@"Key3" : @42} };
109
110 std::unique_ptr<base::Value> value(
111 web::ValueResultFromWKResult(testDictionary));
112 base::DictionaryValue* dictionary = nullptr;
113 value->GetAsDictionary(&dictionary);
114 EXPECT_NE(nullptr, dictionary);
115
116 std::string value1;
117 dictionary->GetString("Key1", &value1);
118 EXPECT_EQ("Value1", value1);
119
120 base::DictionaryValue const* innerDictionary = nullptr;
121 dictionary->GetDictionary("Key2", &innerDictionary);
122 EXPECT_NE(nullptr, innerDictionary);
123
124 double value3;
125 innerDictionary->GetDouble("Key3", &value3);
126 EXPECT_EQ(42, value3);
127 }
128
103 // Tests that a script with undefined result correctly evaluates to string. 129 // Tests that a script with undefined result correctly evaluates to string.
104 TEST_F(WebViewJsUtilsTest, UndefinedEvaluation) { 130 TEST_F(WebViewJsUtilsTest, UndefinedEvaluation) {
105 EXPECT_NSEQ(@"", EvaluateJavaScript(@"{}")); 131 EXPECT_NSEQ(@"", EvaluateJavaScript(@"{}"));
106 } 132 }
107 133
108 // Tests that a script with string result correctly evaluates to string. 134 // Tests that a script with string result correctly evaluates to string.
109 TEST_F(WebViewJsUtilsTest, StringEvaluation) { 135 TEST_F(WebViewJsUtilsTest, StringEvaluation) {
110 EXPECT_NSEQ(@"test", EvaluateJavaScript(@"'test'")); 136 EXPECT_NSEQ(@"test", EvaluateJavaScript(@"'test'"));
111 } 137 }
112 138
(...skipping 10 matching lines...) Expand all
123 EXPECT_NSEQ(@"true", EvaluateJavaScript(@"true")); 149 EXPECT_NSEQ(@"true", EvaluateJavaScript(@"true"));
124 EXPECT_NSEQ(@"false", EvaluateJavaScript(@"false")); 150 EXPECT_NSEQ(@"false", EvaluateJavaScript(@"false"));
125 } 151 }
126 152
127 // Tests that a script with null result correctly evaluates to empty string. 153 // Tests that a script with null result correctly evaluates to empty string.
128 TEST_F(WebViewJsUtilsTest, NullEvaluation) { 154 TEST_F(WebViewJsUtilsTest, NullEvaluation) {
129 EXPECT_NSEQ(@"", EvaluateJavaScript(@"null")); 155 EXPECT_NSEQ(@"", EvaluateJavaScript(@"null"));
130 } 156 }
131 157
132 } // namespace web 158 } // namespace web
OLDNEW
« ios/web/web_state/ui/web_view_js_utils.mm ('K') | « ios/web/web_state/ui/web_view_js_utils.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698