OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/string_util.h" | 5 #include "base/string_util.h" |
6 #include "base/test/test_timeouts.h" | 6 #include "base/test/test_timeouts.h" |
7 #include "chrome/app/chrome_command_ids.h" | 7 #include "chrome/app/chrome_command_ids.h" |
8 #include "chrome/common/chrome_switches.h" | 8 #include "chrome/common/chrome_switches.h" |
9 #include "chrome/common/url_constants.h" | 9 #include "chrome/common/url_constants.h" |
10 #include "chrome/test/automation/tab_proxy.h" | 10 #include "chrome/test/automation/tab_proxy.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 IsSearchProviderTestData StartIsSearchProviderInstalledTest( | 22 IsSearchProviderTestData StartIsSearchProviderInstalledTest( |
23 BrowserProxy* browser_proxy, | 23 BrowserProxy* browser_proxy, |
24 const char* host, | 24 const char* host, |
25 const char* expected_result); | 25 const char* expected_result); |
26 | 26 |
27 void FinishIsSearchProviderInstalledTest( | 27 void FinishIsSearchProviderInstalledTest( |
28 const IsSearchProviderTestData& data); | 28 const IsSearchProviderTestData& data); |
29 | 29 |
30 net::TestServer test_server_; | 30 net::TestServer test_server_; |
| 31 GURL search_provider_test_url_; |
31 bool test_server_started_; | 32 bool test_server_started_; |
32 | 33 |
33 private: | 34 private: |
34 DISALLOW_COPY_AND_ASSIGN(SearchProviderTest); | 35 DISALLOW_COPY_AND_ASSIGN(SearchProviderTest); |
35 }; | 36 }; |
36 | 37 |
37 SearchProviderTest::SearchProviderTest() | 38 SearchProviderTest::SearchProviderTest() |
38 : test_server_(net::TestServer::TYPE_HTTP, | 39 : test_server_(net::TestServer::TYPE_HTTP, |
39 FilePath(FILE_PATH_LITERAL("chrome/test/data"))), | 40 FilePath(FILE_PATH_LITERAL("chrome/test/data"))), |
40 test_server_started_(false) { | 41 test_server_started_(false) { |
41 // The test_server is started in the constructor (rather than the test body) | 42 // The test_server is started in the constructor (rather than the test body) |
42 // so the mapping rules below can include the ephemeral port number. | 43 // so the mapping rules below can include the ephemeral port number. |
43 test_server_started_ = test_server_.Start(); | 44 test_server_started_ = test_server_.Start(); |
44 if (!test_server_started_) | 45 if (!test_server_started_) |
45 return; | 46 return; |
46 | 47 |
47 // Enable the search provider additions. | 48 // Enable the search provider additions. |
48 launch_arguments_.AppendSwitch(switches::kEnableSearchProviderApiV2); | 49 launch_arguments_.AppendSwitch(switches::kEnableSearchProviderApiV2); |
49 | 50 |
50 // Map all hosts to our local server. | 51 // Map all hosts to our local server. |
51 std::string host_rule("MAP * " + test_server_.host_port_pair().ToString()); | 52 std::string host_rule("MAP * " + test_server_.host_port_pair().ToString()); |
52 launch_arguments_.AppendSwitchASCII(switches::kHostRules, host_rule); | 53 launch_arguments_.AppendSwitchASCII(switches::kHostRules, host_rule); |
| 54 |
| 55 // Get the url for the test page. |
| 56 search_provider_test_url_ = |
| 57 test_server_.GetURL("files/is_search_provider_installed.html"); |
53 } | 58 } |
54 | 59 |
55 struct IsSearchProviderTestData { | 60 struct IsSearchProviderTestData { |
56 IsSearchProviderTestData() { | 61 IsSearchProviderTestData() { |
57 } | 62 } |
58 | 63 |
59 IsSearchProviderTestData(TabProxy* t, | 64 IsSearchProviderTestData(TabProxy* t, |
60 std::string h, | 65 std::string h, |
61 GURL url) | 66 GURL url) |
62 : tab(t), | 67 : tab(t), |
(...skipping 23 matching lines...) Expand all Loading... |
86 return IsSearchProviderTestData(); | 91 return IsSearchProviderTestData(); |
87 } | 92 } |
88 | 93 |
89 scoped_refptr<TabProxy> tab(browser_proxy->GetTab(num_tabs)); | 94 scoped_refptr<TabProxy> tab(browser_proxy->GetTab(num_tabs)); |
90 if (!tab.get()) { | 95 if (!tab.get()) { |
91 ADD_FAILURE() << "BrowserProxy::GetTab for the new tab failed."; | 96 ADD_FAILURE() << "BrowserProxy::GetTab for the new tab failed."; |
92 return IsSearchProviderTestData(); | 97 return IsSearchProviderTestData(); |
93 } | 98 } |
94 | 99 |
95 // Go to the test page. | 100 // Go to the test page. |
96 GURL local_url = | 101 GURL test_url(std::string("http://") + host + |
97 test_server_.GetURL("files/is_search_provider_installed.html"); | 102 search_provider_test_url_.path() + "#" + expected_result); |
98 GURL test_url(std::string("http://") + host + local_url.path() + | |
99 "#" + expected_result); | |
100 EXPECT_TRUE(tab->NavigateToURLAsync(test_url)); | 103 EXPECT_TRUE(tab->NavigateToURLAsync(test_url)); |
101 | 104 |
102 // Bundle up information needed to verify the result. | 105 // Bundle up information needed to verify the result. |
103 return IsSearchProviderTestData(tab, host, test_url); | 106 return IsSearchProviderTestData(tab, host, test_url); |
104 } | 107 } |
105 | 108 |
106 void SearchProviderTest::FinishIsSearchProviderInstalledTest( | 109 void SearchProviderTest::FinishIsSearchProviderInstalledTest( |
107 const IsSearchProviderTestData& data) { | 110 const IsSearchProviderTestData& data) { |
108 ASSERT_TRUE(data.tab.get()); | 111 ASSERT_TRUE(data.tab.get()); |
109 | 112 |
110 std::string cookie_name = data.host + "testResult"; | 113 std::string cookie_name = data.host + "testResult"; |
111 std::string escaped_value = | 114 std::string escaped_value = |
112 WaitUntilCookieNonEmpty(data.tab, | 115 WaitUntilCookieNonEmpty(data.tab, |
113 data.test_url, | 116 data.test_url, |
114 cookie_name.c_str(), | 117 cookie_name.c_str(), |
115 TestTimeouts::action_max_timeout_ms()); | 118 TestTimeouts::action_max_timeout_ms()); |
116 | 119 |
117 // Unescapes and normalizes the actual result. | 120 // Unescapes and normalizes the actual result. |
118 std::string value = UnescapeURLComponent( | 121 std::string value = UnescapeURLComponent( |
119 escaped_value, | 122 escaped_value, |
120 UnescapeRule::NORMAL | UnescapeRule::SPACES | | 123 UnescapeRule::NORMAL | UnescapeRule::SPACES | |
121 UnescapeRule::URL_SPECIAL_CHARS | UnescapeRule::CONTROL_CHARS); | 124 UnescapeRule::URL_SPECIAL_CHARS | UnescapeRule::CONTROL_CHARS); |
122 value += "\n"; | 125 value += "\n"; |
123 ReplaceSubstringsAfterOffset(&value, 0, "\r", ""); | 126 ReplaceSubstringsAfterOffset(&value, 0, "\r", ""); |
124 EXPECT_STREQ("1\n", value.c_str()); | 127 EXPECT_STREQ("1\n", value.c_str()); |
| 128 EXPECT_TRUE(data.tab->Close(true)); |
125 } | 129 } |
126 | 130 |
127 // http://code.google.com/p/chromium/issues/detail?id=62777 | 131 // http://code.google.com/p/chromium/issues/detail?id=62777 |
128 TEST_F(SearchProviderTest, FLAKY_TestIsSearchProviderInstalled) { | 132 TEST_F(SearchProviderTest, FLAKY_TestIsSearchProviderInstalled) { |
129 ASSERT_TRUE(test_server_started_); | 133 ASSERT_TRUE(test_server_started_); |
130 | 134 |
131 // Use the default search provider, other installed search provider, and | 135 // Use the default search provider, other installed search provider, and |
132 // one not installed as well. (Note that yahoo isn't tested because the | 136 // one not installed as well. (Note that yahoo isn't tested because the |
133 // its host name varies a lot for different locales unlike Google and Bing, | 137 // its host name varies a lot for different locales unlike Google and Bing, |
134 // which would make the test fail depending on the machine's locale.) | 138 // which would make the test fail depending on the machine's locale.) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 #if 0 | 170 #if 0 |
167 // Remove the calls to FinishIsSearchProviderInstalledTest above when | 171 // Remove the calls to FinishIsSearchProviderInstalledTest above when |
168 // re-enabling this code. | 172 // re-enabling this code. |
169 | 173 |
170 // Do the verification. | 174 // Do the verification. |
171 for (size_t i = 0; i < arraysize(test_data); ++i) { | 175 for (size_t i = 0; i < arraysize(test_data); ++i) { |
172 FinishIsSearchProviderInstalledTest(test_data[i]); | 176 FinishIsSearchProviderInstalledTest(test_data[i]); |
173 } | 177 } |
174 #endif | 178 #endif |
175 } | 179 } |
| 180 |
| 181 TEST_F(SearchProviderTest, TestIsSearchProviderInstalledWithException) { |
| 182 // Change the url for the test page to one that throws an exception when |
| 183 // toString is called on the argument given to isSearchProviderInstalled. |
| 184 search_provider_test_url_ = test_server_.GetURL( |
| 185 "files/is_search_provider_installed_with_exception.html"); |
| 186 |
| 187 scoped_refptr<BrowserProxy> browser(automation()->GetBrowserWindow(0)); |
| 188 FinishIsSearchProviderInstalledTest(StartIsSearchProviderInstalledTest( |
| 189 browser, "www.google.com", "")); |
| 190 } |
OLD | NEW |