OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ios/chrome/browser/ui/static_content/static_html_native_content.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "base/mac/scoped_nsobject.h" |
| 10 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" |
| 11 #include "ios/chrome/browser/ui/static_content/static_html_view_controller.h" |
| 12 #import "ios/chrome/browser/ui/url_loader.h" |
| 13 #include "ios/web/public/test/test_web_thread_bundle.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "testing/gtest_mac.h" |
| 16 #include "testing/platform_test.h" |
| 17 #import "third_party/ocmock/OCMock/OCMock.h" |
| 18 #include "third_party/ocmock/gtest_support.h" |
| 19 |
| 20 @interface StaticHtmlNativeContentTestGenerator : NSObject<HtmlGenerator> |
| 21 @end |
| 22 |
| 23 @implementation StaticHtmlNativeContentTestGenerator |
| 24 - (void)generateHtml:(HtmlCallback)callback { |
| 25 callback(@"<html><body><p>Hello, World!</p></body></html>"); |
| 26 } |
| 27 @end |
| 28 |
| 29 namespace { |
| 30 |
| 31 class StaticHtmlNativeContentTest : public PlatformTest { |
| 32 protected: |
| 33 void SetUp() override { |
| 34 PlatformTest::SetUp(); |
| 35 TestChromeBrowserState::Builder test_cbs_builder; |
| 36 chrome_browser_state_ = test_cbs_builder.Build(); |
| 37 } |
| 38 web::TestWebThreadBundle thread_bundle_; |
| 39 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; |
| 40 }; |
| 41 |
| 42 TEST_F(StaticHtmlNativeContentTest, BasicResourceTest) { |
| 43 GURL url("chrome://foo"); |
| 44 id<UrlLoader> loader = [OCMockObject mockForProtocol:@protocol(UrlLoader)]; |
| 45 base::scoped_nsobject<StaticHtmlNativeContent> content( |
| 46 [[StaticHtmlNativeContent alloc] |
| 47 initWithResourcePathResource:@"about_credits.html" |
| 48 loader:loader |
| 49 browserState:chrome_browser_state_.get() |
| 50 url:url]); |
| 51 |
| 52 ASSERT_EQ(url, [content url]); |
| 53 ASSERT_OCMOCK_VERIFY((OCMockObject*)loader); |
| 54 } |
| 55 |
| 56 TEST_F(StaticHtmlNativeContentTest, BasicInitTest) { |
| 57 GURL url("chrome://foo"); |
| 58 id<UrlLoader> loader = [OCMockObject mockForProtocol:@protocol(UrlLoader)]; |
| 59 base::scoped_nsobject<StaticHtmlNativeContentTestGenerator> generator( |
| 60 [[StaticHtmlNativeContentTestGenerator alloc] init]); |
| 61 |
| 62 base::scoped_nsobject<StaticHtmlViewController> viewController( |
| 63 [[StaticHtmlViewController alloc] |
| 64 initWithGenerator:generator |
| 65 browserState:chrome_browser_state_.get()]); |
| 66 base::scoped_nsobject<StaticHtmlNativeContent> content( |
| 67 [[StaticHtmlNativeContent alloc] initWithLoader:loader |
| 68 staticHTMLViewController:viewController |
| 69 URL:url]); |
| 70 ASSERT_EQ(url, [content url]); |
| 71 ASSERT_OCMOCK_VERIFY((OCMockObject*)loader); |
| 72 } |
| 73 |
| 74 } // namespace |
OLD | NEW |