OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/webui/crw_web_ui_page_builder.h" | 5 #import "ios/web/webui/crw_web_ui_page_builder.h" |
6 | 6 |
7 #import <Foundation/Foundation.h> | 7 #import <Foundation/Foundation.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #import "base/mac/scoped_nsobject.h" | |
11 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
13 #import "testing/gtest_mac.h" | 12 #import "testing/gtest_mac.h" |
14 #include "testing/platform_test.h" | 13 #include "testing/platform_test.h" |
15 #include "url/gurl.h" | 14 #include "url/gurl.h" |
16 | 15 |
| 16 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 17 #error "This file requires ARC support." |
| 18 #endif |
| 19 |
17 namespace { | 20 namespace { |
18 | 21 |
19 // HTML page template. | 22 // HTML page template. |
20 NSString* const kPageTemplate = @"<html><head>%@</head></html>"; | 23 NSString* const kPageTemplate = @"<html><head>%@</head></html>"; |
21 | 24 |
22 // URL for BuildSimplePage. | 25 // URL for BuildSimplePage. |
23 const char* kSimplePageUrl("http://simplepage"); | 26 const char* kSimplePageUrl("http://simplepage"); |
24 // URL for BuildPageWithJSSubresource. | 27 // URL for BuildPageWithJSSubresource. |
25 const char* kJsPageUrl("http://javascriptpage"); | 28 const char* kJsPageUrl("http://javascriptpage"); |
26 // URL for BuildPageWithCSSSubresource. | 29 // URL for BuildPageWithCSSSubresource. |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 } | 165 } |
163 | 166 |
164 @end | 167 @end |
165 | 168 |
166 namespace web { | 169 namespace web { |
167 | 170 |
168 class CRWWebUIPageBuilderTest : public PlatformTest { | 171 class CRWWebUIPageBuilderTest : public PlatformTest { |
169 protected: | 172 protected: |
170 void SetUp() override { | 173 void SetUp() override { |
171 PlatformTest::SetUp(); | 174 PlatformTest::SetUp(); |
172 delegate_.reset([[MockPageBuilderDelegate alloc] init]); | 175 delegate_ = [[MockPageBuilderDelegate alloc] init]; |
173 web_ui_page_builder_.reset( | 176 web_ui_page_builder_ = |
174 [[MockCRWWebUIPageBuilder alloc] initWithDelegate:delegate_]); | 177 [[MockCRWWebUIPageBuilder alloc] initWithDelegate:delegate_]; |
175 } | 178 } |
176 // CRWWebUIPageBuilder for testing. | 179 // CRWWebUIPageBuilder for testing. |
177 base::scoped_nsobject<MockCRWWebUIPageBuilder> web_ui_page_builder_; | 180 MockCRWWebUIPageBuilder* web_ui_page_builder_; |
178 // Delegate for test CRWWebUIPageBuilder. | 181 // Delegate for test CRWWebUIPageBuilder. |
179 base::scoped_nsobject<MockPageBuilderDelegate> delegate_; | 182 MockPageBuilderDelegate* delegate_; |
180 }; | 183 }; |
181 | 184 |
182 // Tests that a page without imports is passed to completion handler unchanged. | 185 // Tests that a page without imports is passed to completion handler unchanged. |
183 TEST_F(CRWWebUIPageBuilderTest, BuildSimplePage) { | 186 TEST_F(CRWWebUIPageBuilderTest, BuildSimplePage) { |
184 NSString* simple_page_html = [NSString stringWithFormat:kPageTemplate, @""]; | 187 NSString* simple_page_html = [NSString stringWithFormat:kPageTemplate, @""]; |
185 [web_ui_page_builder_ buildWebUIPageForURL:GURL(kSimplePageUrl) | 188 [web_ui_page_builder_ buildWebUIPageForURL:GURL(kSimplePageUrl) |
186 completionHandler:^(NSString* result) { | 189 completionHandler:^(NSString* result) { |
187 EXPECT_NSEQ(simple_page_html, result); | 190 EXPECT_NSEQ(simple_page_html, result); |
188 }]; | 191 }]; |
189 } | 192 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 TEST_F(CRWWebUIPageBuilderTest, BuildPageWithWebUIJS) { | 270 TEST_F(CRWWebUIPageBuilderTest, BuildPageWithWebUIJS) { |
268 NSString* core_js_html = | 271 NSString* core_js_html = |
269 PageForTagTemplateAndContent(kJsInlinedTemplate, kCoreJsContent); | 272 PageForTagTemplateAndContent(kJsInlinedTemplate, kCoreJsContent); |
270 [web_ui_page_builder_ buildWebUIPageForURL:GURL(kCoreJsPageUrl) | 273 [web_ui_page_builder_ buildWebUIPageForURL:GURL(kCoreJsPageUrl) |
271 completionHandler:^(NSString* result) { | 274 completionHandler:^(NSString* result) { |
272 EXPECT_NSEQ(core_js_html, result); | 275 EXPECT_NSEQ(core_js_html, result); |
273 }]; | 276 }]; |
274 } | 277 } |
275 | 278 |
276 } // namespace web | 279 } // namespace web |
OLD | NEW |