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

Unified Diff: chrome/browser/extensions/api/feedback_private/feedback_private_apitest.cc

Issue 2840103002: Add new API function: feedbackPrivate.readLogSource (Closed)
Patch Set: Addressed comments from Patch Set 4 Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/api/feedback_private/feedback_private_apitest.cc
diff --git a/chrome/browser/extensions/api/feedback_private/feedback_private_apitest.cc b/chrome/browser/extensions/api/feedback_private/feedback_private_apitest.cc
index de42a7ec285ea2d6665e4efe2a1d94c57cf50062..f0cd4fba6f3359cc2ec84792c17da1ec8adefa03 100644
--- a/chrome/browser/extensions/api/feedback_private/feedback_private_apitest.cc
+++ b/chrome/browser/extensions/api/feedback_private/feedback_private_apitest.cc
@@ -2,21 +2,120 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/macros.h"
#include "base/message_loop/message_loop.h"
+#include "base/task_scheduler/post_task.h"
#include "build/build_config.h"
#include "chrome/browser/extensions/api/feedback_private/feedback_private_api.h"
+#include "chrome/browser/extensions/api/feedback_private/single_log_source_factory.h"
#include "chrome/browser/extensions/extension_apitest.h"
namespace extensions {
+namespace {
+
+using system_logs::SingleLogSource;
+using system_logs::SystemLogsResponse;
+using SupportedSource = system_logs::SingleLogSource::SupportedSource;
+
+// A dummy SingleLogSource that does not require real system logs to be
+// available during testing.
+class TestSingleLogSource : public SingleLogSource {
+ public:
+ explicit TestSingleLogSource(SupportedSource type)
+ : SingleLogSource(type), call_count_(0) {}
+
+ ~TestSingleLogSource() override {}
+
+ // Fetch() will return a single different string each time, in the following
+ // sequence: "a", "bb", "ccc", until a string of 26 z's. Will never return an
+ // empty result.
+ void Fetch(const system_logs::SysLogsSourceCallback& callback) override {
+ int count_modulus = call_count_ % kNumCharsToIterate;
+ std::string result(count_modulus + 1, kInitialChar + count_modulus);
+ CHECK_GT(result.size(), 0U);
+ ++call_count_;
+
+ SystemLogsResponse* result_map = new SystemLogsResponse;
+ result_map->emplace("", result);
+
+ // Do not directly pass the result to the callback, because that's not how
+ // log sources actually work. Instead, simulate the asynchronous operation
+ // of a SingleLogSource by invoking the callback separately.
+ base::PostDelayedTaskWithTraits(
+ FROM_HERE, base::TaskPriority::BACKGROUND,
+ base::Bind(callback, base::Owned(result_map)),
+ base::TimeDelta::FromMilliseconds(0));
+ }
+
+ // Instantiates a new instance of this class. Does not retain ownership. Used
+ // to create a Callback that can be used to override the default behavior of
+ // SingleLogSourceFactory.
+ static SingleLogSource* Create(SupportedSource type) {
+ return new TestSingleLogSource(type);
+ }
+
+ private:
+ // Iterate over the whole lowercase alphabet, starting from 'a'.
+ const int kNumCharsToIterate = 26;
+ const char kInitialChar = 'a';
+
+ // Keep track of how many times Fetch() has been called, in order to determine
+ // its behavior each time.
+ int call_count_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestSingleLogSource);
+};
+
+} // namespace
+
class FeedbackApiTest: public ExtensionApiTest {
public:
FeedbackApiTest() {}
~FeedbackApiTest() override {}
+
+#if defined(OS_CHROMEOS)
+ void SetUp() override {
+ ExtensionApiTest::SetUp();
+
+ create_callback_ = base::Bind(&TestSingleLogSource::Create);
+ SingleLogSourceFactory::InitForTesting(&create_callback_);
+ }
+
+ void TearDown() override {
+ SingleLogSourceFactory::InitForTesting(nullptr);
+ FeedbackPrivateReadLogSourceFunction::SetRateLimitingTimeoutForTesting(
+ nullptr);
+
+ ExtensionApiTest::TearDown();
+ }
+
+ protected:
+ SingleLogSourceFactory::CreateCallback create_callback_;
+#endif // defined(OS_CHROMEOS)
};
IN_PROC_BROWSER_TEST_F(FeedbackApiTest, Basic) {
EXPECT_TRUE(RunExtensionTest("feedback_private/basic")) << message_;
}
+#if defined(OS_CHROMEOS)
+IN_PROC_BROWSER_TEST_F(FeedbackApiTest, ReadLogSource) {
+ const base::TimeDelta timeout(base::TimeDelta::FromMilliseconds(0));
+ FeedbackPrivateReadLogSourceFunction::SetRateLimitingTimeoutForTesting(
+ &timeout);
+
+ EXPECT_TRUE(RunExtensionTest("feedback_private/read_log_source")) << message_;
+}
+
+IN_PROC_BROWSER_TEST_F(FeedbackApiTest, ReadLogSourceRateLimited) {
+ const base::TimeDelta timeout(base::TimeDelta::FromMilliseconds(2000));
+ FeedbackPrivateReadLogSourceFunction::SetRateLimitingTimeoutForTesting(
+ &timeout);
+
+ EXPECT_TRUE(RunExtensionTest("feedback_private/read_log_source_rate_limited"))
+ << message_;
+}
+#endif // defined(OS_CHROMEOS)
+
} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698