QUIC - cleanup changes to sync chromium tree with internal source.
[chromium-blink-merge.git] / chrome / browser / supervised_user / legacy / supervised_user_shared_settings_update_unittest.cc
blob59329ac4bbc207ed7e8d5d99ff3fa044c3819991
1 // Copyright 2014 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.
5 #include "base/bind.h"
6 #include "base/memory/scoped_ptr.h"
7 #include "chrome/browser/supervised_user/legacy/supervised_user_shared_settings_service.h"
8 #include "chrome/browser/supervised_user/legacy/supervised_user_shared_settings_update.h"
9 #include "chrome/test/base/testing_profile.h"
10 #include "content/public/test/test_browser_thread_bundle.h"
11 #include "sync/api/sync_change.h"
12 #include "testing/gtest/include/gtest/gtest.h"
14 class SupervisedUserSharedSettingsUpdateTest : public testing::Test {
15 public:
16 SupervisedUserSharedSettingsUpdateTest() : service_(profile_.GetPrefs()) {}
17 ~SupervisedUserSharedSettingsUpdateTest() override {}
19 void OnSettingUpdated(bool success) {
20 result_.reset(new bool(success));
23 protected:
24 content::TestBrowserThreadBundle thread_bundle_;
25 TestingProfile profile_;
26 SupervisedUserSharedSettingsService service_;
27 scoped_ptr<bool> result_;
30 TEST_F(SupervisedUserSharedSettingsUpdateTest, Success) {
31 SupervisedUserSharedSettingsUpdate update(
32 &service_,
33 "abcdef",
34 "name",
35 scoped_ptr<base::Value>(new base::StringValue("Hans Moleman")),
36 base::Bind(&SupervisedUserSharedSettingsUpdateTest::OnSettingUpdated,
37 base::Unretained(this)));
38 syncer::SyncChangeList changes;
39 changes.push_back(syncer::SyncChange(
40 FROM_HERE,
41 syncer::SyncChange::ACTION_UPDATE,
42 SupervisedUserSharedSettingsService::CreateSyncDataForSetting(
43 "abcdef", "name", base::StringValue("Hans Moleman"), true)));
44 syncer::SyncError error = service_.ProcessSyncChanges(FROM_HERE, changes);
45 EXPECT_FALSE(error.IsSet()) << error.ToString();
46 ASSERT_TRUE(result_);
47 EXPECT_TRUE(*result_);
50 TEST_F(SupervisedUserSharedSettingsUpdateTest, Failure) {
51 SupervisedUserSharedSettingsUpdate update(
52 &service_,
53 "abcdef",
54 "name",
55 scoped_ptr<base::Value>(new base::StringValue("Hans Moleman")),
56 base::Bind(&SupervisedUserSharedSettingsUpdateTest::OnSettingUpdated,
57 base::Unretained(this)));
59 // Syncing down a different change will cause the update to fail.
60 syncer::SyncChangeList changes;
61 changes.push_back(syncer::SyncChange(
62 FROM_HERE,
63 syncer::SyncChange::ACTION_UPDATE,
64 SupervisedUserSharedSettingsService::CreateSyncDataForSetting(
65 "abcdef",
66 "name",
67 base::StringValue("Barney Gumble"),
68 true)));
69 syncer::SyncError error = service_.ProcessSyncChanges(FROM_HERE, changes);
70 EXPECT_FALSE(error.IsSet()) << error.ToString();
71 ASSERT_TRUE(result_);
72 EXPECT_FALSE(*result_);
75 TEST_F(SupervisedUserSharedSettingsUpdateTest, Cancel) {
77 SupervisedUserSharedSettingsUpdate update(
78 &service_,
79 "abcdef",
80 "name",
81 scoped_ptr<base::Value>(new base::StringValue("Hans Moleman")),
82 base::Bind(&SupervisedUserSharedSettingsUpdateTest::OnSettingUpdated,
83 base::Unretained(this)));
84 ASSERT_FALSE(result_);
86 ASSERT_FALSE(result_);