| Index: ios/chrome/browser/ui/settings/do_not_track_collection_view_controller_unittest.mm
|
| diff --git a/ios/chrome/browser/ui/settings/do_not_track_collection_view_controller_unittest.mm b/ios/chrome/browser/ui/settings/do_not_track_collection_view_controller_unittest.mm
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..63100f3a769f356e5684c5997fcf516741576bc9
|
| --- /dev/null
|
| +++ b/ios/chrome/browser/ui/settings/do_not_track_collection_view_controller_unittest.mm
|
| @@ -0,0 +1,74 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#import "ios/chrome/browser/ui/settings/do_not_track_collection_view_controller.h"
|
| +
|
| +#include <memory>
|
| +
|
| +#include "base/compiler_specific.h"
|
| +#include "base/files/file_path.h"
|
| +#include "base/mac/scoped_nsobject.h"
|
| +#include "base/message_loop/message_loop.h"
|
| +#include "components/prefs/pref_member.h"
|
| +#include "components/prefs/pref_registry_simple.h"
|
| +#include "components/prefs/pref_service.h"
|
| +#include "components/sync_preferences/pref_service_mock_factory.h"
|
| +#include "ios/chrome/browser/pref_names.h"
|
| +#import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h"
|
| +#include "ios/chrome/grit/ios_strings.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "testing/gtest_mac.h"
|
| +#include "testing/platform_test.h"
|
| +#include "ui/base/l10n/l10n_util_mac.h"
|
| +
|
| +namespace {
|
| +
|
| +class DoNotTrackCollectionViewControllerTest
|
| + : public CollectionViewControllerTest {
|
| + protected:
|
| + void SetUp() override {
|
| + CollectionViewControllerTest::SetUp();
|
| + pref_service_ = CreateLocalState();
|
| + }
|
| +
|
| + CollectionViewController* NewController() override NS_RETURNS_RETAINED {
|
| + return [[DoNotTrackCollectionViewController alloc]
|
| + initWithPrefs:pref_service_.get()];
|
| + }
|
| +
|
| + std::unique_ptr<PrefService> CreateLocalState() {
|
| + scoped_refptr<PrefRegistrySimple> registry(new PrefRegistrySimple());
|
| + registry->RegisterBooleanPref(prefs::kEnableDoNotTrack, false);
|
| + base::FilePath path("DoNotTrackCollectionViewControllerTest.pref");
|
| +
|
| + sync_preferences::PrefServiceMockFactory factory;
|
| + factory.SetUserPrefsFile(path, message_loop_.task_runner().get());
|
| + return factory.Create(registry.get());
|
| + }
|
| +
|
| + base::MessageLoopForUI message_loop_;
|
| + std::unique_ptr<PrefService> pref_service_;
|
| +};
|
| +
|
| +TEST_F(DoNotTrackCollectionViewControllerTest, TestModelDoNotTrackOff) {
|
| + CreateController();
|
| + CheckController();
|
| + EXPECT_EQ(2, NumberOfSections());
|
| + EXPECT_EQ(1, NumberOfItemsInSection(0));
|
| + CheckSwitchCellStateAndTitleWithId(NO, IDS_IOS_OPTIONS_DO_NOT_TRACK_MOBILE, 0,
|
| + 0);
|
| +}
|
| +
|
| +TEST_F(DoNotTrackCollectionViewControllerTest, TestModelDoNotTrackOn) {
|
| + BooleanPrefMember doNotTrackEnabled;
|
| + doNotTrackEnabled.Init(prefs::kEnableDoNotTrack, pref_service_.get());
|
| + doNotTrackEnabled.SetValue(true);
|
| + CreateController();
|
| + EXPECT_EQ(2, NumberOfSections());
|
| + EXPECT_EQ(1, NumberOfItemsInSection(0));
|
| + CheckSwitchCellStateAndTitleWithId(YES, IDS_IOS_OPTIONS_DO_NOT_TRACK_MOBILE,
|
| + 0, 0);
|
| +}
|
| +
|
| +} // namespace
|
|
|