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

Side by Side Diff: chrome/browser/extensions/api/feedback_private/log_source_access_manager_chromeos_unittest.cc

Issue 2956513004: Rename SingleLogSource to SingleLogFileLogSource (Closed)
Patch Set: Simplify aliases; revert unintended IDL change Created 3 years, 6 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/extensions/api/feedback_private/log_source_access_manag er.h" 5 #include "chrome/browser/extensions/api/feedback_private/log_source_access_manag er.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/strings/stringprintf.h" 10 #include "base/strings/stringprintf.h"
11 #include "chrome/browser/extensions/api/feedback_private/log_source_resource.h" 11 #include "chrome/browser/extensions/api/feedback_private/log_source_resource.h"
12 #include "chrome/browser/extensions/api/feedback_private/single_log_source_facto ry.h" 12 #include "chrome/browser/extensions/api/feedback_private/single_log_source_facto ry.h"
13 #include "chrome/browser/extensions/extension_api_unittest.h" 13 #include "chrome/browser/extensions/extension_api_unittest.h"
14 #include "extensions/browser/api/api_resource_manager.h" 14 #include "extensions/browser/api/api_resource_manager.h"
15 15
16 namespace extensions { 16 namespace extensions {
17 17
18 namespace { 18 namespace {
19 19
20 using api::feedback_private::LOG_SOURCE_MESSAGES; 20 using api::feedback_private::LOG_SOURCE_MESSAGES;
21 using api::feedback_private::LOG_SOURCE_UILATEST; 21 using api::feedback_private::LOG_SOURCE_UILATEST;
22 using api::feedback_private::LogSource;
22 using api::feedback_private::ReadLogSourceResult; 23 using api::feedback_private::ReadLogSourceResult;
23 using api::feedback_private::ReadLogSourceParams; 24 using api::feedback_private::ReadLogSourceParams;
24 using system_logs::SingleLogSource; 25 using system_logs::SystemLogsSource;
25 using SupportedSource = system_logs::SingleLogSource::SupportedSource;
26 26
27 std::unique_ptr<KeyedService> ApiResourceManagerTestFactory( 27 std::unique_ptr<KeyedService> ApiResourceManagerTestFactory(
28 content::BrowserContext* context) { 28 content::BrowserContext* context) {
29 return base::MakeUnique<ApiResourceManager<LogSourceResource>>(context); 29 return base::MakeUnique<ApiResourceManager<LogSourceResource>>(context);
30 } 30 }
31 31
32 // Dummy function used as a callback for FetchFromSource(). 32 // Dummy function used as a callback for FetchFromSource().
33 void OnFetchedFromSource(const ReadLogSourceResult& result) {} 33 void OnFetchedFromSource(const ReadLogSourceResult& result) {}
34 34
35 // A dummy SingleLogSource that does not require real system logs to be 35 // A dummy SystemLogsSource that does not require real system logs to be
36 // available during testing. Always returns an empty result. 36 // available during testing. Always returns an empty result.
37 class EmptySingleLogSource : public SingleLogSource { 37 class EmptySingleLogSource : public system_logs::SystemLogsSource {
38 public: 38 public:
39 explicit EmptySingleLogSource(SupportedSource type) : SingleLogSource(type) {} 39 explicit EmptySingleLogSource(LogSource type)
40 : SystemLogsSource(api::feedback_private::ToString(type)) {}
40 41
41 ~EmptySingleLogSource() override = default; 42 ~EmptySingleLogSource() override = default;
42 43
43 void Fetch(const system_logs::SysLogsSourceCallback& callback) override { 44 void Fetch(const system_logs::SysLogsSourceCallback& callback) override {
44 system_logs::SystemLogsResponse* result_map = 45 system_logs::SystemLogsResponse* result_map =
45 new system_logs::SystemLogsResponse; 46 new system_logs::SystemLogsResponse;
46 result_map->emplace("", ""); 47 result_map->emplace("", "");
47 48
48 // Do not directly pass the result to the callback, because that's not how 49 // Do not directly pass the result to the callback, because that's not how
49 // log sources actually work. Instead, simulate the asynchronous operation 50 // log sources actually work. Instead, simulate the asynchronous operation
50 // of a SingleLogSource by invoking the callback separately. 51 // of a SystemLogsSource by invoking the callback separately.
51 base::ThreadTaskRunnerHandle::Get()->PostTask( 52 base::ThreadTaskRunnerHandle::Get()->PostTask(
52 FROM_HERE, base::Bind(callback, base::Owned(result_map))); 53 FROM_HERE, base::Bind(callback, base::Owned(result_map)));
53 } 54 }
54 55
55 // Instantiates a new instance of this class. Does not retain ownership. Used 56 // Instantiates a new instance of this class. Does not retain ownership. Used
56 // to create a Callback that can be used to override the default behavior of 57 // to create a Callback that can be used to override the default behavior of
57 // SingleLogSourceFactory. 58 // SingleLogSourceFactory.
58 static std::unique_ptr<SingleLogSource> Create(SupportedSource type) { 59 static std::unique_ptr<SystemLogsSource> Create(LogSource type) {
59 return base::MakeUnique<EmptySingleLogSource>(type); 60 return std::unique_ptr<SystemLogsSource>(new EmptySingleLogSource(type));
afakhry 2017/06/24 00:10:16 By the way MakeUnique<EmptySingleLogSource> should
Simon Que 2017/07/10 14:10:13 Done.
60 } 61 }
61 62
62 private: 63 private:
63 DISALLOW_COPY_AND_ASSIGN(EmptySingleLogSource); 64 DISALLOW_COPY_AND_ASSIGN(EmptySingleLogSource);
64 }; 65 };
65 66
66 } // namespace 67 } // namespace
67 68
68 class LogSourceAccessManagerTest : public ExtensionApiUnittest { 69 class LogSourceAccessManagerTest : public ExtensionApiUnittest {
69 public: 70 public:
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 << count; 151 << count;
151 } 152 }
152 EXPECT_EQ(10U, manager.GetNumActiveResourcesForSource(LOG_SOURCE_MESSAGES)); 153 EXPECT_EQ(10U, manager.GetNumActiveResourcesForSource(LOG_SOURCE_MESSAGES));
153 EXPECT_EQ(10U, manager.GetNumActiveResourcesForSource(LOG_SOURCE_UILATEST)); 154 EXPECT_EQ(10U, manager.GetNumActiveResourcesForSource(LOG_SOURCE_UILATEST));
154 155
155 // Wait for all asynchronous operations to complete. 156 // Wait for all asynchronous operations to complete.
156 base::RunLoop().RunUntilIdle(); 157 base::RunLoop().RunUntilIdle();
157 } 158 }
158 159
159 } // namespace extensions 160 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698