forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable <webview>.executeScript outside of Apps and Extensions [1]
This patch enables javascript code injection like <webview>.executeScript({code: ...}), but does not include file injection like <webview>.executeScript({file: ...}). File injection will be in another patch. BUG=434081 Review URL: https://codereview.chromium.org/942533003 Cr-Commit-Position: refs/heads/master@{#319727}
- Loading branch information
hanxi
authored and
Commit bot
committed
Mar 9, 2015
1 parent
7b41c65
commit 79f7a57
Showing
18 changed files
with
189 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2015 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. | ||
|
||
#include "base/macros.h" | ||
#include "base/path_service.h" | ||
#include "chrome/common/chrome_paths.h" | ||
#include "chrome/common/url_constants.h" | ||
#include "chrome/test/base/ui_test_utils.h" | ||
#include "chrome/test/base/web_ui_browser_test.h" | ||
#include "net/test/embedded_test_server/embedded_test_server.h" | ||
|
||
class WebUIWebViewBrowserTest : public WebUIBrowserTest { | ||
public: | ||
WebUIWebViewBrowserTest() {} | ||
|
||
void SetUpOnMainThread() override { | ||
WebUIBrowserTest::SetUpOnMainThread(); | ||
AddLibrary( | ||
base::FilePath(FILE_PATH_LITERAL("webview_execute_script_test.js"))); | ||
|
||
base::FilePath test_data_dir; | ||
PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir); | ||
embedded_test_server()->ServeFilesFromDirectory(test_data_dir); | ||
ASSERT_TRUE(embedded_test_server()->InitializeAndWaitUntilReady()); | ||
} | ||
|
||
GURL GetTestUrl(const std::string& path) const { | ||
return embedded_test_server()->base_url().Resolve(path); | ||
} | ||
|
||
GURL GetWebViewEnabledWebUIURL() const { | ||
return GURL(chrome::kChromeUIChromeSigninURL); | ||
} | ||
|
||
private: | ||
DISALLOW_COPY_AND_ASSIGN(WebUIWebViewBrowserTest); | ||
}; | ||
|
||
IN_PROC_BROWSER_TEST_F(WebUIWebViewBrowserTest, ExecuteScriptCode) { | ||
ui_test_utils::NavigateToURL(browser(), GetWebViewEnabledWebUIURL()); | ||
|
||
ASSERT_TRUE(WebUIBrowserTest::RunJavascriptAsyncTest( | ||
"testExecuteScriptCode", | ||
new base::StringValue(GetTestUrl("empty.html").spec()))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2015 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. | ||
|
||
function createWebview() { | ||
var webview = document.createElement('webview'); | ||
document.body.appendChild(webview); | ||
return webview; | ||
} | ||
|
||
function testExecuteScriptCode(url) { | ||
var webview = createWebview(); | ||
|
||
var onGetBackgroundExecuted = function(results) { | ||
chrome.send('testResult', [results.length == 1 && results[0] == 'red']); | ||
}; | ||
|
||
var onSetBackgroundExecuted = function() { | ||
webview.executeScript({ | ||
code: 'document.body.style.backgroundColor;' | ||
}, onGetBackgroundExecuted); | ||
}; | ||
|
||
var onLoadStop = function() { | ||
webview.executeScript({ | ||
code: 'document.body.style.backgroundColor = \'red\';' | ||
}, onSetBackgroundExecuted); | ||
}; | ||
|
||
webview.addEventListener('loadstop', onLoadStop); | ||
webview.src = url; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.