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

Side by Side Diff: ios/chrome/browser/find_in_page/find_in_page_js_unittest.mm

Issue 2941053002: [ObjC ARC] Converts ios/chrome/browser/find_in_page:unit_tests_nonarc to ARC. (Closed)
Patch Set: Consolidated build.gn 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 <UIKit/UIKit.h> 5 #import <UIKit/UIKit.h>
6 6
7 #include "base/mac/foundation_util.h" 7 #include "base/mac/foundation_util.h"
8 #include "base/mac/scoped_nsobject.h"
9 #include "base/strings/sys_string_conversions.h" 8 #include "base/strings/sys_string_conversions.h"
10 #import "ios/chrome/browser/find_in_page/find_in_page_model.h" 9 #import "ios/chrome/browser/find_in_page/find_in_page_model.h"
11 #import "ios/chrome/browser/find_in_page/js_findinpage_manager.h" 10 #import "ios/chrome/browser/find_in_page/js_findinpage_manager.h"
12 #import "ios/chrome/browser/web/chrome_web_test.h" 11 #import "ios/chrome/browser/web/chrome_web_test.h"
13 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h" 12 #import "ios/web/public/web_state/js/crw_js_injection_receiver.h"
14 #import "ios/web/public/web_state/ui/crw_web_view_proxy.h" 13 #import "ios/web/public/web_state/ui/crw_web_view_proxy.h"
15 #import "ios/web/public/web_state/web_state.h" 14 #import "ios/web/public/web_state/web_state.h"
16 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
17 #include "testing/gtest_mac.h" 16 #include "testing/gtest_mac.h"
18 17
18 #if !defined(__has_feature) || !__has_feature(objc_arc)
19 #error "This file requires ARC support."
20 #endif
21
19 // Unit tests for the find_in_page.js JavaScript file. 22 // Unit tests for the find_in_page.js JavaScript file.
20 23
21 namespace { 24 namespace {
22 25
23 // JavaScript invocation to search for 'foo' (for 1000 milliseconds). 26 // JavaScript invocation to search for 'foo' (for 1000 milliseconds).
24 NSString* kJavaScriptToSearchForFoo = 27 NSString* kJavaScriptToSearchForFoo =
25 @"__gCrWeb.findInPage.highlightWord('foo', false, 1000)"; 28 @"__gCrWeb.findInPage.highlightWord('foo', false, 1000)";
26 29
27 // Other JavaScript functions invoked by the tests. 30 // Other JavaScript functions invoked by the tests.
28 NSString* kJavaScriptIncrementIndex = @"__gCrWeb.findInPage.incrementIndex()"; 31 NSString* kJavaScriptIncrementIndex = @"__gCrWeb.findInPage.incrementIndex()";
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 97
95 // Search for 'foo'. Performing the search sets the index to point to the 98 // Search for 'foo'. Performing the search sets the index to point to the
96 // first visible occurence of 'foo'. 99 // first visible occurence of 'foo'.
97 ExecuteJavaScript(kJavaScriptToSearchForFoo); 100 ExecuteJavaScript(kJavaScriptToSearchForFoo);
98 AssertJavaScriptValue(kJavaScriptIndex, 1); 101 AssertJavaScriptValue(kJavaScriptIndex, 1);
99 AssertJavaScriptValue(kJavaScriptSpansLength, kNumberOfFoosInHtml); 102 AssertJavaScriptValue(kJavaScriptSpansLength, kNumberOfFoosInHtml);
100 } 103 }
101 104
102 void SetUp() override { 105 void SetUp() override {
103 ChromeWebTest::SetUp(); 106 ChromeWebTest::SetUp();
104 findInPageModel_.reset([[FindInPageModel alloc] init]); 107 findInPageModel_ = [[FindInPageModel alloc] init];
105 findInPageJsManager_.reset([base::mac::ObjCCastStrict<JsFindinpageManager>( 108 findInPageJsManager_ = base::mac::ObjCCastStrict<JsFindinpageManager>(
106 [web_state()->GetJSInjectionReceiver() 109 [web_state()->GetJSInjectionReceiver()
107 instanceOfClass:[JsFindinpageManager class]]) retain]); 110 instanceOfClass:[JsFindinpageManager class]]);
108 findInPageJsManager_.get().findInPageModel = findInPageModel_; 111 findInPageJsManager_.findInPageModel = findInPageModel_;
109 } 112 }
110 113
111 base::scoped_nsobject<FindInPageModel> findInPageModel_; 114 FindInPageModel* findInPageModel_;
112 base::scoped_nsobject<JsFindinpageManager> findInPageJsManager_; 115 JsFindinpageManager* findInPageJsManager_;
113 }; 116 };
114 117
115 // Performs a search, then calls |incrementIndex| to loop through the 118 // Performs a search, then calls |incrementIndex| to loop through the
116 // matches, ensuring that when the end is reached the index wraps back to zero. 119 // matches, ensuring that when the end is reached the index wraps back to zero.
117 TEST_F(FindInPageJsTest, IncrementIndex) { 120 TEST_F(FindInPageJsTest, IncrementIndex) {
118 SearchForFoo(); 121 SearchForFoo();
119 122
120 // Increment index until it hits the max index. 123 // Increment index until it hits the max index.
121 for (int i = 2; i < kNumberOfFoosInHtml; i++) { 124 for (int i = 2; i < kNumberOfFoosInHtml; i++) {
122 ExecuteJavaScript(kJavaScriptIncrementIndex); 125 ExecuteJavaScript(kJavaScriptIncrementIndex);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 // point to the first visible occurence of the non-Ascii. 220 // point to the first visible occurence of the non-Ascii.
218 NSString* result = ExecuteJavaScript([NSString 221 NSString* result = ExecuteJavaScript([NSString
219 stringWithFormat:@"__gCrWeb.findInPage.highlightWord('%@', false, 1000)", 222 stringWithFormat:@"__gCrWeb.findInPage.highlightWord('%@', false, 1000)",
220 kNonAscii]); 223 kNonAscii]);
221 DCHECK(result); 224 DCHECK(result);
222 AssertJavaScriptValue(kJavaScriptIndex, 0); 225 AssertJavaScriptValue(kJavaScriptIndex, 0);
223 AssertJavaScriptValue(kJavaScriptSpansLength, 1); 226 AssertJavaScriptValue(kJavaScriptSpansLength, 1);
224 } 227 }
225 228
226 } // namespace 229 } // namespace
OLDNEW
« no previous file with comments | « ios/chrome/browser/find_in_page/BUILD.gn ('k') | ios/chrome/browser/find_in_page/js_findinpage_manager_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698