OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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 "ios/chrome/browser/ui/settings/bandwidth_management_collection_view_con
troller.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "base/compiler_specific.h" |
| 10 #include "base/run_loop.h" |
| 11 #include "base/test/test_simple_task_runner.h" |
| 12 #include "components/pref_registry/pref_registry_syncable.h" |
| 13 #include "components/prefs/testing_pref_service.h" |
| 14 #include "components/sync_preferences/pref_service_mock_factory.h" |
| 15 #include "components/sync_preferences/pref_service_syncable.h" |
| 16 #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" |
| 17 #include "ios/chrome/browser/pref_names.h" |
| 18 #include "ios/chrome/browser/prefs/browser_prefs.h" |
| 19 #import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h
" |
| 20 #import "ios/chrome/browser/ui/settings/dataplan_usage_collection_view_controlle
r.h" |
| 21 #include "ios/chrome/grit/ios_strings.h" |
| 22 #include "ios/chrome/test/ios_chrome_scoped_testing_local_state.h" |
| 23 #include "ios/chrome/test/testing_application_context.h" |
| 24 #include "ios/web/public/test/test_web_thread.h" |
| 25 #include "net/log/test_net_log.h" |
| 26 #include "testing/gtest/include/gtest/gtest.h" |
| 27 #include "ui/base/l10n/l10n_util.h" |
| 28 |
| 29 namespace { |
| 30 |
| 31 class BandwidthManagementCollectionViewControllerTest |
| 32 : public CollectionViewControllerTest { |
| 33 public: |
| 34 BandwidthManagementCollectionViewControllerTest() |
| 35 : loop_(base::MessageLoop::TYPE_IO), |
| 36 ui_thread_(web::WebThread::UI, &loop_), |
| 37 io_thread_(web::WebThread::IO, &loop_) {} |
| 38 |
| 39 protected: |
| 40 void SetUp() override { |
| 41 CollectionViewControllerTest::SetUp(); |
| 42 |
| 43 sync_preferences::PrefServiceMockFactory factory; |
| 44 scoped_refptr<user_prefs::PrefRegistrySyncable> registry( |
| 45 new user_prefs::PrefRegistrySyncable); |
| 46 std::unique_ptr<sync_preferences::PrefServiceSyncable> prefs( |
| 47 factory.CreateSyncable(registry.get())); |
| 48 RegisterBrowserStatePrefs(registry.get()); |
| 49 TestChromeBrowserState::Builder test_cbs_builder; |
| 50 test_cbs_builder.SetPrefService(std::move(prefs)); |
| 51 chrome_browser_state_ = test_cbs_builder.Build(); |
| 52 |
| 53 CreateController(); |
| 54 } |
| 55 |
| 56 void TearDown() override { |
| 57 base::RunLoop().RunUntilIdle(); |
| 58 CollectionViewControllerTest::TearDown(); |
| 59 } |
| 60 |
| 61 CollectionViewController* NewController() override NS_RETURNS_RETAINED { |
| 62 return [[BandwidthManagementCollectionViewController alloc] |
| 63 initWithBrowserState:chrome_browser_state_.get()]; |
| 64 } |
| 65 |
| 66 base::MessageLoop loop_; |
| 67 web::TestWebThread ui_thread_; |
| 68 web::TestWebThread io_thread_; |
| 69 net::TestNetLog net_log_; |
| 70 IOSChromeScopedTestingLocalState local_state_; |
| 71 |
| 72 std::unique_ptr<TestChromeBrowserState> chrome_browser_state_; |
| 73 }; |
| 74 |
| 75 TEST_F(BandwidthManagementCollectionViewControllerTest, TestModel) { |
| 76 CheckController(); |
| 77 EXPECT_EQ(2, NumberOfSections()); |
| 78 |
| 79 const NSInteger action_section = 0; |
| 80 EXPECT_EQ(1, NumberOfItemsInSection(action_section)); |
| 81 // Preload webpages item. |
| 82 NSString* expected_title = |
| 83 l10n_util::GetNSString(IDS_IOS_OPTIONS_PRELOAD_WEBPAGES); |
| 84 NSString* expected_subtitle = [DataplanUsageCollectionViewController |
| 85 currentLabelForPreference:chrome_browser_state_->GetPrefs() |
| 86 basePref:prefs::kNetworkPredictionEnabled |
| 87 wifiPref:prefs::kNetworkPredictionWifiOnly]; |
| 88 CheckTextCellTitleAndSubtitle(expected_title, expected_subtitle, |
| 89 action_section, 0); |
| 90 } |
| 91 |
| 92 } // namespace |
OLD | NEW |