OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include <memory> | |
6 | |
7 #include "chrome/browser/extensions/extension_service_test_base.h" | |
8 #include "chrome/test/base/testing_browser_process.h" | |
9 #include "extensions/browser/extension_function.h" | |
10 #include "testing/gtest/include/gtest/gtest.h" | |
11 | |
12 namespace extensions { | |
13 | |
14 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.
| |
15 const base::ListValue& results, | |
16 const std::string& error, | |
17 functions::HistogramValue histogram_value) { | |
18 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.
| |
19 } | |
20 | |
21 void FailCallback(AsyncExtensionFunction::ResponseType type, | |
22 const base::ListValue& results, | |
23 const std::string& error, | |
24 functions::HistogramValue histogram_value) { | |
25 EXPECT_EQ(ExtensionFunction::ResponseType::FAILED, type); | |
26 } | |
27 | |
28 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.
| |
29 | |
30 class ValidationFunction : public UIThreadExtensionFunction { | |
31 public: | |
32 explicit ValidationFunction(bool should_succeed) | |
33 : should_succeed_(should_succeed) { | |
34 set_response_callback(should_succeed ? base::Bind(&SuccessCallback) | |
35 : base::Bind(&FailCallback)); | |
36 } | |
37 | |
38 ResponseAction Run() override { | |
39 EXPECT_TRUE(should_succeed_); | |
40 return RespondNow(NoArguments()); | |
41 } | |
42 | |
43 private: | |
44 ~ValidationFunction() override {} | |
45 bool should_succeed_; | |
46 }; | |
47 | |
48 | |
49 | |
50 TEST_F(ChromeExtensionFunctionUnitTest, SimpleFunctionTest) { | |
51 scoped_refptr<ExtensionFunction> function(new ValidationFunction(true)); | |
52 function->RunWithValidation()->Execute(); | |
53 } | |
54 | |
55 TEST_F(ChromeExtensionFunctionUnitTest, BrowserShutdownValidationFunctionTest) { | |
56 TestingBrowserProcess::GetGlobal()->SetShuttingDown(true); | |
57 scoped_refptr<ExtensionFunction> function(new ValidationFunction(false)); | |
58 function->RunWithValidation()->Execute(); | |
59 TestingBrowserProcess::GetGlobal()->SetShuttingDown(false); | |
60 } | |
61 | |
62 } // namespace extensions | |
OLD | NEW |