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

Unified Diff: chrome/browser/extensions/api/settings_private/settings_private_apitest.cc

Issue 1163593005: Update chrome.settingsPrivate to support CrOS-only settings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix issues preventing compilation on non-CrOS builds. Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/settings_private/settings_private_apitest.cc
diff --git a/chrome/browser/extensions/api/settings_private/settings_private_apitest.cc b/chrome/browser/extensions/api/settings_private/settings_private_apitest.cc
index 8030ed78df3ae01f5ed57d25b048a13be463e639..d2e48cf57431631bc513e3161479a864782f163c 100644
--- a/chrome/browser/extensions/api/settings_private/settings_private_apitest.cc
+++ b/chrome/browser/extensions/api/settings_private/settings_private_apitest.cc
@@ -13,76 +13,24 @@
#include "content/public/test/test_utils.h"
#include "extensions/common/switches.h"
+#if defined(OS_CHROMEOS)
+#include "chromeos/chromeos_switches.h"
+#endif
+
namespace extensions {
namespace {
-const char kTestPrefName[] = "download.default_directory";
-const char kTestPrefValue[] = "/Downloads";
-
-class TestDelegate : public SettingsPrivateDelegate {
- public:
- explicit TestDelegate(Profile* profile) : SettingsPrivateDelegate(profile) {}
-
- bool SetPref(const std::string& name, const base::Value* value) override {
- // Write to the actual pref service, so that the SettingsPrivateEventRouter
- // dispatches an onPrefsChanged event.
- PrefService* pref_service = profile_->GetPrefs();
- pref_service->Set(name.c_str(), *value);
- return true;
- }
-
- scoped_ptr<base::Value> GetPref(const std::string& name) override {
- if (name.compare(kTestPrefName) != 0)
- return base::Value::CreateNullValue();
-
- return CreateTestPrefObject()->ToValue();
- }
-
- scoped_ptr<base::Value> GetAllPrefs() override {
- base::ListValue* list_value = new base::ListValue();
- list_value->Append(CreateTestPrefObject()->ToValue().release());
- return make_scoped_ptr(list_value);
- }
-
- ~TestDelegate() override {}
-
- private:
- scoped_ptr<api::settings_private::PrefObject> CreateTestPrefObject() {
- scoped_ptr<api::settings_private::PrefObject> pref_object(
- new api::settings_private::PrefObject());
- pref_object->key = std::string(kTestPrefName);
- pref_object->type = api::settings_private::PrefType::PREF_TYPE_STRING;
- pref_object->value.reset(new base::StringValue(kTestPrefValue));
- return pref_object.Pass();
- }
-
- DISALLOW_COPY_AND_ASSIGN(TestDelegate);
-};
-
class SettingsPrivateApiTest : public ExtensionApiTest {
public:
SettingsPrivateApiTest() {}
~SettingsPrivateApiTest() override {}
- static KeyedService* GetSettingsPrivateDelegate(
- content::BrowserContext* profile) {
- CHECK(s_test_delegate_);
- return s_test_delegate_;
- }
-
void SetUpCommandLine(base::CommandLine* command_line) override {
ExtensionApiTest::SetUpCommandLine(command_line);
- }
-
- void SetUpOnMainThread() override {
- ExtensionApiTest::SetUpOnMainThread();
- if (!s_test_delegate_)
- s_test_delegate_ = new TestDelegate(profile());
-
- SettingsPrivateDelegateFactory::GetInstance()->SetTestingFactory(
- profile(), &SettingsPrivateApiTest::GetSettingsPrivateDelegate);
- content::RunAllPendingInMessageLoop();
+#if defined(OS_CHROMEOS)
+ command_line->AppendSwitch(chromeos::switches::kStubCrosSettings);
+#endif
}
protected:
@@ -92,16 +40,10 @@ class SettingsPrivateApiTest : public ExtensionApiTest {
kFlagLoadAsComponent);
}
- // Static pointer to the TestDelegate so that it can be accessed in
- // GetSettingsPrivateDelegate() passed to SetTestingFactory().
- static TestDelegate* s_test_delegate_;
-
private:
DISALLOW_COPY_AND_ASSIGN(SettingsPrivateApiTest);
};
-// static
-TestDelegate* SettingsPrivateApiTest::s_test_delegate_ = NULL;
} // namespace
@@ -121,4 +63,18 @@ IN_PROC_BROWSER_TEST_F(SettingsPrivateApiTest, OnPrefsChanged) {
EXPECT_TRUE(RunSettingsSubtest("onPrefsChanged")) << message_;
}
+#if defined(OS_CHROMEOS)
+IN_PROC_BROWSER_TEST_F(SettingsPrivateApiTest, GetPref_CrOSSetting) {
+ EXPECT_TRUE(RunSettingsSubtest("getPref_CrOSSetting")) << message_;
+}
+
+IN_PROC_BROWSER_TEST_F(SettingsPrivateApiTest, SetPref_CrOSSetting) {
+ EXPECT_TRUE(RunSettingsSubtest("setPref_CrOSSetting")) << message_;
+}
+
+IN_PROC_BROWSER_TEST_F(SettingsPrivateApiTest, OnPrefsChanged_CrOSSetting) {
+ EXPECT_TRUE(RunSettingsSubtest("onPrefsChanged_CrOSSetting")) << message_;
+}
+#endif
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698