Chromium Code Reviews| Index: chrome/browser/errorpage_browsertest.cc |
| =================================================================== |
| --- chrome/browser/errorpage_browsertest.cc (revision 225096) |
| +++ chrome/browser/errorpage_browsertest.cc (working copy) |
| @@ -3,12 +3,16 @@ |
| // found in the LICENSE file. |
| #include "base/bind.h" |
| +#include "base/prefs/pref_service.h" |
| +#include "base/strings/stringprintf.h" |
| #include "base/strings/utf_string_conversions.h" |
| #include "chrome/browser/google/google_util.h" |
| #include "chrome/browser/net/url_request_mock_util.h" |
| +#include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/browser_commands.h" |
| #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| +#include "chrome/common/pref_names.h" |
| #include "chrome/test/base/in_process_browser_test.h" |
| #include "chrome/test/base/ui_test_utils.h" |
| #include "content/public/browser/web_contents.h" |
| @@ -17,6 +21,7 @@ |
| #include "content/test/net/url_request_failed_job.h" |
| #include "content/test/net/url_request_mock_http_job.h" |
| #include "net/base/net_errors.h" |
| +#include "net/base/net_util.h" |
| #include "net/url_request/url_request_filter.h" |
| #include "net/url_request/url_request_job_factory.h" |
| @@ -248,6 +253,16 @@ |
| 1); |
| } |
| +// Returns JavaScrips code that executes plain text search for the page. |
|
mmenke
2013/09/27 14:44:05
nit: Javascript
yuusuke
2013/09/28 10:42:50
Done.
|
| +// Pass into content::ExecuteScriptAndExtractBool as |script| parameter. |
| +std::string GetTextContentContainsStringScript( |
| + const std::string& value_to_search) { |
| + return base::StringPrintf( |
| + "var textContent = document.body.textContent;" |
| + "var hasError = textContent.indexOf('%s') >= 0;" |
| + "domAutomationController.send(hasError);", value_to_search.c_str()); |
|
mmenke
2013/09/27 14:44:05
nit: To make the second parameter stand out a bit
yuusuke
2013/09/28 10:42:50
Done.
|
| +} |
| + |
| // Protocol handler that fails all requests with net::ERR_ADDRESS_UNREACHABLE. |
| class AddressUnreachableProtocolHandler |
| : public net::URLRequestJobFactory::ProtocolHandler { |
| @@ -323,11 +338,66 @@ |
| bool result = false; |
| EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| browser()->tab_strip_model()->GetActiveWebContents(), |
| - "var textContent = document.body.textContent;" |
| - "var hasError = textContent.indexOf('ERR_NAME_NOT_RESOLVED') >= 0;" |
| - "domAutomationController.send(hasError);", |
| + GetTextContentContainsStringScript("ERR_NAME_NOT_RESOLVED"), |
| &result)); |
| EXPECT_TRUE(result); |
| } |
| +// A test fixture that substitutes kMockHostname with IDN. |
|
mmenke
2013/09/27 14:44:05
nit: Think it's ambiguous what "kMockHostname" is
yuusuke
2013/09/28 10:42:50
Done.
|
| +class ErrorPageForIDNTest : public InProcessBrowserTest { |
| + public: |
| + // InProcessBrowserTest: |
| + virtual void SetUpOnMainThread() OVERRIDE { |
| + // Clear AcceptLanguages to force punycode decoding. |
| + browser()->profile()->GetPrefs()->SetString(prefs::kAcceptLanguages, |
| + std::string()); |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, FROM_HERE, |
| + base::Bind(&ErrorPageForIDNTest::AddFilters)); |
| + } |
| + |
| + virtual void CleanUpOnMainThread() OVERRIDE { |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, FROM_HERE, |
| + base::Bind(&ErrorPageForIDNTest::RemoveFilters)); |
| + } |
| + |
| + // Target hostname in ASCII (punycode). |
| + static std::string GetHostname() { |
| + return "xn--d1abbgf6aiiy.xn--p1ai"; |
| + } |
| + |
| + static std::string GetHostnameAsJSUnicode() { |
| + return "\\u043f\\u0440\\u0435\\u0437\\u0438\\u0434\\u0435\\u043d" |
| + "\\u0442.\\u0440\\u0444"; |
| + } |
|
mmenke
2013/09/27 14:44:05
optional nit: Suggest just making these consts, i
yuusuke
2013/09/28 10:42:50
Done.
|
| + |
| + private: |
| + static void AddFilters() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + content::URLRequestFailedJob::AddUrlHandler(GetHostname()); |
| + } |
| + |
| + static void RemoveFilters() { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + net::URLRequestFilter::GetInstance()->ClearHandlers(); |
| + } |
| +}; |
| + |
| +// Make sure error page shows correct unicode for IDN. |
| +IN_PROC_BROWSER_TEST_F(ErrorPageForIDNTest, IDN) { |
| + ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
|
mmenke
2013/09/27 14:44:05
Think it's worth a comment that ERR_UNSAFE_PORT wi
yuusuke
2013/09/28 10:42:50
Done.
|
| + browser(), |
| + URLRequestFailedJob::GetMockHttpUrl(net::ERR_UNSAFE_PORT, |
| + GetHostname()), |
| + 1); |
| + |
| + bool result = false; |
| + EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| + browser()->tab_strip_model()->GetActiveWebContents(), |
| + GetTextContentContainsStringScript(GetHostnameAsJSUnicode()), |
| + &result)); |
| + EXPECT_TRUE(result); |
| +} |
| + |
| } // namespace |