summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chrome_switches_browsertest.cc
blob: c936004b26b441d345e62fba52396e5c86690308 (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
// 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/command_line.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/ui_test_utils.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test_utils.h"
#include "net/test/spawned_test_server/spawned_test_server.h"

class HostRulesTest : public InProcessBrowserTest {
 protected:
  HostRulesTest() {}

  void SetUpCommandLine(base::CommandLine* command_line) override {
    ASSERT_TRUE(test_server()->Start());

    // Map all hosts to our local server.
    std::string host_rule(
        "MAP * " + test_server()->host_port_pair().ToString());
    command_line->AppendSwitchASCII(switches::kHostRules, host_rule);
    // Use no proxy or otherwise this test will fail on a machine that has a
    // proxy configured.
    command_line->AppendSwitch(switches::kNoProxyServer);
  }

 private:
  DISALLOW_COPY_AND_ASSIGN(HostRulesTest);
};

IN_PROC_BROWSER_TEST_F(HostRulesTest, TestMap) {
  // Go to the empty page using www.google.com as the host.
  GURL local_url = test_server()->GetURL("files/empty.html");
  GURL test_url(std::string("http://www.google.com") + local_url.path());
  ui_test_utils::NavigateToURL(browser(), test_url);

  std::string html;
  EXPECT_TRUE(content::ExecuteScriptAndExtractString(
      browser()->tab_strip_model()->GetActiveWebContents(),
      "window.domAutomationController.send(document.body.outerHTML);",
      &html));

  EXPECT_STREQ("<body></body>", html.c_str());
}