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

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: Created 4 years, 4 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* dictionnary =
marq (ping after 24h) 2016/08/23 12:28:26 Spelling: "dictionary".
jif 2016/08/23 12:59:12 Done.
107 @{ @"Key1" : @"Value1",
108 @"Key2" : @{@"Key3" : @42} };
109
110 std::unique_ptr<base::Value> value(web::ValueResultFromWKResult(dictionnary));
111 base::DictionaryValue* dictionary = nullptr;
112 value->GetAsDictionary(&dictionary);
113 EXPECT_NE(nullptr, dictionary);
114
115 std::string value1;
116 dictionary->GetString("Key1", &value1);
117 EXPECT_EQ("Value1", value1);
118
119 base::DictionaryValue const* innerDictionary = nullptr;
120 dictionary->GetDictionary("Key2", &innerDictionary);
121 EXPECT_NE(nullptr, innerDictionary);
122
123 double value3;
124 innerDictionary->GetDouble("Key3", &value3);
125 EXPECT_EQ(42, value3);
126 }
127
103 // Tests that a script with undefined result correctly evaluates to string. 128 // Tests that a script with undefined result correctly evaluates to string.
104 TEST_F(WebViewJsUtilsTest, UndefinedEvaluation) { 129 TEST_F(WebViewJsUtilsTest, UndefinedEvaluation) {
105 EXPECT_NSEQ(@"", EvaluateJavaScript(@"{}")); 130 EXPECT_NSEQ(@"", EvaluateJavaScript(@"{}"));
106 } 131 }
107 132
108 // Tests that a script with string result correctly evaluates to string. 133 // Tests that a script with string result correctly evaluates to string.
109 TEST_F(WebViewJsUtilsTest, StringEvaluation) { 134 TEST_F(WebViewJsUtilsTest, StringEvaluation) {
110 EXPECT_NSEQ(@"test", EvaluateJavaScript(@"'test'")); 135 EXPECT_NSEQ(@"test", EvaluateJavaScript(@"'test'"));
111 } 136 }
112 137
(...skipping 10 matching lines...) Expand all
123 EXPECT_NSEQ(@"true", EvaluateJavaScript(@"true")); 148 EXPECT_NSEQ(@"true", EvaluateJavaScript(@"true"));
124 EXPECT_NSEQ(@"false", EvaluateJavaScript(@"false")); 149 EXPECT_NSEQ(@"false", EvaluateJavaScript(@"false"));
125 } 150 }
126 151
127 // Tests that a script with null result correctly evaluates to empty string. 152 // Tests that a script with null result correctly evaluates to empty string.
128 TEST_F(WebViewJsUtilsTest, NullEvaluation) { 153 TEST_F(WebViewJsUtilsTest, NullEvaluation) {
129 EXPECT_NSEQ(@"", EvaluateJavaScript(@"null")); 154 EXPECT_NSEQ(@"", EvaluateJavaScript(@"null"));
130 } 155 }
131 156
132 } // namespace web 157 } // 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