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

Unified Diff: chrome/test/data/extensions/api_test/feedback_private/read_log_source_rate_limited/test.js

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/test/data/extensions/api_test/feedback_private/read_log_source_rate_limited/test.js
diff --git a/chrome/test/data/extensions/api_test/feedback_private/read_log_source_rate_limited/test.js b/chrome/test/data/extensions/api_test/feedback_private/read_log_source_rate_limited/test.js
new file mode 100644
index 0000000000000000000000000000000000000000..e176df2958e79f2ad8b7edff3827e2b823b942db
--- /dev/null
+++ b/chrome/test/data/extensions/api_test/feedback_private/read_log_source_rate_limited/test.js
@@ -0,0 +1,83 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+var alarmCount = 0;
+// When a log source has returned this many nonzero results, end test.
+var maxNonZeroReadCount = 3;
+
+function incrementalReadRateLimited() {
+ var incrementalParams1 =
+ {source: "messages", readerId: 0, incremental: true};
+ var incrementalParams2 =
+ {source: "ui_latest", readerId: 0, incremental: true};
+
+ // Count the number of times that readLogSource() returned a non-empty result.
+ var numValidReads1 = 0;
+ var numValidReads2 = 0;
+
+ var waitForAlarms = chrome.test.listenForever(
+ chrome.alarms.onAlarm,
+ function(alarm) {
+ console.log("Alarm count: " + alarmCount);
+
+ if (numValidReads1 < maxNonZeroReadCount) {
+ chrome.feedbackPrivate.readLogSource(
+ incrementalParams1,
+ function(count, readerId, response) {
+ if (response.length > 0)
+ ++numValidReads1;
+
+ if (!incrementalParams1.readerId) {
+ incrementalParams1.readerId = readerId;
+ }
+ }.bind(null, alarmCount));
+ }
+ if (numValidReads2 < maxNonZeroReadCount) {
+ chrome.feedbackPrivate.readLogSource(
+ incrementalParams2,
+ function(count, readerId, response) {
+ if (response.length > 0)
+ ++numValidReads2;
+
+ if (!incrementalParams2.readerId) {
+ incrementalParams2.readerId = readerId;
+ }
+ }.bind(null, alarmCount));
+ }
+ // End the test when the number of nonzero reads has reached the limit.
+ if (numValidReads1 >= maxNonZeroReadCount &&
+ numValidReads2 >= maxNonZeroReadCount) {
+ console.log("Single incremental done");
+ chrome.alarms.clearAll();
+
+ // This test was attempting read faster than the max rate limit. Make
+ // sure that some reads did not result in non-empty results.
+ chrome.test.assertTrue(numValidReads1 < alarmCount);
+ chrome.test.assertTrue(numValidReads2 < alarmCount);
+
+ // Close the log sources by passing in incremental = false.
+ incrementalParams1.incremental = false;
+ incrementalParams2.incremental = false;
+ var cleanupFunc = function(readerId, response) {
+ chrome.test.assertEq(readerId, 0);
+ }
+ chrome.feedbackPrivate.readLogSource(incrementalParams1, cleanupFunc);
+ chrome.feedbackPrivate.readLogSource(incrementalParams2, cleanupFunc);
+
+ waitForAlarms();
+ }
+ ++alarmCount;
+ });
+}
+
+function runTestWithAlarm(testFunc, period) {
+ alarmCount = 0;
+ chrome.alarms.create("test_alarm",
+ {delayInMinutes: 0.0, periodInMinutes: period});
+ testFunc();
+}
+
+chrome.test.runTests([
+ runTestWithAlarm.bind(null, incrementalReadRateLimited, 0.01)
+]);

Powered by Google App Engine
This is Rietveld 408576698