blob: 9587618f4ef2272092b0551fa2c345c54c29502b [file] [log] [blame]
// Copyright 2018 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.
#ifndef IOS_CHROME_TEST_SCOPED_EG_SYNCHRONIZATION_DISABLER_H_
#define IOS_CHROME_TEST_SCOPED_EG_SYNCHRONIZATION_DISABLER_H_
#import <EarlGrey/EarlGrey.h>
#include "base/macros.h"
// Disables EarlGrey synchronization in constructor and returns back to the
// original value in destructor.
class ScopedSynchronizationDisabler {
public:
ScopedSynchronizationDisabler()
: saved_eg_synchronization_enabled_value_(GetEgSynchronizationEnabled()) {
SetEgSynchronizationEnabled(NO);
}
~ScopedSynchronizationDisabler() {
SetEgSynchronizationEnabled(saved_eg_synchronization_enabled_value_);
}
private:
static bool GetEgSynchronizationEnabled() {
return [[GREYConfiguration sharedInstance]
boolValueForConfigKey:kGREYConfigKeySynchronizationEnabled];
}
static void SetEgSynchronizationEnabled(BOOL flag) {
[[GREYConfiguration sharedInstance]
setValue:@(flag)
forConfigKey:kGREYConfigKeySynchronizationEnabled];
}
BOOL saved_eg_synchronization_enabled_value_ = NO;
DISALLOW_COPY_AND_ASSIGN(ScopedSynchronizationDisabler);
};
#endif // IOS_CHROME_TEST_SCOPED_EG_SYNCHRONIZATION_DISABLER_H_