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

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: use ExtensionsBrowserClient 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..c1370690f0fe4af754b8228a9bba42e6ec70121a
--- /dev/null
+++ b/chrome/browser/extensions/chrome_extension_function_unittest.cc
@@ -0,0 +1,62 @@
+// 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 {
+
+void SuccessCallback(AsyncExtensionFunction::ResponseType type,
Devlin 2016/07/13 20:23:16 prefer ExtensionFunction::ResponseType
Devlin 2016/07/13 20:23:16 nit: put these in an anonymous namespace.
dgn 2016/07/13 20:40:54 Done.
dgn 2016/07/13 20:40:54 Done.
+ const base::ListValue& results,
+ const std::string& error,
+ functions::HistogramValue histogram_value) {
+ EXPECT_EQ(ExtensionFunction::ResponseType::SUCCEEDED, type);
Devlin 2016/07/13 20:23:16 It would be good to assert that these functions di
dgn 2016/07/13 20:40:54 Done.
+}
+
+void FailCallback(AsyncExtensionFunction::ResponseType type,
+ const base::ListValue& results,
+ const std::string& error,
+ functions::HistogramValue histogram_value) {
+ EXPECT_EQ(ExtensionFunction::ResponseType::FAILED, type);
+}
+
+class ChromeExtensionFunctionUnitTest : public ExtensionServiceTestBase {};
Devlin 2016/07/13 20:23:16 nit: Prefer using ChromeExtensionFunctionUnitTest
dgn 2016/07/13 20:40:54 Added TearDown to the class.
+
+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();
+}
+
+TEST_F(ChromeExtensionFunctionUnitTest, BrowserShutdownValidationFunctionTest) {
+ TestingBrowserProcess::GetGlobal()->SetShuttingDown(true);
+ scoped_refptr<ExtensionFunction> function(new ValidationFunction(false));
+ function->RunWithValidation()->Execute();
+ TestingBrowserProcess::GetGlobal()->SetShuttingDown(false);
+}
+
+} // 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