Make hitting "Enter" submit the add/change profile dialog.
[chromium-blink-merge.git] / chrome / test / base / module_system_test.h
blob457832b05b69fe633b5c6570322476dc0203b4cf
1 // Copyright (c) 2012 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.
5 #ifndef CHROME_TEST_BASE_MODULE_SYSTEM_TEST_H_
6 #define CHROME_TEST_BASE_MODULE_SYSTEM_TEST_H_
8 #include "chrome/renderer/extensions/module_system.h"
9 #include "v8/include/v8.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 class AssertNatives;
13 class StringSourceMap;
15 // Test fixture for testing JS that makes use of the module system.
17 // Typically tests will look like:
19 // TEST_F(MyModuleSystemTest, TestStuff) {
20 // ModuleSystem::NativesEnabledScope natives_enabled(module_system_.get());
21 // RegisterModule("test", "requireNative('assert').AssertTrue(true);");
22 // module_system_->Require("test");
23 // }
25 // By default a test will fail if no method in the native module 'assert' is
26 // called. This behaviour can be overridden by calling ExpectNoAssertionsMade().
27 class ModuleSystemTest : public testing::Test {
28 public:
29 ModuleSystemTest();
30 virtual ~ModuleSystemTest();
32 virtual void TearDown() OVERRIDE;
34 protected:
35 // Register a named JS module in the module system.
36 void RegisterModule(const std::string& name, const std::string& code);
38 // Register a named JS module with source retrieved from a ResourceBundle.
39 void RegisterModule(const std::string& name, int resource_id);
41 // Register a named JS module in the module system and tell the module system
42 // to use it to handle any requireNative() calls for native modules with that
43 // name.
44 void OverrideNativeHandler(const std::string& name, const std::string& code);
46 // Make the test fail if any asserts are called. By default a test will fail
47 // if no asserts are called.
48 void ExpectNoAssertionsMade();
50 // Create an empty object in the global scope with name |name|.
51 v8::Handle<v8::Object> CreateGlobal(const std::string& name);
53 v8::Persistent<v8::Context> context_;
54 v8::HandleScope handle_scope_;
55 AssertNatives* assert_natives_;
56 scoped_ptr<StringSourceMap> source_map_;
57 scoped_ptr<extensions::ModuleSystem> module_system_;
58 bool should_assertions_be_made_;
61 #endif // CHROME_TEST_BASE_MODULE_SYSTEM_TEST_H_