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

Side by Side Diff: ios/chrome/app/application_delegate/app_state_unittest.mm

Issue 2703183003: Remove the now-unnecessary RequestTracker in a unit test.
Patch Set: Created 3 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/app/application_delegate/app_state.h" 5 #import "ios/chrome/app/application_delegate/app_state.h"
6 6
7 #import <QuartzCore/QuartzCore.h> 7 #import <QuartzCore/QuartzCore.h>
8 8
9 #include "base/ios/block_types.h" 9 #include "base/ios/block_types.h"
10 #include "base/mac/scoped_block.h" 10 #include "base/mac/scoped_block.h"
(...skipping 19 matching lines...) Expand all
30 #import "ios/chrome/browser/tabs/tab_model.h" 30 #import "ios/chrome/browser/tabs/tab_model.h"
31 #import "ios/chrome/browser/ui/browser_view_controller.h" 31 #import "ios/chrome/browser/ui/browser_view_controller.h"
32 #import "ios/chrome/browser/ui/main/browser_view_information.h" 32 #import "ios/chrome/browser/ui/main/browser_view_information.h"
33 #import "ios/chrome/browser/ui/settings/settings_navigation_controller.h" 33 #import "ios/chrome/browser/ui/settings/settings_navigation_controller.h"
34 #import "ios/chrome/test/base/scoped_block_swizzler.h" 34 #import "ios/chrome/test/base/scoped_block_swizzler.h"
35 #include "ios/chrome/test/ios_chrome_scoped_testing_chrome_browser_provider.h" 35 #include "ios/chrome/test/ios_chrome_scoped_testing_chrome_browser_provider.h"
36 #include "ios/public/provider/chrome/browser/distribution/app_distribution_provi der.h" 36 #include "ios/public/provider/chrome/browser/distribution/app_distribution_provi der.h"
37 #include "ios/public/provider/chrome/browser/test_chrome_browser_provider.h" 37 #include "ios/public/provider/chrome/browser/test_chrome_browser_provider.h"
38 #include "ios/public/provider/chrome/browser/user_feedback/test_user_feedback_pr ovider.h" 38 #include "ios/public/provider/chrome/browser/user_feedback/test_user_feedback_pr ovider.h"
39 #import "ios/testing/ocmock_complex_type_helper.h" 39 #import "ios/testing/ocmock_complex_type_helper.h"
40 #include "ios/web/net/request_tracker_impl.h"
41 #include "ios/web/public/test/test_web_thread_bundle.h" 40 #include "ios/web/public/test/test_web_thread_bundle.h"
42 #include "testing/platform_test.h" 41 #include "testing/platform_test.h"
43 #import "third_party/ocmock/OCMock/OCMock.h" 42 #import "third_party/ocmock/OCMock/OCMock.h"
44 #include "third_party/ocmock/gtest_support.h" 43 #include "third_party/ocmock/gtest_support.h"
45 44
46 #if !defined(__has_feature) || !__has_feature(objc_arc) 45 #if !defined(__has_feature) || !__has_feature(objc_arc)
47 #error "This file requires ARC support." 46 #error "This file requires ARC support."
48 #endif 47 #endif
49 48
50 #pragma mark - Class definition. 49 #pragma mark - Class definition.
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 id browser_view_information_; 280 id browser_view_information_;
282 DecisionBlock safe_mode_swizzle_block_; 281 DecisionBlock safe_mode_swizzle_block_;
283 HandleStartupParam handle_startup_swizzle_block_; 282 HandleStartupParam handle_startup_swizzle_block_;
284 ProceduralBlock metrics_mediator_swizzle_block_; 283 ProceduralBlock metrics_mediator_swizzle_block_;
285 std::unique_ptr<ScopedBlockSwizzler> safe_mode_swizzler_; 284 std::unique_ptr<ScopedBlockSwizzler> safe_mode_swizzler_;
286 std::unique_ptr<ScopedBlockSwizzler> handle_startup_swizzler_; 285 std::unique_ptr<ScopedBlockSwizzler> handle_startup_swizzler_;
287 std::unique_ptr<ScopedBlockSwizzler> metrics_mediator_swizzler_; 286 std::unique_ptr<ScopedBlockSwizzler> metrics_mediator_swizzler_;
288 __block BOOL metrics_mediator_called_; 287 __block BOOL metrics_mediator_called_;
289 }; 288 };
290 289
291 // TODO(crbug.com/585700): remove this.
292 // Creates a requestTracker, needed for teardown.
293 void createTracker(BOOL* created, base::Lock* lock) {
294 web::RequestTrackerImpl::GetTrackerForRequestGroupID(@"test");
295 base::AutoLock scoped_lock(*lock);
296 *created = YES;
297 }
298
299 // Used to have a thread handling the closing of the IO threads. 290 // Used to have a thread handling the closing of the IO threads.
300 class AppStateWithThreadTest : public PlatformTest { 291 class AppStateWithThreadTest : public PlatformTest {
301 protected: 292 protected:
302 AppStateWithThreadTest() 293 AppStateWithThreadTest()
303 : thread_bundle_(web::TestWebThreadBundle::REAL_IO_THREAD) { 294 : thread_bundle_(web::TestWebThreadBundle::REAL_IO_THREAD) {}
sdefresne 2017/02/21 10:40:30 Can you try to not pass web::TestWebThreadBundle::
304 BOOL created = NO;
305 base::Lock* lock = new base::Lock;
306
307 web::WebThread::PostTask(web::WebThread::IO, FROM_HERE,
308 base::Bind(&createTracker, &created, lock));
309
310 CFTimeInterval start = CACurrentMediaTime();
311
312 // Poll for at most 1s, waiting for the Tracker creation.
313 while (1) {
314 base::AutoLock scoped_lock(*lock);
315 if (created)
316 return;
317 if (CACurrentMediaTime() - start > 1.0) {
318 trackerCreationFailed();
319 return;
320 }
321 // Ensure that other threads have a chance to run even on a single-core
322 // devices.
323 pthread_yield_np();
324 }
325 }
326
327 void trackerCreationFailed() {
328 FAIL() << "Tracker creation took too much time.";
329 }
330 295
331 private: 296 private:
332 web::TestWebThreadBundle thread_bundle_; 297 web::TestWebThreadBundle thread_bundle_;
333 }; 298 };
334 299
335 #pragma mark - Tests. 300 #pragma mark - Tests.
336 301
337 // Tests -isInSafeMode returns true if there is a SafeModeController. 302 // Tests -isInSafeMode returns true if there is a SafeModeController.
338 TEST_F(AppStateTest, isInSafeModeTest) { 303 TEST_F(AppStateTest, isInSafeModeTest) {
339 // Setup. 304 // Setup.
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 // Action. 891 // Action.
927 [appState applicationDidEnterBackground:application 892 [appState applicationDidEnterBackground:application
928 memoryHelper:memoryHelper 893 memoryHelper:memoryHelper
929 tabSwitcherIsActive:YES]; 894 tabSwitcherIsActive:YES];
930 895
931 // Tests. 896 // Tests.
932 EXPECT_OCMOCK_VERIFY(startupInformation); 897 EXPECT_OCMOCK_VERIFY(startupInformation);
933 EXPECT_TRUE(metricsMediatorHasBeenCalled()); 898 EXPECT_TRUE(metricsMediatorHasBeenCalled());
934 EXPECT_EQ(NSUInteger(0), [window subviews].count); 899 EXPECT_EQ(NSUInteger(0), [window subviews].count);
935 } 900 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698