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

Unified Diff: chrome/browser/extensions/chrome_extension_function_unittest.cc

Issue 2118473002: 😴 Skip some KeepAlive registrations on shutdown. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 5 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/chrome_extension_function_unittest.cc
diff --git a/chrome/browser/extensions/chrome_extension_function_unittest.cc b/chrome/browser/extensions/chrome_extension_function_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..090f5f0e9566d909ed456687bd2d79690a94a930
--- /dev/null
+++ b/chrome/browser/extensions/chrome_extension_function_unittest.cc
@@ -0,0 +1,80 @@
+// Copyright 2016 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.
+
+#include <memory>
+
+#include "chrome/browser/extensions/extension_service_test_base.h"
+#include "chrome/test/base/testing_browser_process.h"
+#include "extensions/browser/extension_function.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace extensions {
+
+namespace {
+
+int g_callback_runs = 0;
Devlin 2016/07/15 17:59:39 global variables are pretty fragile in unittests t
dgn 2016/07/18 14:44:04 Thanks! I didn't think about using Bind like that.
+
+void SuccessCallback(ExtensionFunction::ResponseType type,
+ const base::ListValue& results,
+ const std::string& error,
+ functions::HistogramValue histogram_value) {
+ EXPECT_EQ(ExtensionFunction::ResponseType::SUCCEEDED, type);
+ ++g_callback_runs;
+}
+
+void FailCallback(ExtensionFunction::ResponseType type,
+ const base::ListValue& results,
+ const std::string& error,
+ functions::HistogramValue histogram_value) {
+ EXPECT_EQ(ExtensionFunction::ResponseType::FAILED, type);
+ ++g_callback_runs;
+}
+
+} // namespace
+
+class ChromeExtensionFunctionUnitTest : public ExtensionServiceTestBase {
+
+ public:
+ void TearDown() override {
+ g_callback_runs = 0;
+ ExtensionServiceTestBase::TearDown();
+ }
+
+};
+
+class ValidationFunction : public UIThreadExtensionFunction {
+ public:
+ explicit ValidationFunction(bool should_succeed)
+ : should_succeed_(should_succeed) {
+ set_response_callback(should_succeed ? base::Bind(&SuccessCallback)
+ : base::Bind(&FailCallback));
+ }
+
+ ResponseAction Run() override {
+ EXPECT_TRUE(should_succeed_);
+ return RespondNow(NoArguments());
+ }
+
+ private:
+ ~ValidationFunction() override {}
+ bool should_succeed_;
+};
+
+
+
+TEST_F(ChromeExtensionFunctionUnitTest, SimpleFunctionTest) {
+ scoped_refptr<ExtensionFunction> function(new ValidationFunction(true));
+ function->RunWithValidation()->Execute();
+ EXPECT_EQ(1, g_callback_runs);
+}
+
+TEST_F(ChromeExtensionFunctionUnitTest, BrowserShutdownValidationFunctionTest) {
+ TestingBrowserProcess::GetGlobal()->SetShuttingDown(true);
+ scoped_refptr<ExtensionFunction> function(new ValidationFunction(false));
+ function->RunWithValidation()->Execute();
+ TestingBrowserProcess::GetGlobal()->SetShuttingDown(false);
+ EXPECT_EQ(1, g_callback_runs);
+}
+
+} // namespace extensions

Powered by Google App Engine
This is Rietveld 408576698