Upstream version 5.34.97.0
[platform/framework/web/crosswalk.git] / src / xwalk / test / base / in_process_browser_test.h
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.
4
5 #ifndef XWALK_TEST_BASE_IN_PROCESS_BROWSER_TEST_H_
6 #define XWALK_TEST_BASE_IN_PROCESS_BROWSER_TEST_H_
7
8 #include <vector>
9
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"
19
20 class CommandLine;
21
22 namespace content {
23 class ContentRendererClient;
24 }
25
26 namespace net {
27 class RuleBasedHostResolverProc;
28 }
29
30 class RuntimeRegistry : public xwalk::Runtime::Observer {
31  public:
32   typedef std::vector<xwalk::Runtime*> RuntimeList;
33   RuntimeRegistry();
34   virtual ~RuntimeRegistry();
35
36   void CloseAll();
37   const RuntimeList& runtimes() const { return runtimes_; }
38
39  private:
40   virtual void OnRuntimeAdded(xwalk::Runtime* runtime) OVERRIDE;
41   virtual void OnRuntimeRemoved(xwalk::Runtime* runtime) OVERRIDE;
42
43   RuntimeList runtimes_;
44 };
45
46 // Base class for tests wanting to bring up a runtime (aka. browser) in the
47 // unit test process.
48 //
49 // Reference comments in chrome/test/base/in_process_browser_test.h file
50 // about how to write a InProcessBrowserTest.
51 //
52 class InProcessBrowserTest : public content::BrowserTestBase {
53  public:
54   typedef RuntimeRegistry::RuntimeList RuntimeList;
55
56   InProcessBrowserTest();
57   virtual ~InProcessBrowserTest();
58
59   // Configures everything for an in process browser test, then invokes
60   // BrowserMain. BrowserMain ends up invoking RunTestOnMainThreadLoop.
61   virtual void SetUp() OVERRIDE;
62
63  protected:
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(); }
70
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() {}
74
75   // BrowserTestBase:
76   virtual void RunTestOnMainThreadLoop() OVERRIDE;
77
78   // Return a CommandLine object that is used to relaunch the browser_test
79   // binary as a browser process.
80   CommandLine GetCommandLineForRelaunch();
81
82  private:
83   // Create data path directory for this test to avoid pollution in default
84   // data path. Return true if success.
85   bool CreateDataPathDir();
86
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);
90
91   scoped_ptr<RuntimeRegistry> runtime_registry_;
92   // FIXME : Should be removed.
93   xwalk::Runtime* runtime_;
94
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_;
98 };
99
100 #endif  // XWALK_TEST_BASE_IN_PROCESS_BROWSER_TEST_H_