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