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

Unified Diff: chrome/browser/chromeos/preferences_chromeos_browsertest.cc

Issue 2698913005: Re-enable preferences service access for browser+ash (Closed)
Patch Set: . Created 3 years, 10 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/chromeos/preferences_chromeos_browsertest.cc
diff --git a/chrome/browser/chromeos/preferences_chromeos_browsertest.cc b/chrome/browser/chromeos/preferences_chromeos_browsertest.cc
index 93812b0559b4ab1794188d9861f11a55fa15f11d..86712c64fa506a965d7cd669f4df28f4692bb62f 100644
--- a/chrome/browser/chromeos/preferences_chromeos_browsertest.cc
+++ b/chrome/browser/chromeos/preferences_chromeos_browsertest.cc
@@ -5,10 +5,16 @@
#include <stddef.h>
#include <sys/types.h>
+#include <set>
+#include <string>
+
#include "ash/shell.h"
#include "base/command_line.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/run_loop.h"
+#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/input_method/input_method_manager_impl.h"
#include "chrome/browser/chromeos/login/login_manager_test.h"
@@ -20,12 +26,20 @@
#include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h"
#include "chrome/browser/chromeos/system/fake_input_device_settings.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_chromeos.h"
+#include "chrome/browser/ui/browser.h"
#include "chrome/common/pref_names.h"
+#include "chrome/test/base/in_process_browser_test.h"
#include "chromeos/chromeos_switches.h"
#include "components/feedback/tracing_manager.h"
#include "components/prefs/pref_service.h"
+#include "components/prefs/pref_store.h"
+#include "components/prefs/writeable_pref_store.h"
#include "components/user_manager/user_manager.h"
+#include "content/public/common/service_manager_connection.h"
#include "content/public/test/test_utils.h"
+#include "services/preferences/public/cpp/pref_client_store.h"
+#include "services/preferences/public/interfaces/preferences.mojom.h"
+#include "services/service_manager/public/cpp/connector.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/ime/chromeos/fake_ime_keyboard.h"
#include "ui/events/event_utils.h"
@@ -141,6 +155,60 @@ class PreferencesTest : public LoginManagerTest {
DISALLOW_COPY_AND_ASSIGN(PreferencesTest);
};
+class PreferencesServiceBrowserTest : public InProcessBrowserTest {
+ public:
+ PreferencesServiceBrowserTest() {}
+
+ protected:
+ static service_manager::Connector* connector() {
+ return content::ServiceManagerConnection::GetForProcess()->GetConnector();
+ }
+
+ void WaitForPrefChange(PrefStore* store, const std::string& key) {
+ base::RunLoop run_loop;
+ TestPrefObserver observer(key, run_loop.QuitClosure());
+ store->AddObserver(&observer);
+ run_loop.Run();
+ store->RemoveObserver(&observer);
+ }
+
+ int GetIntegerPrefValue(PrefStore* store, const std::string& key) {
+ int int_value = 0;
+ const base::Value* value = nullptr;
+ EXPECT_TRUE(store->GetValue(key, &value));
sky 2017/02/17 17:44:22 If this returns false, won't the next line crash?
Ken Rockot(use gerrit already) 2017/02/17 18:58:22 Done
+ EXPECT_TRUE(value->GetAsInteger(&int_value));
+ return int_value;
+ }
+
+ private:
+ class TestPrefObserver : public PrefStore::Observer {
+ public:
+ TestPrefObserver(const std::string& pref_name,
+ const base::Closure& callback)
+ : pref_name_(pref_name), callback_(callback) {}
+
+ ~TestPrefObserver() override {}
+
+ // PrefStore::Observer:
+ void OnPrefValueChanged(const std::string& key) override {
+ if (key == pref_name_)
jonross 2017/02/16 21:53:35 Have this be an EXPECT_EQ? That way we fail explic
Ken Rockot(use gerrit already) 2017/02/17 00:00:31 I think the test should tolerate other prefs being
jonross 2017/02/17 02:15:46 SGTM
+ callback_.Run();
+ }
+
+ void OnInitializationCompleted(bool success) override {
+ ASSERT_TRUE(success);
+ }
+
+ private:
+ const std::string pref_name_;
+ const base::Closure callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestPrefObserver);
+ };
+
+ DISALLOW_COPY_AND_ASSIGN(PreferencesServiceBrowserTest);
+};
+
IN_PROC_BROWSER_TEST_F(PreferencesTest, PRE_MultiProfiles) {
RegisterUser(test_users_[0].GetUserEmail());
RegisterUser(test_users_[1].GetUserEmail());
@@ -214,4 +282,39 @@ IN_PROC_BROWSER_TEST_F(PreferencesTest, MultiProfiles) {
CheckLocalStateCorrespondsToPrefs(prefs1);
}
+IN_PROC_BROWSER_TEST_F(PreferencesServiceBrowserTest, Basic) {
+ prefs::mojom::PreferencesServiceFactoryPtr factory_a;
+ connector()->BindInterface(prefs::mojom::kServiceName, &factory_a);
+ scoped_refptr<preferences::PrefClientStore> pref_store_a =
+ new preferences::PrefClientStore(std::move(factory_a));
+
+ prefs::mojom::PreferencesServiceFactoryPtr factory_b;
+ connector()->BindInterface(prefs::mojom::kServiceName, &factory_b);
+ scoped_refptr<preferences::PrefClientStore> pref_store_b =
+ new preferences::PrefClientStore(std::move(factory_b));
+
+ constexpr int kInitialValue = 1;
+ PrefService* pref_service = browser()->profile()->GetPrefs();
jonross 2017/02/16 21:53:35 This exposes the test to other preferences being u
Ken Rockot(use gerrit already) 2017/02/17 00:00:31 I started going down this route just to see what i
jonross 2017/02/17 02:15:46 Thanks for the clarification. I'm fine with treati
+ pref_service->SetInteger(prefs::kMouseSensitivity, kInitialValue);
+
+ pref_store_a->Subscribe({prefs::kMouseSensitivity});
+ WaitForPrefChange(pref_store_a.get(), prefs::kMouseSensitivity);
+ EXPECT_EQ(kInitialValue,
+ GetIntegerPrefValue(pref_store_a.get(), prefs::kMouseSensitivity));
+
+ pref_store_b->Subscribe({prefs::kMouseSensitivity});
+ WaitForPrefChange(pref_store_b.get(), prefs::kMouseSensitivity);
+ EXPECT_EQ(kInitialValue,
+ GetIntegerPrefValue(pref_store_b.get(), prefs::kMouseSensitivity));
+
+ const int kTestValue = 42;
+ pref_store_a->SetValue(prefs::kMouseSensitivity,
+ base::MakeUnique<base::FundamentalValue>(kTestValue),
+ WriteablePrefStore::DEFAULT_PREF_WRITE_FLAGS);
+
+ WaitForPrefChange(pref_store_b.get(), prefs::kMouseSensitivity);
+ EXPECT_EQ(kTestValue,
+ GetIntegerPrefValue(pref_store_b.get(), prefs::kMouseSensitivity));
+}
+
} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698