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

Side by Side Diff: chrome/browser/extensions/api/settings_private/settings_private_apitest.cc

Issue 1061613002: chrome.settingsPrivate: Implement onPrefsChanged event handling. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix a direct memory leak 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/prefs/pref_service.h"
6 #include "base/values.h" 7 #include "base/values.h"
7 #include "chrome/browser/extensions/api/settings_private/settings_private_delega te.h" 8 #include "chrome/browser/extensions/api/settings_private/settings_private_delega te.h"
8 #include "chrome/browser/extensions/api/settings_private/settings_private_delega te_factory.h" 9 #include "chrome/browser/extensions/api/settings_private/settings_private_delega te_factory.h"
9 #include "chrome/browser/extensions/extension_apitest.h" 10 #include "chrome/browser/extensions/extension_apitest.h"
10 #include "chrome/common/extensions/api/settings_private.h" 11 #include "chrome/common/extensions/api/settings_private.h"
11 #include "components/keyed_service/core/keyed_service.h" 12 #include "components/keyed_service/core/keyed_service.h"
12 #include "content/public/test/test_utils.h" 13 #include "content/public/test/test_utils.h"
13 #include "extensions/common/switches.h" 14 #include "extensions/common/switches.h"
14 15
15 namespace extensions { 16 namespace extensions {
16 17
17 namespace { 18 namespace {
18 19
19 const char kTestPrefName[] = "test.foo_bar"; 20 const char kTestPrefName[] = "download.default_directory";
20 const char kTestPrefValue[] = "baz"; 21 const char kTestPrefValue[] = "/Downloads";
21 22
22 class TestDelegate : public SettingsPrivateDelegate { 23 class TestDelegate : public SettingsPrivateDelegate {
23 public: 24 public:
24 explicit TestDelegate(Profile* profile) : SettingsPrivateDelegate(profile) {} 25 explicit TestDelegate(Profile* profile) : SettingsPrivateDelegate(profile) {}
25 26
26 bool SetPref(const std::string& name, const base::Value* value) override { 27 bool SetPref(const std::string& name, const base::Value* value) override {
28 // Write to the actual pref service, so that the SettingsPrivateEventRouter
29 // dispatches an onPrefsChanged event.
30 PrefService* pref_service = profile_->GetPrefs();
31 pref_service->Set(name.c_str(), *value);
27 return true; 32 return true;
28 } 33 }
29 34
30 scoped_ptr<base::Value> GetPref(const std::string& name) override { 35 scoped_ptr<base::Value> GetPref(const std::string& name) override {
31 if (name.compare(kTestPrefName) != 0) 36 if (name.compare(kTestPrefName) != 0)
32 return make_scoped_ptr(base::Value::CreateNullValue()); 37 return make_scoped_ptr(base::Value::CreateNullValue());
33 38
34 return CreateTestPrefObject()->ToValue(); 39 return CreateTestPrefObject()->ToValue();
35 } 40 }
36 41
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 } 108 }
104 109
105 IN_PROC_BROWSER_TEST_F(SettingsPrivateApiTest, GetPref) { 110 IN_PROC_BROWSER_TEST_F(SettingsPrivateApiTest, GetPref) {
106 EXPECT_TRUE(RunSettingsSubtest("getPref")) << message_; 111 EXPECT_TRUE(RunSettingsSubtest("getPref")) << message_;
107 } 112 }
108 113
109 IN_PROC_BROWSER_TEST_F(SettingsPrivateApiTest, GetAllPrefs) { 114 IN_PROC_BROWSER_TEST_F(SettingsPrivateApiTest, GetAllPrefs) {
110 EXPECT_TRUE(RunSettingsSubtest("getAllPrefs")) << message_; 115 EXPECT_TRUE(RunSettingsSubtest("getAllPrefs")) << message_;
111 } 116 }
112 117
118 IN_PROC_BROWSER_TEST_F(SettingsPrivateApiTest, OnPrefsChanged) {
119 EXPECT_TRUE(RunSettingsSubtest("onPrefsChanged")) << message_;
120 }
121
113 } // namespace extensions 122 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698