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

Side by Side Diff: ios/chrome/browser/ui/preload_controller_unittest.mm

Issue 2936833002: [ObjC ARC] Converts ios/chrome/browser/ui:unit_tests to ARC. (Closed)
Patch Set: Fix bad ARC guard. Created 3 years, 6 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 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 #include <memory> 5 #include <memory>
6 6
7 #include "base/ios/device_util.h" 7 #include "base/ios/device_util.h"
8 #include "base/mac/scoped_nsobject.h"
9 #include "base/run_loop.h" 8 #include "base/run_loop.h"
10 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
11 #include "components/prefs/pref_service.h" 10 #include "components/prefs/pref_service.h"
12 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" 11 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
13 #include "ios/chrome/browser/pref_names.h" 12 #include "ios/chrome/browser/pref_names.h"
14 #import "ios/chrome/browser/ui/preload_controller.h" 13 #import "ios/chrome/browser/ui/preload_controller.h"
15 #include "ios/web/public/test/test_web_thread_bundle.h" 14 #include "ios/web/public/test/test_web_thread_bundle.h"
16 #include "net/url_request/test_url_fetcher_factory.h" 15 #include "net/url_request/test_url_fetcher_factory.h"
17 #include "testing/gmock/include/gmock/gmock.h" 16 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/platform_test.h" 17 #include "testing/platform_test.h"
19 18
19 #if !defined(__has_feature) || !__has_feature(objc_arc)
20 #error "This file requires ARC support."
21 #endif
22
20 @interface PreloadController (ExposedForTesting) 23 @interface PreloadController (ExposedForTesting)
21 - (BOOL)shouldPreloadURL:(const GURL&)url; 24 - (BOOL)shouldPreloadURL:(const GURL&)url;
22 - (BOOL)isPrerenderingEnabled; 25 - (BOOL)isPrerenderingEnabled;
23 - (BOOL)isPrefetchingEnabled; 26 - (BOOL)isPrefetchingEnabled;
24 - (const GURL)urlToPrefetchURL:(const GURL&)url; 27 - (const GURL)urlToPrefetchURL:(const GURL&)url;
25 - (BOOL)hasPrefetchedURL:(const GURL&)url; 28 - (BOOL)hasPrefetchedURL:(const GURL&)url;
26 @end 29 @end
27 30
28 namespace { 31 namespace {
29 32
(...skipping 30 matching lines...) Expand all
60 protected: 63 protected:
61 void SetUp() override { 64 void SetUp() override {
62 TestChromeBrowserState::Builder test_cbs_builder; 65 TestChromeBrowserState::Builder test_cbs_builder;
63 chrome_browser_state_ = test_cbs_builder.Build(); 66 chrome_browser_state_ = test_cbs_builder.Build();
64 // Set up a NetworkChangeNotifier so that the test can simulate Wi-Fi vs. 67 // Set up a NetworkChangeNotifier so that the test can simulate Wi-Fi vs.
65 // cellular connection. 68 // cellular connection.
66 network_change_notifier_.reset(new TestNetworkChangeNotifier); 69 network_change_notifier_.reset(new TestNetworkChangeNotifier);
67 70
68 test_url_fetcher_factory_.reset(new net::TestURLFetcherFactory()); 71 test_url_fetcher_factory_.reset(new net::TestURLFetcherFactory());
69 72
70 controller_.reset([[PreloadController alloc] 73 controller_ = [[PreloadController alloc]
71 initWithBrowserState:chrome_browser_state_.get()]); 74 initWithBrowserState:chrome_browser_state_.get()];
72 }; 75 };
73 76
74 // Set the "Preload webpages" setting to "Always". 77 // Set the "Preload webpages" setting to "Always".
75 void PreloadWebpagesAlways() { 78 void PreloadWebpagesAlways() {
76 chrome_browser_state_->GetPrefs()->SetBoolean( 79 chrome_browser_state_->GetPrefs()->SetBoolean(
77 prefs::kNetworkPredictionEnabled, YES); 80 prefs::kNetworkPredictionEnabled, YES);
78 chrome_browser_state_->GetPrefs()->SetBoolean( 81 chrome_browser_state_->GetPrefs()->SetBoolean(
79 prefs::kNetworkPredictionWifiOnly, NO); 82 prefs::kNetworkPredictionWifiOnly, NO);
80 } 83 }
81 84
(...skipping 18 matching lines...) Expand all
100 103
101 void SimulateCellularConnection() { 104 void SimulateCellularConnection() {
102 network_change_notifier_->SimulateNetworkConnectionChange( 105 network_change_notifier_->SimulateNetworkConnectionChange(
103 net::NetworkChangeNotifier::CONNECTION_3G); 106 net::NetworkChangeNotifier::CONNECTION_3G);
104 } 107 }
105 108
106 web::TestWebThreadBundle thread_bundle_; 109 web::TestWebThreadBundle thread_bundle_;
107 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; 110 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_;
108 std::unique_ptr<TestNetworkChangeNotifier> network_change_notifier_; 111 std::unique_ptr<TestNetworkChangeNotifier> network_change_notifier_;
109 std::unique_ptr<net::TestURLFetcherFactory> test_url_fetcher_factory_; 112 std::unique_ptr<net::TestURLFetcherFactory> test_url_fetcher_factory_;
110 base::scoped_nsobject<PreloadController> controller_; 113 PreloadController* controller_;
111 }; 114 };
112 115
113 // Tests that the preload controller does not try to preload non-web urls. 116 // Tests that the preload controller does not try to preload non-web urls.
114 TEST_F(PreloadControllerTest, ShouldPreloadURL) { 117 TEST_F(PreloadControllerTest, ShouldPreloadURL) {
115 EXPECT_TRUE([controller_ shouldPreloadURL:GURL("http://www.google.com/")]); 118 EXPECT_TRUE([controller_ shouldPreloadURL:GURL("http://www.google.com/")]);
116 EXPECT_TRUE([controller_ shouldPreloadURL:GURL("https://www.google.com/")]); 119 EXPECT_TRUE([controller_ shouldPreloadURL:GURL("https://www.google.com/")]);
117 120
118 EXPECT_FALSE([controller_ shouldPreloadURL:GURL()]); 121 EXPECT_FALSE([controller_ shouldPreloadURL:GURL()]);
119 EXPECT_FALSE([controller_ shouldPreloadURL:GURL("chrome://newtab")]); 122 EXPECT_FALSE([controller_ shouldPreloadURL:GURL("chrome://newtab")]);
120 EXPECT_FALSE([controller_ shouldPreloadURL:GURL("about:flags")]); 123 EXPECT_FALSE([controller_ shouldPreloadURL:GURL("about:flags")]);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 256
254 // Prefetch |second| and verify it's the only one that returns true. 257 // Prefetch |second| and verify it's the only one that returns true.
255 [controller_ prefetchURL:second 258 [controller_ prefetchURL:second
256 transition:ui::PAGE_TRANSITION_FROM_ADDRESS_BAR]; 259 transition:ui::PAGE_TRANSITION_FROM_ADDRESS_BAR];
257 EXPECT_FALSE([controller_ hasPrefetchedURL:first]); 260 EXPECT_FALSE([controller_ hasPrefetchedURL:first]);
258 EXPECT_TRUE([controller_ hasPrefetchedURL:second]); 261 EXPECT_TRUE([controller_ hasPrefetchedURL:second]);
259 EXPECT_FALSE([controller_ hasPrefetchedURL:bogus]); 262 EXPECT_FALSE([controller_ hasPrefetchedURL:bogus]);
260 } 263 }
261 264
262 } // anonymous namespace 265 } // anonymous namespace
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/page_not_available_controller_unittest.mm ('k') | ios/chrome/browser/ui/ui_util_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698