1// Copyright 2019 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/web_view/internal/cwv_flags_internal.h" 6 7#include <memory> 8#include <set> 9 10#include "base/test/task_environment.h" 11#include "components/flags_ui/pref_service_flags_storage.h" 12#include "components/prefs/in_memory_pref_store.h" 13#include "components/prefs/pref_registry_simple.h" 14#include "components/prefs/pref_service.h" 15#include "components/prefs/pref_service_factory.h" 16#import "testing/gtest_mac.h" 17#include "testing/platform_test.h" 18 19#if !defined(__has_feature) || !__has_feature(objc_arc) 20#error "This file requires ARC support." 21#endif 22 23namespace ios_web_view { 24 25class CWVFlagsTest : public PlatformTest { 26 protected: 27 CWVFlagsTest() { 28 auto pref_registry = base::MakeRefCounted<PrefRegistrySimple>(); 29 flags_ui::PrefServiceFlagsStorage::RegisterPrefs(pref_registry.get()); 30 31 scoped_refptr<PersistentPrefStore> pref_store = new InMemoryPrefStore(); 32 PrefServiceFactory factory; 33 factory.set_user_prefs(pref_store); 34 35 pref_service_ = factory.Create(pref_registry.get()); 36 flags_storage_ = std::make_unique<flags_ui::PrefServiceFlagsStorage>( 37 pref_service_.get()); 38 flags_ = [[CWVFlags alloc] initWithPrefService:pref_service_.get()]; 39 } 40 41 std::unique_ptr<PrefService> pref_service_; 42 std::unique_ptr<flags_ui::PrefServiceFlagsStorage> flags_storage_; 43 CWVFlags* flags_; 44}; 45 46// Tests CWVFlags' usesSyncAndWalletSandbox setter. 47TEST_F(CWVFlagsTest, SetUsesSyncAndWalletSandbox) { 48 flags_.usesSyncAndWalletSandbox = YES; 49 std::set<std::string> stored_flags = flags_storage_->GetFlags(); 50 EXPECT_NE(stored_flags.end(), stored_flags.find(kUseSyncSandboxFlagName)); 51 EXPECT_NE(stored_flags.end(), 52 stored_flags.find(kUseWalletSandboxFlagNameEnabled)); 53 54 flags_.usesSyncAndWalletSandbox = NO; 55 stored_flags = flags_storage_->GetFlags(); 56 EXPECT_EQ(stored_flags.end(), stored_flags.find(kUseSyncSandboxFlagName)); 57 EXPECT_EQ(stored_flags.end(), 58 stored_flags.find(kUseWalletSandboxFlagNameEnabled)); 59} 60 61// Tests CWVFlag's usesSyncAndWalletSandbox getter. 62TEST_F(CWVFlagsTest, GetUsesSyncAndWalletSadnbox) { 63 flags_storage_->SetFlags( 64 {kUseSyncSandboxFlagName, kUseWalletSandboxFlagNameEnabled}); 65 EXPECT_TRUE(flags_.usesSyncAndWalletSandbox); 66 67 flags_storage_->SetFlags({kUseWalletSandboxFlagNameDisabled}); 68 EXPECT_FALSE(flags_.usesSyncAndWalletSandbox); 69} 70 71} // namespace ios_web_view 72