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 "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"
26 class ContentRendererClient;
30 class RuleBasedHostResolverProc;
33 // Base class for tests wanting to bring up a runtime (aka. browser) in the
36 // Reference comments in chrome/test/base/in_process_browser_test.h file
37 // about how to write a InProcessBrowserTest.
39 class InProcessBrowserTest : public content::BrowserTestBase,
40 public xwalk::Runtime::Observer {
42 using RuntimeList = std::vector<xwalk::Runtime*>;
44 InProcessBrowserTest();
45 virtual ~InProcessBrowserTest();
47 // Configures everything for an in process browser test, then invokes
48 // BrowserMain. BrowserMain ends up invoking RunTestOnMainThreadLoop.
49 virtual void SetUp() override;
52 const RuntimeList& runtimes() const { return runtimes_.get(); }
54 xwalk::Runtime* CreateRuntime(
55 const GURL& url = GURL(),
56 const xwalk::NativeAppWindow::CreateParams& params =
57 xwalk::NativeAppWindow::CreateParams());
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() {}
64 virtual void RunTestOnMainThreadLoop() override;
67 // xwalk::Runtime::Observer
68 virtual void OnNewRuntimeAdded(xwalk::Runtime* runtime) override;
69 virtual void OnRuntimeClosed(xwalk::Runtime* runtime) override;
72 // Create data path directory for this test to avoid pollution in default
73 // data path. Return true if success.
74 bool CreateDataPathDir();
76 ScopedVector<xwalk::Runtime> runtimes_;
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_;
83 #endif // XWALK_TEST_BASE_IN_PROCESS_BROWSER_TEST_H_