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 |