1 // Copyright (c) 2013 Intel Corporation. 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 XWALK_TEST_BASE_IN_PROCESS_BROWSER_TEST_H_
6 #define XWALK_TEST_BASE_IN_PROCESS_BROWSER_TEST_H_
10 #include "base/compiler_specific.h"
11 #include "base/files/scoped_temp_dir.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "content/public/common/page_transition_types.h"
15 #include "content/public/test/browser_test.h"
16 #include "content/public/test/browser_test_base.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18 #include "xwalk/runtime/browser/runtime.h"
25 class ContentRendererClient;
29 class RuleBasedHostResolverProc;
32 class RuntimeRegistry : public xwalk::Runtime::Observer {
34 typedef std::vector<xwalk::Runtime*> RuntimeList;
36 virtual ~RuntimeRegistry();
39 const RuntimeList& runtimes() const { return runtimes_; }
42 virtual void OnRuntimeAdded(xwalk::Runtime* runtime) OVERRIDE;
43 virtual void OnRuntimeRemoved(xwalk::Runtime* runtime) OVERRIDE;
45 RuntimeList runtimes_;
48 // Base class for tests wanting to bring up a runtime (aka. browser) in the
51 // Reference comments in chrome/test/base/in_process_browser_test.h file
52 // about how to write a InProcessBrowserTest.
54 class InProcessBrowserTest : public content::BrowserTestBase {
56 typedef RuntimeRegistry::RuntimeList RuntimeList;
58 InProcessBrowserTest();
59 virtual ~InProcessBrowserTest();
61 // Configures everything for an in process browser test, then invokes
62 // BrowserMain. BrowserMain ends up invoking RunTestOnMainThreadLoop.
63 virtual void SetUp() OVERRIDE;
66 // FIXME : Two following methods should be removed!
67 xwalk::Runtime* runtime() const { return runtime_; }
68 const RuntimeList& runtimes() const;
69 // Use this as an observer when create a 'Runtime' instance within a test.
70 RuntimeRegistry* runtime_registry() const {
71 return runtime_registry_.get(); }
73 // Override this to add any custom cleanup code that needs to be done on the
74 // main thread before the browser is torn down.
75 virtual void ProperMainThreadCleanup() {}
78 virtual void RunTestOnMainThreadLoop() OVERRIDE;
80 // Return a CommandLine object that is used to relaunch the browser_test
81 // binary as a browser process.
82 base::CommandLine GetCommandLineForRelaunch();
85 // Create data path directory for this test to avoid pollution in default
86 // data path. Return true if success.
87 bool CreateDataPathDir();
89 // Prepare command line that will be used to launch the child browser process
90 // with an in-process test.
91 void PrepareTestCommandLine(base::CommandLine* command_line);
93 scoped_ptr<RuntimeRegistry> runtime_registry_;
94 // FIXME : Should be removed.
95 xwalk::Runtime* runtime_;
97 // Temporary data path directory. Used only when a data path directory is not
98 // specified in the command line.
99 base::ScopedTempDir temp_data_path_dir_;
102 #endif // XWALK_TEST_BASE_IN_PROCESS_BROWSER_TEST_H_