OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. 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 #include "chrome/common/chrome_switches.h" |
| 6 #include "chrome/test/automation/automation_proxy.h" |
| 7 #include "chrome/test/automation/browser_proxy.h" |
| 8 #include "chrome/test/automation/tab_proxy.h" |
| 9 #include "chrome/test/ui/ui_test.h" |
| 10 #include "net/test/test_server.h" |
| 11 |
| 12 class HostRulesTest : public UITest { |
| 13 protected: |
| 14 HostRulesTest(); |
| 15 |
| 16 net::TestServer test_server_; |
| 17 bool test_server_started_; |
| 18 |
| 19 private: |
| 20 DISALLOW_COPY_AND_ASSIGN(HostRulesTest); |
| 21 }; |
| 22 |
| 23 HostRulesTest::HostRulesTest() |
| 24 : test_server_(net::TestServer::TYPE_HTTP, |
| 25 FilePath(FILE_PATH_LITERAL("chrome/test/data"))), |
| 26 test_server_started_(false) { |
| 27 dom_automation_enabled_ = true; |
| 28 |
| 29 // The test_server is started in the constructor (rather than the test body) |
| 30 // so the mapping rules below can include the ephemeral port number. |
| 31 // TODO(phajdan.jr): Change this code when we can ask the test server whether |
| 32 // it started. |
| 33 test_server_started_ = test_server_.Start(); |
| 34 if (!test_server_started_) |
| 35 return; |
| 36 |
| 37 // Map all hosts to our local server. |
| 38 std::string host_rule("MAP * " + test_server_.host_port_pair().ToString()); |
| 39 launch_arguments_.AppendSwitchASCII(switches::kHostRules, host_rule); |
| 40 } |
| 41 |
| 42 TEST_F(HostRulesTest, TestMap) { |
| 43 ASSERT_TRUE(test_server_started_); |
| 44 |
| 45 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
| 46 ASSERT_TRUE(browser.get()); |
| 47 |
| 48 scoped_refptr<TabProxy> tab(browser->GetActiveTab()); |
| 49 ASSERT_TRUE(tab.get()); |
| 50 |
| 51 // Go to the empty page using www.google.com as the host. |
| 52 GURL local_url = test_server_.GetURL("files/empty.html"); |
| 53 GURL test_url(std::string("http://www.google.com") + local_url.path()); |
| 54 EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(test_url)); |
| 55 |
| 56 std::wstring html; |
| 57 EXPECT_TRUE(tab->ExecuteAndExtractString( |
| 58 L"", |
| 59 L"window.domAutomationController.send(document.body.outerHTML);", |
| 60 &html)); |
| 61 |
| 62 EXPECT_STREQ(L"<body></body>", html.c_str()); |
| 63 } |
OLD | NEW |