summaryrefslogtreecommitdiffstats
path: root/extensions/renderer/api/mojo_private/mojo_private_unittest.cc
blob: 344cbe9da6c5d2f556af0c42b7f23e898c2f77b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright 2015 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 "extensions/renderer/api_test_base.h"

#include "base/macros.h"
#include "gin/modules/module_registry.h"

// A test launcher for tests for the mojoPrivate API defined in
// extensions/test/data/mojo_private_unittest.js.

namespace extensions {

class MojoPrivateApiTest : public ApiTestBase {
 public:
  MojoPrivateApiTest() = default;

  gin::ModuleRegistry* module_registry() {
    return gin::ModuleRegistry::From(env()->context()->v8_context());
  }

 private:
  DISALLOW_COPY_AND_ASSIGN(MojoPrivateApiTest);
};

TEST_F(MojoPrivateApiTest, Define) {
  ASSERT_NO_FATAL_FAILURE(RunTest("mojo_private_unittest.js", "testDefine"));
  EXPECT_EQ(1u, module_registry()->available_modules().count("testModule"));
}

TEST_F(MojoPrivateApiTest, DefineRegistersModule) {
  ASSERT_NO_FATAL_FAILURE(
      RunTest("mojo_private_unittest.js", "testDefineRegistersModule"));
  EXPECT_EQ(1u, module_registry()->available_modules().count("testModule"));
  EXPECT_EQ(1u, module_registry()->available_modules().count("dependency"));
}

TEST_F(MojoPrivateApiTest, DefineModuleDoesNotExist) {
  ASSERT_NO_FATAL_FAILURE(
      RunTest("mojo_private_unittest.js", "testDefineModuleDoesNotExist"));
  EXPECT_EQ(0u, module_registry()->available_modules().count("testModule"));
  EXPECT_EQ(0u,
            module_registry()->available_modules().count("does not exist!"));
  EXPECT_EQ(1u, module_registry()->unsatisfied_dependencies().count(
                    "does not exist!"));
}

TEST_F(MojoPrivateApiTest, RequireAsync) {
  ASSERT_NO_FATAL_FAILURE(
      RunTest("mojo_private_unittest.js", "testRequireAsync"));
}

TEST_F(MojoPrivateApiTest, DefineAndRequire) {
  ASSERT_NO_FATAL_FAILURE(
      RunTest("mojo_private_unittest.js", "testDefineAndRequire"));
}

}  // namespace extensions