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

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
« no previous file with comments | « no previous file | chrome/browser/lifetime/scoped_keep_alive.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..fa681c239899613d6b5c34ba73d2d8e3a696a388
--- /dev/null
+++ b/chrome/browser/extensions/chrome_extension_function_unittest.cc
@@ -0,0 +1,72 @@
+// 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 {
+
+void SuccessCallback(bool* did_respond,
+ ExtensionFunction::ResponseType type,
+ const base::ListValue& results,
+ const std::string& error,
+ functions::HistogramValue histogram_value) {
+ EXPECT_EQ(ExtensionFunction::ResponseType::SUCCEEDED, type);
+ *did_respond = true;
+}
+
+void FailCallback(bool* did_respond,
+ ExtensionFunction::ResponseType type,
+ const base::ListValue& results,
+ const std::string& error,
+ functions::HistogramValue histogram_value) {
+ EXPECT_EQ(ExtensionFunction::ResponseType::FAILED, type);
+ *did_respond = true;
+}
+
+class ValidationFunction : public UIThreadExtensionFunction {
+ public:
+ explicit ValidationFunction(bool should_succeed)
+ : should_succeed_(should_succeed), did_respond_(false) {
+ set_response_callback(base::Bind(
+ (should_succeed ? &SuccessCallback : &FailCallback), &did_respond_));
+ }
+
+ ResponseAction Run() override {
+ EXPECT_TRUE(should_succeed_);
+ return RespondNow(NoArguments());
+ }
+
+ bool did_respond() { return did_respond_; }
+
+ private:
+ ~ValidationFunction() override {}
+ bool should_succeed_;
+ bool did_respond_;
+};
+} // namespace
+
+using ChromeExtensionFunctionUnitTest = ExtensionServiceTestBase;
+
+TEST_F(ChromeExtensionFunctionUnitTest, SimpleFunctionTest) {
+ scoped_refptr<ValidationFunction> function(new ValidationFunction(true));
+ function->RunWithValidation()->Execute();
+ EXPECT_TRUE(function->did_respond());
+}
+
+TEST_F(ChromeExtensionFunctionUnitTest, BrowserShutdownValidationFunctionTest) {
+ TestingBrowserProcess::GetGlobal()->SetShuttingDown(true);
+ scoped_refptr<ValidationFunction> function(new ValidationFunction(false));
+ function->RunWithValidation()->Execute();
+ TestingBrowserProcess::GetGlobal()->SetShuttingDown(false);
+ EXPECT_TRUE(function->did_respond());
+}
+
+} // namespace extensions
« no previous file with comments | « no previous file | chrome/browser/lifetime/scoped_keep_alive.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698