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 test_server_started_ = test_server_.Start(); | |
Paweł Hajdan Jr.
2011/06/08 09:05:55
nit: Please add a TODO(phajdan.jr) to change this
| |
32 if (!test_server_started_) | |
33 return; | |
34 | |
35 // Map all hosts to our local server. | |
36 std::string host_rule("MAP * " + test_server_.host_port_pair().ToString()); | |
37 launch_arguments_.AppendSwitchASCII(switches::kHostRules, host_rule); | |
38 } | |
39 | |
40 TEST_F(HostRulesTest, TestMap) { | |
41 ASSERT_TRUE(test_server_started_); | |
42 | |
43 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | |
44 ASSERT_TRUE(browser.get()) << "GetBrowserWindow failed."; | |
Paweł Hajdan Jr.
2011/06/08 09:05:55
nit: Generally there is no need for those "GetBrow
| |
45 | |
46 scoped_refptr<TabProxy> tab(browser->GetActiveTab()); | |
47 ASSERT_TRUE(tab.get()) << "BrowserProxy::GetActiveTab failed."; | |
48 | |
49 // Go to the empty page using www.google.com as the host. | |
50 GURL local_url = test_server_.GetURL("files/empty.html"); | |
51 GURL test_url(std::string("http://www.google.com") + local_url.path()); | |
52 EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(test_url)); | |
53 | |
54 std::wstring html; | |
55 EXPECT_TRUE(tab->ExecuteAndExtractString( | |
56 L"", | |
57 L"window.domAutomationController.send(document.body.outerHTML);", | |
58 &html)); | |
59 | |
60 EXPECT_STREQ(L"<body></body>", html.c_str()); | |
61 } | |
OLD | NEW |