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

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

Issue 2933363002: [ObjC ARC] Converts ios/web:ios_web_web_state_ui_unittests to ARC. (Closed)
Patch Set: Review nits. Created 3 years, 6 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 #import "base/mac/bind_objc_block.h" 9 #import "base/mac/bind_objc_block.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 12
13 #if !defined(__has_feature) || !__has_feature(objc_arc)
14 #error "This file requires ARC support."
15 #endif
16
13 namespace web { 17 namespace web {
14 18
15 // Tests that ValueResultFromWKResult converts nil value to nullptr. 19 // Tests that ValueResultFromWKResult converts nil value to nullptr.
16 TEST(WebViewJsUtilsTest, ValueResultFromUndefinedWKResult) { 20 TEST(WebViewJsUtilsTest, ValueResultFromUndefinedWKResult) {
17 EXPECT_FALSE(ValueResultFromWKResult(nil)); 21 EXPECT_FALSE(ValueResultFromWKResult(nil));
18 } 22 }
19 23
20 // Tests that ValueResultFromWKResult converts string to Value::Type::STRING. 24 // Tests that ValueResultFromWKResult converts string to Value::Type::STRING.
21 TEST(WebViewJsUtilsTest, ValueResultFromStringWKResult) { 25 TEST(WebViewJsUtilsTest, ValueResultFromStringWKResult) {
22 std::unique_ptr<base::Value> value(web::ValueResultFromWKResult(@"test")); 26 std::unique_ptr<base::Value> value(web::ValueResultFromWKResult(@"test"));
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 [NSMutableDictionary dictionaryWithCapacity:1]; 130 [NSMutableDictionary dictionaryWithCapacity:1];
127 NSMutableDictionary* test_dictionary_2 = 131 NSMutableDictionary* test_dictionary_2 =
128 [NSMutableDictionary dictionaryWithCapacity:1]; 132 [NSMutableDictionary dictionaryWithCapacity:1];
129 const char* key = "key"; 133 const char* key = "key";
130 NSString* obj_c_key = 134 NSString* obj_c_key =
131 [NSString stringWithCString:key encoding:NSASCIIStringEncoding]; 135 [NSString stringWithCString:key encoding:NSASCIIStringEncoding];
132 test_dictionary[obj_c_key] = test_dictionary_2; 136 test_dictionary[obj_c_key] = test_dictionary_2;
133 test_dictionary_2[obj_c_key] = test_dictionary; 137 test_dictionary_2[obj_c_key] = test_dictionary;
134 138
135 // Break the retain cycle so that the dictionaries are freed. 139 // Break the retain cycle so that the dictionaries are freed.
136 base::ScopedClosureRunner runner(base::BindBlock(^{ 140 base::ScopedClosureRunner runner(base::BindBlockArc(^{
137 [test_dictionary_2 removeAllObjects]; 141 [test_dictionary_2 removeAllObjects];
138 })); 142 }));
139 143
140 // Check that parsing the dictionary stopped at a depth of 144 // Check that parsing the dictionary stopped at a depth of
141 // |kMaximumParsingRecursionDepth|. 145 // |kMaximumParsingRecursionDepth|.
142 std::unique_ptr<base::Value> value = 146 std::unique_ptr<base::Value> value =
143 web::ValueResultFromWKResult(test_dictionary); 147 web::ValueResultFromWKResult(test_dictionary);
144 base::DictionaryValue* current_dictionary = nullptr; 148 base::DictionaryValue* current_dictionary = nullptr;
145 base::DictionaryValue* inner_dictionary = nullptr; 149 base::DictionaryValue* inner_dictionary = nullptr;
146 150
(...skipping 12 matching lines...) Expand all
159 163
160 // Tests that an NSArray with a cycle does not cause infinite recursion. 164 // Tests that an NSArray with a cycle does not cause infinite recursion.
161 TEST(WebViewJsUtilsTest, ValueResultFromArrayWithDepthCheckWKResult) { 165 TEST(WebViewJsUtilsTest, ValueResultFromArrayWithDepthCheckWKResult) {
162 // Create an array with a cycle. 166 // Create an array with a cycle.
163 NSMutableArray* test_array = [NSMutableArray arrayWithCapacity:1]; 167 NSMutableArray* test_array = [NSMutableArray arrayWithCapacity:1];
164 NSMutableArray* test_array_2 = [NSMutableArray arrayWithCapacity:1]; 168 NSMutableArray* test_array_2 = [NSMutableArray arrayWithCapacity:1];
165 test_array[0] = test_array_2; 169 test_array[0] = test_array_2;
166 test_array_2[0] = test_array; 170 test_array_2[0] = test_array;
167 171
168 // Break the retain cycle so that the arrays are freed. 172 // Break the retain cycle so that the arrays are freed.
169 base::ScopedClosureRunner runner(base::BindBlock(^{ 173 base::ScopedClosureRunner runner(base::BindBlockArc(^{
170 [test_array removeAllObjects]; 174 [test_array removeAllObjects];
171 })); 175 }));
172 176
173 // Check that parsing the array stopped at a depth of 177 // Check that parsing the array stopped at a depth of
174 // |kMaximumParsingRecursionDepth|. 178 // |kMaximumParsingRecursionDepth|.
175 std::unique_ptr<base::Value> value = web::ValueResultFromWKResult(test_array); 179 std::unique_ptr<base::Value> value = web::ValueResultFromWKResult(test_array);
176 base::ListValue* current_list = nullptr; 180 base::ListValue* current_list = nullptr;
177 base::ListValue* inner_list = nullptr; 181 base::ListValue* inner_list = nullptr;
178 182
179 value->GetAsList(&current_list); 183 value->GetAsList(&current_list);
180 EXPECT_NE(nullptr, current_list); 184 EXPECT_NE(nullptr, current_list);
181 185
182 for (int current_depth = 0; current_depth <= kMaximumParsingRecursionDepth; 186 for (int current_depth = 0; current_depth <= kMaximumParsingRecursionDepth;
183 current_depth++) { 187 current_depth++) {
184 EXPECT_NE(nullptr, current_list); 188 EXPECT_NE(nullptr, current_list);
185 inner_list = nullptr; 189 inner_list = nullptr;
186 current_list->GetList(0, &inner_list); 190 current_list->GetList(0, &inner_list);
187 current_list = inner_list; 191 current_list = inner_list;
188 } 192 }
189 EXPECT_EQ(nullptr, current_list); 193 EXPECT_EQ(nullptr, current_list);
190 } 194 }
191 195
192 } // namespace web 196 } // namespace web
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698