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