Upstream version 11.39.256.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 "base/memory/scoped_vector.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 "ui/base/page_transition_types.h"
19 #include "xwalk/runtime/browser/runtime.h"
20
21 namespace base {
22 class CommandLine;
23 }
24
25 namespace content {
26 class ContentRendererClient;
27 }
28
29 namespace net {
30 class RuleBasedHostResolverProc;
31 }
32
33 // Base class for tests wanting to bring up a runtime (aka. browser) in the
34 // unit test process.
35 //
36 // Reference comments in chrome/test/base/in_process_browser_test.h file
37 // about how to write a InProcessBrowserTest.
38 //
39 class InProcessBrowserTest : public content::BrowserTestBase,
40                              public xwalk::Runtime::Observer {
41  public:
42   using RuntimeList = std::vector<xwalk::Runtime*>;
43
44   InProcessBrowserTest();
45   virtual ~InProcessBrowserTest();
46
47   // Configures everything for an in process browser test, then invokes
48   // BrowserMain. BrowserMain ends up invoking RunTestOnMainThreadLoop.
49   virtual void SetUp() override;
50
51  protected:
52   const RuntimeList& runtimes() const { return runtimes_.get(); }
53
54   xwalk::Runtime* CreateRuntime(
55       const GURL& url = GURL(),
56       const xwalk::NativeAppWindow::CreateParams& params =
57         xwalk::NativeAppWindow::CreateParams());
58
59   // Override this to add any custom cleanup code that needs to be done on the
60   // main thread before the browser is torn down.
61   virtual void ProperMainThreadCleanup() {}
62
63   // BrowserTestBase:
64   virtual void RunTestOnMainThreadLoop() override;
65
66  private:
67   // xwalk::Runtime::Observer
68   virtual void OnNewRuntimeAdded(xwalk::Runtime* runtime) override;
69   virtual void OnRuntimeClosed(xwalk::Runtime* runtime) override;
70
71   void CloseAll();
72   // Create data path directory for this test to avoid pollution in default
73   // data path. Return true if success.
74   bool CreateDataPathDir();
75
76   ScopedVector<xwalk::Runtime> runtimes_;
77
78   // Temporary data path directory. Used only when a data path directory is not
79   // specified in the command line.
80   base::ScopedTempDir temp_data_path_dir_;
81 };
82
83 #endif  // XWALK_TEST_BASE_IN_PROCESS_BROWSER_TEST_H_