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 <Foundation/Foundation.h> |
| 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "base/message_loop/message_loop.h" |
| 10 #include "base/strings/sys_string_conversions.h" |
| 11 #import "ios/chrome/browser/tabs/tab.h" |
| 12 #import "ios/chrome/browser/ui/open_in_controller.h" |
| 13 #import "ios/chrome/browser/ui/open_in_controller_testing.h" |
| 14 #include "ios/web/public/test/test_web_thread.h" |
| 15 #import "ios/web/web_state/ui/crw_web_controller.h" |
| 16 #include "net/url_request/test_url_fetcher_factory.h" |
| 17 #include "net/url_request/url_fetcher_delegate.h" |
| 18 #include "testing/platform_test.h" |
| 19 #import "third_party/ocmock/OCMock/OCMock.h" |
| 20 #include "third_party/ocmock/gtest_support.h" |
| 21 |
| 22 namespace { |
| 23 |
| 24 class OpenInControllerTest : public PlatformTest { |
| 25 public: |
| 26 OpenInControllerTest() { |
| 27 io_thread_.reset( |
| 28 new web::TestWebThread(web::WebThread::IO, &message_loop_)); |
| 29 } |
| 30 |
| 31 void TearDown() override { PlatformTest::TearDown(); } |
| 32 |
| 33 void SetUp() override { |
| 34 PlatformTest::SetUp(); |
| 35 GURL documentURL = GURL("http://www.test.com/doc.pdf"); |
| 36 parent_view_.reset([[UIView alloc] init]); |
| 37 id webController = [OCMockObject niceMockForClass:[CRWWebController class]]; |
| 38 open_in_controller_.reset([[OpenInController alloc] |
| 39 initWithRequestContext:nil |
| 40 webController:webController]); |
| 41 [open_in_controller_ enableWithDocumentURL:documentURL |
| 42 suggestedFilename:@"doc.pdf"]; |
| 43 } |
| 44 // |TestURLFetcher| requires a |MessageLoop|. |
| 45 base::MessageLoopForUI message_loop_; |
| 46 // Add |io_thread_| to release |URLRequestContextGetter| in |
| 47 // |URLFetcher::Core|. |
| 48 std::unique_ptr<web::TestWebThread> io_thread_; |
| 49 // Creates a |TestURLFetcherFactory|, which automatically sets itself as |
| 50 // |URLFetcher|'s factory. |
| 51 net::TestURLFetcherFactory factory_; |
| 52 base::scoped_nsobject<OpenInController> open_in_controller_; |
| 53 base::scoped_nsobject<UIView> parent_view_; |
| 54 }; |
| 55 |
| 56 TEST_F(OpenInControllerTest, DISABLED_TestDisplayOpenInMenu) { |
| 57 id documentController = |
| 58 [OCMockObject niceMockForClass:[UIDocumentInteractionController class]]; |
| 59 [open_in_controller_ setDocumentInteractionController:documentController]; |
| 60 [open_in_controller_ startDownload]; |
| 61 [[[documentController expect] andReturnValue:[NSNumber numberWithBool:YES]] |
| 62 presentOpenInMenuFromRect:CGRectMake(0, 0, 0, 0) |
| 63 inView:OCMOCK_ANY |
| 64 animated:YES]; |
| 65 |
| 66 net::TestURLFetcher* fetcher = factory_.GetFetcherByID(0); |
| 67 DCHECK(fetcher); |
| 68 DCHECK(fetcher->delegate()); |
| 69 fetcher->set_response_code(200); |
| 70 // Set the response for the set URLFetcher to be a blank PDF. |
| 71 NSMutableData* pdfData = [NSMutableData data]; |
| 72 UIGraphicsBeginPDFContextToData(pdfData, CGRectMake(0, 0, 100, 100), @{}); |
| 73 UIGraphicsBeginPDFPage(); |
| 74 UIGraphicsEndPDFContext(); |
| 75 unsigned char* array = (unsigned char*)[pdfData bytes]; |
| 76 fetcher->SetResponseString(std::string((char*)array, sizeof(pdfData))); |
| 77 fetcher->SetResponseFilePath(base::FilePath("path/to/file.pdf")); |
| 78 fetcher->delegate()->OnURLFetchComplete(fetcher); |
| 79 EXPECT_OCMOCK_VERIFY(documentController); |
| 80 } |
| 81 |
| 82 } // namespace |
OLD | NEW |