OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2010 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 "base/file_path.h" | |
6 #include "chrome/app/chrome_dll_resource.h" | |
7 #include "chrome/common/chrome_switches.h" | |
8 #include "chrome/test/automation/tab_proxy.h" | |
9 #include "chrome/test/ui/ui_layout_test.h" | |
10 #include "chrome/test/ui_test_utils.h" | |
11 #include "net/base/escape.h" | |
12 #include "net/url_request/url_request_unittest.h" | |
13 | |
14 class SearchProviderTest : public UITest { | |
15 protected: | |
16 SearchProviderTest(); | |
17 virtual ~SearchProviderTest(); | |
18 | |
19 void TestIsSearchProviderInstalledForHost( | |
20 TabProxy* tab, | |
21 const char* host, | |
22 const char* expected_result); | |
23 | |
24 scoped_refptr<HTTPTestServer> server_; | |
25 | |
26 private: | |
27 DISALLOW_COPY_AND_ASSIGN(SearchProviderTest); | |
28 }; | |
29 | |
30 SearchProviderTest::SearchProviderTest() | |
31 : server_(HTTPTestServer::CreateServer(L"chrome/test/data", NULL)) { | |
32 if (!server_) | |
Paweł Hajdan Jr.
2010/07/16 00:14:32
How about just ASSERT/EXPECT_TRUE(server_)? Failin
| |
33 return; | |
34 | |
35 // Enable the search provider additions. | |
36 launch_arguments_.AppendSwitch(switches::kEnableSearchProviderApiV2); | |
37 | |
38 // Map all hosts to our local server. | |
39 GURL server_url = server_->TestServerPage(""); | |
40 std::string host_rule = "MAP * "; | |
41 host_rule.append(server_url.host()); | |
42 if (server_url.has_port()) { | |
43 host_rule.append(":"); | |
44 host_rule.append(server_url.port()); | |
45 } | |
46 launch_arguments_.AppendSwitchWithValue(switches::kHostRules, | |
47 host_rule); | |
48 } | |
49 | |
50 SearchProviderTest::~SearchProviderTest() { | |
51 server_->Stop(); | |
52 } | |
53 | |
54 void SearchProviderTest::TestIsSearchProviderInstalledForHost( | |
55 TabProxy* tab, | |
56 const char* host, | |
57 const char* expected_result) { | |
58 ASSERT_TRUE(server_); | |
59 GURL local_url = | |
60 server_->TestServerPage("files/is_search_provider_installed.html"); | |
61 GURL test_url(std::string("http://") + host + local_url.path() + | |
62 "#" + expected_result); | |
63 EXPECT_EQ(AUTOMATION_MSG_NAVIGATION_SUCCESS, tab->NavigateToURL(test_url)); | |
64 std::string cookie_name = std::string(host) + "testResult"; | |
65 std::string escaped_value = | |
66 WaitUntilCookieNonEmpty(tab, test_url, | |
67 cookie_name.c_str(), action_max_timeout_ms()); | |
68 | |
69 // Unescapes and normalizes the actual result. | |
70 std::string value = UnescapeURLComponent(escaped_value, | |
71 UnescapeRule::NORMAL | UnescapeRule::SPACES | | |
72 UnescapeRule::URL_SPECIAL_CHARS | UnescapeRule::CONTROL_CHARS); | |
73 value += "\n"; | |
74 ReplaceSubstringsAfterOffset(&value, 0, "\r", ""); | |
75 EXPECT_STREQ("1\n", value.c_str()); | |
76 } | |
77 | |
78 TEST_F(SearchProviderTest, TestIsSearchProviderInstalled) { | |
79 // Verify the default search provider, other installed search provider, and | |
80 // one not installed as well. | |
81 scoped_refptr<TabProxy> tab(GetActiveTab()); | |
82 ASSERT_TRUE(tab.get()); | |
83 TestIsSearchProviderInstalledForHost(tab, "www.google.com", "2"); | |
84 TestIsSearchProviderInstalledForHost(tab, "www.bing.com", "1"); | |
85 TestIsSearchProviderInstalledForHost(tab, "localhost", "0"); | |
86 | |
87 // Verify that there are no search providers reported in incognito mode. | |
88 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); | |
89 ASSERT_TRUE(browser.get()); | |
90 ASSERT_TRUE(browser->RunCommand(IDC_NEW_INCOGNITO_WINDOW)); | |
91 scoped_refptr<BrowserProxy> incognito(automation()->GetBrowserWindow(1)); | |
92 ASSERT_TRUE(incognito.get()); | |
93 scoped_refptr<TabProxy> incognito_tab(incognito->GetTab(0)); | |
94 ASSERT_TRUE(incognito_tab.get()); | |
95 TestIsSearchProviderInstalledForHost(incognito_tab, "www.google.com", "0"); | |
96 TestIsSearchProviderInstalledForHost(incognito_tab, "www.bing.com", "0"); | |
97 TestIsSearchProviderInstalledForHost(incognito_tab, "localhost", "0"); | |
98 } | |
OLD | NEW |