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

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

Issue 2327783002: Fix domdistiller for new JS execution (Closed)
Patch Set: comments test 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/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/mac/bind_objc_block.h" 9 #include "base/mac/bind_objc_block.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 86
87 base::DictionaryValue const* inner_dictionary = nullptr; 87 base::DictionaryValue const* inner_dictionary = nullptr;
88 dictionary->GetDictionary("Key2", &inner_dictionary); 88 dictionary->GetDictionary("Key2", &inner_dictionary);
89 EXPECT_NE(nullptr, inner_dictionary); 89 EXPECT_NE(nullptr, inner_dictionary);
90 90
91 double value3; 91 double value3;
92 inner_dictionary->GetDouble("Key3", &value3); 92 inner_dictionary->GetDouble("Key3", &value3);
93 EXPECT_EQ(42, value3); 93 EXPECT_EQ(42, value3);
94 } 94 }
95 95
96 // Tests that ValueResultFromWKResult converts NSArray to properly
97 // initialized base::ListValue.
98 TEST(WebViewJsUtilsTest, ValueResultFromArrayWKResult) {
Eugene But (OOO till 7-30) 2016/09/19 21:52:27 Could you please add test for stack smashing case
lody 2016/09/20 13:41:37 Done, and test caught bug! (insert "is such a thin
99 NSArray* test_array = @[ @"Value1", @[ @YES ], @42 ];
100
101 std::unique_ptr<base::Value> value(web::ValueResultFromWKResult(test_array));
102 base::ListValue* list = nullptr;
103 value->GetAsList(&list);
104 EXPECT_NE(nullptr, list);
105
106 size_t list_size = 3;
107 EXPECT_EQ(list_size, list->GetSize());
108
109 std::string value1;
110 list->GetString(0, &value1);
111 EXPECT_EQ("Value1", value1);
112
113 base::ListValue const* inner_list;
Eugene But (OOO till 7-30) 2016/09/19 21:52:27 Please initialize
lody 2016/09/20 13:41:37 Done.
114 list->GetList(1, &inner_list);
115 EXPECT_NE(nullptr, inner_list);
116
117 double value3;
118 list->GetDouble(2, &value3);
119 EXPECT_EQ(42, value3);
120 }
121
96 // Tests that an NSDictionary with a cycle does not cause infinite recursion. 122 // Tests that an NSDictionary with a cycle does not cause infinite recursion.
97 TEST(WebViewJsUtilsTest, ValueResultFromDictionaryWithDepthCheckWKResult) { 123 TEST(WebViewJsUtilsTest, ValueResultFromDictionaryWithDepthCheckWKResult) {
98 // Create a dictionary with a cycle. 124 // Create a dictionary with a cycle.
99 NSMutableDictionary* test_dictionary = 125 NSMutableDictionary* test_dictionary =
100 [NSMutableDictionary dictionaryWithCapacity:1]; 126 [NSMutableDictionary dictionaryWithCapacity:1];
101 NSMutableDictionary* test_dictionary_2 = 127 NSMutableDictionary* test_dictionary_2 =
102 [NSMutableDictionary dictionaryWithCapacity:1]; 128 [NSMutableDictionary dictionaryWithCapacity:1];
103 const char* key = "key"; 129 const char* key = "key";
104 NSString* obj_c_key = 130 NSString* obj_c_key =
105 [NSString stringWithCString:key encoding:NSASCIIStringEncoding]; 131 [NSString stringWithCString:key encoding:NSASCIIStringEncoding];
(...skipping 19 matching lines...) Expand all
125 current_depth++) { 151 current_depth++) {
126 EXPECT_NE(nullptr, current_dictionary); 152 EXPECT_NE(nullptr, current_dictionary);
127 inner_dictionary = nullptr; 153 inner_dictionary = nullptr;
128 current_dictionary->GetDictionary(key, &inner_dictionary); 154 current_dictionary->GetDictionary(key, &inner_dictionary);
129 current_dictionary = inner_dictionary; 155 current_dictionary = inner_dictionary;
130 } 156 }
131 EXPECT_EQ(nullptr, current_dictionary); 157 EXPECT_EQ(nullptr, current_dictionary);
132 } 158 }
133 159
134 } // namespace web 160 } // namespace web
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698