Index: chrome/test/data/extensions/api_test/stubs/content_script.js |
diff --git a/chrome/test/data/extensions/api_test/stubs/content_script.js b/chrome/test/data/extensions/api_test/stubs/content_script.js |
index c72215ae6bf4babc71904f456b551be3fe676bac..409a6e23c5c08eb39ef2693384ea0eaad24858d8 100644 |
--- a/chrome/test/data/extensions/api_test/stubs/content_script.js |
+++ b/chrome/test/data/extensions/api_test/stubs/content_script.js |
@@ -73,46 +73,26 @@ function testPath(path, expectError) { |
var module = chrome; |
for (var i = 0; i < parts.length; i++) { |
if (i < parts.length - 1) { |
- // Not the last component. Should not throw an exception, but allowed to |
- // be undefined (because some paths are only defined on some platforms). |
- try { |
- module = module[parts[i]]; |
- } catch (err) { |
- logToConsoleAndStdout("testPath failed on " + |
- parts.slice(0, i+1).join('.') + '(' + err + ')'); |
- return false; |
- } |
+ // Not the last component. Allowed to be undefined because some paths are |
+ // only defined on some platforms. |
+ module = module[parts[i]]; |
if (typeof(module) == "undefined") |
return true; |
} else { |
// This is the last component - we expect it to either be undefined or |
// to throw an error on access. |
- try { |
- if (typeof(module[parts[i]]) == "undefined" && |
- path != "extension.lastError" && |
- path != "runtime.lastError") { |
- if (expectError) { |
- return true; |
- } else { |
- logToConsoleAndStdout(" fail (should not be undefined): " + path); |
- return false; |
- } |
- } else if (!expectError) { |
- return true; |
- } |
- } catch (err) { |
- if (!expectError) { |
- logToConsoleAndStdout(" fail (did not expect error): " + path); |
- return false; |
- } |
- var str = err.toString(); |
- if (str.search("can only be used in extension processes.") != -1) { |
+ if (typeof(module[parts[i]]) == "undefined" && |
+ // lastError being defined depends on there being an error obviously. |
+ path != "extension.lastError" && |
+ path != "runtime.lastError") { |
+ if (expectError) { |
return true; |
} else { |
- logToConsoleAndStdout( |
- "fail: " + path + " (wrong error: '" + str + "')"); |
+ logToConsoleAndStdout(" fail (should not be undefined): " + path); |
return false; |
} |
+ } else if (!expectError) { |
+ return true; |
} |
} |
} |
@@ -157,7 +137,12 @@ function doTest(privilegedPaths, unprivilegedPaths) { |
// Returns a function that will test a path and record any failures. |
function makeTestFunction(expectError) { |
return function(path) { |
- if (!testPath(path, expectError)) { |
+ // runtime.connect and runtime.sendMessage are available in all contexts, |
+ // unlike the runtime API in general. |
+ var expectErrorForPath = expectError && |
+ path != 'runtime.connect' && |
+ path != 'runtime.sendMessage'; |
+ if (!testPath(path, expectErrorForPath)) { |
success = false; |
failures.push(path); |
} |