OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 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 #include "base/bind.h" | |
6 #include "base/memory/scoped_ptr.h" | |
7 #include "chrome/browser/managed_mode/managed_user_shared_settings_service.h" | |
8 #include "chrome/browser/managed_mode/managed_user_shared_settings_update.h" | |
9 #include "chrome/test/base/testing_profile.h" | |
10 #include "sync/api/sync_change.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | |
12 | |
13 class ManagedUserSharedSettingsUpdateTest : public testing::Test { | |
14 public: | |
15 ManagedUserSharedSettingsUpdateTest() : service_(profile_.GetPrefs()) {} | |
16 virtual ~ManagedUserSharedSettingsUpdateTest() {} | |
17 | |
18 void OnSettingUpdated(bool success) { | |
19 result_.reset(new bool(success)); | |
20 } | |
21 | |
22 protected: | |
23 TestingProfile profile_; | |
24 ManagedUserSharedSettingsService service_; | |
25 scoped_ptr<bool> result_; | |
26 }; | |
27 | |
28 TEST_F(ManagedUserSharedSettingsUpdateTest, Success) { | |
29 ManagedUserSharedSettingsUpdate update( | |
30 &service_, | |
31 "abcdef", | |
32 "name", | |
33 scoped_ptr<base::Value>(new base::StringValue("Hans Moleman")), | |
34 base::Bind(&ManagedUserSharedSettingsUpdateTest::OnSettingUpdated, | |
35 base::Unretained(this))); | |
36 syncer::SyncChangeList changes; | |
37 changes.push_back(syncer::SyncChange( | |
38 FROM_HERE, | |
39 syncer::SyncChange::ACTION_UPDATE, | |
40 ManagedUserSharedSettingsService::CreateSyncDataForSetting( | |
41 "abcdef", "name", base::StringValue("Hans Moleman"), true))); | |
42 syncer::SyncError error = service_.ProcessSyncChanges(FROM_HERE, changes); | |
43 EXPECT_FALSE(error.IsSet()) << error.ToString(); | |
44 ASSERT_TRUE(result_); | |
45 EXPECT_TRUE(*result_); | |
46 } | |
47 | |
48 TEST_F(ManagedUserSharedSettingsUpdateTest, Failure) { | |
49 ManagedUserSharedSettingsUpdate update( | |
50 &service_, | |
51 "abcdef", | |
52 "name", | |
53 scoped_ptr<base::Value>(new base::StringValue("Hans Moleman")), | |
54 base::Bind(&ManagedUserSharedSettingsUpdateTest::OnSettingUpdated, | |
55 base::Unretained(this))); | |
56 syncer::SyncChangeList changes; | |
57 changes.push_back(syncer::SyncChange( | |
58 FROM_HERE, | |
59 syncer::SyncChange::ACTION_UPDATE, | |
60 ManagedUserSharedSettingsService::CreateSyncDataForSetting( | |
61 "abcdef", | |
62 "name", | |
63 base::StringValue("Barney Gumble"), | |
Pam (message me for reviews)
2014/01/08 10:30:40
Please add a comment pointing this out as the fail
Bernhard Bauer
2014/01/08 11:42:04
Done.
| |
64 true))); | |
65 syncer::SyncError error = service_.ProcessSyncChanges(FROM_HERE, changes); | |
66 EXPECT_FALSE(error.IsSet()) << error.ToString(); | |
67 ASSERT_TRUE(result_); | |
68 EXPECT_FALSE(*result_); | |
69 } | |
70 | |
71 TEST_F(ManagedUserSharedSettingsUpdateTest, Cancel) { | |
72 { | |
73 ManagedUserSharedSettingsUpdate update( | |
74 &service_, | |
75 "abcdef", | |
76 "name", | |
77 scoped_ptr<base::Value>(new base::StringValue("Hans Moleman")), | |
78 base::Bind(&ManagedUserSharedSettingsUpdateTest::OnSettingUpdated, | |
79 base::Unretained(this))); | |
80 ASSERT_FALSE(result_); | |
81 } | |
82 ASSERT_FALSE(result_); | |
83 } | |
OLD | NEW |