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

Unified 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, 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 side-by-side diff with in-line comments
Download patch
Index: ios/web/web_state/ui/web_view_js_utils_unittest.mm
diff --git a/ios/web/web_state/ui/web_view_js_utils_unittest.mm b/ios/web/web_state/ui/web_view_js_utils_unittest.mm
index cf4b440c9ab4a4cf39eb229affc4802323ef7cb8..beb48b689d5e232b5624abd7271d5a11c855afde 100644
--- a/ios/web/web_state/ui/web_view_js_utils_unittest.mm
+++ b/ios/web/web_state/ui/web_view_js_utils_unittest.mm
@@ -100,6 +100,32 @@ TEST_F(WebViewJsUtilsTest, ValueResultFromNullWKResult) {
EXPECT_EQ(base::Value::TYPE_NULL, value->GetType());
}
+// Tests that ValueResultFromWKResult converts NSDictionaries to properly
+// initialized base::DictionaryValue.
+TEST_F(WebViewJsUtilsTest, ValueResultFromDictionaryWKResult) {
+ NSDictionary* testDictionary =
+ @{ @"Key1" : @"Value1",
+ @"Key2" : @{@"Key3" : @42} };
+
+ std::unique_ptr<base::Value> value(
+ web::ValueResultFromWKResult(testDictionary));
+ base::DictionaryValue* dictionary = nullptr;
+ value->GetAsDictionary(&dictionary);
+ EXPECT_NE(nullptr, dictionary);
+
+ std::string value1;
+ dictionary->GetString("Key1", &value1);
+ EXPECT_EQ("Value1", value1);
+
+ base::DictionaryValue const* innerDictionary = nullptr;
+ dictionary->GetDictionary("Key2", &innerDictionary);
+ EXPECT_NE(nullptr, innerDictionary);
+
+ double value3;
+ innerDictionary->GetDouble("Key3", &value3);
+ EXPECT_EQ(42, value3);
+}
+
// Tests that a script with undefined result correctly evaluates to string.
TEST_F(WebViewJsUtilsTest, UndefinedEvaluation) {
EXPECT_NSEQ(@"", EvaluateJavaScript(@"{}"));
« 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