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

Side by Side Diff: chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h

Issue 1019283004: Switch to direct use of OwnerSettingsServiceChromeOS::Set() in tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address code review comments. Created 5 years, 8 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
OLDNEW
(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 #ifndef CHROME_BROWSER_CHROMEOS_SETTINGS_SCOPED_CROS_SETTINGS_TEST_HELPER_H_
6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_SCOPED_CROS_SETTINGS_TEST_HELPER_H_
7
8 #include <string>
9
10 #include "base/macros.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
13 #include "chromeos/settings/cros_settings_provider.h"
14
15 class Profile;
16
17 namespace base {
18 class Value;
19 }
20
21 namespace chromeos {
22
23 class FakeOwnerSettingsService;
24 class ScopedTestCrosSettings;
25 class ScopedTestDeviceSettingsService;
26
27 class ScopedCrosSettingsTestHelper {
28 public:
29 ScopedCrosSettingsTestHelper();
30
31 // In some cases it is required to pass |create_settings_service| as false:
32 // If the test already has a device settings service and/or CrosSettings set
33 // up by another (included or base) class, creating another one causes crash.
bartfab (slow) 2015/04/14 14:10:09 Nit: s/included/instantiated/
Ivan Podogov 2015/04/14 14:40:37 Done.
34 explicit ScopedCrosSettingsTestHelper(bool create_settings_service);
35 ~ScopedCrosSettingsTestHelper();
36
37 // Methods to replace and restore CrosSettingsProvider for the specified
38 // |path|.
39 void ReplaceProvider(const std::string& path);
40 void RestoreProvider();
41
42 // Method to create an owner settings service that uses
43 // |stub_settings_provider_| as settings write path.
44 scoped_ptr<FakeOwnerSettingsService> CreateOwnerSettingsService(
45 Profile* profile);
46
47 // These methods simply call the according |stub_settings_provider_| method.
48 void SetTrustedStatus(CrosSettingsProvider::TrustedStatus status);
49 void SetCurrentUserIsOwner(bool owner);
50 void Set(const std::string& path, const base::Value& in_value);
51
52 // Convenience forms of Set() from CrosSettingsProvider. These methods will
53 // replace any existing value at that |path|, even if it has a different type.
54 void SetBoolean(const std::string& path, bool in_value);
55 void SetInteger(const std::string& path, int in_value);
56 void SetDouble(const std::string& path, double in_value);
57 void SetString(const std::string& path, const std::string& in_value);
58
59 // This may be called before |ReplaceProvider| to copy values currently stored
60 // in the old provider. If the method is called after |ReplaceProvider|, then
61 // the value is retreived from |real_settings_provider_| for any |path|.
62 void CopyStoredValue(const std::string& path);
63
64 // Write the setting from |path| to local state so that it can be retreived
65 // later on browser test startup by the device settings service.
66 void StoreCachedDeviceSetting(const std::string& path);
67
68 private:
69 // Helpers used to mock out cros settings.
70 scoped_ptr<ScopedTestDeviceSettingsService> test_device_settings_service_;
71 scoped_ptr<ScopedTestCrosSettings> test_cros_settings_;
72 CrosSettingsProvider* real_settings_provider_ = nullptr;
73 StubCrosSettingsProvider stub_settings_provider_;
74
75 void Initialize(bool create_settings_service);
76
77 DISALLOW_COPY_AND_ASSIGN(ScopedCrosSettingsTestHelper);
78 };
79
80 } // namespace chromeos
81
82 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_SCOPED_CROS_SETTINGS_TEST_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698