OLD | NEW |
---|---|
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 #ifndef SERVICES_NATIVE_SUPPORT_PROCESS_TEST_BASE_H_ | 5 #ifndef SERVICES_AUTHENTICATION_ACCOUNTS_DB_MANAGER_H_ |
6 #define SERVICES_NATIVE_SUPPORT_PROCESS_TEST_BASE_H_ | 6 #define SERVICES_AUTHENTICATION_ACCOUNTS_DB_MANAGER_H_ |
7 | 7 |
8 #include <type_traits> | 8 #include <type_traits> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "mojo/public/cpp/application/application_test_base.h" | 11 #include "mojo/services/files/interfaces/files.mojom.h" |
12 #include "mojo/services/native_support/interfaces/process.mojom.h" | |
13 | 12 |
14 namespace native_support { | 13 namespace authentication { |
15 | 14 |
16 // TODO(vtl): Stuff copied from mojo/public/cpp/bindings/lib/template_util.h. | 15 // TODO(ukode): Stuff copied from mojo/public/cpp/bindings/lib/template_util.h. |
jln (very slow on Chromium)
2015/12/08 22:27:29
This should definitely not be in this .h file.
If
ukode
2015/12/16 19:24:13
Acknowledged. +Vtl
| |
17 typedef char YesType; | 16 typedef char YesType; |
18 | 17 |
19 struct NoType { | 18 struct NoType { |
20 YesType dummy[2]; | 19 YesType dummy[2]; |
21 }; | 20 }; |
22 | 21 |
23 template <typename T> | 22 template <typename T> |
24 struct IsMoveOnlyType { | 23 struct IsMoveOnlyType { |
25 template <typename U> | 24 template <typename U> |
26 static YesType Test(const typename U::MoveOnlyTypeForCPP03*); | 25 static YesType Test(const typename U::MoveOnlyTypeForCPP03*); |
27 | 26 |
28 template <typename U> | 27 template <typename U> |
29 static NoType Test(...); | 28 static NoType Test(...); |
30 | 29 |
31 static const bool value = | 30 static const bool value = |
32 sizeof(Test<T>(0)) == sizeof(YesType) && !std::is_const<T>::value; | 31 sizeof(Test<T>(0)) == sizeof(YesType) && !std::is_const<T>::value; |
33 }; | 32 }; |
34 | 33 |
35 template <typename T> | 34 template <typename T> |
36 typename std::enable_if<!IsMoveOnlyType<T>::value, T>::type& Forward(T& t) { | 35 typename std::enable_if<!IsMoveOnlyType<T>::value, T>::type& Forward(T& t) { |
37 return t; | 36 return t; |
38 } | 37 } |
39 | 38 |
40 template <typename T> | 39 template <typename T> |
41 typename std::enable_if<IsMoveOnlyType<T>::value, T>::type Forward(T& t) { | 40 typename std::enable_if<IsMoveOnlyType<T>::value, T>::type Forward(T& t) { |
42 return t.Pass(); | 41 return t.Pass(); |
43 } | 42 } |
44 // TODO(vtl): (End of stuff copied from template_util.h.) | 43 // TODO(ukode): (End of stuff copied from template_util.h.) |
45 | 44 |
46 template <typename T1> | 45 template <typename T1> |
47 mojo::Callback<void(T1)> Capture(T1* t1) { | 46 mojo::Callback<void(T1)> Capture(T1* t1) { |
48 return [t1](T1 got_t1) { *t1 = Forward(got_t1); }; | 47 return [t1](T1 got_t1) { *t1 = Forward(got_t1); }; |
49 } | 48 } |
50 | 49 |
51 template <typename T1, typename T2> | 50 template <typename T1, typename T2> |
52 mojo::Callback<void(T1, T2)> Capture(T1* t1, T2* t2) { | 51 mojo::Callback<void(T1, T2)> Capture(T1* t1, T2* t2) { |
53 return [t1, t2](T1 got_t1, T2 got_t2) { | 52 return [t1, t2](T1 got_t1, T2 got_t2) { |
54 *t1 = Forward(got_t1); | 53 *t1 = Forward(got_t1); |
55 *t2 = Forward(got_t2); | 54 *t2 = Forward(got_t2); |
56 }; | 55 }; |
57 } | 56 } |
58 | 57 |
59 class ProcessTestBase : public mojo::test::ApplicationTestBase { | 58 class AccountsDbManager { |
jln (very slow on Chromium)
2015/12/08 22:27:29
Please, document your class and methods as per sty
ukode
2015/12/16 19:24:13
Done.
| |
60 public: | 59 public: |
61 ProcessTestBase(); | 60 AccountsDbManager(); |
62 ~ProcessTestBase() override; | 61 explicit AccountsDbManager(mojo::files::FilesPtr files); |
62 ~AccountsDbManager(); | |
63 | 63 |
64 void SetUp() override; | 64 bool UpdateAccount(const mojo::String& username, |
65 | 65 const mojo::String& account_data); |
66 protected: | 66 void GetAccountDataForUser(const mojo::String& username, |
67 ProcessPtr& process() { return process_; } | 67 mojo::String& user_data); |
68 mojo::Array<uint8_t> FetchAllAccounts(); | |
68 | 69 |
69 private: | 70 private: |
70 ProcessPtr process_; | 71 bool checkIfUserExists(const std::string& user_data); |
jln (very slow on Chromium)
2015/12/08 22:27:29
This method looks unimplemented, no?
jln (very slow on Chromium)
2015/12/08 22:27:29
nit: Capital C in CheckIfUserExists)
ukode
2015/12/16 19:24:13
Good catch, Had it before, later removed it as it
ukode
2015/12/16 19:24:13
Done.
| |
72 mojo::files::DirectoryPtr directory_; | |
jln (very slow on Chromium)
2015/12/08 22:27:29
Nit: vertical space
ukode
2015/12/16 19:24:13
Done.
| |
73 std::string contents_; | |
71 | 74 |
72 DISALLOW_COPY_AND_ASSIGN(ProcessTestBase); | 75 DISALLOW_COPY_AND_ASSIGN(AccountsDbManager); |
73 }; | 76 }; |
74 | 77 |
75 } // namespace native_support | 78 } // namespace authentication |
76 | 79 |
77 #endif // SERVICES_NATIVE_SUPPORT_PROCESS_TEST_BASE_H_ | 80 #endif // SERVICES_AUTHENTICATION_ACCOUNTS_DB_MANAGER_H_ |
OLD | NEW |