Commit 24e04298 authored by mihaip@chromium.org's avatar mihaip@chromium.org

Check for warnings when loading extensions in browser tests.

Test extension should be well-formed. Having warnings is often an early
indicator that something else is wrong (see for example https://chromiumcodereview.appspot.com/10852016/).

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151123 0039d316-1c4b-4281-b951-d872f2087c98
parent e841144e
......@@ -145,7 +145,8 @@ IN_PROC_BROWSER_TEST_F(ExtensionApiTest, PageActionRemovePopup) {
// Tests old-style pageActions API that is deprecated but we don't want to
// break.
IN_PROC_BROWSER_TEST_F(ExtensionApiTest, OldPageActions) {
ASSERT_TRUE(RunExtensionTest("page_action/old_api")) << message_;
ASSERT_TRUE(RunExtensionTestIgnoreManifestWarnings("page_action/old_api")) <<
message_;
const Extension* extension = GetSingleLoadedExtension();
ASSERT_TRUE(extension) << message_;
......
......@@ -158,11 +158,13 @@ void ExtensionWebRequestApiTest::RunPermissionTest(
ExtensionTestMessageListener listener("done", true);
ExtensionTestMessageListener listener_incognito("done_incognito", true);
ASSERT_TRUE(LoadExtensionWithOptions(
int load_extension_flags = kFlagNone;
if (load_extension_with_incognito_permission)
load_extension_flags |= kFlagEnableIncognito;
ASSERT_TRUE(LoadExtensionWithFlags(
test_data_dir_.AppendASCII("webrequest_permissions")
.AppendASCII(extension_directory),
load_extension_with_incognito_permission,
false));
load_extension_flags));
// Test that navigation in regular window is properly redirected.
EXPECT_TRUE(listener.WaitUntilSatisfied());
......
......@@ -121,6 +121,12 @@ bool ExtensionApiTest::RunExtensionTestIncognito(const char* extension_name) {
extension_name, "", kFlagEnableIncognito | kFlagEnableFileAccess);
}
bool ExtensionApiTest::RunExtensionTestIgnoreManifestWarnings(
const char* extension_name) {
return RunExtensionTestImpl(
extension_name, "", kFlagEnableFileAccess | kFlagIgnoreManifestWarnings);
}
bool ExtensionApiTest::RunComponentExtensionTest(const char* extension_name) {
return RunExtensionTestImpl(
extension_name, "", kFlagEnableFileAccess | kFlagLoadAsComponent);
......@@ -167,8 +173,6 @@ bool ExtensionApiTest::RunPlatformAppTest(const char* extension_name) {
bool ExtensionApiTest::RunExtensionTestImpl(const char* extension_name,
const std::string& page_url,
int flags) {
bool enable_incognito = (flags & kFlagEnableIncognito) != 0;
bool enable_fileaccess = (flags & kFlagEnableFileAccess) != 0;
bool load_as_component = (flags & kFlagLoadAsComponent) != 0;
bool launch_platform_app = (flags & kFlagLaunchPlatformApp) != 0;
bool use_incognito = (flags & kFlagUseIncognito) != 0;
......@@ -183,8 +187,14 @@ bool ExtensionApiTest::RunExtensionTestImpl(const char* extension_name,
if (load_as_component) {
extension = LoadExtensionAsComponent(extension_path);
} else {
extension = LoadExtensionWithOptions(extension_path,
enable_incognito, enable_fileaccess);
int browser_test_flags = ExtensionBrowserTest::kFlagNone;
if (flags & kFlagEnableIncognito)
browser_test_flags |= ExtensionBrowserTest::kFlagEnableIncognito;
if (flags & kFlagEnableFileAccess)
browser_test_flags |= ExtensionBrowserTest::kFlagEnableFileAccess;
if (flags & kFlagIgnoreManifestWarnings)
browser_test_flags |= ExtensionBrowserTest::kFlagIgnoreManifestWarnings;
extension = LoadExtensionWithFlags(extension_path, browser_test_flags);
}
if (!extension) {
message_ = "Failed to load extension.";
......
......@@ -52,7 +52,11 @@ class ExtensionApiTest : public ExtensionBrowserTest {
kFlagLoadAsComponent = 1 << 3,
// Launch the extension as a platform app.
kFlagLaunchPlatformApp = 1 << 4
kFlagLaunchPlatformApp = 1 << 4,
// Don't fail when the loaded manifest has warnings (should only be used
// when testing deprecated features).
kFlagIgnoreManifestWarnings = 1 << 5
};
ExtensionApiTest();
......@@ -109,6 +113,9 @@ class ExtensionApiTest : public ExtensionBrowserTest {
// Same as RunExtensionTest, but enables the extension for incognito mode.
bool RunExtensionTestIncognito(const char* extension_name);
// Same as RunExtensionTest, but ignores any warnings in the manifest.
bool RunExtensionTestIgnoreManifestWarnings(const char* extension_name);
// Same as RunExtensionTest, but loads extension as component.
bool RunComponentExtensionTest(const char* extension_name);
......
......@@ -71,8 +71,8 @@ void ExtensionBrowserTest::SetUpCommandLine(CommandLine* command_line) {
#endif
}
const Extension* ExtensionBrowserTest::LoadExtensionWithOptions(
const FilePath& path, bool incognito_enabled, bool fileaccess_enabled) {
const Extension* ExtensionBrowserTest::LoadExtensionWithFlags(
const FilePath& path, int flags) {
ExtensionService* service = browser()->profile()->GetExtensionService();
{
content::NotificationRegistrar registrar;
......@@ -100,6 +100,25 @@ const Extension* ExtensionBrowserTest::LoadExtensionWithOptions(
if (!extension)
return NULL;
if (!(flags & kFlagIgnoreManifestWarnings)) {
const Extension::InstallWarningVector& install_warnings =
extension->install_warnings();
if (!install_warnings.empty()) {
std::string install_warnings_message = StringPrintf(
"Unexpected warnings when loading test extension %s:\n",
path.AsUTF8Unsafe().c_str());
for (Extension::InstallWarningVector::const_iterator it =
install_warnings.begin(); it != install_warnings.end(); ++it) {
install_warnings_message += " " + it->message + "\n";
}
EXPECT_TRUE(extension->install_warnings().empty()) <<
install_warnings_message;
return NULL;
}
}
const std::string extension_id = extension->id();
// The call to OnExtensionInstalled ensures the other extension prefs
......@@ -118,8 +137,8 @@ const Extension* ExtensionBrowserTest::LoadExtensionWithOptions(
content::Source<Profile>(browser()->profile()));
CHECK(!service->IsIncognitoEnabled(extension_id));
if (incognito_enabled) {
service->SetIsIncognitoEnabled(extension_id, incognito_enabled);
if (flags & kFlagEnableIncognito) {
service->SetIsIncognitoEnabled(extension_id, true);
load_signal.Wait();
extension = service->GetExtensionById(extension_id, false);
CHECK(extension) << extension_id << " not found after reloading.";
......@@ -131,8 +150,8 @@ const Extension* ExtensionBrowserTest::LoadExtensionWithOptions(
chrome::NOTIFICATION_EXTENSION_LOADED,
content::Source<Profile>(browser()->profile()));
CHECK(service->AllowFileAccess(extension));
if (!fileaccess_enabled) {
service->SetAllowFileAccess(extension, fileaccess_enabled);
if (!(flags & kFlagEnableFileAccess)) {
service->SetAllowFileAccess(extension, false);
load_signal.Wait();
extension = service->GetExtensionById(extension_id, false);
CHECK(extension) << extension_id << " not found after reloading.";
......@@ -146,12 +165,13 @@ const Extension* ExtensionBrowserTest::LoadExtensionWithOptions(
}
const Extension* ExtensionBrowserTest::LoadExtension(const FilePath& path) {
return LoadExtensionWithOptions(path, false, true);
return LoadExtensionWithFlags(path, kFlagEnableFileAccess);
}
const Extension* ExtensionBrowserTest::LoadExtensionIncognito(
const FilePath& path) {
return LoadExtensionWithOptions(path, true, true);
return LoadExtensionWithFlags(path,
kFlagEnableFileAccess | kFlagEnableIncognito);
}
const Extension* ExtensionBrowserTest::LoadExtensionAsComponent(
......
......@@ -24,6 +24,21 @@
class ExtensionBrowserTest : virtual public InProcessBrowserTest,
public content::NotificationObserver {
protected:
// Flags used to configure how the tests are run.
enum Flags {
kFlagNone = 0,
// Allow the extension to run in incognito mode.
kFlagEnableIncognito = 1 << 0,
// Allow file access for the extension.
kFlagEnableFileAccess = 1 << 1,
// Don't fail when the loaded manifest has warnings (should only be used
// when testing deprecated features).
kFlagIgnoreManifestWarnings = 1 << 2
};
ExtensionBrowserTest();
virtual ~ExtensionBrowserTest();
......@@ -35,10 +50,8 @@ class ExtensionBrowserTest : virtual public InProcessBrowserTest,
// Same as above, but enables the extension in incognito mode first.
const extensions::Extension* LoadExtensionIncognito(const FilePath& path);
const extensions::Extension* LoadExtensionWithOptions(
const FilePath& path,
bool incognito_enabled,
bool fileaccess_enabled);
const extensions::Extension* LoadExtensionWithFlags(
const FilePath& path, int flags);
// Loads extension and imitates that it is a component extension.
const extensions::Extension* LoadExtensionAsComponent(const FilePath& path);
......
......@@ -27,9 +27,11 @@ class ExtensionResourceRequestPolicyTest : public ExtensionApiTest {
IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, OriginPrivileges) {
host_resolver()->AddRule("*", "127.0.0.1");
ASSERT_TRUE(test_server()->Start());
ASSERT_TRUE(LoadExtension(test_data_dir_
ASSERT_TRUE(LoadExtensionWithFlags(test_data_dir_
.AppendASCII("extension_resource_request_policy")
.AppendASCII("extension")));
.AppendASCII("extension"),
// Tests manifest_version 1 behavior, so warnings are expected.
ExtensionBrowserTest::kFlagIgnoreManifestWarnings));
GURL web_resource(
test_server()->GetURL(
......@@ -82,9 +84,11 @@ IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, OriginPrivileges) {
// A different extension. Legacy (manifest_version 1) extensions should always
// be able to load each other's resources.
ASSERT_TRUE(LoadExtension(test_data_dir_
ASSERT_TRUE(LoadExtensionWithFlags(test_data_dir_
.AppendASCII("extension_resource_request_policy")
.AppendASCII("extension2")));
.AppendASCII("extension2"),
// Tests manifest_version 1 behavior, so warnings are expected.
ExtensionBrowserTest::kFlagIgnoreManifestWarnings));
ui_test_utils::NavigateToURL(
browser(),
GURL("chrome-extension://pbkkcbgdkliohhfaeefcijaghglkahja/index.html"));
......@@ -97,19 +101,25 @@ IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, OriginPrivileges) {
IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest,
ExtensionCanLoadHostedAppIcons) {
ASSERT_TRUE(LoadExtension(test_data_dir_
ASSERT_TRUE(LoadExtensionWithFlags(test_data_dir_
.AppendASCII("extension_resource_request_policy")
.AppendASCII("extension")));
.AppendASCII("extension"),
// Tests manifest_version 1 behavior, so warnings are expected.
ExtensionBrowserTest::kFlagIgnoreManifestWarnings));
ASSERT_TRUE(RunExtensionSubtest(
"extension_resource_request_policy/extension2/",
"can_load_icons_from_hosted_apps.html"));
"can_load_icons_from_hosted_apps.html",
// Tests manifest_version 1 behavior, so warnings are expected.
ExtensionApiTest::kFlagIgnoreManifestWarnings)) << message_;
}
IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, Audio) {
EXPECT_TRUE(RunExtensionSubtest(
"extension_resource_request_policy/extension2",
"audio.html"));
"audio.html",
// Tests manifest_version 1 behavior, so warnings are expected.
ExtensionApiTest::kFlagIgnoreManifestWarnings)) << message_;
}
#if defined(OS_MACOSX)
......@@ -122,7 +132,9 @@ IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, Audio) {
IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, MAYBE_Video) {
EXPECT_TRUE(RunExtensionSubtest(
"extension_resource_request_policy/extension2",
"video.html"));
"video.html",
// Tests manifest_version 1 behavior, so warnings are expected.
ExtensionApiTest::kFlagIgnoreManifestWarnings)) << message_;
}
// This test times out regularly on win_rel trybots. See http://crbug.com/122154
......@@ -250,7 +262,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionResourceRequestPolicyTest, Iframe) {
.AppendASCII("inaccessible")));
EXPECT_TRUE(RunExtensionSubtest(
"extension_resource_request_policy/web_accessible",
"iframe.html"));
"iframe.html")) << message_;
}
#if defined(OS_MACOSX)
......
{
"name": "chrome.experimental.accessibility",
"version": "0.1",
"manifest_version": 2,
"description": "browser test for chrome.experimental.accessibility.getAlertsForTab API",
"background": {
"scripts": ["background.js"]
......
......@@ -10,24 +10,6 @@
<body>
<div>Below should be a canvas rendered with canvas2D</div>
<canvas id="my-canvas" width="100" height="100"></canvas>
<script type="application/javascript">
canvas = document.getElementById("my-canvas");
if (canvas) {
if (canvas.getContext) {
context = canvas.getContext("2d");
if (context) {
context.fillStyle = 'red';
context.fillRect(20, 20, 40, 40);
chrome.test.notifyPass();
} else {
chrome.test.notifyFail("unable to getContext('2d')");
}
} else {
chrome.test.notifyFail("canvas.getContext null");
}
} else {
chrome.test.notifyFail("couldn't find element my-canvas");
}
</script>
<script src="background.js"></script>
</body>
</html>
// Copyright (c) 2012 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.
canvas = document.getElementById("my-canvas");
if (canvas) {
if (canvas.getContext) {
context = canvas.getContext("2d");
if (context) {
context.fillStyle = 'red';
context.fillRect(20, 20, 40, 40);
chrome.test.notifyPass();
} else {
chrome.test.notifyFail("unable to getContext('2d')");
}
} else {
chrome.test.notifyFail("canvas.getContext null");
}
} else {
chrome.test.notifyFail("couldn't find element my-canvas");
}
......@@ -4,5 +4,6 @@
"background": {
"page": "background.html"
},
"version": "0.1"
"version": "0.1",
"manifest_version": 2
}
<img src="chrome-extension://fnbdbepgnidhjejikpionpfohdjjogpm/test.png"
onload="chrome.test.notifyPass()"
onerror="chrome.test.notifyFail()">
onerror="chrome.test.notifyFail('Should not have loaded')">
<html>
<head>
<title>Not Loaded</title>
<script type="text/javascript">
function load(e) {
document.title = "Loaded";
}
function error(e) {
document.title = "Not Loaded";
}
</script>
</head>
<head><title>Not Loaded</title></head>
<body>
<img src="chrome://extension-icon/apocjbpjpkghdepdngjlknfpmabcmlao/24/0"
testsize="24px"
onload="load(event);"
onerror="error(event);"/>
<script src="index.js"></script>
</body>
</head>
</html>
// Copyright (c) 2012 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.
var img = document.createElement('img');
img.onload = function() {
document.title = 'Loaded';
};
img.onerror = function() {
document.title = 'Not Loaded';
};
img.src = 'chrome://extension-icon/apocjbpjpkghdepdngjlknfpmabcmlao/24/0';
document.body.appendChild(img);
......@@ -3,6 +3,7 @@
"key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCk/WWuKvmfJx/Q0ldDrtXsP7JbFOPtP7rfasiAlmQoJpW4ECHpqTqj/i/E68MVLzAagp790vUeSgyJF4U0P3eHf8e6pskyrEz0+UYt6PElEIjyOnMu5JY3c6l7NdeJK5DVI0SIsspeA1HmxUQ+7CCv7A4fTCwwp1UNjQsG56feeQIDAQAB",
"name": "test",
"version": "0.1",
"manifest_version": 2,
"permissions": [],
"incognito": "split",
"icons": {
......
<script type="text/javascript">
var TOTAL = 4;
var count = 0;
function load(e) {
if (++count < TOTAL)
return;
// Good. All the images have loaded. Now make sure they're the correct size.
var imgs = document.getElementsByTagName('img');
for (var x = 0; x < imgs.length; x++) {
var style = getComputedStyle(imgs[x]);
var size = imgs[x].getAttribute('testsize');
if (style.height != size || style.width != size) {
document.title = "Incorrect size on " + imgs[x].src;
return;
}
}
// Success!
document.title = "Loaded";
}
function error(e) {
// We failed to load an image that should have loaded.
document.title = "Not loaded: " + e.target.src;
}
</script>
<!-- Tests loading a standard 128px icon. -->
<img src="chrome://extension-icon/gbmgkahjioeacddebbnengilkgbkhodg/128/0"
testsize="128px"
onload="load(event);"
onerror="error(event);"/>
<!--
Tests loading a standard 48px icon with a MATCH_SMALLER.
This should not be resized to 48px.
-->
<img src="chrome://extension-icon/gbmgkahjioeacddebbnengilkgbkhodg/48/2"
testsize="32px"
onload="load(event);"
onerror="error(event);"/>
<!--
Tests loading a standard 32px icon, grayscale. We assume that we
actually got a grayscale image back here.
-->
<img src="chrome://extension-icon/gbmgkahjioeacddebbnengilkgbkhodg/32/1?grayscale=true"
testsize="32px"
onload="load(event);"
onerror="error(event);"/>
<!--
Tests loading a 16px by resizing the 32px version (MATCH_BIGGER).
This should be resized to 16px.
-->
<img src="chrome://extension-icon/gbmgkahjioeacddebbnengilkgbkhodg/16/1"
testsize="16px"
onload="load(event);"
onerror="error(event);"/>
<body>
<script src="index.js"></script>
</body>
// Copyright (c) 2012 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.
var TEST_CASES = [
// Tests loading a standard 128px icon.
{
url: 'chrome://extension-icon/gbmgkahjioeacddebbnengilkgbkhodg/128/0',
expectedSize: 128
},
// Tests loading a standard 48px icon with a MATCH_SMALLER.
// This should not be resized to 48px.
{
url: 'chrome://extension-icon/gbmgkahjioeacddebbnengilkgbkhodg/48/2',
expectedSize: 32
},
// Tests loading a standard 32px icon, grayscale. We assume that we actually
// got a grayscale image back here.
{
url: 'chrome://extension-icon/gbmgkahjioeacddebbnengilkgbkhodg/' +
'32/1?grayscale=true',
expectedSize: 32
},
// Tests loading a 16px by resizing the 32px version (MATCH_BIGGER).
// This should be resized to 16px.
{
url: 'chrome://extension-icon/gbmgkahjioeacddebbnengilkgbkhodg/16/1',
expectedSize: 16
}
];
var loadedImageCount = 0;
TEST_CASES.forEach(function(testCase) {
var img = document.createElement('img');
img.onload = function() {
if (img.naturalWidth != testCase.expectedSize ||
img.naturalHeight != testCase.expectedSize) {
document.title = 'Incorrect size on ' + testCase.url +
' Expected: ' + testCase.expectedSize + 'x' + testCase.expectedSize +
' Actual: ' + img.naturalWidth + 'x' + img.naturalHeight;
return;
}
if (++loadedImageCount == TEST_CASES.length) {
document.title = 'Loaded';
}
};
img.onerror = function() {
// We failed to load an image that should have loaded.
document.title = 'Couldn\'t load ' + testCase.url;
};
img.src = testCase.url;
document.body.appendChild(img);
});
......@@ -3,6 +3,7 @@
"key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCuBACa7q+sBalhnUT3lsGuuZ9PEzfoJCBoPJdCS0cfQGqAlgbBsKKqnLLgrUuK9g23PYcGTOryxnJ0eLr3Wl+gkV+CcZ4i64qfBSPt+WCTO4F9XHnqJVWRDjNY+7q0ytf8X6wdgA6ebTx4OE1t52nudNhGgYcFkRYwNAjwV5PKzQIDAQAB",
"name": "test",
"version": "0.1",
"manifest_version": 2,
"permissions": [ "management" ],
"incognito": "split",
"icons": {
......
<html>
<head>
<script src="tab_util.js"></script>
<script>
function keyboard(e) {
if (e.charCode == Q_KEY)
window.location = 'c.html';
}
</script>
<script src="a.js"></script>
</head>
<body onkeypress="keyboard(event)">
<body>
<a href="b.html" style="position:absolute; left:10px; top:10px;">b.html</a>
</body>
</head>
// Copyright (c) 2012 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.
onkeypress = function(e) {
if (e.charCode == Q_KEY)
window.location = 'c.html';
};
......@@ -2,5 +2,6 @@
"name": "chrome.experimental.offscreenTabs API test",
"description": "tests offscrene tabs API",
"version": "1",
"manifest_version": 2,
"permissions": [ "experimental", "*://*/*" ]
}
......@@ -6,6 +6,5 @@
"background": {
"scripts": ["background.js"]
},
"permissions": ["permissions"],
"optional_permissions": ["tabs"]
}
<script>
// Copyright (c) 2012 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.
......@@ -17,4 +16,3 @@ chrome.extension.onRequest.addListener(function(msg, sender, responseFunc) {
// On first install, send a success message so the test can continue.
chrome.test.notifyPass();
</script>
......@@ -24,6 +24,12 @@ chrome.extension.sendRequest("getApi", function(apis) {
if (typeof(module[section]) == "undefined")
return;
module[section].forEach(function(entry) {
// Ignore entries that are not applicable to the manifest that we're
// running under.
if (entry.maximumManifestVersion && entry.maximumManifestVersion < 2) {
return;
}
var path = namespace + "." + entry.name;
if (module.unprivileged || entry.unprivileged) {
unprivilegedPaths.push(path);
......
{
"name": "Content Script Extension API Stubs Test",
"version": "1.0",
"background_page": "background.html",
"manifest_version": 2,
"background": {
"scripts": ["background.js"]
},
"content_scripts": [
{
"matches": ["http://*/*"],
......
......@@ -2,6 +2,7 @@
"key": "MIGdMA0GCSqGSIb3DQEBAQUAA4GLADCBhwKBgQChptAQ0n4R56N03nWQ1ogR7DVRBjGo80Vw6G9KLjzZv44D8rq5Q5IkeQrtKgWyZfXevlsCe3LaLo18rcz8iZx6lK2xhLdUR+ORjsjuBfdEL5a5cWeRTSxf75AcqndQsmpwMBdrMTCZ8jQNusUI+XlrihLNNJuI5TM4vNINI5bYFQIBIw==",
"name": "chrome.terminalPrivate.apitest",
"version": "0.1",
"manifest_version": 2,
"description": "end-to-end test for terminalPrivate api. Test opens two crosh processes, starts infinite loop that echos 'aaaa' in both of them and observes output.",
"permissions": ["terminalPrivate"]
}
<body onload="document.location='b.html'"></body>
<script src="a.js"></script>
// Copyright (c) 2012 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.
onload = function() {
document.location='b.html';
}
<!-- Navigates from an extension URL to a HTTP URL causing a process switch. -->
<script>
function navigate() {
location.href =
"http://127.0.0.1:" +
location.search.substr(1) +
"/files/extensions/api_test/webnavigation/crossProcess/empty.html";
}
</script>
<body onload="setTimeout(navigate, 0)"></body>
<script src="a.js"></script>
// Copyright (c) 2012 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.
onload = function() {
setTimeout(function() {
location.href =
"http://127.0.0.1:" +
location.search.substr(1) +
"/files/extensions/api_test/webnavigation/crossProcess/empty.html";
}, 0);
};
<!-- Starting on an extension URL, redirects through an app extent to an HTTP
URL, causing two process switches. -->
<script>
function navigate() {
var target =
"http://127.0.0.1:" +
location.search.substr(1) +
"/files/extensions/api_test/webnavigation/crossProcess/empty.html";
location.href =
"http://www.a.com:" +
location.search.substr(1) +
"/server-redirect?" + target;
}
</script>
<body onload="setTimeout(navigate, 0)"></body>
<script src="c.js"></script>
// Copyright (c) 2012 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.
onload = function() {
setTimeout(function() {
var target =
"http://127.0.0.1:" +
location.search.substr(1) +
"/files/extensions/api_test/webnavigation/crossProcess/empty.html";
location.href =
"http://www.a.com:" +
location.search.substr(1) +
"/server-redirect?" + target;
}, 0);
};
<!-- Redirects to a slowly loading page and starts a new navigation before it
commits. -->
<script>
var target =
location.origin + location.pathname.replace("d.html", "empty.html");
function navigate() {
location.href =
"http://127.0.0.1:" + location.search.substr(1) + "/test1";
}
function navigate2() {
location.href = target;
}
</script>
<body onload="setTimeout(navigate, 0)"></body>
<script src="d.js"></script>
// Copyright (c) 2012 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.
var target =
location.origin + location.pathname.replace("d.html", "empty.html");
onload = function() {
setTimeout(function() {
location.href =
"http://127.0.0.1:" + location.search.substr(1) + "/test1";
}, 0);
};
function navigate2() {
location.href = target;
}
<!-- Redirects to a slowly loading page, and then updates its history state
before the new load commits. -->
<script>
function updateHistory() {
history.pushState({}, "", "empty.html");
}
function navigate() {
location.href =
"http://127.0.0.1:" + location.search.substr(1) + "/test2";
}
</script>
<body onload="setTimeout(navigate, 0)"></body>
<script src="e.js"></script>
// Copyright (c) 2012 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 updateHistory() {
history.pushState({}, "", "empty.html");
}
onload = function() {
setTimeout(function() {
location.href =
"http://127.0.0.1:" + location.search.substr(1) + "/test2";
}, 0);
};
<!-- Redirects to a slowly loading page and then updates its reference
fragment before the new page commits. -->
<script>
var target = location.href + "#foo";
function updateFragment() {
location.href = target;
}
function navigate() {
location.href =
"http://127.0.0.1:" + location.search.substr(1) + "/test3";
}
</script>
<body onload="setTimeout(navigate, 0)"></body>
<script src="f.js"></script>
// Copyright (c) 2012 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.
var target = location.href + "#foo";
function updateFragment() {
location.href = target;
}
onload = function() {
setTimeout(function() {
location.href =
"http://127.0.0.1:" + location.search.substr(1) + "/test3";
}, 0);
};
<!-- Page with a slowly loading iframe that updates its reference fragment
before the iframe commits. -->
<script>
var target = location.href + "#foo";
function updateFragment() {
location.href = target;
}
function loadframe() {
var frame = document.getElementById("frame");
frame.src = "http://127.0.0.1:" + location.search.substr(1) + "/test4";
}
</script>
<body onload="loadframe()">
<script src="g.js"></script>
<body>
<iframe id="frame"></frame>
</body>
// Copyright (c) 2012 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.
var target = location.href + "#foo";
function updateFragment() {
location.href = target;
}
onload = function() {
var frame = document.getElementById("frame");
frame.src = "http://127.0.0.1:" + location.search.substr(1) + "/test4";
};
<!-- Page with a slowly loading iframe that updates its history state before
the iframe commits. -->
<script>
function updateHistory() {
history.pushState({}, "", "empty.html");
}
function loadframe() {
var frame = document.getElementById("frame");
frame.src = "http://127.0.0.1:" + location.search.substr(1) + "/test5";
}
</script>
<body onload="loadframe()">
<script src="h.js"></script>
<body>
<iframe id="frame"></frame>
</body>
// Copyright (c) 2012 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 updateHistory() {
history.pushState({}, "", "empty.html");
}
onload = function() {
var frame = document.getElementById("frame");
frame.src = "http://127.0.0.1:" + location.search.substr(1) + "/test5";
};
<!-- Redirects to a slowly loading page but then replaces its history state
before the page commits. -->
<script>
function updateHistory() {
history.replaceState({}, "", "empty.html");
}
function navigate() {
location.href =
"http://127.0.0.1:" + location.search.substr(1) + "/test6";
}
</script>
<body onload="setTimeout(navigate, 0)"></body>
<script src="i.js"></script>
// Copyright (c) 2012 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 updateHistory() {
history.replaceState({}, "", "empty.html");
}
onload = function() {
setTimeout(function() {
location.href =
"http://127.0.0.1:" + location.search.substr(1) + "/test6";
}, 0);
};
<body onload="document.location = 'c.html'"></body>
<script src="b.js"></script>
// Copyright (c) 2012 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.
onload = function() {
document.location = 'c.html';
};
<script>
stop();
</script>
<img src="nonexistant/img.gif">
<script src="e.js"></script>
<img src="nonexistent/img.gif">
// Copyright (c) 2012 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.
stop();
<body onload="document.location='b.html'"></body>
<script src="a.js"></script>
// Copyright (c) 2012 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.
onload = function() {
document.location='b.html';
}
<html>
<head>
<script>
function navigate() {
if (window.sessionStorage['redirected'] != 1) {
window.sessionStorage['redirected'] = 1;
// Required so this results in a history entry being created.
window.setTimeout('document.location = "b.html"', 0);
}
}
</script>
</head>
<body onload="navigate()"></body>
</html>
<script src="a.js"></script>
// Copyright (c) 2012 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.
onload = function() {
if (window.sessionStorage['redirected'] != 1) {
window.sessionStorage['redirected'] = 1;
// Required so this results in a history entry being created.
window.setTimeout(function() {document.location = 'b.html'}, 0);
}
};
<body onload="history.back();"></body>
<script src="b.js"></script>
// Copyright (c) 2012 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.
onload = function() {
history.back();
};
<body onload="history.pushState({}, 'foo', 'b.html');"></body>
<script src="a.js"></script>
// Copyright (c) 2012 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.
onload = function() {
history.pushState({}, 'foo', 'b.html');
};
<body onload='document.location = "c.html"'></body>
<script src="b.js"></script>
// Copyright (c) 2012 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.
onload = function() {
document.location = 'c.html';
};
<html><body>
<script>
function loadF() {
var iframe = document.createElement('iframe');
iframe.src = "f.html";
var div = document.getElementById('f');
div.appendChild(iframe);
}
</script>
<iframe src="e.html" onload="loadF()"></iframe><div id="f"></div></body></html>
<body>
<script src="d.js"></script>
</body>
// Copyright (c) 2012 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.
var eFrame = document.createElement('iframe');
eFrame.onload = function() {
var fFrame = document.createElement('iframe');
fFrame.src = 'f.html';
document.body.appendChild(fFrame);
};
eFrame.src = 'e.html';
document.body.appendChild(eFrame);
<body onload='document.location = "g.html"'></body>
<script src="f.js"></script>
// Copyright (c) 2012 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.
onload = function() {
document.location = 'g.html';
};
<html>
<head>
<script>
function navigate() {
parent.location.href='c.html';
location.replace('about:blank');
}
</script>
</head>
<body onload="navigate()"></body>
</body>
</html>
<script src="i.js"></script>
// Copyright (c) 2012 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.
onload = function() {
parent.location.href = 'c.html';
location.replace('about:blank');
};
{
"name": "webNavigation",
"version": "1.0",
"manifest_version": 2,
"description": "Tests the webNavigation API events.",
"permissions": ["webNavigation", "tabs"]
}
<body onload='window.open("b.html")'></body>
<script src="a.js"></script>
// Copyright (c) 2012 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.
onload = function() {
window.open('b.html');
}
<body onload='document.location = "a.html#anchor";'></body>
<script src="a.js"></script>
// Copyright (c) 2012 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.
onload = function() {
document.location = 'a.html#anchor';
}
<script>
chrome.webNavigation.onBeforeNavigate.addListener(
function(details) {});
chrome.webNavigation.onCommitted.addListener(
function(details) {});
chrome.webNavigation.onDOMContentLoaded.addListener(
function(details) {});
chrome.webNavigation.onCompleted.addListener(
function(details) {});
chrome.webNavigation.onErrorOccurred.addListener(
function(details) {});
chrome.webNavigation.onCreatedNavigationTarget.addListener(
function(details) {});
chrome.test.notifyPass();
</script>
<script src="test_api.js"></script>
// Copyright (c) 2012 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.
chrome.webNavigation.onBeforeNavigate.addListener(
function(details) {});
chrome.webNavigation.onCommitted.addListener(
function(details) {});
chrome.webNavigation.onDOMContentLoaded.addListener(
function(details) {});
chrome.webNavigation.onCompleted.addListener(
function(details) {});
chrome.webNavigation.onErrorOccurred.addListener(
function(details) {});
chrome.webNavigation.onCreatedNavigationTarget.addListener(
function(details) {});
chrome.test.notifyPass();
<script src="test_clientRedirect.js"></script>
<script src="framework.js"></script>
<script>
runTests();
</script>
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function runTests() {
onload = function() {
var getURL = chrome.extension.getURL;
chrome.tabs.create({"url": "about:blank"}, function(tab) {
var tabId = tab.id;
......@@ -77,4 +77,4 @@ function runTests() {
},
]);
});
}
};
<script src="test_crossProcess.js"></script>
<script src="framework.js"></script>
<script>
runTests();
</script>
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function runTests() {
onload = function() {
var getURL = chrome.extension.getURL;
var URL_REGULAR =
"http://127.0.0.1:PORT/files/extensions/api_test/webnavigation/crossProcess/empty.html";
......@@ -635,4 +635,4 @@ function runTests() {
]);
});
});
}
};
<script src="test_failures.js"></script>
<script src="framework.js"></script>
<script>
runTests();
</script>
......@@ -2,36 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function runTests() {
onload = function() {
var getURL = chrome.extension.getURL;
chrome.tabs.create({"url": "about:blank"}, function(tab) {
var tabId = tab.id;
chrome.test.runTests([
// Navigates to a non-existant page.
function nonExistant() {
expect([
{ label: "onBeforeNavigate",
event: "onBeforeNavigate",
details: { frameId: 0,
processId: 0,
tabId: 0,
timeStamp: 0,
url: getURL('failures/nonexistant.html') }},
{ label: "onErrorOccurred",
event: "onErrorOccurred",
details: { error: "net::ERR_FILE_NOT_FOUND",
frameId: 0,
processId: 0,
tabId: 0,
timeStamp: 0,
url: getURL('failures/nonexistant.html') }}],
[["onBeforeNavigate", "onErrorOccurred"]]);
chrome.tabs.update(tabId, { url: getURL('failures/nonexistant.html') });
},
// An page that tries to load an non-existant iframe.
function nonExistantIframe() {
// An page that tries to load an non-existent iframe.
function nonExistentIframe() {
expect([
{ label: "a-onBeforeNavigate",
event: "onBeforeNavigate",
......@@ -84,8 +62,8 @@ function runTests() {
chrome.tabs.update(tabId, { url: getURL('failures/d.html') });
},
// An iframe navigates to a non-existant page.
function nonExistantIframeNavigation() {
// An iframe navigates to a non-existent page.
function nonExistentIframeNavigation() {
expect([
{ label: "a-onBeforeNavigate",
event: "onBeforeNavigate",
......@@ -208,6 +186,32 @@ function runTests() {
"onErrorOccurred"]]);
chrome.tabs.update(tabId, { url: getURL('failures/e.html') });
},
// Navigates to a non-existent page (this test case must be last,
// otherwise the non-existant URL breaks tests that follow, since loading
// those test pages is seen as a non-extension -> extension URL
// transition, which is forbidden by web_accessible_resources enforcement
// in manifest version 2.)
function nonExistent() {
expect([
{ label: "onBeforeNavigate",
event: "onBeforeNavigate",
details: { frameId: 0,
processId: 0,
tabId: 0,
timeStamp: 0,
url: getURL('failures/nonexistent.html') }},
{ label: "onErrorOccurred",
event: "onErrorOccurred",
details: { error: "net::ERR_FILE_NOT_FOUND",
frameId: 0,
processId: 0,
tabId: 0,
timeStamp: 0,
url: getURL('failures/nonexistent.html') }}],
[["onBeforeNavigate", "onErrorOccurred"]]);
chrome.tabs.update(tabId, { url: getURL('failures/nonexistent.html') });
},
]);
});
}
};
<script src="test_filtered.js"></script>
<script src="framework.js"></script>
<script>
runTests();
</script>
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function runTests() {
onload = function() {
var getURL = chrome.extension.getURL;
chrome.tabs.create({"url": "about:blank"}, function(tab) {
var tabId = tab.id;
......@@ -25,4 +25,4 @@ function runTests() {
}
]);
});
}
};
<script src="test_forwardBack.js"></script>
<script src="framework.js"></script>
<script>
runTests();
</script>
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function runTests() {
onload = function() {
var getURL = chrome.extension.getURL;
chrome.tabs.create({"url": "about:blank"}, function(tab) {
var tabId = tab.id;
......@@ -108,4 +108,4 @@ function runTests() {
},
]);
});
}
};
<script>
var URL = chrome.extension.getURL("getFrame/a.html");
var tabId = -1;
var processId = -1;
chrome.test.runTests([
function testGetFrame() {
chrome.tabs.create({"url": "about:blank"}, function(tab) {
tabId = tab.id;
var done = chrome.test.listenForever(
chrome.webNavigation.onCommitted,
function (details) {
if (details.tabId != tabId)
return;
if (details.url != URL)
return;
processId = details.processId;
chrome.webNavigation.getFrame(
{tabId: tabId, frameId: 0, processId: processId},
function(details) {
chrome.test.assertEq({errorOccurred: false, url: URL},
details);
done();
});
});
chrome.tabs.update(tabId, {url: URL});
});
},
function testGetInvalidFrame() {
chrome.webNavigation.getFrame(
{tabId: tabId, frameId: 1, processId: processId},
function (details) {
chrome.test.assertEq(null, details);
chrome.test.succeed();
});
},
function testGetAllFrames() {
chrome.webNavigation.getAllFrames(
{tabId: tabId},
function (details) {
chrome.test.assertEq(
[{errorOccurred: false,
frameId: 0,
processId: processId,
url: URL}],
details);
chrome.test.succeed();
});
}
]);
</script>
<script src="test_getFrame.js"></script>
// Copyright (c) 2012 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.
var URL = chrome.extension.getURL("getFrame/a.html");
var tabId = -1;
var processId = -1;
chrome.test.runTests([
function testGetFrame() {
chrome.tabs.create({"url": "about:blank"}, function(tab) {
tabId = tab.id;
var done = chrome.test.listenForever(
chrome.webNavigation.onCommitted,
function (details) {
if (details.tabId != tabId)
return;
if (details.url != URL)
return;
processId = details.processId;
chrome.webNavigation.getFrame(
{tabId: tabId, frameId: 0, processId: processId},
function(details) {
chrome.test.assertEq({errorOccurred: false, url: URL},
details);
done();
});
});
chrome.tabs.update(tabId, {url: URL});
});
},
function testGetInvalidFrame() {
chrome.webNavigation.getFrame(
{tabId: tabId, frameId: 1, processId: processId},
function (details) {
chrome.test.assertEq(null, details);
chrome.test.succeed();
});
},
function testGetAllFrames() {
chrome.webNavigation.getAllFrames(
{tabId: tabId},
function (details) {
chrome.test.assertEq(
[{errorOccurred: false,
frameId: 0,
processId: processId,
url: URL}],
details);
chrome.test.succeed();
});
}
]);
<script src="test_history.js"></script>
<script src="framework.js"></script>
<script>
runTests();
</script>
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function runTests() {
onload = function() {
var getURL = chrome.extension.getURL;
chrome.tabs.create({"url": "about:blank"}, function(tab) {
var tabId = tab.id;
......@@ -55,4 +55,4 @@ function runTests() {
},
]);
});
}
};
<script src="test_iframe.js"></script>
<script src="framework.js"></script>
<script>
runTests();
</script>
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function runTests() {
onload = function() {
var getURL = chrome.extension.getURL;
chrome.tabs.create({"url": "about:blank"}, function(tab) {
var tabId = tab.id;
......@@ -349,4 +349,4 @@ function runTests() {
},
]);
});
}
};
<script src="test_openTab.js"></script>
<script src="framework.js"></script>
<script>
runTests();
</script>
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function runTests() {
onload = function() {
var getURL = chrome.extension.getURL;
chrome.tabs.create({"url": "about:blank"}, function(tab) {
var tabId = tab.id;
......@@ -197,4 +197,4 @@ function runTests() {
},
]);
});
}
};
<script src="test_prerender.js"></script>
<script src="framework.js"></script>
<script>
runTests();
</script>
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function runTests() {
onload = function() {
var getURL = chrome.extension.getURL;
var URL_LOAD =
"http://127.0.0.1:PORT/files/prerender/prerender_loader.html";
......@@ -96,4 +96,4 @@ function runTests() {
]);
});
});
}
};
<script src="test_referenceFragment.js"></script>
<script src="framework.js"></script>
<script>
runTests();
</script>
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function runTests() {
onload = function() {
var getURL = chrome.extension.getURL;
chrome.tabs.create({"url": "about:blank"}, function(tab) {
var tabId = tab.id;
......@@ -55,4 +55,4 @@ function runTests() {
},
]);
});
}
};
<script src="test_requestOpenTab.js"></script>
<script src="framework.js"></script>
<script>
runTests();
</script>
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function runTests() {
onload = function() {
var getURL = chrome.extension.getURL;
chrome.tabs.create({"url": "about:blank"}, function(tab) {
var tabId = tab.id;
......@@ -90,4 +90,4 @@ function runTests() {
},
]);
});
}
};
<script src="test_serverRedirect.js"></script>
<script src="framework.js"></script>
<script>
runTests();
</script>
......@@ -2,8 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function runTests() {
var getURL = chrome.extension.getURL;
onload = function() {
var URL_LOAD =
"http://www.a.com:PORT/files/extensions/api_test/webnavigation/serverRedirect/a.html";
var URL_LOAD_REDIRECT = "http://www.a.com:PORT/server-redirect";
......@@ -56,4 +55,4 @@ function runTests() {
]);
});
});
}
};
<script src="test_simpleLoad.js"></script>
<script src="framework.js"></script>
<script>
runTests();
</script>
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
function runTests() {
onload = function() {
var getURL = chrome.extension.getURL;
chrome.tabs.create({"url": "about:blank"}, function(tab) {
var tabId = tab.id;
......@@ -46,4 +46,4 @@ function runTests() {
},
]);
});
}
};
<script src="test_targetBlank.js"></script>
<script src="framework.js"></script>
<script>
runTests();
</script>
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