Commit cbcf3b5b authored by toyoshim@chromium.org's avatar toyoshim@chromium.org

Translate: browser test for Chrome Translate in an isolated world

An browser test which cover whole translate process was disabled tentatively.
This is because now Translate scripts runs inside a v8 isolated world and
it make impossible to run with local testing server.
This change introduce a flag to change the allowed server for XHR, and
make the test enabled again.
Note that this flag is warned by infobar when it is enabled.

BUG=268785
TEST=browser_tests --gtest_filter='Translate*.*'
TBR=hajimehoshi@chromium.org

Review URL: https://chromiumcodereview.appspot.com/14180010

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@215912 0039d316-1c4b-4281-b951-d872f2087c98
parent 92500900
...@@ -1473,6 +1473,7 @@ void ChromeContentBrowserClient::AppendExtraCommandLineSwitches( ...@@ -1473,6 +1473,7 @@ void ChromeContentBrowserClient::AppendExtraCommandLineSwitches(
switches::kRecordMode, switches::kRecordMode,
switches::kSilentDumpOnDCHECK, switches::kSilentDumpOnDCHECK,
switches::kSpdyProxyAuthOrigin, switches::kSpdyProxyAuthOrigin,
switches::kTranslateSecurityOrigin,
switches::kWhitelistedExtensionID, switches::kWhitelistedExtensionID,
}; };
......
...@@ -36,6 +36,7 @@ void ShowBadFlagsPrompt(Browser* browser) { ...@@ -36,6 +36,7 @@ void ShowBadFlagsPrompt(Browser* browser) {
extensions::switches::kExtensionsOnChromeURLs, extensions::switches::kExtensionsOnChromeURLs,
// This parameter should be used only for server side developments. // This parameter should be used only for server side developments.
switches::kTranslateScriptURL, switches::kTranslateScriptURL,
switches::kTranslateSecurityOrigin,
NULL NULL
}; };
......
...@@ -1398,6 +1398,9 @@ const char kTrackActiveVisitTime[] = "track-active-visit-time"; ...@@ -1398,6 +1398,9 @@ const char kTrackActiveVisitTime[] = "track-active-visit-time";
// Overrides the default server used for Google Translate. // Overrides the default server used for Google Translate.
const char kTranslateScriptURL[] = "translate-script-url"; const char kTranslateScriptURL[] = "translate-script-url";
// Overrides security-origin with which Translate runs in an isolated world.
const char kTranslateSecurityOrigin[] = "translate-security-origin";
// Disables same-origin check on HTTP resources pushed via a SPDY proxy. // Disables same-origin check on HTTP resources pushed via a SPDY proxy.
// The value is the host:port of the trusted proxy. // The value is the host:port of the trusted proxy.
const char kTrustedSpdyProxy[] = "trusted-spdy-proxy"; const char kTrustedSpdyProxy[] = "trusted-spdy-proxy";
......
...@@ -374,6 +374,7 @@ extern const char kTestType[]; ...@@ -374,6 +374,7 @@ extern const char kTestType[];
extern const char kTestingChannelID[]; extern const char kTestingChannelID[];
extern const char kTrackActiveVisitTime[]; extern const char kTrackActiveVisitTime[];
extern const char kTranslateScriptURL[]; extern const char kTranslateScriptURL[];
extern const char kTranslateSecurityOrigin[];
extern const char kTrustedSpdyProxy[]; extern const char kTrustedSpdyProxy[];
extern const char kTryChromeAgain[]; extern const char kTryChromeAgain[];
extern const char kUninstallExtension[]; extern const char kUninstallExtension[];
......
...@@ -357,9 +357,15 @@ void TranslateHelper::OnTranslatePage(int page_id, ...@@ -357,9 +357,15 @@ void TranslateHelper::OnTranslatePage(int page_id,
chrome::ISOLATED_WORLD_ID_TRANSLATE, chrome::ISOLATED_WORLD_ID_TRANSLATE,
WebString::fromUTF8(kContentSecurityPolicy)); WebString::fromUTF8(kContentSecurityPolicy));
std::string security_origin(kSecurityOrigin);
CommandLine* command_line = CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(switches::kTranslateSecurityOrigin)) {
security_origin =
command_line->GetSwitchValueASCII(switches::kTranslateSecurityOrigin);
}
frame->setIsolatedWorldSecurityOrigin( frame->setIsolatedWorldSecurityOrigin(
chrome::ISOLATED_WORLD_ID_TRANSLATE, chrome::ISOLATED_WORLD_ID_TRANSLATE,
WebSecurityOrigin::create(GURL(kSecurityOrigin))); WebSecurityOrigin::create(GURL(security_origin)));
} }
if (!IsTranslateLibAvailable()) { if (!IsTranslateLibAvailable()) {
......
...@@ -7,6 +7,9 @@ found in the LICENSE file. ...@@ -7,6 +7,9 @@ found in the LICENSE file.
<head> <head>
<title>fr_test.html: check if Chrome Translate works</title> <title>fr_test.html: check if Chrome Translate works</title>
<meta http-equiv="content-language" content="fr"> <meta http-equiv="content-language" content="fr">
<meta http-equiv="Content-Security-Policy" content="default-src 'self'">
<script>world='ng';</script> <!-- This line doesn't run because of CSP. -->
<script src="fr_test.js"></script>
</head> </head>
<body> <body>
<div>bonjour Chrome Translate.</div> <div>bonjour Chrome Translate.</div>
......
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
if (typeof world != 'undefined') {
div_log('CSP doesn\'t work');
document.title = 'FAIL';
return;
}
world='main';
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment