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

Side by Side Diff: chrome/browser/chromeos/login/signed_settings_helper_unittest.cc

Issue 5671003: [Chrome OS] Plumb new error codes from SignedSettings to consumers of the API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove untoward log statement Created 10 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/chromeos/login/signed_settings_helper.h" 5 #include "chrome/browser/chromeos/login/signed_settings_helper.h"
6 6
7 #include "chrome/browser/browser_thread.h" 7 #include "chrome/browser/browser_thread.h"
8 #include "chrome/browser/chromeos/cros/cros_library.h" 8 #include "chrome/browser/chromeos/cros/cros_library.h"
9 #include "chrome/browser/chromeos/login/mock_ownership_service.h" 9 #include "chrome/browser/chromeos/login/mock_ownership_service.h"
10 #include "chrome/browser/chromeos/login/owner_manager.h" 10 #include "chrome/browser/chromeos/login/owner_manager.h"
11 #include "chrome/browser/chromeos/login/signed_settings.h" 11 #include "chrome/browser/chromeos/login/signed_settings.h"
12 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 using ::testing::_; 15 using ::testing::_;
16 using ::testing::InSequence; 16 using ::testing::InSequence;
17 17
18 namespace chromeos { 18 namespace chromeos {
19 19
20 class MockSignedSettingsHelperCallback : public SignedSettingsHelper::Callback { 20 class MockSignedSettingsHelperCallback : public SignedSettingsHelper::Callback {
21 public: 21 public:
22 MOCK_METHOD2(OnCheckWhiteListCompleted, void( 22 MOCK_METHOD2(OnCheckWhitelistCompleted, void(
23 bool success, const std::string& email)); 23 SignedSettings::ReturnCode code, const std::string& email));
24 MOCK_METHOD2(OnWhitelistCompleted, void( 24 MOCK_METHOD2(OnWhitelistCompleted, void(
25 bool success, const std::string& email)); 25 SignedSettings::ReturnCode code, const std::string& email));
26 MOCK_METHOD2(OnUnwhitelistCompleted, void( 26 MOCK_METHOD2(OnUnwhitelistCompleted, void(
27 bool success, const std::string& email)); 27 SignedSettings::ReturnCode code, const std::string& email));
28 MOCK_METHOD3(OnStorePropertyCompleted, void( 28 MOCK_METHOD3(OnStorePropertyCompleted, void(
29 bool success, const std::string& name, const std::string& value)); 29 SignedSettings::ReturnCode code,
30 const std::string& name,
31 const std::string& value));
30 MOCK_METHOD3(OnRetrievePropertyCompleted, void( 32 MOCK_METHOD3(OnRetrievePropertyCompleted, void(
31 bool success, const std::string& name, const std::string& value)); 33 SignedSettings::ReturnCode code,
34 const std::string& name,
35 const std::string& value));
32 }; 36 };
33 37
34 class SignedSettingsHelperTest : public ::testing::Test, 38 class SignedSettingsHelperTest : public ::testing::Test,
35 public SignedSettingsHelper::TestDelegate { 39 public SignedSettingsHelper::TestDelegate {
36 public: 40 public:
37 SignedSettingsHelperTest() 41 SignedSettingsHelperTest()
38 : fake_email_("fakey"), 42 : fake_email_("fakey"),
39 fake_prop_("prop_name"), 43 fake_prop_("prop_name"),
40 fake_value_("stub"), 44 fake_value_("stub"),
41 message_loop_(MessageLoop::TYPE_UI), 45 message_loop_(MessageLoop::TYPE_UI),
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 85
82 ScopedStubCrosEnabler stub_cros_enabler_; 86 ScopedStubCrosEnabler stub_cros_enabler_;
83 }; 87 };
84 88
85 TEST_F(SignedSettingsHelperTest, SerializedOps) { 89 TEST_F(SignedSettingsHelperTest, SerializedOps) {
86 MockSignedSettingsHelperCallback cb; 90 MockSignedSettingsHelperCallback cb;
87 91
88 EXPECT_CALL(m_, IsAlreadyOwned()).Times(2); 92 EXPECT_CALL(m_, IsAlreadyOwned()).Times(2);
89 InSequence s; 93 InSequence s;
90 EXPECT_CALL(m_, StartVerifyAttempt(_, _, _)).Times(1); 94 EXPECT_CALL(m_, StartVerifyAttempt(_, _, _)).Times(1);
91 EXPECT_CALL(cb, OnCheckWhiteListCompleted(true, _)) 95 EXPECT_CALL(cb, OnCheckWhitelistCompleted(SignedSettings::SUCCESS, _))
92 .Times(1); 96 .Times(1);
93 EXPECT_CALL(m_, StartSigningAttempt(_, _)).Times(1); 97 EXPECT_CALL(m_, StartSigningAttempt(_, _)).Times(1);
94 EXPECT_CALL(cb, OnWhitelistCompleted(true, _)) 98 EXPECT_CALL(cb, OnWhitelistCompleted(SignedSettings::SUCCESS, _))
95 .Times(1); 99 .Times(1);
96 EXPECT_CALL(m_, StartSigningAttempt(_, _)).Times(1); 100 EXPECT_CALL(m_, StartSigningAttempt(_, _)).Times(1);
97 EXPECT_CALL(cb, OnUnwhitelistCompleted(true, _)) 101 EXPECT_CALL(cb, OnUnwhitelistCompleted(SignedSettings::SUCCESS, _))
98 .Times(1); 102 .Times(1);
99 EXPECT_CALL(m_, StartSigningAttempt(_, _)).Times(1); 103 EXPECT_CALL(m_, StartSigningAttempt(_, _)).Times(1);
100 EXPECT_CALL(cb, OnStorePropertyCompleted(true, _, _)) 104 EXPECT_CALL(cb, OnStorePropertyCompleted(SignedSettings::SUCCESS, _, _))
101 .Times(1); 105 .Times(1);
102 EXPECT_CALL(m_, StartVerifyAttempt(_, _, _)).Times(1); 106 EXPECT_CALL(m_, StartVerifyAttempt(_, _, _)).Times(1);
103 EXPECT_CALL(cb, OnRetrievePropertyCompleted(true, _, _)) 107 EXPECT_CALL(cb, OnRetrievePropertyCompleted(SignedSettings::SUCCESS, _, _))
104 .Times(1); 108 .Times(1);
105 109
106 pending_ops_ = 5; 110 pending_ops_ = 5;
107 SignedSettingsHelper::Get()->StartCheckWhitelistOp(fake_email_, &cb); 111 SignedSettingsHelper::Get()->StartCheckWhitelistOp(fake_email_, &cb);
108 SignedSettingsHelper::Get()->StartWhitelistOp(fake_email_, true, &cb); 112 SignedSettingsHelper::Get()->StartWhitelistOp(fake_email_, true, &cb);
109 SignedSettingsHelper::Get()->StartWhitelistOp(fake_email_, false, &cb); 113 SignedSettingsHelper::Get()->StartWhitelistOp(fake_email_, false, &cb);
110 SignedSettingsHelper::Get()->StartStorePropertyOp(fake_prop_, fake_value_, 114 SignedSettingsHelper::Get()->StartStorePropertyOp(fake_prop_, fake_value_,
111 &cb); 115 &cb);
112 SignedSettingsHelper::Get()->StartRetrieveProperty(fake_prop_, &cb); 116 SignedSettingsHelper::Get()->StartRetrieveProperty(fake_prop_, &cb);
113 117
114 message_loop_.Run(); 118 message_loop_.Run();
115 } 119 }
116 120
117 TEST_F(SignedSettingsHelperTest, CanceledOps) { 121 TEST_F(SignedSettingsHelperTest, CanceledOps) {
118 MockSignedSettingsHelperCallback cb; 122 MockSignedSettingsHelperCallback cb;
119 123
120 EXPECT_CALL(m_, IsAlreadyOwned()).Times(2); 124 EXPECT_CALL(m_, IsAlreadyOwned()).Times(2);
121 InSequence s; 125 InSequence s;
122 EXPECT_CALL(m_, StartVerifyAttempt(_, _, _)).Times(1); 126 EXPECT_CALL(m_, StartVerifyAttempt(_, _, _)).Times(1);
123 EXPECT_CALL(cb, OnCheckWhiteListCompleted(true, _)) 127 EXPECT_CALL(cb, OnCheckWhitelistCompleted(SignedSettings::SUCCESS, _))
124 .Times(1); 128 .Times(1);
125 EXPECT_CALL(m_, StartSigningAttempt(_, _)).Times(1); 129 EXPECT_CALL(m_, StartSigningAttempt(_, _)).Times(1);
126 EXPECT_CALL(cb, OnWhitelistCompleted(true, _)) 130 EXPECT_CALL(cb, OnWhitelistCompleted(SignedSettings::SUCCESS, _))
127 .Times(1); 131 .Times(1);
128 EXPECT_CALL(m_, StartSigningAttempt(_, _)).Times(1); 132 EXPECT_CALL(m_, StartSigningAttempt(_, _)).Times(1);
129 EXPECT_CALL(cb, OnUnwhitelistCompleted(true, _)) 133 EXPECT_CALL(cb, OnUnwhitelistCompleted(SignedSettings::SUCCESS, _))
130 .Times(1); 134 .Times(1);
131 135
132 // CheckWhitelistOp for cb_to_be_canceled still gets executed but callback 136 // CheckWhitelistOp for cb_to_be_canceled still gets executed but callback
133 // does not happen. 137 // does not happen.
134 EXPECT_CALL(m_, StartVerifyAttempt(_, _, _)).Times(1); 138 EXPECT_CALL(m_, StartVerifyAttempt(_, _, _)).Times(1);
135 139
136 EXPECT_CALL(m_, StartSigningAttempt(_, _)).Times(1); 140 EXPECT_CALL(m_, StartSigningAttempt(_, _)).Times(1);
137 EXPECT_CALL(cb, OnStorePropertyCompleted(true, _, _)) 141 EXPECT_CALL(cb, OnStorePropertyCompleted(SignedSettings::SUCCESS, _, _))
138 .Times(1); 142 .Times(1);
139 EXPECT_CALL(m_, StartVerifyAttempt(_, _, _)).Times(1); 143 EXPECT_CALL(m_, StartVerifyAttempt(_, _, _)).Times(1);
140 EXPECT_CALL(cb, OnRetrievePropertyCompleted(true, _, _)) 144 EXPECT_CALL(cb, OnRetrievePropertyCompleted(SignedSettings::SUCCESS, _, _))
141 .Times(1); 145 .Times(1);
142 146
143 pending_ops_ = 6; 147 pending_ops_ = 6;
144 SignedSettingsHelper::Get()->StartCheckWhitelistOp(fake_email_, &cb); 148 SignedSettingsHelper::Get()->StartCheckWhitelistOp(fake_email_, &cb);
145 SignedSettingsHelper::Get()->StartWhitelistOp(fake_email_, true, &cb); 149 SignedSettingsHelper::Get()->StartWhitelistOp(fake_email_, true, &cb);
146 SignedSettingsHelper::Get()->StartWhitelistOp(fake_email_, false, &cb); 150 SignedSettingsHelper::Get()->StartWhitelistOp(fake_email_, false, &cb);
147 151
148 MockSignedSettingsHelperCallback cb_to_be_canceled; 152 MockSignedSettingsHelperCallback cb_to_be_canceled;
149 SignedSettingsHelper::Get()->StartCheckWhitelistOp(fake_email_, 153 SignedSettingsHelper::Get()->StartCheckWhitelistOp(fake_email_,
150 &cb_to_be_canceled); 154 &cb_to_be_canceled);
151 SignedSettingsHelper::Get()->CancelCallback(&cb_to_be_canceled); 155 SignedSettingsHelper::Get()->CancelCallback(&cb_to_be_canceled);
152 156
153 SignedSettingsHelper::Get()->StartStorePropertyOp(fake_prop_, fake_value_, 157 SignedSettingsHelper::Get()->StartStorePropertyOp(fake_prop_, fake_value_,
154 &cb); 158 &cb);
155 SignedSettingsHelper::Get()->StartRetrieveProperty(fake_prop_, &cb); 159 SignedSettingsHelper::Get()->StartRetrieveProperty(fake_prop_, &cb);
156 160
157 message_loop_.Run(); 161 message_loop_.Run();
158 } 162 }
159 163
160 } // namespace chromeos 164 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/signed_settings_helper.cc ('k') | chrome/browser/chromeos/login/signed_settings_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698