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

Side by Side Diff: ios/chrome/browser/ui/downloads/download_manager_controller_unittest.mm

Issue 2740473002: DownloadManagerController now uses WebState (Closed)
Patch Set: Created 3 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/chrome/browser/ui/downloads/download_manager_controller.h" 5 #import "ios/chrome/browser/ui/downloads/download_manager_controller.h"
6 6
7 #import <UIKit/UIKit.h> 7 #import <UIKit/UIKit.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
11 #import "base/mac/scoped_nsobject.h" 11 #import "base/mac/scoped_nsobject.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #import "ios/chrome/browser/store_kit/store_kit_launcher.h" 13 #import "ios/chrome/browser/store_kit/store_kit_launcher.h"
14 #import "ios/chrome/browser/store_kit/store_kit_tab_helper.h"
15 #import "ios/chrome/browser/web/chrome_web_test.h"
14 #include "ios/web/public/test/test_web_thread.h" 16 #include "ios/web/public/test/test_web_thread.h"
15 #include "net/base/net_errors.h" 17 #include "net/base/net_errors.h"
16 #include "net/http/http_response_headers.h" 18 #include "net/http/http_response_headers.h"
17 #include "net/url_request/test_url_fetcher_factory.h" 19 #include "net/url_request/test_url_fetcher_factory.h"
18 #include "net/url_request/url_fetcher_delegate.h" 20 #include "net/url_request/url_fetcher_delegate.h"
19 #include "net/url_request/url_request_test_util.h" 21 #include "net/url_request/url_request_test_util.h"
20 #include "testing/gtest_mac.h" 22 #include "testing/gtest_mac.h"
21 #include "testing/platform_test.h" 23 #include "testing/platform_test.h"
24 #import "third_party/ocmock/OCMock/OCMock.h"
22 25
23 using net::HttpResponseHeaders; 26 using net::HttpResponseHeaders;
24 using net::URLRequestStatus; 27 using net::URLRequestStatus;
25 28
26 @interface DownloadManagerController (ExposedForTesting) 29 @interface DownloadManagerController (ExposedForTesting)
27 - (UIView*)documentContainer; 30 - (UIView*)documentContainer;
28 - (UIView*)progressBar; 31 - (UIView*)progressBar;
29 - (UIImageView*)documentIcon; 32 - (UIImageView*)documentIcon;
30 - (UIImageView*)foldIcon; 33 - (UIImageView*)foldIcon;
31 - (UILabel*)timeLeftLabel; 34 - (UILabel*)timeLeftLabel;
32 - (UILabel*)fileTypeLabel; 35 - (UILabel*)fileTypeLabel;
33 - (UILabel*)fileNameLabel; 36 - (UILabel*)fileNameLabel;
34 - (UILabel*)errorOrSizeLabel; 37 - (UILabel*)errorOrSizeLabel;
35 - (UIImageView*)errorIcon; 38 - (UIImageView*)errorIcon;
36 - (UIView*)actionBar; 39 - (UIView*)actionBar;
37 - (UIButton*)downloadButton; 40 - (UIButton*)downloadButton;
38 - (UIButton*)cancelButton; 41 - (UIButton*)cancelButton;
39 - (UIButton*)openInButton; 42 - (UIButton*)openInButton;
40 - (UIButton*)googleDriveButton; 43 - (UIButton*)googleDriveButton;
41 - (long long)totalFileSize; 44 - (long long)totalFileSize;
42 @end 45 @end
43 46
44 @interface TestStoreKitLauncher : NSObject<StoreKitLauncher>
45 @end
46
47 @implementation TestStoreKitLauncher
48 - (void)openAppStore:(NSString*)appId {
49 }
50 @end
51
52 namespace { 47 namespace {
53 48
54 const GURL kTestURL = GURL("http://www.example.com/test_download_file.txt"); 49 const GURL kTestURL = GURL("http://www.example.com/test_download_file.txt");
55 50
56 class DownloadManagerControllerTest : public PlatformTest { 51 class DownloadManagerControllerTest : public ChromeWebTest {
rohitrao (ping after 24h) 2017/03/07 13:51:22 These changes end up making the test more heavywei
pkl (ping after 24h if needed) 2017/03/07 22:07:19 Acknowledged.
57 public:
58 DownloadManagerControllerTest()
59 : _message_loop(base::MessageLoop::TYPE_UI),
60 _ui_thread(web::WebThread::UI, &_message_loop) {}
61
62 protected: 52 protected:
63 void SetUp() override { 53 void SetUp() override {
64 PlatformTest::SetUp(); 54 ChromeWebTest::SetUp();
65
66 _request_context_getter =
67 new net::TestURLRequestContextGetter(_message_loop.task_runner());
68
69 _fetcher_factory.reset(new net::TestURLFetcherFactory()); 55 _fetcher_factory.reset(new net::TestURLFetcherFactory());
70 56 StoreKitTabHelper::CreateForWebState(web_state());
71 _store_kit_launcher.reset([[TestStoreKitLauncher alloc] init]); 57 StoreKitTabHelper* helper = StoreKitTabHelper::FromWebState(web_state());
72 58 id mock_launcher =
59 [OCMockObject niceMockForProtocol:@protocol(StoreKitLauncher)];
60 helper->SetLauncher(mock_launcher);
73 _controller.reset([[DownloadManagerController alloc] 61 _controller.reset([[DownloadManagerController alloc]
74 initWithURL:kTestURL 62 initWithWebState:web_state()
75 requestContextGetter:_request_context_getter.get() 63 downloadURL:kTestURL]);
76 storeKitLauncher:_store_kit_launcher.get()]);
77 } 64 }
78 65
79 base::MessageLoop _message_loop;
80 web::TestWebThread _ui_thread;
81 base::scoped_nsobject<TestStoreKitLauncher> _store_kit_launcher;
82 scoped_refptr<net::TestURLRequestContextGetter> _request_context_getter;
83 std::unique_ptr<net::TestURLFetcherFactory> _fetcher_factory; 66 std::unique_ptr<net::TestURLFetcherFactory> _fetcher_factory;
84 base::scoped_nsobject<DownloadManagerController> _controller; 67 base::scoped_nsobject<DownloadManagerController> _controller;
85 }; 68 };
86 69
87 TEST_F(DownloadManagerControllerTest, TestXibViewConnections) { 70 TEST_F(DownloadManagerControllerTest, TestXibViewConnections) {
88 EXPECT_TRUE([_controller documentContainer]); 71 EXPECT_TRUE([_controller documentContainer]);
89 EXPECT_TRUE([_controller progressBar]); 72 EXPECT_TRUE([_controller progressBar]);
90 EXPECT_TRUE([_controller documentIcon]); 73 EXPECT_TRUE([_controller documentIcon]);
91 EXPECT_TRUE([_controller foldIcon]); 74 EXPECT_TRUE([_controller foldIcon]);
92 EXPECT_TRUE([_controller timeLeftLabel]); 75 EXPECT_TRUE([_controller timeLeftLabel]);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 EXPECT_FALSE( 129 EXPECT_FALSE(
147 [[UIApplication sharedApplication] isNetworkActivityIndicatorVisible]); 130 [[UIApplication sharedApplication] isNetworkActivityIndicatorVisible]);
148 131
149 EXPECT_TRUE([_controller fileTypeLabel].hidden); 132 EXPECT_TRUE([_controller fileTypeLabel].hidden);
150 EXPECT_FALSE([_controller downloadButton].hidden); 133 EXPECT_FALSE([_controller downloadButton].hidden);
151 EXPECT_FALSE([_controller errorIcon].hidden); 134 EXPECT_FALSE([_controller errorIcon].hidden);
152 EXPECT_FALSE([_controller errorOrSizeLabel].hidden); 135 EXPECT_FALSE([_controller errorOrSizeLabel].hidden);
153 } 136 }
154 137
155 } // namespace 138 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698