summaryrefslogtreecommitdiffstats
path: root/chrome/common/chrome_switches_uitest.cc
blob: feb8d9dffffb13848b23da783c167898165d2647 (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
60
61
62
63
// Copyright (c) 2011 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 "chrome/common/chrome_switches.h"
#include "chrome/test/automation/automation_proxy.h"
#include "chrome/test/automation/browser_proxy.h"
#include "chrome/test/automation/tab_proxy.h"
#include "chrome/test/ui/ui_test.h"
#include "net/test/test_server.h"

class HostRulesTest : public UITest {
 protected:
  HostRulesTest();

  net::TestServer test_server_;
  bool test_server_started_;

 private:
  DISALLOW_COPY_AND_ASSIGN(HostRulesTest);
};

HostRulesTest::HostRulesTest()
    : test_server_(net::TestServer::TYPE_HTTP,
                   FilePath(FILE_PATH_LITERAL("chrome/test/data"))),
      test_server_started_(false) {
  dom_automation_enabled_  = true;

  // The test_server is started in the constructor (rather than the test body)
  // so the mapping rules below can include the ephemeral port number.
  // TODO(phajdan.jr): Change this code when we can ask the test server whether
  // it started.
  test_server_started_ = test_server_.Start();
  if (!test_server_started_)
    return;

  // Map all hosts to our local server.
  std::string host_rule("MAP * " + test_server_.host_port_pair().ToString());
  launch_arguments_.AppendSwitchASCII(switches::kHostRules, host_rule);
}

TEST_F(HostRulesTest, TestMap) {
  ASSERT_TRUE(test_server_started_);

  scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0));
  ASSERT_TRUE(browser.get());

  scoped_refptr<TabProxy> tab(browser->GetActiveTab());
  ASSERT_TRUE(tab.get());

  // 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());
  EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(test_url));

  std::wstring html;
  EXPECT_TRUE(tab->ExecuteAndExtractString(
      L"",
      L"window.domAutomationController.send(document.body.outerHTML);",
      &html));

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