summaryrefslogtreecommitdiffstats
path: root/content/test/layout_browsertest.h
blob: c4064660e799b41e2a7fdbd44de348093bab7d1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/file_path.h"
#include "base/scoped_temp_dir.h"
#include "content/test/content_browser_test.h"

class GURL;
class LayoutTestHttpServer;
namespace content {
class WebKitTestController;
}

class InProcessBrowserLayoutTest : public content::ContentBrowserTest {
 public:
  explicit InProcessBrowserLayoutTest(const FilePath& test_parent_dir,
                                      const FilePath& test_case_dir);
  // Used when running HTTP layout tests. Starts the server in the constructor
  // and keeps it running through the lifetime of this test. This is done to
  // avoid flakiness in restarting the server while the port is still in use.
  // If -1 is passed for |port|, a random number will be used. This is
  // recommended when possible, in case multiple tests are running at the same
  // time. For some tests this isn't possible though, because they use resources
  // that hardcode a specific port.
  InProcessBrowserLayoutTest(const FilePath& test_parent_dir,
                             const FilePath& test_case_dir,
                             int port);
  virtual ~InProcessBrowserLayoutTest();

  virtual void SetUpInProcessBrowserTestFixture() OVERRIDE;
  virtual void SetUpOnMainThread() OVERRIDE;
  virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
  // Runs a layout test given its filename relative to the path given to the
  // constructor.
  void RunLayoutTest(const std::string& test_case_file_name);
  // Runs a layout test using the HTTP test server. The second constructor must
  // have been used.
  void RunHttpLayoutTest(const std::string& test_case_file_name);

 private:
  void RunLayoutTestInternal(const std::string& test_case_file_name,
                             const GURL& url);
  std::string SaveResults(const std::string& expected,
                          const std::string& actual);

  FilePath layout_test_dir_;
  FilePath test_parent_dir_;
  FilePath test_case_dir_;
  FilePath rebase_result_dir_;
  FilePath rebase_result_chromium_dir_;
  FilePath rebase_result_win_dir_;
  int port_;  // -2 means no port.  -1 means random.
  scoped_ptr<LayoutTestHttpServer> test_http_server_;

  scoped_ptr<content::WebKitTestController> test_controller_;

  DISALLOW_COPY_AND_ASSIGN(InProcessBrowserLayoutTest);
};