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

Unified Diff: ios/chrome/browser/translate/js_language_detection_manager_unittest.mm

Issue 2889043002: [ObjC ARC] Converts ios/chrome/browser/translate:unit_tests to ARC. (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « ios/chrome/browser/translate/BUILD.gn ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/translate/js_language_detection_manager_unittest.mm
diff --git a/ios/chrome/browser/translate/js_language_detection_manager_unittest.mm b/ios/chrome/browser/translate/js_language_detection_manager_unittest.mm
index 6ec7d4270f00cde44f9f84c9dd7dbae53a3004d2..b513d9943a72cb9f0ea47f4a1028e2aa431307b7 100644
--- a/ios/chrome/browser/translate/js_language_detection_manager_unittest.mm
+++ b/ios/chrome/browser/translate/js_language_detection_manager_unittest.mm
@@ -10,7 +10,6 @@
#include <vector>
#include "base/bind.h"
-#include "base/mac/scoped_nsobject.h"
#import "base/test/ios/wait_util.h"
#include "base/values.h"
#import "ios/chrome/browser/web/chrome_web_test.h"
@@ -21,18 +20,21 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/gtest_mac.h"
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
namespace {
const char kExpectedLanguage[] = "Foo";
// Returns an NSString filled with the char 'a' of length |length|.
NSString* GetLongString(NSUInteger length) {
- base::scoped_nsobject<NSMutableData> data(
- [[NSMutableData alloc] initWithLength:length]);
+ NSMutableData* data = [[NSMutableData alloc] initWithLength:length];
memset([data mutableBytes], 'a', length);
NSString* long_string =
[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
- return [long_string autorelease];
+ return long_string;
}
} // namespace
@@ -43,9 +45,9 @@
protected:
void SetUp() override {
ChromeWebTest::SetUp();
- manager_.reset(static_cast<JsLanguageDetectionManager*>(
- [[web_state()->GetJSInjectionReceiver()
- instanceOfClass:[JsLanguageDetectionManager class]] retain]));
+ manager_ = static_cast<JsLanguageDetectionManager*>(
+ [web_state()->GetJSInjectionReceiver()
+ instanceOfClass:[JsLanguageDetectionManager class]]);
ASSERT_TRUE(manager_);
}
@@ -93,14 +95,14 @@ void ExpectHttpContentLanguage(NSString* expected_http_content_language) {
// Verifies if |__gCrWeb.languageDetection.getTextContent| correctly extracts
// the text content from an HTML page.
void ExpectTextContent(NSString* expected_text_content) {
- base::scoped_nsobject<NSString> script([[NSString alloc]
+ NSString* script = [[NSString alloc]
initWithFormat:
@"__gCrWeb.languageDetection.getTextContent(document.body, %lu);",
- language_detection::kMaxIndexChars]);
+ language_detection::kMaxIndexChars];
InjectJsAndVerify(script, expected_text_content);
}
- base::scoped_nsobject<JsLanguageDetectionManager> manager_;
+ JsLanguageDetectionManager* manager_;
};
// Tests that |hasBeenInjected| returns YES after |inject| call.
@@ -126,10 +128,10 @@ void ExpectTextContent(NSString* expected_text_content) {
// Tests correctness of |document.documentElement.lang| attribute.
TEST_F(JsLanguageDetectionManagerTest, HtmlLang) {
- base::scoped_nsobject<NSString> html;
+ NSString* html;
// Non-empty attribute.
- html.reset([[NSString alloc]
- initWithFormat:@"<html lang='%s'></html>", kExpectedLanguage]);
+ html = [[NSString alloc]
+ initWithFormat:@"<html lang='%s'></html>", kExpectedLanguage];
LoadHtmlAndInject(html);
ExpectHtmlLang(@(kExpectedLanguage));
@@ -138,8 +140,8 @@ void ExpectTextContent(NSString* expected_text_content) {
ExpectHtmlLang(@"");
// Test with mixed case.
- html.reset([[NSString alloc]
- initWithFormat:@"<html lAnG='%s'></html>", kExpectedLanguage]);
+ html = [[NSString alloc]
+ initWithFormat:@"<html lAnG='%s'></html>", kExpectedLanguage];
LoadHtmlAndInject(html);
ExpectHtmlLang(@(kExpectedLanguage));
}
@@ -149,23 +151,23 @@ void ExpectTextContent(NSString* expected_text_content) {
// No content language.
LoadHtmlAndInject(@"<html></html>");
ExpectHttpContentLanguage(@"");
- base::scoped_nsobject<NSString> html;
+ NSString* html;
// Some content language.
- html.reset(([[NSString alloc]
+ html = ([[NSString alloc]
initWithFormat:@"<html><head>"
"<meta http-equiv='content-language' content='%s'>"
"</head></html>",
- kExpectedLanguage]));
+ kExpectedLanguage]);
LoadHtmlAndInject(html);
ExpectHttpContentLanguage(@(kExpectedLanguage));
// Test with mixed case.
- html.reset(([[NSString alloc]
+ html = ([[NSString alloc]
initWithFormat:@"<html><head>"
"<meta http-equiv='cOnTenT-lAngUAge' content='%s'>"
"</head></html>",
- kExpectedLanguage]));
+ kExpectedLanguage]);
LoadHtmlAndInject(html);
ExpectHttpContentLanguage(@(kExpectedLanguage));
}
@@ -219,19 +221,18 @@ void ExpectTextContent(NSString* expected_text_content) {
TEST_F(JsLanguageDetectionManagerTest, LongTextContent) {
// Very long string.
NSUInteger kLongStringLength = language_detection::kMaxIndexChars - 5;
- base::scoped_nsobject<NSMutableString> long_string(
- [GetLongString(kLongStringLength) mutableCopy]);
+ NSMutableString* long_string = [GetLongString(kLongStringLength) mutableCopy];
[long_string appendString:@" b cdefghijklmnopqrstuvwxyz"];
// The string should be cut at the last whitespace, after the 'b' character.
- base::scoped_nsobject<NSString> html([[NSString alloc]
- initWithFormat:@"<html><body>%@</html></body>", long_string.get()]);
+ NSString* html = [[NSString alloc]
+ initWithFormat:@"<html><body>%@</html></body>", long_string];
LoadHtmlAndInject(html);
- base::scoped_nsobject<NSString> script([[NSString alloc]
+ NSString* script = [[NSString alloc]
initWithFormat:
@"__gCrWeb.languageDetection.getTextContent(document.body, %lu);",
- language_detection::kMaxIndexChars]);
+ language_detection::kMaxIndexChars];
NSString* result = web::ExecuteJavaScript(manager_, script);
EXPECT_EQ(language_detection::kMaxIndexChars, [result length]);
}
« no previous file with comments | « ios/chrome/browser/translate/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698