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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/lifetime/scoped_keep_alive.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 namespace {
15
16 void SuccessCallback(bool* did_respond,
17 ExtensionFunction::ResponseType type,
18 const base::ListValue& results,
19 const std::string& error,
20 functions::HistogramValue histogram_value) {
21 EXPECT_EQ(ExtensionFunction::ResponseType::SUCCEEDED, type);
22 *did_respond = true;
23 }
24
25 void FailCallback(bool* did_respond,
26 ExtensionFunction::ResponseType type,
27 const base::ListValue& results,
28 const std::string& error,
29 functions::HistogramValue histogram_value) {
30 EXPECT_EQ(ExtensionFunction::ResponseType::FAILED, type);
31 *did_respond = true;
32 }
33
34 class ValidationFunction : public UIThreadExtensionFunction {
35 public:
36 explicit ValidationFunction(bool should_succeed)
37 : should_succeed_(should_succeed), did_respond_(false) {
38 set_response_callback(base::Bind(
39 (should_succeed ? &SuccessCallback : &FailCallback), &did_respond_));
40 }
41
42 ResponseAction Run() override {
43 EXPECT_TRUE(should_succeed_);
44 return RespondNow(NoArguments());
45 }
46
47 bool did_respond() { return did_respond_; }
48
49 private:
50 ~ValidationFunction() override {}
51 bool should_succeed_;
52 bool did_respond_;
53 };
54 } // namespace
55
56 using ChromeExtensionFunctionUnitTest = ExtensionServiceTestBase;
57
58 TEST_F(ChromeExtensionFunctionUnitTest, SimpleFunctionTest) {
59 scoped_refptr<ValidationFunction> function(new ValidationFunction(true));
60 function->RunWithValidation()->Execute();
61 EXPECT_TRUE(function->did_respond());
62 }
63
64 TEST_F(ChromeExtensionFunctionUnitTest, BrowserShutdownValidationFunctionTest) {
65 TestingBrowserProcess::GetGlobal()->SetShuttingDown(true);
66 scoped_refptr<ValidationFunction> function(new ValidationFunction(false));
67 function->RunWithValidation()->Execute();
68 TestingBrowserProcess::GetGlobal()->SetShuttingDown(false);
69 EXPECT_TRUE(function->did_respond());
70 }
71
72 } // namespace extensions
OLDNEW
« 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