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"
23 class ContentRendererClient;
27 class RuleBasedHostResolverProc;
30 class RuntimeRegistry : public xwalk::Runtime::Observer {
32 typedef std::vector<xwalk::Runtime*> RuntimeList;
34 virtual ~RuntimeRegistry();
37 const RuntimeList& runtimes() const { return runtimes_; }
40 virtual void OnRuntimeAdded(xwalk::Runtime* runtime) OVERRIDE;
41 virtual void OnRuntimeRemoved(xwalk::Runtime* runtime) OVERRIDE;
43 RuntimeList runtimes_;
46 // Base class for tests wanting to bring up a runtime (aka. browser) in the
49 // Reference comments in chrome/test/base/in_process_browser_test.h file
50 // about how to write a InProcessBrowserTest.
52 class InProcessBrowserTest : public content::BrowserTestBase {
54 typedef RuntimeRegistry::RuntimeList RuntimeList;
56 InProcessBrowserTest();
57 virtual ~InProcessBrowserTest();
59 // Configures everything for an in process browser test, then invokes
60 // BrowserMain. BrowserMain ends up invoking RunTestOnMainThreadLoop.
61 virtual void SetUp() OVERRIDE;
64 // FIXME : Two following methods should be removed!
65 xwalk::Runtime* runtime() const { return runtime_; }
66 const RuntimeList& runtimes() const;
67 // Use this as an observer when create a 'Runtime' instance within a test.
68 RuntimeRegistry* runtime_registry() const {
69 return runtime_registry_.get(); }
71 // Override this to add any custom cleanup code that needs to be done on the
72 // main thread before the browser is torn down.
73 virtual void ProperMainThreadCleanup() {}
76 virtual void RunTestOnMainThreadLoop() OVERRIDE;
78 // Return a CommandLine object that is used to relaunch the browser_test
79 // binary as a browser process.
80 CommandLine GetCommandLineForRelaunch();
83 // Create data path directory for this test to avoid pollution in default
84 // data path. Return true if success.
85 bool CreateDataPathDir();
87 // Prepare command line that will be used to launch the child browser process
88 // with an in-process test.
89 void PrepareTestCommandLine(CommandLine* command_line);
91 scoped_ptr<RuntimeRegistry> runtime_registry_;
92 // FIXME : Should be removed.
93 xwalk::Runtime* runtime_;
95 // Temporary data path directory. Used only when a data path directory is not
96 // specified in the command line.
97 base::ScopedTempDir temp_data_path_dir_;
100 #endif // XWALK_TEST_BASE_IN_PROCESS_BROWSER_TEST_H_