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

Side by Side Diff: extensions/renderer/mojo/keep_alive_client_unittest.cc

Issue 2409073002: Use mojo from the PDF extension instead of using an extension API.
Patch Set: Created 4 years, 2 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 | « extensions/renderer/module_system.cc ('k') | extensions/renderer/resources/binding.js » ('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 2014 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 <utility>
6
7 #include "base/macros.h"
8 #include "extensions/common/mojo/keep_alive.mojom.h"
9 #include "extensions/renderer/api_test_base.h"
10 #include "grit/extensions_renderer_resources.h"
11 #include "mojo/public/cpp/bindings/strong_binding.h"
12
13 // A test launcher for tests for the stash client defined in
14 // extensions/test/data/keep_alive_client_unittest.js.
15
16 namespace extensions {
17 namespace {
18
19 // A KeepAlive implementation that calls provided callbacks on creation and
20 // destruction.
21 class TestKeepAlive : public KeepAlive {
22 public:
23 explicit TestKeepAlive(const base::Closure& on_destruction)
24 : on_destruction_(on_destruction) {}
25
26 ~TestKeepAlive() override { on_destruction_.Run(); }
27
28 static void Create(const base::Closure& on_creation,
29 const base::Closure& on_destruction,
30 KeepAliveRequest keep_alive) {
31 mojo::MakeStrongBinding(base::MakeUnique<TestKeepAlive>(on_destruction),
32 std::move(keep_alive));
33 on_creation.Run();
34 }
35
36 private:
37 const base::Closure on_destruction_;
38 };
39
40 } // namespace
41
42 class KeepAliveClientTest : public ApiTestBase {
43 public:
44 KeepAliveClientTest() {}
45
46 void SetUp() override {
47 ApiTestBase::SetUp();
48 interface_provider()->AddInterface(
49 base::Bind(&TestKeepAlive::Create,
50 base::Bind(&KeepAliveClientTest::KeepAliveCreated,
51 base::Unretained(this)),
52 base::Bind(&KeepAliveClientTest::KeepAliveDestroyed,
53 base::Unretained(this))));
54 created_keep_alive_ = false;
55 destroyed_keep_alive_ = false;
56 }
57
58 void WaitForKeepAlive() {
59 // Wait for a keep-alive to be created and destroyed.
60 while (!created_keep_alive_ || !destroyed_keep_alive_) {
61 base::RunLoop run_loop;
62 stop_run_loop_ = run_loop.QuitClosure();
63 run_loop.Run();
64 }
65 EXPECT_TRUE(created_keep_alive_);
66 EXPECT_TRUE(destroyed_keep_alive_);
67 }
68
69 private:
70 void KeepAliveCreated() {
71 created_keep_alive_ = true;
72 if (!stop_run_loop_.is_null())
73 stop_run_loop_.Run();
74 }
75 void KeepAliveDestroyed() {
76 destroyed_keep_alive_ = true;
77 if (!stop_run_loop_.is_null())
78 stop_run_loop_.Run();
79 }
80
81 bool created_keep_alive_;
82 bool destroyed_keep_alive_;
83 base::Closure stop_run_loop_;
84
85 DISALLOW_COPY_AND_ASSIGN(KeepAliveClientTest);
86 };
87
88 TEST_F(KeepAliveClientTest, KeepAliveWithSuccessfulCall) {
89 RunTest("keep_alive_client_unittest.js", "testKeepAliveWithSuccessfulCall");
90 WaitForKeepAlive();
91 }
92
93 TEST_F(KeepAliveClientTest, KeepAliveWithError) {
94 RunTest("keep_alive_client_unittest.js", "testKeepAliveWithError");
95 WaitForKeepAlive();
96 }
97
98 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/module_system.cc ('k') | extensions/renderer/resources/binding.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698